mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-08 15:06:08 +02:00
Merge branch 'main' into GH2520
This commit is contained in:
commit
939402f663
@ -7,3 +7,5 @@ win-wpf/
|
||||
mattermost-plugin/
|
||||
website/
|
||||
linux/
|
||||
go.work
|
||||
go.work.sum
|
||||
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -1 +0,0 @@
|
||||
* @mattermost/core-focalboard
|
93
.github/workflows/ci.yml
vendored
93
.github/workflows/ci.yml
vendored
@ -8,6 +8,10 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
||||
EXCLUDE_ENTERPRISE: true
|
||||
|
||||
jobs:
|
||||
|
||||
ci-ubuntu-server:
|
||||
@ -23,26 +27,57 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.18.1
|
||||
|
||||
- name: "Test server: ${{matrix['db']}}"
|
||||
run: make server-test-${{matrix['db']}}
|
||||
run: cd focalboard; make server-test-${{matrix['db']}}
|
||||
|
||||
ci-ubuntu-webapp:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
- name: npm ci
|
||||
run: |
|
||||
cd webapp && npm ci && cd -
|
||||
cd mattermost-plugin/webapp && npm ci
|
||||
cd focalboard/webapp && npm ci && cd -
|
||||
cd focalboard/mattermost-plugin/webapp && npm ci
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -55,19 +90,19 @@ jobs:
|
||||
node-version: 16.1.0
|
||||
|
||||
- name: Build Linux server
|
||||
run: make server-linux-package
|
||||
run: cd focalboard; make server-linux-package
|
||||
|
||||
- name: Copy server binary for Cypress
|
||||
run: cp bin/linux/focalboard-server bin/
|
||||
run: cp focalboard/bin/linux/focalboard-server focalboard/bin/
|
||||
|
||||
- name: Upload server package
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: focalboard-server-linux-amd64.tar.gz
|
||||
path: ${{ github.workspace }}/dist/focalboard-server-linux-amd64.tar.gz
|
||||
path: ${{ github.workspace }}/focalboard/dist/focalboard-server-linux-amd64.tar.gz
|
||||
|
||||
- name: Lint & test webapp
|
||||
run: make webapp-ci
|
||||
run: cd focalboard; make webapp-ci
|
||||
|
||||
ci-windows-server:
|
||||
runs-on: windows-2022
|
||||
@ -80,6 +115,23 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -87,7 +139,7 @@ jobs:
|
||||
go-version: 1.18.1
|
||||
|
||||
- name: "Test server (minimum): ${{matrix['db']}}"
|
||||
run: make server-test-mini-${{matrix['db']}}
|
||||
run: cd focalboard; make server-test-mini-${{matrix['db']}}
|
||||
|
||||
ci-mac-server:
|
||||
runs-on: macos-11
|
||||
@ -100,6 +152,23 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -107,4 +176,4 @@ jobs:
|
||||
go-version: 1.18.1
|
||||
|
||||
- name: "Test server (minimum): ${{matrix['db']}}"
|
||||
run: make server-test-mini-${{matrix['db']}}
|
||||
run: cd focalboard; make server-test-mini-${{matrix['db']}}
|
||||
|
146
.github/workflows/dev-release.yml
vendored
146
.github/workflows/dev-release.yml
vendored
@ -7,29 +7,49 @@ on:
|
||||
branches: [ main, release-** ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
||||
EXCLUDE_ENTERPRISE: true
|
||||
|
||||
jobs:
|
||||
|
||||
ubuntu:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
|
||||
- name: Replace token 1 server
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 1 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: Replace token 2 server
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 2 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: npm ci
|
||||
run: cd webapp; npm ci --no-optional
|
||||
run: cd focalboard/webapp; npm ci --no-optional
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -51,7 +71,7 @@ jobs:
|
||||
run: sudo apt-get install libwebkit2gtk-4.0-dev
|
||||
|
||||
- name: Build Linux server and app
|
||||
run: make server-linux-package linux-app
|
||||
run: cd focalboard/; make server-linux-package linux-app
|
||||
env:
|
||||
BUILD_NUMBER: ${{ github.run_id }}
|
||||
|
||||
@ -59,13 +79,13 @@ jobs:
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: focalboard-server-linux-amd64.tar.gz
|
||||
path: ${{ github.workspace }}/dist/focalboard-server-linux-amd64.tar.gz
|
||||
path: ${{ github.workspace }}/focalboard/dist/focalboard-server-linux-amd64.tar.gz
|
||||
|
||||
- name: Upload app package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: focalboard-linux.tar.gz
|
||||
path: ${{ github.workspace }}/linux/dist/focalboard-linux.tar.gz
|
||||
path: ${{ github.workspace }}/focalboard/linux/dist/focalboard-linux.tar.gz
|
||||
|
||||
macos:
|
||||
runs-on: macos-11
|
||||
@ -74,21 +94,37 @@ jobs:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
- name: Replace token 1 server
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 1 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: Replace token 2 server
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 2 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: npm ci
|
||||
run: cd webapp; npm ci --no-optional
|
||||
run: cd focalboard/webapp; npm ci --no-optional
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -99,7 +135,7 @@ jobs:
|
||||
run: ls -n /Applications/ | grep Xcode*
|
||||
|
||||
- name: Build macOS
|
||||
run: make mac-app
|
||||
run: cd focalboard; make mac-app
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
|
||||
BUILD_NUMBER: ${{ github.run_id }}
|
||||
@ -108,7 +144,7 @@ jobs:
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: focalboard-mac.zip
|
||||
path: ${{ github.workspace }}/mac/dist/focalboard-mac.zip
|
||||
path: ${{ github.workspace }}/focalboard/mac/dist/focalboard-mac.zip
|
||||
|
||||
windows:
|
||||
runs-on: windows-2022
|
||||
@ -116,24 +152,40 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
- name: Replace token 1 server
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 1 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: Replace token 2 server
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 2 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
|
||||
- name: npm ci
|
||||
run: cd webapp; npm ci --no-optional
|
||||
run: cd focalboard/webapp; npm ci --no-optional
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -146,10 +198,10 @@ jobs:
|
||||
nuget-version: '5.x'
|
||||
|
||||
- name: NuGet Restore
|
||||
run: nuget restore win-wpf\Focalboard.sln
|
||||
run: nuget restore focalboard\win-wpf\Focalboard.sln
|
||||
|
||||
- name: Build Windows WPF app
|
||||
run: make win-wpf-app
|
||||
run: cd focalboard; make win-wpf-app
|
||||
env:
|
||||
BUILD_NUMBER: ${{ github.run_id }}
|
||||
|
||||
@ -157,35 +209,51 @@ jobs:
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: focalboard.msix
|
||||
path: ${{ github.workspace }}/win-wpf/focalboard.msix
|
||||
path: ${{ github.workspace }}/focalboard/win-wpf/focalboard.msix
|
||||
|
||||
- name: Upload app zip package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: focalboard-win.zip
|
||||
path: ${{ github.workspace }}/win-wpf/dist/focalboard-win.zip
|
||||
path: ${{ github.workspace }}/focalboard/win-wpf/dist/focalboard-win.zip
|
||||
|
||||
plugin:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
|
||||
- name: Replace token 1 server
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 1 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_dataplane_url,${{ secrets.RUDDER_DATAPLANE_URL }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: Replace token 2 server
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/server/services/telemetry/telemetry.go
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/server/services/telemetry/telemetry.go
|
||||
|
||||
- name: Replace token 2 webapp
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/mattermost-plugin/webapp/src/index.tsx
|
||||
run: sed -i -e "s,placeholder_rudder_key,${{ secrets.RUDDER_DEV_KEY }},g" ${{ github.workspace }}/focalboard/mattermost-plugin/webapp/src/index.tsx
|
||||
|
||||
- name: npm ci
|
||||
run: cd webapp; npm ci --no-optional
|
||||
run: cd focalboard/webapp; npm ci --no-optional
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
@ -198,21 +266,21 @@ jobs:
|
||||
node-version: 16.1.0
|
||||
|
||||
- name: Build webapp
|
||||
run: make webapp
|
||||
run: cd focalboard; make webapp
|
||||
|
||||
- name: npm ci plugin dependencies
|
||||
run: cd mattermost-plugin/webapp; npm ci --no-optional
|
||||
run: cd focalboard/mattermost-plugin/webapp; npm ci --no-optional
|
||||
|
||||
- name: Build plugin
|
||||
run: cd mattermost-plugin; make dist
|
||||
run: cd focalboard/mattermost-plugin; make dist
|
||||
env:
|
||||
BUILD_NUMBER: ${{ github.run_id }}
|
||||
|
||||
- name: Rename plugin file
|
||||
run: cd mattermost-plugin/dist; mv focalboard-*.tar.gz mattermost-plugin-focalboard.tar.gz
|
||||
run: cd focalboard/mattermost-plugin/dist; mv focalboard-*.tar.gz mattermost-plugin-focalboard.tar.gz
|
||||
|
||||
- name: Upload plugin artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mattermost-plugin-focalboard.tar.gz
|
||||
path: ${{ github.workspace }}/mattermost-plugin/dist/mattermost-plugin-focalboard.tar.gz
|
||||
path: ${{ github.workspace }}/focalboard/mattermost-plugin/dist/mattermost-plugin-focalboard.tar.gz
|
||||
|
25
.github/workflows/lint-server.yml
vendored
25
.github/workflows/lint-server.yml
vendored
@ -7,6 +7,10 @@ on:
|
||||
branches: [ main, release-** ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
||||
EXCLUDE_ENTERPRISE: true
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
name: plugin
|
||||
@ -16,7 +20,26 @@ jobs:
|
||||
with:
|
||||
go-version: 1.18.1
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: "focalboard"
|
||||
- id: "mattermostServer"
|
||||
uses: actions/checkout@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref: ${{ env.BRANCH_NAME }}
|
||||
- uses: actions/checkout@v3
|
||||
if: steps.mattermostServer.outcome == 'failure'
|
||||
with:
|
||||
repository: "mattermost/mattermost-server"
|
||||
fetch-depth: "20"
|
||||
path: "mattermost-server"
|
||||
ref : "master"
|
||||
- name: set up golangci-lint
|
||||
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
|
||||
- name: lint
|
||||
run: make server-lint
|
||||
run: |
|
||||
cd focalboard
|
||||
make server-lint
|
||||
|
4
.github/workflows/prod-release.yml
vendored
4
.github/workflows/prod-release.yml
vendored
@ -2,6 +2,10 @@ name: Production-Release
|
||||
|
||||
on: workflow_dispatch
|
||||
|
||||
env:
|
||||
EXCLUDE_SERVER: true
|
||||
EXCLUDE_ENTERPRISE: true
|
||||
|
||||
jobs:
|
||||
|
||||
ubuntu:
|
||||
|
3
Makefile
3
Makefile
@ -39,8 +39,9 @@ prebuild: ## Run prebuild actions (install dependencies etc.).
|
||||
|
||||
ci: webapp-ci server-test ## Simulate CI, locally.
|
||||
|
||||
setup-go-work: export EXCLUDE_ENTERPRISE ?= true
|
||||
setup-go-work: ## Sets up a go.work file
|
||||
go run ./mattermost-plugin/build/gowork/main.go
|
||||
go run ./build/gowork/main.go
|
||||
|
||||
templates-archive: setup-go-work ## Build templates archive file
|
||||
cd server/assets/build-template-archive; go run -tags '$(BUILD_TAGS)' main.go --dir="../templates-boardarchive" --out="../templates.boardarchive"
|
||||
|
@ -39,22 +39,30 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stdout, "go.work written successfully.")
|
||||
fmt.Fprintln(os.Stdout, content)
|
||||
}
|
||||
|
||||
func makeGoWork(ci bool) string {
|
||||
repos := map[string]string{
|
||||
"../mattermost-server": "EXCLUDE_SERVER",
|
||||
"../enterprise": "EXCLUDE_ENTERPRISE",
|
||||
"./mattermost-plugin": "EXCLUDE_PLUGIN",
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
b.WriteString("go 1.18\n\n")
|
||||
b.WriteString("use ./mattermost-plugin\n")
|
||||
b.WriteString("use ./server\n")
|
||||
|
||||
for repo, envVarName := range repos {
|
||||
if !isEnvVarTrue(envVarName, true) {
|
||||
b.WriteString(fmt.Sprintf("use %s\n", repo))
|
||||
}
|
||||
}
|
||||
|
||||
if ci {
|
||||
b.WriteString("use ./linux\n")
|
||||
} else {
|
||||
b.WriteString("use ../mattermost-server\n")
|
||||
b.WriteString("use ../enterprise\n")
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ FROM golang:1.18.3@sha256:b203dc573d81da7b3176264bfa447bd7c10c9347689be405403818
|
||||
WORKDIR /go/src/focalboard
|
||||
ADD . /go/src/focalboard
|
||||
|
||||
RUN make server-linux
|
||||
|
||||
RUN EXCLUDE_PLUGIN=true EXCLUDE_SERVER=true EXCLUDE_ENTERPRISE=true make server-linux
|
||||
RUN mkdir /data
|
||||
|
||||
## Final image
|
||||
|
13
linux/go.mod
13
linux/go.mod
@ -7,7 +7,7 @@ replace github.com/mattermost/focalboard/server => ../server
|
||||
require (
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/mattermost/focalboard/server v0.0.0-00010101000000-000000000000
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220711175838-7ee7523729e6
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933
|
||||
github.com/webview/webview v0.0.0-20220314230258-a2b7746141c3
|
||||
)
|
||||
|
||||
@ -15,10 +15,11 @@ require (
|
||||
github.com/Masterminds/squirrel v1.5.2 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||
github.com/blang/semver/v4 v4.0.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/francoispqt/gojay v1.2.13 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
@ -28,7 +29,10 @@ require (
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/graph-gophers/graphql-go v1.4.0 // indirect
|
||||
github.com/hashicorp/go-hclog v1.2.1 // indirect
|
||||
github.com/hashicorp/go-plugin v1.4.4 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.15.6 // indirect
|
||||
@ -41,7 +45,7 @@ require (
|
||||
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
|
||||
github.com/mattermost/logr/v2 v2.0.15 // indirect
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.28-0.20220623051512-0afd85e854d4 // indirect
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.29-0.20220801143717-73008cfda2fb // indirect
|
||||
github.com/mattermost/morph v0.0.0-20220401091636-39f834798da8 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
@ -51,6 +55,7 @@ require (
|
||||
github.com/minio/minio-go/v7 v7.0.28 // indirect
|
||||
github.com/minio/sha256-simd v1.0.0 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
@ -92,6 +97,8 @@ require (
|
||||
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.11 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220614165028-45ed7f3ff16e // indirect
|
||||
google.golang.org/grpc v1.47.0 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.6 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
|
1431
linux/go.sum
1431
linux/go.sum
File diff suppressed because it is too large
Load Diff
@ -61,7 +61,7 @@ apply:
|
||||
./build/bin/manifest apply
|
||||
|
||||
setup-go-work: ## Sets up a go.work file
|
||||
cd ..; go run ./mattermost-plugin/build/gowork/main.go
|
||||
cd ..; go run ./build/gowork/main.go
|
||||
|
||||
## Runs eslint and golangci-lint
|
||||
.PHONY: check-style
|
||||
|
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-git/go-git/v5 v5.1.0
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220705131644-b99bd0d04915
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.7.2
|
||||
sigs.k8s.io/yaml v1.2.0
|
||||
@ -14,7 +14,7 @@ require (
|
||||
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||
github.com/emirpasic/gods v1.12.0 // indirect
|
||||
github.com/francoispqt/gojay v1.2.13 // indirect
|
||||
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
|
||||
|
@ -28,8 +28,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 h1:AQLr//nh20BzN3hIWj2+/Gt3FwSs8Nwo/nz4hMIcLPg=
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09/go.mod h1:nYia/MIs9OyvXXYboPmNOj0gVWo97Wx0sde+ZuKkoM4=
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a h1:etIrTD8BQqzColk9nKRusM9um5+1q0iOEJLqfBMIK64=
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a/go.mod h1:emQhSYTXqB0xxjLITTw4EaWZ+8IIQYw+kx9GqNUKdLg=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
@ -118,8 +118,8 @@ github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ=
|
||||
github.com/mattermost/logr/v2 v2.0.15 h1:+WNbGcsc3dBao65eXlceB6dTILNJRIrvubnsTl3zBew=
|
||||
github.com/mattermost/logr/v2 v2.0.15/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220705131644-b99bd0d04915 h1:W7y+l87t0qORLQMFXtz/s9rxftWZDop8Es6wYQLr5vk=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220705131644-b99bd0d04915/go.mod h1:e2CtTtnty6oH8CiHm40cMOqJ+dJeWEK39/tobCkeMAk=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933 h1:h7EibO8cwWeK8dLhC/A5tKGbkYSuJKZ0+2EXW7jDHoA=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933/go.mod h1:otnBnKY9Y0eNkUKeD161de+BUBlESwANTnrkPT/392Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
@ -247,6 +247,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022 h1:0qjDla5xICC2suMtyRH/QqX3B1btXTfNsIt/i4LFgO0=
|
||||
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
@ -270,9 +271,12 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 h1:PgOr27OhUx2IRqGJ2RxAWI4dJQ7bi9cSrB82uzFzfUA=
|
||||
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
|
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.28-0.20220623051512-0afd85e854d4
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.29-0.20220801143717-73008cfda2fb
|
||||
github.com/stretchr/testify v1.7.2
|
||||
)
|
||||
|
||||
@ -49,7 +49,7 @@ require (
|
||||
github.com/disintegration/imaging v1.6.2 // indirect
|
||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/fatih/set v0.2.1 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.3 // indirect
|
||||
@ -96,7 +96,7 @@ require (
|
||||
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
|
||||
github.com/mattermost/logr/v2 v2.0.15 // indirect
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220711175838-7ee7523729e6 // indirect
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933 // indirect
|
||||
github.com/mattermost/morph v0.0.0-20220401091636-39f834798da8 // indirect
|
||||
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0 // indirect
|
||||
github.com/mattermost/squirrel v0.2.0 // indirect
|
||||
|
@ -582,6 +582,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
||||
github.com/dvyukov/go-fuzz v0.0.0-20210429054444-fca39067bc72/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 h1:AQLr//nh20BzN3hIWj2+/Gt3FwSs8Nwo/nz4hMIcLPg=
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09/go.mod h1:nYia/MIs9OyvXXYboPmNOj0gVWo97Wx0sde+ZuKkoM4=
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a h1:etIrTD8BQqzColk9nKRusM9um5+1q0iOEJLqfBMIK64=
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a/go.mod h1:emQhSYTXqB0xxjLITTw4EaWZ+8IIQYw+kx9GqNUKdLg=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
@ -1240,6 +1242,8 @@ github.com/mattermost/mattermost-plugin-api v0.0.27 h1:zFKQ6JW1/f0MfR5dP9P2umNNY
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.27/go.mod h1:MM+tZ+36Obm9jqcveoxY2RFbwLaZKZUgR1zUlc0UBYw=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.28-0.20220623051512-0afd85e854d4 h1:TF1yBBsLntuNb3wc3DRg30S9i6tv1JwtREtXd7Gnv9E=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.28-0.20220623051512-0afd85e854d4/go.mod h1:jtiaM6selJi1Od1zGZDGO78hZyG0gI4/I2/8mza4OZg=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.29-0.20220801143717-73008cfda2fb h1:q1qXKVv59rA2gcQ7lVLc5OlWBmfsR3i8mdGD5EZesyk=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.29-0.20220801143717-73008cfda2fb/go.mod h1:PIeo40t9VTA4Wu1FwjzH7QmcgC3SRyk/ohCwJw4/oSo=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20210901153517-42e75fad4dae/go.mod h1:kmxJuVgpX13Th+e5L1ZsBs4aq+ETmmDg9joo5r4cIw8=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220622145221-00016e3a4ff4/go.mod h1:e2CtTtnty6oH8CiHm40cMOqJ+dJeWEK39/tobCkeMAk=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220630162014-b45ff0be5d61 h1:e0HqxbOXRsm4UZ7HqZ4tagzEvlqlyfJcYp0vZ+Jg2dE=
|
||||
@ -1248,6 +1252,8 @@ github.com/mattermost/mattermost-server/v6 v6.0.0-20220705131644-b99bd0d04915 h1
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220705131644-b99bd0d04915/go.mod h1:e2CtTtnty6oH8CiHm40cMOqJ+dJeWEK39/tobCkeMAk=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220711175838-7ee7523729e6 h1:lfkO5s/ZwuD2esAHGX+0EtmcsAVXJ0S5Xn37uWW/WoQ=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220711175838-7ee7523729e6/go.mod h1:e2CtTtnty6oH8CiHm40cMOqJ+dJeWEK39/tobCkeMAk=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933 h1:h7EibO8cwWeK8dLhC/A5tKGbkYSuJKZ0+2EXW7jDHoA=
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933/go.mod h1:otnBnKY9Y0eNkUKeD161de+BUBlESwANTnrkPT/392Y=
|
||||
github.com/mattermost/mattermost-server/v6 v6.3.0/go.mod h1:L9gIoi9ESBh/NefsaZCfOVBMnbhx+v3kXhInGt3DQmA=
|
||||
github.com/mattermost/mattermost-server/v6 v6.7.2 h1:rRss2/R5LNbyc/P1OA4kSWuVq+rmnxwepuwGpTwL+U4=
|
||||
github.com/mattermost/mattermost-server/v6 v6.7.2/go.mod h1:b/iDf7Jn2Pd2jWGzaznoVNT811JZpemdmNGP7M/a7Ao=
|
||||
@ -2148,6 +2154,7 @@ golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qx
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022 h1:0qjDla5xICC2suMtyRH/QqX3B1btXTfNsIt/i4LFgO0=
|
||||
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
|
@ -7,7 +7,7 @@
|
||||
"release_notes_url": "https://github.com/mattermost/focalboard/releases",
|
||||
"icon_path": "assets/starter-template-icon.svg",
|
||||
"version": "7.3.0",
|
||||
"min_server_version": "7.0.0",
|
||||
"min_server_version": "7.2.0",
|
||||
"server": {
|
||||
"executables": {
|
||||
"linux-amd64": "server/dist/plugin-linux-amd64",
|
||||
|
@ -6,6 +6,8 @@ package product
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@ -34,7 +36,7 @@ type serviceAPIAdapter struct {
|
||||
func newServiceAPIAdapter(api *boardsProduct) *serviceAPIAdapter {
|
||||
return &serviceAPIAdapter{
|
||||
api: api,
|
||||
ctx: &request.Context{},
|
||||
ctx: request.EmptyContext(api.logger),
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +96,7 @@ func (a *serviceAPIAdapter) GetUserByEmail(email string) (*mm_model.User, error)
|
||||
}
|
||||
|
||||
func (a *serviceAPIAdapter) UpdateUser(user *mm_model.User) (*mm_model.User, error) {
|
||||
user, appErr := a.api.userService.UpdateUser(user, true)
|
||||
user, appErr := a.api.userService.UpdateUser(a.ctx, user, true)
|
||||
return user, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
@ -205,5 +207,12 @@ func (a *serviceAPIAdapter) GetDiagnosticID() string {
|
||||
return a.api.systemService.GetDiagnosticId()
|
||||
}
|
||||
|
||||
//
|
||||
// Router service.
|
||||
//
|
||||
func (a *serviceAPIAdapter) RegisterRouter(sub *mux.Router) {
|
||||
a.api.routerService.RegisterRouter(boardsProductName, sub)
|
||||
}
|
||||
|
||||
// Ensure the adapter implements ServicesAPI.
|
||||
var _ model.ServicesAPI = &serviceAPIAdapter{}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/focalboard/mattermost-plugin/server/boards"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
||||
@ -197,6 +198,8 @@ func (bp *boardsProduct) Start() error {
|
||||
return fmt.Errorf("failed to create Boards service: %w", err)
|
||||
}
|
||||
|
||||
model.LogServerInfo(bp.logger)
|
||||
|
||||
bp.boardsApp = boardsApp
|
||||
if err := bp.boardsApp.Start(); err != nil {
|
||||
return fmt.Errorf("failed to start Boards service: %w", err)
|
||||
|
@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
@ -208,5 +209,12 @@ func (a *pluginAPIAdapter) GetDiagnosticID() string {
|
||||
return a.api.GetDiagnosticId()
|
||||
}
|
||||
|
||||
//
|
||||
// Router service.
|
||||
//
|
||||
func (a *pluginAPIAdapter) RegisterRouter(sub *mux.Router) {
|
||||
// NOOP for plugin
|
||||
}
|
||||
|
||||
// Ensure the adapter implements ServicesAPI.
|
||||
var _ model.ServicesAPI = &pluginAPIAdapter{}
|
||||
|
@ -170,6 +170,11 @@ func (b *BoardsApp) Start() error {
|
||||
if err := b.server.Start(); err != nil {
|
||||
return fmt.Errorf("error starting Boards server: %w", err)
|
||||
}
|
||||
|
||||
b.servicesAPI.RegisterRouter(b.server.GetRootRouter())
|
||||
|
||||
b.logger.Info("Boards product successfully started.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ func createDelivery(servicesAPI model.ServicesAPI, serverRoot string) (*pluginde
|
||||
Username: botUsername,
|
||||
DisplayName: botDisplayname,
|
||||
Description: botDescription,
|
||||
OwnerId: model.SystemUserID,
|
||||
}
|
||||
botID, err := servicesAPI.EnsureBot(bot)
|
||||
if err != nil {
|
||||
|
2
mattermost-plugin/server/manifest.go
generated
2
mattermost-plugin/server/manifest.go
generated
@ -21,7 +21,7 @@ const manifestStr = `
|
||||
"release_notes_url": "https://github.com/mattermost/focalboard/releases",
|
||||
"icon_path": "assets/starter-template-icon.svg",
|
||||
"version": "7.3.0",
|
||||
"min_server_version": "7.0.0",
|
||||
"min_server_version": "7.2.0",
|
||||
"server": {
|
||||
"executables": {
|
||||
"darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/focalboard/mattermost-plugin/server/boards"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
|
||||
pluginapi "github.com/mattermost/mattermost-plugin-api"
|
||||
|
||||
@ -52,6 +53,8 @@ func (p *Plugin) OnActivate() error {
|
||||
return fmt.Errorf("cannot activate plugin: %w", err)
|
||||
}
|
||||
|
||||
model.LogServerInfo(logger)
|
||||
|
||||
p.boardsApp = boardsApp
|
||||
return p.boardsApp.Start()
|
||||
}
|
||||
|
@ -107,7 +107,7 @@
|
||||
"text-summary"
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "identity-obj-proxy",
|
||||
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/../../webapp/__mocks__/fileMock.js",
|
||||
"^.+\\.(scss|css)$": "<rootDir>/tests/style_mock.json",
|
||||
"^.*i18n.*\\.(json)$": "<rootDir>/tests/i18n_mock.json",
|
||||
"^bundle-loader\\?lazy\\!(.*)$": "$1",
|
||||
|
@ -181,20 +181,28 @@ exports[`components/boardSelector renders with some results 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
@ -212,20 +220,28 @@ exports[`components/boardSelector renders with some results 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
@ -243,20 +259,28 @@ exports[`components/boardSelector renders with some results 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
|
@ -5,20 +5,28 @@ exports[`components/boardSelectorItem renders board without title 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Untitled board
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
@ -41,20 +49,28 @@ exports[`components/boardSelectorItem renders linked board 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Test title
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Test title
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
@ -77,20 +93,28 @@ exports[`components/boardSelectorItem renders not linked board 1`] = `
|
||||
<div
|
||||
class="BoardSelectorItem"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
<div
|
||||
class="resultLine"
|
||||
class="BoardSelectorItem-info"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
<span
|
||||
class="icon"
|
||||
>
|
||||
Test title
|
||||
</div>
|
||||
<i
|
||||
class="CompassIcon icon-product-boards"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
class="resultLine"
|
||||
>
|
||||
<div
|
||||
class="resultTitle"
|
||||
>
|
||||
Test title
|
||||
</div>
|
||||
<div
|
||||
class="resultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="linkUnlinkButton"
|
||||
|
@ -52,7 +52,7 @@
|
||||
|
||||
.head,
|
||||
.searchResults {
|
||||
padding: 0 32px 32px;
|
||||
padding: 0 32px 24px;
|
||||
}
|
||||
|
||||
.searchResults {
|
||||
@ -139,7 +139,7 @@
|
||||
position: absolute;
|
||||
left: 13px;
|
||||
font-size: 18px;
|
||||
top: 14px;
|
||||
top: 13px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
opacity: 0.48;
|
||||
|
@ -55,7 +55,7 @@ describe('components/boardSelector', () => {
|
||||
})
|
||||
|
||||
it('renders with no results', async () => {
|
||||
mockedOctoClient.search.mockResolvedValueOnce([])
|
||||
mockedOctoClient.searchLinkableBoards.mockResolvedValueOnce([])
|
||||
|
||||
const store = mockStateStore([], state)
|
||||
const {container} = render(wrapIntl(
|
||||
@ -74,7 +74,7 @@ describe('components/boardSelector', () => {
|
||||
})
|
||||
|
||||
it('renders with some results', async () => {
|
||||
mockedOctoClient.search.mockResolvedValueOnce([createBoard(), createBoard(), createBoard()])
|
||||
mockedOctoClient.searchLinkableBoards.mockResolvedValueOnce([createBoard(), createBoard(), createBoard()])
|
||||
|
||||
const store = mockStateStore([], state)
|
||||
const {container} = render(wrapIntl(
|
||||
|
@ -12,8 +12,7 @@ import {useWebsockets} from '../../../../webapp/src/hooks/websockets'
|
||||
import octoClient from '../../../../webapp/src/octoClient'
|
||||
import mutator from '../../../../webapp/src/mutator'
|
||||
import {getCurrentTeamId, getAllTeams, Team} from '../../../../webapp/src/store/teams'
|
||||
import {createBoard, BoardsAndBlocks, Board} from '../../../../webapp/src/blocks/board'
|
||||
import {createBoardView} from '../../../../webapp/src/blocks/boardView'
|
||||
import {createBoard, Board} from '../../../../webapp/src/blocks/board'
|
||||
import {useAppSelector, useAppDispatch} from '../../../../webapp/src/store/hooks'
|
||||
import {EmptySearch, EmptyResults} from '../../../../webapp/src/components/searchDialog/searchDialog'
|
||||
import ConfirmationDialog from '../../../../webapp/src/components/confirmationDialogBox'
|
||||
@ -21,11 +20,13 @@ import Dialog from '../../../../webapp/src/components/dialog'
|
||||
import SearchIcon from '../../../../webapp/src/widgets/icons/search'
|
||||
import Button from '../../../../webapp/src/widgets/buttons/button'
|
||||
import {getCurrentLinkToChannel, setLinkToChannel} from '../../../../webapp/src/store/boards'
|
||||
import TelemetryClient, {TelemetryCategory, TelemetryActions} from '../../../../webapp/src/telemetry/telemetryClient'
|
||||
import {WSClient} from '../../../../webapp/src/wsclient'
|
||||
import {SuiteWindow} from '../../../../webapp/src/types/index'
|
||||
|
||||
import BoardSelectorItem from './boardSelectorItem'
|
||||
|
||||
const windowAny = (window as SuiteWindow)
|
||||
|
||||
import './boardSelector.scss'
|
||||
|
||||
const BoardSelector = () => {
|
||||
@ -49,7 +50,7 @@ const BoardSelector = () => {
|
||||
if (query.trim().length === 0 || !teamId) {
|
||||
return
|
||||
}
|
||||
const items = await octoClient.search(teamId, query)
|
||||
const items = await octoClient.searchLinkableBoards(teamId, query)
|
||||
|
||||
setResults(items)
|
||||
setIsSearching(false)
|
||||
@ -107,27 +108,21 @@ const BoardSelector = () => {
|
||||
}
|
||||
|
||||
const newLinkedBoard = async (): Promise<void> => {
|
||||
const board = {...createBoard(), teamId, channelId: currentChannel}
|
||||
window.open(`${windowAny.frontendBaseURL}/team/${teamId}/new/${currentChannel}`, '_blank', 'noopener')
|
||||
dispatch(setLinkToChannel(''))
|
||||
}
|
||||
|
||||
const view = createBoardView()
|
||||
view.fields.viewType = 'board'
|
||||
view.parentId = board.id
|
||||
view.boardId = board.id
|
||||
view.title = intl.formatMessage({id: 'View.NewBoardTitle', defaultMessage: 'Board view'})
|
||||
|
||||
await mutator.createBoardsAndBlocks(
|
||||
{boards: [board], blocks: [view]},
|
||||
'add linked board',
|
||||
async (bab: BoardsAndBlocks): Promise<void> => {
|
||||
const windowAny: any = window
|
||||
const newBoard = bab.boards[0]
|
||||
// TODO: Maybe create a new event for create linked board
|
||||
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.CreateBoard, {board: newBoard?.id})
|
||||
windowAny.WebappUtils.browserHistory.push(`/boards/team/${teamId}/${newBoard.id}`)
|
||||
dispatch(setLinkToChannel(''))
|
||||
},
|
||||
async () => {return},
|
||||
)
|
||||
let confirmationSubText
|
||||
if (showLinkBoardConfirmation?.channelId !== '') {
|
||||
confirmationSubText = intl.formatMessage({
|
||||
id: 'boardSelector.confirm-link-board-subtext-with-other-channel',
|
||||
defaultMessage: 'When you link "{boardName}" to the channel, all members of the channel (existing and new) will be able to edit it.{lineBreak} This board is currently linked to another channel. It will be unlinked if you choose to link it here.'
|
||||
}, {boardName: showLinkBoardConfirmation?.title, lineBreak: <p/>})
|
||||
} else {
|
||||
confirmationSubText = intl.formatMessage({
|
||||
id: 'boardSelector.confirm-link-board-subtext',
|
||||
defaultMessage: 'When you link "{boardName}" to the channel, all members of the channel (existing and new) will be able to edit it. You can unlink a board from a channel at any time.'
|
||||
}, {boardName: showLinkBoardConfirmation?.title})
|
||||
}
|
||||
|
||||
return (
|
||||
@ -146,11 +141,9 @@ const BoardSelector = () => {
|
||||
<ConfirmationDialog
|
||||
dialogBox={{
|
||||
heading: intl.formatMessage({id: 'boardSelector.confirm-link-board', defaultMessage: 'Link board to channel'}),
|
||||
subText: intl.formatMessage({
|
||||
id: 'boardSelector.confirm-link-board-subtext',
|
||||
defaultMessage: 'Linking the "{boardName}" board to this channel would give all members of this channel "Editor" access to the board. Are you sure you want to link it?'
|
||||
}, {boardName: showLinkBoardConfirmation.title}),
|
||||
subText: confirmationSubText,
|
||||
confirmButtonText: intl.formatMessage({id: 'boardSelector.confirm-link-board-button', defaultMessage: 'Yes, link board'}),
|
||||
destructive: showLinkBoardConfirmation?.channelId !== '',
|
||||
onConfirm: () => linkBoard(showLinkBoardConfirmation, true),
|
||||
onClose: () => setShowLinkBoardConfirmation(null),
|
||||
}}
|
||||
@ -168,7 +161,7 @@ const BoardSelector = () => {
|
||||
onClick={() => newLinkedBoard()}
|
||||
emphasis='secondary'
|
||||
>
|
||||
<FormattedMessage
|
||||
<FormattedMessage
|
||||
id='boardSelector.create-a-board'
|
||||
defaultMessage='Create a board'
|
||||
/>
|
||||
|
@ -5,9 +5,24 @@
|
||||
padding: 10px 0;
|
||||
margin: 0 35px;
|
||||
|
||||
.BoardSelectorItem-info {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 18px;
|
||||
align-items: flex-start;
|
||||
margin-right: 10px;
|
||||
|
||||
i {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.resultLine {
|
||||
@ -34,5 +49,6 @@
|
||||
display: flex;
|
||||
align-self: center;
|
||||
align-items: center;
|
||||
padding-left: 16px;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import {useIntl, FormattedMessage} from 'react-intl'
|
||||
|
||||
import {Board} from '../../../../webapp/src/blocks/board'
|
||||
import Button from '../../../../webapp/src/widgets/buttons/button'
|
||||
import CompassIcon from '../../../../webapp/src/widgets/icons/compassIcon'
|
||||
|
||||
import './boardSelectorItem.scss'
|
||||
|
||||
@ -23,10 +24,12 @@ const BoardSelectorItem = (props: Props) => {
|
||||
const resultTitle = item.title || untitledBoardTitle
|
||||
return (
|
||||
<div className='BoardSelectorItem'>
|
||||
<span className='icon'>{item.icon}</span>
|
||||
<div className='resultLine'>
|
||||
<div className='resultTitle'>{resultTitle}</div>
|
||||
<div className='resultDescription'>{item.description}</div>
|
||||
<div className='BoardSelectorItem-info'>
|
||||
<span className='icon'>{item.icon || <CompassIcon icon='product-boards'/>}</span>
|
||||
<div className='resultLine'>
|
||||
<div className='resultTitle'>{resultTitle}</div>
|
||||
<div className='resultDescription'>{item.description}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='linkUnlinkButton'>
|
||||
{item.channelId === currentChannel &&
|
||||
@ -44,7 +47,7 @@ const BoardSelectorItem = (props: Props) => {
|
||||
onClick={() => props.linkBoard(item)}
|
||||
emphasis='primary'
|
||||
>
|
||||
<FormattedMessage
|
||||
<FormattedMessage
|
||||
id='boardSelector.link'
|
||||
defaultMessage='Link'
|
||||
/>
|
||||
|
@ -13,9 +13,12 @@ import OptionsIcon from '../../../../webapp/src/widgets/icons/options'
|
||||
import DeleteIcon from '../../../../webapp/src/widgets/icons/delete'
|
||||
import Menu from '../../../../webapp/src/widgets/menu'
|
||||
import MenuWrapper from '../../../../webapp/src/widgets/menuWrapper'
|
||||
import {SuiteWindow} from '../../../../webapp/src/types/index'
|
||||
|
||||
import './rhsChannelBoardItem.scss'
|
||||
|
||||
const windowAny = (window as SuiteWindow)
|
||||
|
||||
type Props = {
|
||||
board: Board
|
||||
}
|
||||
@ -30,8 +33,7 @@ const RHSChannelBoardItem = (props: Props) => {
|
||||
}
|
||||
|
||||
const handleBoardClicked = (boardID: string) => {
|
||||
const windowAny: any = window
|
||||
windowAny.WebappUtils.browserHistory.push(`/boards/team/${team.id}/${boardID}`)
|
||||
window.open(`${windowAny.frontendBaseURL}/team/${team.id}/${boardID}`, '_blank', 'noopener')
|
||||
}
|
||||
|
||||
const onUnlinkBoard = async (board: Board) => {
|
||||
|
@ -37,6 +37,11 @@ describe('components/rhsChannelBoards', () => {
|
||||
current: team,
|
||||
currentId: team.id,
|
||||
},
|
||||
users: {
|
||||
me: {
|
||||
id: 'user-id',
|
||||
},
|
||||
},
|
||||
language: {
|
||||
value: 'en',
|
||||
},
|
||||
|
@ -10,9 +10,17 @@ import {useWebsockets} from '../../../../webapp/src/hooks/websockets'
|
||||
|
||||
import {Board, BoardMember} from '../../../../webapp/src/blocks/board'
|
||||
import {getCurrentTeamId} from '../../../../webapp/src/store/teams'
|
||||
import {IUser} from '../../../../webapp/src/user'
|
||||
import {getMe, fetchMe} from '../../../../webapp/src/store/users'
|
||||
import {loadBoards} from '../../../../webapp/src/store/initialLoad'
|
||||
import {getCurrentChannel} from '../../../../webapp/src/store/channels'
|
||||
import {getMySortedBoards, setLinkToChannel, updateBoards, updateMembers} from '../../../../webapp/src/store/boards'
|
||||
import {
|
||||
getMySortedBoards,
|
||||
setLinkToChannel,
|
||||
updateBoards,
|
||||
updateMembersEnsuringBoardsAndUsers,
|
||||
addMyBoardMemberships,
|
||||
} from '../../../../webapp/src/store/boards'
|
||||
import {useAppSelector, useAppDispatch} from '../../../../webapp/src/store/hooks'
|
||||
import AddIcon from '../../../../webapp/src/widgets/icons/add'
|
||||
import Button from '../../../../webapp/src/widgets/buttons/button'
|
||||
@ -29,11 +37,13 @@ const RHSChannelBoards = () => {
|
||||
const boards = useAppSelector(getMySortedBoards)
|
||||
const teamId = useAppSelector(getCurrentTeamId)
|
||||
const currentChannel = useAppSelector(getCurrentChannel)
|
||||
const me = useAppSelector<IUser|null>(getMe)
|
||||
const dispatch = useAppDispatch()
|
||||
const intl = useIntl()
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(loadBoards())
|
||||
dispatch(fetchMe())
|
||||
}, [])
|
||||
|
||||
useWebsockets(teamId || '', (wsClient: WSClient) => {
|
||||
@ -41,7 +51,12 @@ const RHSChannelBoards = () => {
|
||||
dispatch(updateBoards(boards))
|
||||
}
|
||||
const onChangeMemberHandler = (_: WSClient, members: BoardMember[]): void => {
|
||||
dispatch(updateMembers(members))
|
||||
dispatch(updateMembersEnsuringBoardsAndUsers(members))
|
||||
|
||||
if (me) {
|
||||
const myBoardMemberships = members.filter((boardMember) => boardMember.userId === me.id)
|
||||
dispatch(addMyBoardMemberships(myBoardMemberships))
|
||||
}
|
||||
}
|
||||
|
||||
wsClient.addOnChange(onChangeBoardHandler, 'board')
|
||||
@ -51,7 +66,7 @@ const RHSChannelBoards = () => {
|
||||
wsClient.removeOnChange(onChangeBoardHandler, 'board')
|
||||
wsClient.removeOnChange(onChangeMemberHandler, 'boardMembers')
|
||||
}
|
||||
}, [])
|
||||
}, [me])
|
||||
|
||||
if (!boards) {
|
||||
return null
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import React, {useEffect} from 'react'
|
||||
import {createIntl, createIntlCache} from 'react-intl'
|
||||
import {Store, Action} from 'redux'
|
||||
import {Provider as ReduxProvider} from 'react-redux'
|
||||
import {createBrowserHistory, History} from 'history'
|
||||
@ -13,6 +14,7 @@ import {selectTeam} from 'mattermost-redux/actions/teams'
|
||||
|
||||
import {SuiteWindow} from '../../../webapp/src/types/index'
|
||||
import {UserSettings} from '../../../webapp/src/userSettings'
|
||||
import {getMessages, getCurrentLanguage} from '../../../webapp/src/i18n'
|
||||
|
||||
|
||||
const windowAny = (window as SuiteWindow)
|
||||
@ -37,6 +39,7 @@ import '../../../webapp/src/styles/focalboard-variables.scss'
|
||||
import '../../../webapp/src/styles/main.scss'
|
||||
import '../../../webapp/src/styles/labels.scss'
|
||||
import octoClient from '../../../webapp/src/octoClient'
|
||||
import {Constants} from '../../../webapp/src/constants'
|
||||
|
||||
import BoardsUnfurl from './components/boardsUnfurl/boardsUnfurl'
|
||||
import RHSChannelBoards from './components/rhsChannelBoards'
|
||||
@ -182,6 +185,13 @@ export default class Plugin {
|
||||
windowAny.frontendBaseURL = subpath + windowAny.frontendBaseURL
|
||||
windowAny.baseURL = subpath + windowAny.baseURL
|
||||
browserHistory = customHistory()
|
||||
const cache = createIntlCache()
|
||||
const intl = createIntl({
|
||||
// modeled after <IntlProvider> in webapp/src/app.tsx
|
||||
locale: getCurrentLanguage(),
|
||||
messages: getMessages(getCurrentLanguage())
|
||||
}, cache)
|
||||
|
||||
|
||||
this.registry = registry
|
||||
|
||||
@ -240,7 +250,9 @@ export default class Plugin {
|
||||
const currentTeamID = mmStore.getState().entities.teams.currentTeamId
|
||||
if (currentTeamID && currentTeamID !== prevTeamID) {
|
||||
if (prevTeamID && window.location.pathname.startsWith(windowAny.frontendBaseURL || '')) {
|
||||
browserHistory.push(`/team/${currentTeamID}`)
|
||||
// Don't re-push the URL if we're already on a URL for the current team
|
||||
if (!window.location.pathname.startsWith(`${(windowAny.frontendBaseURL || '')}/team/${currentTeamID}`))
|
||||
browserHistory.push(`/team/${currentTeamID}`)
|
||||
}
|
||||
prevTeamID = currentTeamID
|
||||
store.dispatch(setTeam(currentTeamID))
|
||||
@ -249,6 +261,19 @@ export default class Plugin {
|
||||
}
|
||||
})
|
||||
|
||||
let fbPrevTeamID = store.getState().teams.currentId
|
||||
store.subscribe(() => {
|
||||
const currentTeamID: string = store.getState().teams.currentId
|
||||
const currentUserId = mmStore.getState().entities.users.currentUserId
|
||||
if (currentTeamID !== fbPrevTeamID) {
|
||||
fbPrevTeamID = currentTeamID
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
mmStore.dispatch(selectTeam(currentTeamID))
|
||||
localStorage.setItem(`user_prev_team:${currentUserId}`, currentTeamID)
|
||||
}
|
||||
})
|
||||
|
||||
if (this.registry.registerProduct) {
|
||||
windowAny.frontendBaseURL = subpath + '/boards'
|
||||
|
||||
@ -284,8 +309,9 @@ export default class Plugin {
|
||||
|
||||
const goToFocalboardTemplate = () => {
|
||||
const currentTeam = mmStore.getState().entities.teams.currentTeamId
|
||||
const currentChannel = mmStore.getState().entities.channels.currentChannelId
|
||||
TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.ClickChannelIntro, {teamID: currentTeam})
|
||||
window.open(`${windowAny.frontendBaseURL}/team/${currentTeam}`, '_blank', 'noopener')
|
||||
window.open(`${windowAny.frontendBaseURL}/team/${currentTeam}/new/${currentChannel}`, '_blank', 'noopener')
|
||||
}
|
||||
|
||||
if (registry.registerChannelIntroButtonAction) {
|
||||
@ -294,7 +320,7 @@ export default class Plugin {
|
||||
|
||||
if (this.registry.registerAppBarComponent) {
|
||||
const appBarIconURL = windowAny.baseURL + '/public/app-bar-icon.png'
|
||||
this.registry.registerAppBarComponent(appBarIconURL, () => mmStore.dispatch(toggleRHSPlugin), 'Boards')
|
||||
this.registry.registerAppBarComponent(appBarIconURL, () => mmStore.dispatch(toggleRHSPlugin), intl.formatMessage({id: 'AppBar.Tooltip', defaultMessage: 'Toggle Linked Boards'}))
|
||||
}
|
||||
|
||||
this.registry.registerPostWillRenderEmbedComponent(
|
||||
@ -309,6 +335,21 @@ export default class Plugin {
|
||||
),
|
||||
false
|
||||
)
|
||||
|
||||
// Insights handler
|
||||
if (this.registry?.registerInsightsHandler) {
|
||||
this.registry?.registerInsightsHandler(async (timeRange: string, page: number, perPage: number, teamId: string, insightType: string) => {
|
||||
if (insightType === Constants.myInsights) {
|
||||
const data = await octoClient.getMyTopBoards(timeRange, page, perPage, teamId)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
const data = await octoClient.getTeamTopBoards(timeRange, page, perPage, teamId)
|
||||
|
||||
return data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.boardSelectorId = this.registry.registerRootComponent((props: {webSocketClient: MMWebSocketClient}) => (
|
||||
@ -354,11 +395,6 @@ export default class Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
windowAny.setTeamInSidebar = (teamID: string) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
mmStore.dispatch(selectTeam(teamID))
|
||||
}
|
||||
windowAny.getCurrentTeamId = (): string => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
|
@ -17,6 +17,7 @@ export interface PluginRegistry {
|
||||
registerAppBarComponent(iconURL: string, action: (channel: Channel, member: ChannelMembership) => void, tooltipText: React.ReactNode)
|
||||
registerRightHandSidebarComponent(component: React.ElementType, title: React.Element)
|
||||
registerRootComponent(component: React.ElementType)
|
||||
registerInsightsHandler(handler: (timeRange: string, page: number, perPage: number, teamId: string, insightType: string) => void)
|
||||
|
||||
// Add more if needed from https://developers.mattermost.com/extend/plugins/webapp/reference
|
||||
}
|
||||
|
22
pull_request_template.md
Normal file
22
pull_request_template.md
Normal file
@ -0,0 +1,22 @@
|
||||
<!-- Thank you for contributing a pull request! Here are a few tips to help you:
|
||||
|
||||
1. If this is your first contribution, make sure you've read the Contribution Checklist https://developers.mattermost.com/contribute/getting-started/contribution-checklist/
|
||||
2. Read our blog post about "Submitting Great PRs" https://developers.mattermost.com/blog/2019-01-24-submitting-great-prs
|
||||
3. Take a look at other repository specific documentation at https://developers.mattermost.com/contribute
|
||||
|
||||
Assign two reviewers for this pull request from the names suggested. If no names are suggested or you are not sure who to assign, set `Core Focalboard` as the reviewer.
|
||||
-->
|
||||
|
||||
#### Summary
|
||||
<!--
|
||||
A description of what this pull request does, as well as QA test steps (if applicable and if not already added to the ticket).
|
||||
-->
|
||||
|
||||
#### Ticket Link
|
||||
<!--
|
||||
If this pull request addresses a Github issue, please link the relevant issue, e.g.
|
||||
|
||||
Fixes https://github.com/mattermost/focalboard/issues/XXXXX
|
||||
|
||||
Otherwise, link the JIRA ticket.
|
||||
-->
|
4403
server/api/api.go
4403
server/api/api.go
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,13 @@ const (
|
||||
archiveExtension = ".boardarchive"
|
||||
)
|
||||
|
||||
func (a *API) registerAchivesRoutes(r *mux.Router) {
|
||||
// Archive APIs
|
||||
r.HandleFunc("/boards/{boardID}/archive/export", a.sessionRequired(a.handleArchiveExportBoard)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/archive/import", a.sessionRequired(a.handleArchiveImport)).Methods("POST")
|
||||
r.HandleFunc("/teams/{teamID}/archive/export", a.sessionRequired(a.handleArchiveExportTeam)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleArchiveExportBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID}/archive/export archiveExportBoard
|
||||
//
|
||||
@ -84,75 +91,6 @@ func (a *API) handleArchiveExportBoard(w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleArchiveExportTeam(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/archive/export archiveExportTeam
|
||||
//
|
||||
// Exports an archive of all blocks for all the boards in a team.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Id of team
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// content:
|
||||
// application-octet-stream:
|
||||
// type: string
|
||||
// format: binary
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
if a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in plugin mode", nil)
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
ctx := r.Context()
|
||||
session, _ := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "archiveExportTeam", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("TeamID", teamID)
|
||||
|
||||
boards, err := a.app.GetBoardsForUserAndTeam(userID, teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
ids := []string{}
|
||||
for _, board := range boards {
|
||||
ids = append(ids, board.ID)
|
||||
}
|
||||
|
||||
opts := model.ExportArchiveOptions{
|
||||
TeamID: teamID,
|
||||
BoardIDs: ids,
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("archive-%s%s", time.Now().Format("2006-01-02"), archiveExtension)
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+filename)
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
|
||||
if err := a.app.ExportArchive(w, opts); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleArchiveImport(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /teams/{teamID}/archive/import archiveImport
|
||||
//
|
||||
@ -225,3 +163,72 @@ func (a *API) handleArchiveImport(w http.ResponseWriter, r *http.Request) {
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleArchiveExportTeam(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/archive/export archiveExportTeam
|
||||
//
|
||||
// Exports an archive of all blocks for all the boards in a team.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Id of team
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// content:
|
||||
// application-octet-stream:
|
||||
// type: string
|
||||
// format: binary
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
if a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in plugin mode", nil)
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
ctx := r.Context()
|
||||
session, _ := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "archiveExportTeam", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("TeamID", teamID)
|
||||
|
||||
boards, err := a.app.GetBoardsForUserAndTeam(userID, teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
ids := []string{}
|
||||
for _, board := range boards {
|
||||
ids = append(ids, board.ID)
|
||||
}
|
||||
|
||||
opts := model.ExportArchiveOptions{
|
||||
TeamID: teamID,
|
||||
BoardIDs: ids,
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("archive-%s%s", time.Now().Format("2006-01-02"), archiveExtension)
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+filename)
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
|
||||
if err := a.app.ExportArchive(w, opts); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -19,123 +17,15 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
const (
|
||||
MinimumPasswordLength = 8
|
||||
)
|
||||
|
||||
type ParamError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (pe ParamError) Error() string {
|
||||
return pe.msg
|
||||
}
|
||||
|
||||
// LoginRequest is a login request
|
||||
// swagger:model
|
||||
type LoginRequest struct {
|
||||
// Type of login, currently must be set to "normal"
|
||||
// required: true
|
||||
Type string `json:"type"`
|
||||
|
||||
// If specified, login using username
|
||||
// required: false
|
||||
Username string `json:"username"`
|
||||
|
||||
// If specified, login using email
|
||||
// required: false
|
||||
Email string `json:"email"`
|
||||
|
||||
// Password
|
||||
// required: true
|
||||
Password string `json:"password"`
|
||||
|
||||
// MFA token
|
||||
// required: false
|
||||
// swagger:ignore
|
||||
MfaToken string `json:"mfa_token"`
|
||||
}
|
||||
|
||||
// LoginResponse is a login response
|
||||
// swagger:model
|
||||
type LoginResponse struct {
|
||||
// Session token
|
||||
// required: true
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func LoginResponseFromJSON(data io.Reader) (*LoginResponse, error) {
|
||||
var resp LoginResponse
|
||||
if err := json.NewDecoder(data).Decode(&resp); err != nil {
|
||||
return nil, err
|
||||
func (a *API) registerAuthRoutes(r *mux.Router) {
|
||||
// personal-server specific routes. These are not needed in plugin mode.
|
||||
if !a.isPlugin {
|
||||
r.HandleFunc("/login", a.handleLogin).Methods("POST")
|
||||
r.HandleFunc("/logout", a.sessionRequired(a.handleLogout)).Methods("POST")
|
||||
r.HandleFunc("/register", a.handleRegister).Methods("POST")
|
||||
r.HandleFunc("/teams/{teamID}/regenerate_signup_token", a.sessionRequired(a.handlePostTeamRegenerateSignupToken)).Methods("POST")
|
||||
r.HandleFunc("/users/{userID}/changepassword", a.sessionRequired(a.handleChangePassword)).Methods("POST")
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// RegisterRequest is a user registration request
|
||||
// swagger:model
|
||||
type RegisterRequest struct {
|
||||
// User name
|
||||
// required: true
|
||||
Username string `json:"username"`
|
||||
|
||||
// User's email
|
||||
// required: true
|
||||
Email string `json:"email"`
|
||||
|
||||
// Password
|
||||
// required: true
|
||||
Password string `json:"password"`
|
||||
|
||||
// Registration authorization token
|
||||
// required: true
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func (rd *RegisterRequest) IsValid() error {
|
||||
if strings.TrimSpace(rd.Username) == "" {
|
||||
return ParamError{"username is required"}
|
||||
}
|
||||
if strings.TrimSpace(rd.Email) == "" {
|
||||
return ParamError{"email is required"}
|
||||
}
|
||||
if !auth.IsEmailValid(rd.Email) {
|
||||
return ParamError{"invalid email format"}
|
||||
}
|
||||
if rd.Password == "" {
|
||||
return ParamError{"password is required"}
|
||||
}
|
||||
return isValidPassword(rd.Password)
|
||||
}
|
||||
|
||||
// ChangePasswordRequest is a user password change request
|
||||
// swagger:model
|
||||
type ChangePasswordRequest struct {
|
||||
// Old password
|
||||
// required: true
|
||||
OldPassword string `json:"oldPassword"`
|
||||
|
||||
// New password
|
||||
// required: true
|
||||
NewPassword string `json:"newPassword"`
|
||||
}
|
||||
|
||||
// IsValid validates a password change request.
|
||||
func (rd *ChangePasswordRequest) IsValid() error {
|
||||
if rd.OldPassword == "" {
|
||||
return ParamError{"old password is required"}
|
||||
}
|
||||
if rd.NewPassword == "" {
|
||||
return ParamError{"new password is required"}
|
||||
}
|
||||
return isValidPassword(rd.NewPassword)
|
||||
}
|
||||
|
||||
func isValidPassword(password string) error {
|
||||
if len(password) < MinimumPasswordLength {
|
||||
return ParamError{fmt.Sprintf("password must be at least %d characters", MinimumPasswordLength)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
@ -187,7 +77,7 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var loginData LoginRequest
|
||||
var loginData model.LoginRequest
|
||||
err = json.Unmarshal(requestBody, &loginData)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
@ -205,7 +95,7 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "incorrect login", err)
|
||||
return
|
||||
}
|
||||
json, err := json.Marshal(LoginResponse{Token: token})
|
||||
json, err := json.Marshal(model.LoginResponse{Token: token})
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
@ -315,7 +205,7 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var registerData RegisterRequest
|
||||
var registerData model.RegisterRequest
|
||||
err = json.Unmarshal(requestBody, ®isterData)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
@ -425,7 +315,7 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var requestData ChangePasswordRequest
|
||||
var requestData model.ChangePasswordRequest
|
||||
if err = json.Unmarshal(requestBody, &requestData); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
|
758
server/api/blocks.go
Normal file
758
server/api/blocks.go
Normal file
@ -0,0 +1,758 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/app"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerBlocksRoutes(r *mux.Router) {
|
||||
// Blocks APIs
|
||||
r.HandleFunc("/boards/{boardID}/blocks", a.attachSession(a.handleGetBlocks, false)).Methods("GET")
|
||||
r.HandleFunc("/boards/{boardID}/blocks", a.sessionRequired(a.handlePostBlocks)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/blocks", a.sessionRequired(a.handlePatchBlocks)).Methods("PATCH")
|
||||
r.HandleFunc("/boards/{boardID}/blocks/{blockID}", a.sessionRequired(a.handleDeleteBlock)).Methods("DELETE")
|
||||
r.HandleFunc("/boards/{boardID}/blocks/{blockID}", a.sessionRequired(a.handlePatchBlock)).Methods("PATCH")
|
||||
r.HandleFunc("/boards/{boardID}/blocks/{blockID}/undelete", a.sessionRequired(a.handleUndeleteBlock)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/blocks/{blockID}/duplicate", a.sessionRequired(a.handleDuplicateBlock)).Methods("POST")
|
||||
}
|
||||
|
||||
func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID}/blocks getBlocks
|
||||
//
|
||||
// Returns blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: parent_id
|
||||
// in: query
|
||||
// description: ID of parent block, omit to specify all blocks
|
||||
// required: false
|
||||
// type: string
|
||||
// - name: type
|
||||
// in: query
|
||||
// description: Type of blocks to return, omit to specify all types
|
||||
// required: false
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Block"
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
query := r.URL.Query()
|
||||
parentID := query.Get("parent_id")
|
||||
blockType := query.Get("type")
|
||||
all := query.Get("all")
|
||||
blockID := query.Get("block_id")
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
hasValidReadToken := a.hasValidReadTokenForBoard(r, boardID)
|
||||
if userID == "" && !hasValidReadToken {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "Board not found", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasValidReadToken {
|
||||
if board.IsTemplate && board.Type == model.BoardTypeOpen {
|
||||
if board.TeamID != model.GlobalTeamID && !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board template"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("parentID", parentID)
|
||||
auditRec.AddMeta("blockType", blockType)
|
||||
auditRec.AddMeta("all", all)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
var blocks []model.Block
|
||||
var block *model.Block
|
||||
switch {
|
||||
case all != "":
|
||||
blocks, err = a.app.GetBlocksForBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
case blockID != "":
|
||||
block, err = a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if block != nil {
|
||||
if block.BoardID != boardID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
blocks = append(blocks, *block)
|
||||
}
|
||||
default:
|
||||
blocks, err = a.app.GetBlocks(boardID, parentID, blockType)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
a.logger.Debug("GetBlocks",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("parentID", parentID),
|
||||
mlog.String("blockType", blockType),
|
||||
mlog.String("blockID", blockID),
|
||||
mlog.Int("block_count", len(blocks)),
|
||||
)
|
||||
|
||||
var bErr error
|
||||
blocks, bErr = a.app.ApplyCloudLimits(blocks)
|
||||
if bErr != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", bErr)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, json)
|
||||
|
||||
auditRec.AddMeta("blockCount", len(blocks))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/blocks updateBlocks
|
||||
//
|
||||
// Insert blocks. The specified IDs will only be used to link
|
||||
// blocks with existing ones, the rest will be replaced by server
|
||||
// generated IDs
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: disable_notify
|
||||
// in: query
|
||||
// description: Disables notifications (for bulk data inserting)
|
||||
// required: false
|
||||
// type: bool
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: array of blocks to insert or update
|
||||
// required: true
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Block"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// items:
|
||||
// $ref: '#/definitions/Block'
|
||||
// type: array
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
val := r.URL.Query().Get("disable_notify")
|
||||
disableNotify := val == True
|
||||
|
||||
// in phase 1 we use "manage_board_cards", but we would have to
|
||||
// check on specific actions for phase 2
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var blocks []model.Block
|
||||
|
||||
err = json.Unmarshal(requestBody, &blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, block := range blocks {
|
||||
// Error checking
|
||||
if len(block.Type) < 1 {
|
||||
message := fmt.Sprintf("missing type for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.CreateAt < 1 {
|
||||
message := fmt.Sprintf("invalid createAt for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.UpdateAt < 1 {
|
||||
message := fmt.Sprintf("invalid UpdateAt for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.BoardID != boardID {
|
||||
message := fmt.Sprintf("invalid BoardID for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
blocks = model.GenerateBlockIDs(blocks, a.logger)
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "postBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("disable_notify", disableNotify)
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
model.StampModificationMetadata(userID, blocks, auditRec)
|
||||
|
||||
// this query param exists when creating template from board, or board from template
|
||||
sourceBoardID := r.URL.Query().Get("sourceBoardID")
|
||||
if sourceBoardID != "" {
|
||||
if updateFileIDsErr := a.app.CopyCardFiles(sourceBoardID, blocks); updateFileIDsErr != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", updateFileIDsErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
newBlocks, err := a.app.InsertBlocks(blocks, session.UserID, !disableNotify)
|
||||
if err != nil {
|
||||
if errors.Is(err, app.ErrViewsLimitReached) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
} else {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("POST Blocks",
|
||||
mlog.Int("block_count", len(blocks)),
|
||||
mlog.Bool("disable_notify", disableNotify),
|
||||
)
|
||||
|
||||
json, err := json.Marshal(newBlocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, json)
|
||||
|
||||
auditRec.AddMeta("blockCount", len(blocks))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /boards/{boardID}/blocks/{blockID} deleteBlock
|
||||
//
|
||||
// Deletes a block
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: blockID
|
||||
// in: path
|
||||
// description: ID of block to delete
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: block not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
blockID := vars["blockID"]
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
|
||||
block, err := a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if block == nil || block.BoardID != boardID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteBlock", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
err = a.app.DeleteBlock(blockID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("DELETE Block", mlog.String("boardID", boardID), mlog.String("blockID", blockID))
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUndeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/blocks/{blockID}/undelete undeleteBlock
|
||||
//
|
||||
// Undeletes a block
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: blockID
|
||||
// in: path
|
||||
// description: ID of block to undelete
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BlockPatch"
|
||||
// '404':
|
||||
// description: block not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
vars := mux.Vars(r)
|
||||
blockID := vars["blockID"]
|
||||
boardID := vars["boardID"]
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
block, err := a.app.GetLastBlockHistoryEntry(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if block == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if board.ID != block.BoardID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modify board members"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "undeleteBlock", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
undeletedBlock, err := a.app.UndeleteBlock(blockID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
undeletedBlockData, err := json.Marshal(undeletedBlock)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("UNDELETE Block", mlog.String("blockID", blockID))
|
||||
jsonBytesResponse(w, http.StatusOK, undeletedBlockData)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePatchBlock(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PATCH /boards/{boardID}/blocks/{blockID} patchBlock
|
||||
//
|
||||
// Partially updates a block
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: blockID
|
||||
// in: path
|
||||
// description: ID of block to patch
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: block patch to apply
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BlockPatch"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: block not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
blockID := vars["blockID"]
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
|
||||
block, err := a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if block == nil || block.BoardID != boardID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var patch *model.BlockPatch
|
||||
err = json.Unmarshal(requestBody, &patch)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "patchBlock", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
err = a.app.PatchBlock(blockID, patch, userID)
|
||||
if errors.Is(err, app.ErrPatchUpdatesLimitedCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("PATCH Block", mlog.String("boardID", boardID), mlog.String("blockID", blockID))
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePatchBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PATCH /boards/{boardID}/blocks/ patchBlocks
|
||||
//
|
||||
// Partially updates batch of blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Workspace ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: block Ids and block patches to apply
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BlockPatchBatch"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var patches *model.BlockPatchBatch
|
||||
err = json.Unmarshal(requestBody, &patches)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "patchBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
for i := range patches.BlockIDs {
|
||||
auditRec.AddMeta("block_"+strconv.FormatInt(int64(i), 10), patches.BlockIDs[i])
|
||||
}
|
||||
|
||||
for _, blockID := range patches.BlockIDs {
|
||||
var block *model.Block
|
||||
block, err = a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
if !a.permissions.HasPermissionToBoard(userID, block.BoardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = a.app.PatchBlocks(teamID, patches, userID)
|
||||
if errors.Is(err, app.ErrPatchUpdatesLimitedCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("PATCH Blocks", mlog.String("patches", strconv.Itoa(len(patches.BlockIDs))))
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDuplicateBlock(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/blocks/{blockID}/duplicate duplicateBlock
|
||||
//
|
||||
// Returns the new created blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: blockID
|
||||
// in: path
|
||||
// description: Block ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Block"
|
||||
// '404':
|
||||
// description: board or block not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
blockID := mux.Vars(r)["blockID"]
|
||||
userID := getUserID(r)
|
||||
query := r.URL.Query()
|
||||
asTemplate := query.Get("asTemplate")
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
}
|
||||
|
||||
if userID == "" {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
|
||||
block, err := a.app.GetBlockByID(blockID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if block == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if board.ID != block.BoardID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modify board members"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "duplicateBlock", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("blockID", blockID)
|
||||
|
||||
a.logger.Debug("DuplicateBlock",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("blockID", blockID),
|
||||
)
|
||||
|
||||
blocks, err := a.app.DuplicateBlock(boardID, blockID, userID, asTemplate == True)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
656
server/api/boards.go
Normal file
656
server/api/boards.go
Normal file
@ -0,0 +1,656 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/app"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerBoardsRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/teams/{teamID}/boards", a.sessionRequired(a.handleGetBoards)).Methods("GET")
|
||||
r.HandleFunc("/boards", a.sessionRequired(a.handleCreateBoard)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}", a.attachSession(a.handleGetBoard, false)).Methods("GET")
|
||||
r.HandleFunc("/boards/{boardID}", a.sessionRequired(a.handlePatchBoard)).Methods("PATCH")
|
||||
r.HandleFunc("/boards/{boardID}", a.sessionRequired(a.handleDeleteBoard)).Methods("DELETE")
|
||||
r.HandleFunc("/boards/{boardID}/duplicate", a.sessionRequired(a.handleDuplicateBoard)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/undelete", a.sessionRequired(a.handleUndeleteBoard)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/metadata", a.sessionRequired(a.handleGetBoardMetadata)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleGetBoards(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/boards getBoards
|
||||
//
|
||||
// Returns team boards
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getBoards", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
|
||||
// retrieve boards list
|
||||
boards, err := a.app.GetBoardsForUserAndTeam(userID, teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("GetBoards",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.Int("boardsCount", len(boards)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(boards)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("boardsCount", len(boards))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleCreateBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards createBoard
|
||||
//
|
||||
// Creates a new board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: the board to create
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/Board'
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var newBoard *model.Board
|
||||
if err = json.Unmarshal(requestBody, &newBoard); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if newBoard.Type == model.BoardTypeOpen {
|
||||
if !a.permissions.HasPermissionToTeam(userID, newBoard.TeamID, model.PermissionCreatePublicChannel) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to create public boards"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !a.permissions.HasPermissionToTeam(userID, newBoard.TeamID, model.PermissionCreatePrivateChannel) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to create private boards"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = newBoard.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "createBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("teamID", newBoard.TeamID)
|
||||
auditRec.AddMeta("boardType", newBoard.Type)
|
||||
|
||||
// create board
|
||||
board, err := a.app.CreateBoard(newBoard, userID, true)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("CreateBoard",
|
||||
mlog.String("teamID", board.TeamID),
|
||||
mlog.String("boardID", board.ID),
|
||||
mlog.String("boardType", string(board.Type)),
|
||||
mlog.String("userID", userID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(board)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID} getBoard
|
||||
//
|
||||
// Returns a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
hasValidReadToken := a.hasValidReadTokenForBoard(r, boardID)
|
||||
if userID == "" && !hasValidReadToken {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasValidReadToken {
|
||||
if board.Type == model.BoardTypePrivate {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
a.logger.Debug("GetBoard",
|
||||
mlog.String("boardID", boardID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(board)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePatchBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PATCH /boards/{boardID} patchBoard
|
||||
//
|
||||
// Partially updates a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: board patch to apply
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardPatch"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/Board'
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var patch *model.BoardPatch
|
||||
if err = json.Unmarshal(requestBody, &patch); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = patch.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardProperties) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying board properties"})
|
||||
return
|
||||
}
|
||||
|
||||
if patch.Type != nil || patch.MinimumRole != nil {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardType) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying board type"})
|
||||
return
|
||||
}
|
||||
}
|
||||
if patch.ChannelID != nil {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardRoles) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying board access"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "patchBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("userID", userID)
|
||||
|
||||
// patch board
|
||||
updatedBoard, err := a.app.PatchBoard(patch, boardID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("PatchBoard",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("userID", userID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(updatedBoard)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /boards/{boardID} deleteBoard
|
||||
//
|
||||
// Removes a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
// Check if board exists
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionDeleteBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to delete board"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
if err := a.app.DeleteBoard(boardID, userID); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("DELETE Board", mlog.String("boardID", boardID))
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDuplicateBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/duplicate duplicateBoard
|
||||
//
|
||||
// Returns the new created board and all the blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardsAndBlocks'
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
query := r.URL.Query()
|
||||
asTemplate := query.Get("asTemplate")
|
||||
toTeam := query.Get("toTeam")
|
||||
|
||||
if userID == "" {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if toTeam == "" && !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
if toTeam != "" && !a.permissions.HasPermissionToTeam(userID, toTeam, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
if board.IsTemplate && board.Type == model.BoardTypeOpen {
|
||||
if board.TeamID != model.GlobalTeamID && !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "duplicateBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
a.logger.Debug("DuplicateBoard",
|
||||
mlog.String("boardID", boardID),
|
||||
)
|
||||
|
||||
boardsAndBlocks, _, err := a.app.DuplicateBoard(boardID, userID, toTeam, asTemplate == True)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(boardsAndBlocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUndeleteBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/undelete undeleteBoard
|
||||
//
|
||||
// Undeletes a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: ID of board to undelete
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "undeleteBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionDeleteBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to undelete board"})
|
||||
return
|
||||
}
|
||||
|
||||
err := a.app.UndeleteBoard(boardID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("UNDELETE Board", mlog.String("boardID", boardID))
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetBoardMetadata(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID}/metadata getBoardMetadata
|
||||
//
|
||||
// Returns a board's metadata
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardMetadata"
|
||||
// '404':
|
||||
// description: board not found
|
||||
// '501':
|
||||
// description: required license not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
board, boardMetadata, err := a.app.GetBoardMetadata(boardID)
|
||||
if errors.Is(err, app.ErrInsufficientLicense) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil || boardMetadata == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if board.Type == model.BoardTypePrivate {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getBoardMetadata", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
data, err := json.Marshal(boardMetadata)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
426
server/api/boards_and_blocks.go
Normal file
426
server/api/boards_and_blocks.go
Normal file
@ -0,0 +1,426 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/app"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerBoardsAndBlocksRoutes(r *mux.Router) {
|
||||
// BoardsAndBlocks APIs
|
||||
r.HandleFunc("/boards-and-blocks", a.sessionRequired(a.handleCreateBoardsAndBlocks)).Methods("POST")
|
||||
r.HandleFunc("/boards-and-blocks", a.sessionRequired(a.handlePatchBoardsAndBlocks)).Methods("PATCH")
|
||||
r.HandleFunc("/boards-and-blocks", a.sessionRequired(a.handleDeleteBoardsAndBlocks)).Methods("DELETE")
|
||||
}
|
||||
|
||||
func (a *API) handleCreateBoardsAndBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards-and-blocks insertBoardsAndBlocks
|
||||
//
|
||||
// Creates new boards and blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: the boards and blocks to create
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardsAndBlocks"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardsAndBlocks'
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var newBab *model.BoardsAndBlocks
|
||||
if err = json.Unmarshal(requestBody, &newBab); err != nil {
|
||||
// a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(newBab.Boards) == 0 {
|
||||
message := "at least one board is required"
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
teamID := ""
|
||||
boardIDs := map[string]bool{}
|
||||
for _, board := range newBab.Boards {
|
||||
boardIDs[board.ID] = true
|
||||
|
||||
if teamID == "" {
|
||||
teamID = board.TeamID
|
||||
continue
|
||||
}
|
||||
|
||||
if teamID != board.TeamID {
|
||||
message := "cannot create boards for multiple teams"
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if board.ID == "" {
|
||||
message := "boards need an ID to be referenced from the blocks"
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board template"})
|
||||
return
|
||||
}
|
||||
|
||||
for _, block := range newBab.Blocks {
|
||||
// Error checking
|
||||
if len(block.Type) < 1 {
|
||||
message := fmt.Sprintf("missing type for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.CreateAt < 1 {
|
||||
message := fmt.Sprintf("invalid createAt for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.UpdateAt < 1 {
|
||||
message := fmt.Sprintf("invalid UpdateAt for block id %s", block.ID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !boardIDs[block.BoardID] {
|
||||
message := fmt.Sprintf("invalid BoardID %s (not exists in the created boards)", block.BoardID)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// IDs of boards and blocks are used to confirm that they're
|
||||
// linked and then regenerated by the server
|
||||
newBab, err = model.GenerateBoardsAndBlocksIDs(newBab, a.logger)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "createBoardsAndBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
auditRec.AddMeta("userID", userID)
|
||||
auditRec.AddMeta("boardsCount", len(newBab.Boards))
|
||||
auditRec.AddMeta("blocksCount", len(newBab.Blocks))
|
||||
|
||||
// create boards and blocks
|
||||
bab, err := a.app.CreateBoardsAndBlocks(newBab, userID, true)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("CreateBoardsAndBlocks",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.String("userID", userID),
|
||||
mlog.Int("boardCount", len(bab.Boards)),
|
||||
mlog.Int("blockCount", len(bab.Blocks)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(bab)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePatchBoardsAndBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PATCH /boards-and-blocks patchBoardsAndBlocks
|
||||
//
|
||||
// Patches a set of related boards and blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: the patches for the boards and blocks
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/PatchBoardsAndBlocks"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardsAndBlocks'
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var pbab *model.PatchBoardsAndBlocks
|
||||
if err = json.Unmarshal(requestBody, &pbab); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = pbab.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
teamID := ""
|
||||
boardIDMap := map[string]bool{}
|
||||
for i, boardID := range pbab.BoardIDs {
|
||||
boardIDMap[boardID] = true
|
||||
patch := pbab.BoardPatches[i]
|
||||
|
||||
if err = patch.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardProperties) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying board properties"})
|
||||
return
|
||||
}
|
||||
|
||||
if patch.Type != nil || patch.MinimumRole != nil {
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardType) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying board type"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
board, err2 := a.app.GetBoard(boardID)
|
||||
if err2 != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err2)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if teamID == "" {
|
||||
teamID = board.TeamID
|
||||
}
|
||||
if teamID != board.TeamID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, blockID := range pbab.BlockIDs {
|
||||
block, err2 := a.app.GetBlockByID(blockID)
|
||||
if err2 != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err2)
|
||||
return
|
||||
}
|
||||
if block == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := boardIDMap[block.BoardID]; !ok {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, block.BoardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying cards"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "patchBoardsAndBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardsCount", len(pbab.BoardIDs))
|
||||
auditRec.AddMeta("blocksCount", len(pbab.BlockIDs))
|
||||
|
||||
bab, err := a.app.PatchBoardsAndBlocks(pbab, userID)
|
||||
if errors.Is(err, app.ErrPatchUpdatesLimitedCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("PATCH BoardsAndBlocks",
|
||||
mlog.Int("boardsCount", len(pbab.BoardIDs)),
|
||||
mlog.Int("blocksCount", len(pbab.BlockIDs)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(bab)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteBoardsAndBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /boards-and-blocks deleteBoardsAndBlocks
|
||||
//
|
||||
// Deletes boards and blocks
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: the boards and blocks to delete
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/DeleteBoardsAndBlocks"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var dbab *model.DeleteBoardsAndBlocks
|
||||
if err = json.Unmarshal(requestBody, &dbab); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// user must have permission to delete all the boards, and that
|
||||
// would include the permission to manage their blocks
|
||||
teamID := ""
|
||||
boardIDMap := map[string]bool{}
|
||||
for _, boardID := range dbab.Boards {
|
||||
boardIDMap[boardID] = true
|
||||
// all boards in the request should belong to the same team
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
if teamID == "" {
|
||||
teamID = board.TeamID
|
||||
}
|
||||
if teamID != board.TeamID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
// permission check
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionDeleteBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to delete board"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, blockID := range dbab.Blocks {
|
||||
block, err2 := a.app.GetBlockByID(blockID)
|
||||
if err2 != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err2)
|
||||
return
|
||||
}
|
||||
if block == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := boardIDMap[block.BoardID]; !ok {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, block.BoardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modifying cards"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := dbab.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteBoardsAndBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardsCount", len(dbab.Boards))
|
||||
auditRec.AddMeta("blocksCount", len(dbab.Blocks))
|
||||
|
||||
if err := a.app.DeleteBoardsAndBlocks(dbab, userID); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("DELETE BoardsAndBlocks",
|
||||
mlog.Int("boardsCount", len(dbab.Boards)),
|
||||
mlog.Int("blocksCount", len(dbab.Blocks)),
|
||||
)
|
||||
|
||||
// response
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
auditRec.Success()
|
||||
}
|
401
server/api/categories.go
Normal file
401
server/api/categories.go
Normal file
@ -0,0 +1,401 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/app"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
)
|
||||
|
||||
func (a *API) registerCategoriesRoutes(r *mux.Router) {
|
||||
// Category APIs
|
||||
r.HandleFunc("/teams/{teamID}/categories", a.sessionRequired(a.handleCreateCategory)).Methods(http.MethodPost)
|
||||
r.HandleFunc("/teams/{teamID}/categories/{categoryID}", a.sessionRequired(a.handleUpdateCategory)).Methods(http.MethodPut)
|
||||
r.HandleFunc("/teams/{teamID}/categories/{categoryID}", a.sessionRequired(a.handleDeleteCategory)).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/teams/{teamID}/categories", a.sessionRequired(a.handleGetUserCategoryBoards)).Methods(http.MethodGet)
|
||||
r.HandleFunc("/teams/{teamID}/categories/{categoryID}/boards/{boardID}", a.sessionRequired(a.handleUpdateCategoryBoard)).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
func (a *API) handleCreateCategory(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /teams/{teamID}/categories createCategory
|
||||
//
|
||||
// Create a category for boards
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: category to create
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Category"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Category"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var category model.Category
|
||||
|
||||
err = json.Unmarshal(requestBody, &category)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "createCategory", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
// user can only create category for themselves
|
||||
if category.UserID != session.UserID {
|
||||
a.errorResponse(
|
||||
w,
|
||||
r.URL.Path,
|
||||
http.StatusBadRequest,
|
||||
fmt.Sprintf("userID %s and category userID %s mismatch", session.UserID, category.UserID),
|
||||
nil,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
if category.TeamID != teamID {
|
||||
a.errorResponse(
|
||||
w,
|
||||
r.URL.Path,
|
||||
http.StatusBadRequest,
|
||||
"teamID mismatch",
|
||||
nil,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
createdCategory, err := a.app.CreateCategory(&category)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(createdCategory)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.AddMeta("categoryID", createdCategory.ID)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUpdateCategory(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PUT /teams/{teamID}/categories/{categoryID} updateCategory
|
||||
//
|
||||
// Create a category for boards
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: categoryID
|
||||
// in: path
|
||||
// description: Category ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: category to update
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Category"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Category"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
categoryID := vars["categoryID"]
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var category model.Category
|
||||
err = json.Unmarshal(requestBody, &category)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "updateCategory", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
if categoryID != category.ID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "categoryID mismatch in patch and body", nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
// user can only update category for themselves
|
||||
if category.UserID != session.UserID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "user ID mismatch in session and category", nil)
|
||||
return
|
||||
}
|
||||
|
||||
teamID := vars["teamID"]
|
||||
if category.TeamID != teamID {
|
||||
a.errorResponse(
|
||||
w,
|
||||
r.URL.Path,
|
||||
http.StatusBadRequest,
|
||||
"teamID mismatch",
|
||||
nil,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
updatedCategory, err := a.app.UpdateCategory(&category)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, app.ErrorCategoryDeleted):
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", err)
|
||||
case errors.Is(err, app.ErrorCategoryPermissionDenied):
|
||||
// TODO: The permissions should be handled as much as possible at
|
||||
// the API level, this needs to be changed
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", err)
|
||||
default:
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(updatedCategory)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteCategory(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /teams/{teamID}/categories/{categoryID} deleteCategory
|
||||
//
|
||||
// Delete a category
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: categoryID
|
||||
// in: path
|
||||
// description: Category ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
vars := mux.Vars(r)
|
||||
|
||||
userID := session.UserID
|
||||
teamID := vars["teamID"]
|
||||
categoryID := vars["categoryID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteCategory", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
deletedCategory, err := a.app.DeleteCategory(categoryID, userID, teamID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, app.ErrorInvalidCategory):
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
case errors.Is(err, app.ErrorCategoryPermissionDenied):
|
||||
// TODO: The permissions should be handled as much as possible at
|
||||
// the API level, this needs to be changed
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", err)
|
||||
default:
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(deletedCategory)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetUserCategoryBoards(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/categories getUserCategoryBoards
|
||||
//
|
||||
// Gets the user's board categories
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// items:
|
||||
// "$ref": "#/definitions/CategoryBoards"
|
||||
// type: array
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getUserCategoryBoards", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
categoryBlocks, err := a.app.GetUserCategoryBoards(userID, teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(categoryBlocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUpdateCategoryBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /teams/{teamID}/categories/{categoryID}/boards/{boardID} updateCategoryBoard
|
||||
//
|
||||
// Set the category of a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: categoryID
|
||||
// in: path
|
||||
// description: Category ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "updateCategoryBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
vars := mux.Vars(r)
|
||||
categoryID := vars["categoryID"]
|
||||
boardID := vars["boardID"]
|
||||
teamID := vars["teamID"]
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
// TODO: Check the category and the team matches
|
||||
err := a.app.AddUpdateUserCategoryBoard(teamID, userID, categoryID, boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, []byte("ok"))
|
||||
auditRec.Success()
|
||||
}
|
104
server/api/channels.go
Normal file
104
server/api/channels.go
Normal file
@ -0,0 +1,104 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerChannelsRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/teams/{teamID}/channels/{channelID}", a.sessionRequired(a.handleGetChannel)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleGetChannel(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/channels/{channelID} getChannel
|
||||
//
|
||||
// Returns the requested channel
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: channelID
|
||||
// in: path
|
||||
// description: Channel ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Channel"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
channelID := mux.Vars(r)["channelID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToChannel(userID, channelID, model.PermissionReadChannel) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to channel"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getChannel", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
auditRec.AddMeta("channelID", teamID)
|
||||
|
||||
channel, err := a.app.GetChannel(teamID, channelID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("GetChannel",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.String("channelID", channelID),
|
||||
)
|
||||
|
||||
if channel.TeamId != teamID {
|
||||
if channel.Type != mm_model.ChannelTypeDirect && channel.Type != mm_model.ChannelTypeGroup {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
data, err := json.Marshal(channel)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
41
server/api/config.go
Normal file
41
server/api/config.go
Normal file
@ -0,0 +1,41 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (a *API) registerConfigRoutes(r *mux.Router) {
|
||||
// Config APIs
|
||||
r.HandleFunc("/clientConfig", a.getClientConfig).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) getClientConfig(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /clientConfig getClientConfig
|
||||
//
|
||||
// Returns the client configuration
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ClientConfig"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
clientConfig := a.app.GetClientConfig()
|
||||
|
||||
configData, err := json.Marshal(clientConfig)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
jsonBytesResponse(w, http.StatusOK, configData)
|
||||
}
|
259
server/api/files.go
Normal file
259
server/api/files.go
Normal file
@ -0,0 +1,259 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
// FileUploadResponse is the response to a file upload
|
||||
// swagger:model
|
||||
type FileUploadResponse struct {
|
||||
// The FileID to retrieve the uploaded file
|
||||
// required: true
|
||||
FileID string `json:"fileId"`
|
||||
}
|
||||
|
||||
func FileUploadResponseFromJSON(data io.Reader) (*FileUploadResponse, error) {
|
||||
var fileUploadResponse FileUploadResponse
|
||||
|
||||
if err := json.NewDecoder(data).Decode(&fileUploadResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fileUploadResponse, nil
|
||||
}
|
||||
|
||||
func (a *API) registerFilesRoutes(r *mux.Router) {
|
||||
// Files API
|
||||
r.HandleFunc("/files/teams/{teamID}/{boardID}/{filename}", a.attachSession(a.handleServeFile, false)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/{boardID}/files", a.sessionRequired(a.handleUploadFile)).Methods("POST")
|
||||
}
|
||||
|
||||
func (a *API) handleServeFile(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /files/teams/{teamID}/{boardID}/{filename} getFile
|
||||
//
|
||||
// Returns the contents of an uploaded file
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// - image/jpg
|
||||
// - image/png
|
||||
// - image/gif
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: filename
|
||||
// in: path
|
||||
// description: name of the file
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: file not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
filename := vars["filename"]
|
||||
userID := getUserID(r)
|
||||
|
||||
hasValidReadToken := a.hasValidReadTokenForBoard(r, boardID)
|
||||
if userID == "" && !hasValidReadToken {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasValidReadToken && !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board"})
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getFile", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("teamID", board.TeamID)
|
||||
auditRec.AddMeta("filename", filename)
|
||||
|
||||
contentType := "image/jpg"
|
||||
|
||||
fileExtension := strings.ToLower(filepath.Ext(filename))
|
||||
if fileExtension == "png" {
|
||||
contentType = "image/png"
|
||||
}
|
||||
|
||||
if fileExtension == "gif" {
|
||||
contentType = "image/gif"
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
fileInfo, err := a.app.GetFileInfo(filename)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if fileInfo != nil && fileInfo.Archived {
|
||||
fileMetadata := map[string]interface{}{
|
||||
"archived": true,
|
||||
"name": fileInfo.Name,
|
||||
"size": fileInfo.Size,
|
||||
"extension": fileInfo.Extension,
|
||||
}
|
||||
|
||||
data, jsonErr := json.Marshal(fileMetadata)
|
||||
if jsonErr != nil {
|
||||
a.logger.Error("failed to marshal archived file metadata", mlog.String("filename", filename), mlog.Err(jsonErr))
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", jsonErr)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusBadRequest, data)
|
||||
return
|
||||
}
|
||||
|
||||
fileReader, err := a.app.GetFileReader(board.TeamID, boardID, filename)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
defer fileReader.Close()
|
||||
http.ServeContent(w, r, filename, time.Now(), fileReader)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /teams/{teamID}/boards/{boardID}/files uploadFile
|
||||
//
|
||||
// Upload a binary file, attached to a root block
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
// - multipart/form-data
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: ID of the team
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: uploaded file
|
||||
// in: formData
|
||||
// type: file
|
||||
// description: The file to upload
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/FileUploadResponse"
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to make board changes"})
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if a.app.GetConfig().MaxFileSize > 0 {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, a.app.GetConfig().MaxFileSize)
|
||||
}
|
||||
|
||||
file, handle, err := r.FormFile(UploadFormFileKey)
|
||||
if err != nil {
|
||||
if strings.HasSuffix(err.Error(), "http: request body too large") {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusRequestEntityTooLarge, "", err)
|
||||
return
|
||||
}
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "uploadFile", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("teamID", board.TeamID)
|
||||
auditRec.AddMeta("filename", handle.Filename)
|
||||
|
||||
fileID, err := a.app.SaveFile(file, board.TeamID, boardID, handle.Filename)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("uploadFile",
|
||||
mlog.String("filename", handle.Filename),
|
||||
mlog.String("fileID", fileID),
|
||||
)
|
||||
data, err := json.Marshal(FileUploadResponse{FileID: fileID})
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("fileID", fileID)
|
||||
auditRec.Success()
|
||||
}
|
242
server/api/insights.go
Normal file
242
server/api/insights.go
Normal file
@ -0,0 +1,242 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
|
||||
func (a *API) registerInsightsRoutes(r *mux.Router) {
|
||||
// Insights APIs
|
||||
r.HandleFunc("/teams/{teamID}/boards/insights", a.sessionRequired(a.handleTeamBoardsInsights)).Methods("GET")
|
||||
r.HandleFunc("/users/me/boards/insights", a.sessionRequired(a.handleUserBoardsInsights)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleTeamBoardsInsights(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/boards/insights handleTeamBoardsInsights
|
||||
//
|
||||
// Returns team boards insights
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: time_range
|
||||
// in: query
|
||||
// description: duration of data to calculate insights for
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page offset for top boards
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: per_page
|
||||
// in: query
|
||||
// description: limit for boards in a page.
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/BoardInsight"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
userID := getUserID(r)
|
||||
query := r.URL.Query()
|
||||
timeRange := query.Get("time_range")
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "Access denied to team", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getTeamBoardsInsights", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
|
||||
page, err := strconv.Atoi(query.Get("page"))
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "error converting page parameter to integer", err)
|
||||
return
|
||||
}
|
||||
if page < 0 {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Invalid page parameter", nil)
|
||||
}
|
||||
|
||||
perPage, err := strconv.Atoi(query.Get("per_page"))
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "error converting per_page parameter to integer", err)
|
||||
return
|
||||
}
|
||||
if perPage < 0 {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Invalid page parameter", nil)
|
||||
}
|
||||
|
||||
userTimezone, aErr := a.app.GetUserTimezone(userID)
|
||||
if aErr != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Error getting time zone of user", aErr)
|
||||
return
|
||||
}
|
||||
userLocation, _ := time.LoadLocation(userTimezone)
|
||||
if userLocation == nil {
|
||||
userLocation = time.Now().UTC().Location()
|
||||
}
|
||||
// get unix time for duration
|
||||
startTime := mmModel.StartOfDayForTimeRange(timeRange, userLocation)
|
||||
boardsInsights, err := a.app.GetTeamBoardsInsights(userID, teamID, &mmModel.InsightsOpts{
|
||||
StartUnixMilli: mmModel.GetMillisForTime(*startTime),
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "time_range="+timeRange, err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(boardsInsights)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("teamBoardsInsightCount", len(boardsInsights.Items))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUserBoardsInsights(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /users/me/boards/insights getUserBoardsInsights
|
||||
//
|
||||
// Returns user boards insights
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: time_range
|
||||
// in: query
|
||||
// description: duration of data to calculate insights for
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page offset for top boards
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: per_page
|
||||
// in: query
|
||||
// description: limit for boards in a page.
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/BoardInsight"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
userID := getUserID(r)
|
||||
query := r.URL.Query()
|
||||
teamID := query.Get("team_id")
|
||||
timeRange := query.Get("time_range")
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "Access denied to team", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getUserBoardsInsights", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
page, err := strconv.Atoi(query.Get("page"))
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "error converting page parameter to integer", err)
|
||||
return
|
||||
}
|
||||
|
||||
if page < 0 {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Invalid page parameter", nil)
|
||||
}
|
||||
perPage, err := strconv.Atoi(query.Get("per_page"))
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "error converting per_page parameter to integer", err)
|
||||
return
|
||||
}
|
||||
|
||||
if perPage < 0 {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Invalid page parameter", nil)
|
||||
}
|
||||
userTimezone, aErr := a.app.GetUserTimezone(userID)
|
||||
if aErr != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "Error getting time zone of user", aErr)
|
||||
return
|
||||
}
|
||||
userLocation, _ := time.LoadLocation(userTimezone)
|
||||
if userLocation == nil {
|
||||
userLocation = time.Now().UTC().Location()
|
||||
}
|
||||
// get unix time for duration
|
||||
startTime := mmModel.StartOfDayForTimeRange(timeRange, userLocation)
|
||||
boardsInsights, err := a.app.GetUserBoardsInsights(userID, teamID, &mmModel.InsightsOpts{
|
||||
StartUnixMilli: mmModel.GetMillisForTime(*startTime),
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "time_range="+timeRange, err)
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(boardsInsights)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("userBoardInsightCount", len(boardsInsights.Items))
|
||||
auditRec.Success()
|
||||
}
|
80
server/api/limits.go
Normal file
80
server/api/limits.go
Normal file
@ -0,0 +1,80 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (a *API) registerLimitsRoutes(r *mux.Router) {
|
||||
// limits
|
||||
r.HandleFunc("/limits", a.sessionRequired(a.handleCloudLimits)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/notifyadminupgrade", a.sessionRequired(a.handleNotifyAdminUpgrade)).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
func (a *API) handleCloudLimits(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /limits cloudLimits
|
||||
//
|
||||
// Fetches the cloud limits of the server.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardsCloudLimits"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardsCloudLimits, err := a.app.GetBoardsCloudLimits()
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(boardsCloudLimits)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (a *API) handleNotifyAdminUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /api/v2/teams/{teamID}/notifyadminupgrade handleNotifyAdminUpgrade
|
||||
//
|
||||
// Notifies admins for upgrade request.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", errAPINotSupportedInStandaloneMode)
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
|
||||
if err := a.app.NotifyPortalAdminsUpgradeRequest(teamID); err != nil {
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
}
|
||||
}
|
535
server/api/members.go
Normal file
535
server/api/members.go
Normal file
@ -0,0 +1,535 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/app"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerMembersRoutes(r *mux.Router) {
|
||||
// Member APIs
|
||||
r.HandleFunc("/boards/{boardID}/members", a.sessionRequired(a.handleGetMembersForBoard)).Methods("GET")
|
||||
r.HandleFunc("/boards/{boardID}/members", a.sessionRequired(a.handleAddMember)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/members/{userID}", a.sessionRequired(a.handleUpdateMember)).Methods("PUT")
|
||||
r.HandleFunc("/boards/{boardID}/members/{userID}", a.sessionRequired(a.handleDeleteMember)).Methods("DELETE")
|
||||
r.HandleFunc("/boards/{boardID}/join", a.sessionRequired(a.handleJoinBoard)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/leave", a.sessionRequired(a.handleLeaveBoard)).Methods("POST")
|
||||
}
|
||||
|
||||
func (a *API) handleGetMembersForBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID}/members getMembersForBoard
|
||||
//
|
||||
// Returns the members of the board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/BoardMember"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to board members"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getMembersForBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
members, err := a.app.GetMembersForBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("GetMembersForBoard",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.Int("membersCount", len(members)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleAddMember(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/members addMember
|
||||
//
|
||||
// Adds a new member to a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: membership to replace the current one with
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardMember"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardMember'
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardRoles) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modify board members"})
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var reqBoardMember *model.BoardMember
|
||||
if err = json.Unmarshal(requestBody, &reqBoardMember); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if reqBoardMember.UserID == "" {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// currently all memberships are created as editors by default
|
||||
newBoardMember := &model.BoardMember{
|
||||
UserID: reqBoardMember.UserID,
|
||||
BoardID: boardID,
|
||||
SchemeEditor: true,
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "addMember", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("addedUserID", reqBoardMember.UserID)
|
||||
|
||||
member, err := a.app.AddMemberToBoard(newBoardMember)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("AddMember",
|
||||
mlog.String("boardID", board.ID),
|
||||
mlog.String("addedUserID", reqBoardMember.UserID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(member)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleJoinBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/join joinBoard
|
||||
//
|
||||
// Become a member of a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardMember'
|
||||
// '404':
|
||||
// description: board not found
|
||||
// '403':
|
||||
// description: access denied
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
if userID == "" {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
if board.Type != model.BoardTypeOpen {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, board.TeamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
newBoardMember := &model.BoardMember{
|
||||
UserID: userID,
|
||||
BoardID: boardID,
|
||||
SchemeAdmin: board.MinimumRole == model.BoardRoleAdmin,
|
||||
SchemeEditor: board.MinimumRole == model.BoardRoleNone || board.MinimumRole == model.BoardRoleEditor,
|
||||
SchemeCommenter: board.MinimumRole == model.BoardRoleCommenter,
|
||||
SchemeViewer: board.MinimumRole == model.BoardRoleViewer,
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "joinBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("addedUserID", userID)
|
||||
|
||||
member, err := a.app.AddMemberToBoard(newBoardMember)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("JoinBoard",
|
||||
mlog.String("boardID", board.ID),
|
||||
mlog.String("addedUserID", userID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(member)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleLeaveBoard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/leave leaveBoard
|
||||
//
|
||||
// Remove your own membership from a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: board not found
|
||||
// '403':
|
||||
// description: access denied
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
if userID == "" {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionViewBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "leaveBoard", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("addedUserID", userID)
|
||||
|
||||
err = a.app.DeleteBoardMember(boardID, userID)
|
||||
if errors.Is(err, app.ErrBoardMemberIsLastAdmin) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("LeaveBoard",
|
||||
mlog.String("boardID", board.ID),
|
||||
mlog.String("addedUserID", userID),
|
||||
)
|
||||
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUpdateMember(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PUT /boards/{boardID}/members/{userID} updateMember
|
||||
//
|
||||
// Updates a board member
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: userID
|
||||
// in: path
|
||||
// description: User ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: membership to replace the current one with
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/BoardMember"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// $ref: '#/definitions/BoardMember'
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
paramsUserID := mux.Vars(r)["userID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var reqBoardMember *model.BoardMember
|
||||
if err = json.Unmarshal(requestBody, &reqBoardMember); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
newBoardMember := &model.BoardMember{
|
||||
UserID: paramsUserID,
|
||||
BoardID: boardID,
|
||||
SchemeAdmin: reqBoardMember.SchemeAdmin,
|
||||
SchemeEditor: reqBoardMember.SchemeEditor,
|
||||
SchemeCommenter: reqBoardMember.SchemeCommenter,
|
||||
SchemeViewer: reqBoardMember.SchemeViewer,
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardRoles) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modify board members"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "patchMember", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("patchedUserID", paramsUserID)
|
||||
|
||||
member, err := a.app.UpdateBoardMember(newBoardMember)
|
||||
if errors.Is(err, app.ErrBoardMemberIsLastAdmin) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("PatchMember",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("patchedUserID", paramsUserID),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(member)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteMember(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /boards/{boardID}/members/{userID} deleteMember
|
||||
//
|
||||
// Deletes a member from a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: userID
|
||||
// in: path
|
||||
// description: User ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
paramsUserID := mux.Vars(r)["userID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
board, err := a.app.GetBoard(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if board == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardRoles) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to modify board members"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteMember", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
auditRec.AddMeta("addedUserID", paramsUserID)
|
||||
|
||||
deleteErr := a.app.DeleteBoardMember(boardID, paramsUserID)
|
||||
if errors.Is(deleteErr, app.ErrBoardMemberIsLastAdmin) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", deleteErr)
|
||||
return
|
||||
}
|
||||
if deleteErr != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", deleteErr)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("DeleteMember",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("addedUserID", paramsUserID),
|
||||
)
|
||||
|
||||
// response
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
73
server/api/onboarding.go
Normal file
73
server/api/onboarding.go
Normal file
@ -0,0 +1,73 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
)
|
||||
|
||||
func (a *API) registerOnboardingRoutes(r *mux.Router) {
|
||||
// Onboarding tour endpoints APIs
|
||||
r.HandleFunc("/teams/{teamID}/onboard", a.sessionRequired(a.handleOnboard)).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
func (a *API) handleOnboard(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /team/{teamID}/onboard onboard
|
||||
//
|
||||
// Onboards a user on Boards.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: object
|
||||
// properties:
|
||||
// teamID:
|
||||
// type: string
|
||||
// description: Team ID
|
||||
// boardID:
|
||||
// type: string
|
||||
// description: Board ID
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to create board"})
|
||||
return
|
||||
}
|
||||
|
||||
teamID, boardID, err := a.app.PrepareOnboardingTour(userID, teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
response := map[string]string{
|
||||
"teamID": teamID,
|
||||
"boardID": boardID,
|
||||
}
|
||||
data, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
}
|
324
server/api/search.go
Normal file
324
server/api/search.go
Normal file
@ -0,0 +1,324 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerSearchRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/teams/{teamID}/channels", a.sessionRequired(a.handleSearchMyChannels)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/boards/search", a.sessionRequired(a.handleSearchBoards)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/boards/search/linkable", a.sessionRequired(a.handleSearchLinkableBoards)).Methods("GET")
|
||||
r.HandleFunc("/boards/search", a.sessionRequired(a.handleSearchAllBoards)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleSearchMyChannels(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/channels searchMyChannels
|
||||
//
|
||||
// Returns the user available channels
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: search
|
||||
// in: query
|
||||
// description: string to filter channels list
|
||||
// required: false
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Channel"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
query := r.URL.Query()
|
||||
searchQuery := query.Get("search")
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "searchMyChannels", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
|
||||
channels, err := a.app.SearchUserChannels(teamID, userID, searchQuery)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("GetUserChannels",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.Int("channelsCount", len(channels)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(channels)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("channelsCount", len(channels))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleSearchBoards(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/boards/search searchBoards
|
||||
//
|
||||
// Returns the boards that match with a search term in the team
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: q
|
||||
// in: query
|
||||
// description: The search term. Must have at least one character
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
term := r.URL.Query().Get("q")
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
if len(term) == 0 {
|
||||
jsonStringResponse(w, http.StatusOK, "[]")
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "searchBoards", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
|
||||
// retrieve boards list
|
||||
boards, err := a.app.SearchBoardsForUserInTeam(teamID, term, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("SearchBoards",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.Int("boardsCount", len(boards)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(boards)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("boardsCount", len(boards))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleSearchLinkableBoards(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/boards/search/linkable searchLinkableBoards
|
||||
//
|
||||
// Returns the boards that match with a search term in the team and the
|
||||
// user has permission to manage members
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: q
|
||||
// in: query
|
||||
// description: The search term. Must have at least one character
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
if !a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
term := r.URL.Query().Get("q")
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
if len(term) == 0 {
|
||||
jsonStringResponse(w, http.StatusOK, "[]")
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "searchLinkableBoards", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
|
||||
// retrieve boards list
|
||||
boards, err := a.app.SearchBoardsForUserInTeam(teamID, term, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
linkableBoards := []*model.Board{}
|
||||
for _, board := range boards {
|
||||
if a.permissions.HasPermissionToBoard(userID, board.ID, model.PermissionManageBoardRoles) {
|
||||
linkableBoards = append(linkableBoards, board)
|
||||
}
|
||||
}
|
||||
|
||||
a.logger.Debug("SearchLinkableBoards",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.Int("boardsCount", len(linkableBoards)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(linkableBoards)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("boardsCount", len(linkableBoards))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleSearchAllBoards(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/search searchBoards
|
||||
//
|
||||
// Returns the boards that match with a search term
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: q
|
||||
// in: query
|
||||
// description: The search term. Must have at least one character
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
term := r.URL.Query().Get("q")
|
||||
userID := getUserID(r)
|
||||
|
||||
if len(term) == 0 {
|
||||
jsonStringResponse(w, http.StatusOK, "[]")
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "searchAllBoards", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
|
||||
// retrieve boards list
|
||||
boards, err := a.app.SearchBoardsForUser(term, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("SearchAllBoards",
|
||||
mlog.Int("boardsCount", len(boards)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(boards)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("boardsCount", len(boards))
|
||||
auditRec.Success()
|
||||
}
|
181
server/api/sharing.go
Normal file
181
server/api/sharing.go
Normal file
@ -0,0 +1,181 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerSharingRoutes(r *mux.Router) {
|
||||
// Sharing APIs
|
||||
r.HandleFunc("/boards/{boardID}/sharing", a.sessionRequired(a.handlePostSharing)).Methods("POST")
|
||||
r.HandleFunc("/boards/{boardID}/sharing", a.sessionRequired(a.handleGetSharing)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleGetSharing(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /boards/{boardID}/sharing getSharing
|
||||
//
|
||||
// Returns sharing information for a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Sharing"
|
||||
// '404':
|
||||
// description: board not found
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
boardID := vars["boardID"]
|
||||
|
||||
userID := getUserID(r)
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionShareBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to sharing the board"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getSharing", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("boardID", boardID)
|
||||
|
||||
sharing, err := a.app.GetSharing(boardID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
if sharing == nil {
|
||||
jsonStringResponse(w, http.StatusOK, "")
|
||||
return
|
||||
}
|
||||
|
||||
sharingData, err := json.Marshal(sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, sharingData)
|
||||
|
||||
a.logger.Debug("GET sharing",
|
||||
mlog.String("boardID", boardID),
|
||||
mlog.String("shareID", sharing.ID),
|
||||
mlog.Bool("enabled", sharing.Enabled),
|
||||
)
|
||||
auditRec.AddMeta("shareID", sharing.ID)
|
||||
auditRec.AddMeta("enabled", sharing.Enabled)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePostSharing(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /boards/{boardID}/sharing postSharing
|
||||
//
|
||||
// Sets sharing information for a board
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: boardID
|
||||
// in: path
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: sharing information for a root block
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Sharing"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
|
||||
userID := getUserID(r)
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionShareBoard) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to sharing the board"})
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var sharing model.Sharing
|
||||
err = json.Unmarshal(requestBody, &sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Stamp boardID from the URL
|
||||
sharing.ID = boardID
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "postSharing", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("shareID", sharing.ID)
|
||||
auditRec.AddMeta("enabled", sharing.Enabled)
|
||||
|
||||
// Stamp ModifiedBy
|
||||
modifiedBy := userID
|
||||
if userID == model.SingleUser {
|
||||
modifiedBy = ""
|
||||
}
|
||||
sharing.ModifiedBy = modifiedBy
|
||||
|
||||
if userID == model.SingleUser {
|
||||
userID = ""
|
||||
}
|
||||
|
||||
if !a.app.GetClientConfig().EnablePublicSharedBoards {
|
||||
a.logger.Warn(
|
||||
"Attempt to turn on sharing for board via API failed, sharing off in configuration.",
|
||||
mlog.String("boardID", sharing.ID),
|
||||
mlog.String("userID", userID))
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "Turning on sharing for board failed, see log for details.", nil)
|
||||
return
|
||||
}
|
||||
|
||||
sharing.ModifiedBy = userID
|
||||
|
||||
err = a.app.UpsertSharing(sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
a.logger.Debug("POST sharing", mlog.String("sharingID", sharing.ID))
|
||||
auditRec.Success()
|
||||
}
|
236
server/api/subscriptions.go
Normal file
236
server/api/subscriptions.go
Normal file
@ -0,0 +1,236 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerSubscriptionsRoutes(r *mux.Router) {
|
||||
// Subscription APIs
|
||||
r.HandleFunc("/subscriptions", a.sessionRequired(a.handleCreateSubscription)).Methods("POST")
|
||||
r.HandleFunc("/subscriptions/{blockID}/{subscriberID}", a.sessionRequired(a.handleDeleteSubscription)).Methods("DELETE")
|
||||
r.HandleFunc("/subscriptions/{subscriberID}", a.sessionRequired(a.handleGetSubscriptions)).Methods("GET")
|
||||
}
|
||||
|
||||
// subscriptions
|
||||
|
||||
func (a *API) handleCreateSubscription(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /subscriptions createSubscription
|
||||
//
|
||||
// Creates a subscription to a block for a user. The user will receive change notifications for the block.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: subscription definition
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Subscription"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var sub model.Subscription
|
||||
|
||||
err = json.Unmarshal(requestBody, &sub)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = sub.IsValid(); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "createSubscription", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("subscriber_id", sub.SubscriberID)
|
||||
auditRec.AddMeta("block_id", sub.BlockID)
|
||||
|
||||
// User can only create subscriptions for themselves (for now)
|
||||
if session.UserID != sub.SubscriberID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "userID and subscriberID mismatch", nil)
|
||||
return
|
||||
}
|
||||
|
||||
// check for valid block
|
||||
block, err := a.app.GetBlockByID(sub.BlockID)
|
||||
if err != nil || block == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "invalid blockID", err)
|
||||
return
|
||||
}
|
||||
|
||||
subNew, err := a.app.CreateSubscription(&sub)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("CREATE subscription",
|
||||
mlog.String("subscriber_id", subNew.SubscriberID),
|
||||
mlog.String("block_id", subNew.BlockID),
|
||||
)
|
||||
|
||||
json, err := json.Marshal(subNew)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, json)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteSubscription(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation DELETE /subscriptions/{blockID}/{subscriberID} deleteSubscription
|
||||
//
|
||||
// Deletes a subscription a user has for a a block. The user will no longer receive change notifications for the block.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: blockID
|
||||
// in: path
|
||||
// description: Block ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: subscriberID
|
||||
// in: path
|
||||
// description: Subscriber ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
vars := mux.Vars(r)
|
||||
blockID := vars["blockID"]
|
||||
subscriberID := vars["subscriberID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "deleteSubscription", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("block_id", blockID)
|
||||
auditRec.AddMeta("subscriber_id", subscriberID)
|
||||
|
||||
// User can only delete subscriptions for themselves
|
||||
if session.UserID != subscriberID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "access denied", nil)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := a.app.DeleteSubscription(blockID, subscriberID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("DELETE subscription",
|
||||
mlog.String("blockID", blockID),
|
||||
mlog.String("subscriberID", subscriberID),
|
||||
)
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetSubscriptions(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /subscriptions/{subscriberID} getSubscriptions
|
||||
//
|
||||
// Gets subscriptions for a user.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: subscriberID
|
||||
// in: path
|
||||
// description: Subscriber ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
vars := mux.Vars(r)
|
||||
subscriberID := vars["subscriberID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getSubscriptions", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("subscriber_id", subscriberID)
|
||||
|
||||
// User can only get subscriptions for themselves (for now)
|
||||
if session.UserID != subscriberID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "access denied", nil)
|
||||
return
|
||||
}
|
||||
|
||||
subs, err := a.app.GetSubscriptions(subscriberID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("GET subscriptions",
|
||||
mlog.String("subscriberID", subscriberID),
|
||||
mlog.Int("count", len(subs)),
|
||||
)
|
||||
|
||||
json, err := json.Marshal(subs)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
jsonBytesResponse(w, http.StatusOK, json)
|
||||
|
||||
auditRec.AddMeta("subscription_count", len(subs))
|
||||
auditRec.Success()
|
||||
}
|
26
server/api/system.go
Normal file
26
server/api/system.go
Normal file
@ -0,0 +1,26 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (a *API) registerSystemRoutes(r *mux.Router) {
|
||||
// System APIs
|
||||
r.HandleFunc("/hello", a.handleHello).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleHello(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /hello hello
|
||||
//
|
||||
// Responds with `Hello` if the web service is running.
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - text/plain
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
stringResponse(w, "Hello")
|
||||
}
|
245
server/api/teams.go
Normal file
245
server/api/teams.go
Normal file
@ -0,0 +1,245 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
"github.com/mattermost/focalboard/server/utils"
|
||||
)
|
||||
|
||||
func (a *API) registerTeamsRoutes(r *mux.Router) {
|
||||
// Team APIs
|
||||
r.HandleFunc("/teams", a.sessionRequired(a.handleGetTeams)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}", a.sessionRequired(a.handleGetTeam)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/users", a.sessionRequired(a.handleGetTeamUsers)).Methods("GET")
|
||||
r.HandleFunc("/teams/{teamID}/archive/export", a.sessionRequired(a.handleArchiveExportTeam)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleGetTeams(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams getTeams
|
||||
//
|
||||
// Returns information of all the teams
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Team"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
teams, err := a.app.GetTeamsForUser(userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getTeams", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamCount", len(teams))
|
||||
|
||||
data, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetTeam(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID} getTeam
|
||||
//
|
||||
// Returns information of the root team
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/Team"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
var err error
|
||||
|
||||
if a.MattermostAuth {
|
||||
team, err = a.app.GetTeam(teamID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
if team == nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "invalid team", nil)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
team, err = a.app.GetRootTeam()
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getTeam", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("resultTeamID", team.ID)
|
||||
|
||||
data, err := json.Marshal(team)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handlePostTeamRegenerateSignupToken(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /teams/{teamID}/regenerate_signup_token regenerateSignupToken
|
||||
//
|
||||
// Regenerates the signup token for the root team
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
if a.MattermostAuth {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in plugin mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
team, err := a.app.GetRootTeam()
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "regenerateSignupToken", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
team.SignupToken = utils.NewID(utils.IDTypeToken)
|
||||
|
||||
err = a.app.UpsertTeamSignupToken(*team)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonStringResponse(w, http.StatusOK, "{}")
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetTeamUsers(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/users getTeamUsers
|
||||
//
|
||||
// Returns team users
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: search
|
||||
// in: query
|
||||
// description: string to filter users list
|
||||
// required: false
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
teamID := vars["teamID"]
|
||||
userID := getUserID(r)
|
||||
query := r.URL.Query()
|
||||
searchQuery := query.Get("search")
|
||||
|
||||
if !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "Access denied to team", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getUsers", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
|
||||
users, err := a.app.SearchTeamUsers(teamID, searchQuery)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "searchQuery="+searchQuery, err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("userCount", len(users))
|
||||
auditRec.Success()
|
||||
}
|
90
server/api/templates.go
Normal file
90
server/api/templates.go
Normal file
@ -0,0 +1,90 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *API) registerTemplatesRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/teams/{teamID}/templates", a.sessionRequired(a.handleGetTemplates)).Methods("GET")
|
||||
}
|
||||
|
||||
func (a *API) handleGetTemplates(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /teams/{teamID}/templates getTemplates
|
||||
//
|
||||
// Returns team templates
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: teamID
|
||||
// in: path
|
||||
// description: Team ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Board"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
teamID := mux.Vars(r)["teamID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
if teamID != model.GlobalTeamID && !a.permissions.HasPermissionToTeam(userID, teamID, model.PermissionViewTeam) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", PermissionError{"access denied to team"})
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getTemplates", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("teamID", teamID)
|
||||
|
||||
// retrieve boards list
|
||||
boards, err := a.app.GetTemplateBoards(teamID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
results := []*model.Board{}
|
||||
for _, board := range boards {
|
||||
if board.Type == model.BoardTypeOpen {
|
||||
results = append(results, board)
|
||||
} else if a.permissions.HasPermissionToBoard(userID, board.ID, model.PermissionViewBoard) {
|
||||
results = append(results, board)
|
||||
}
|
||||
}
|
||||
|
||||
a.logger.Debug("GetTemplates",
|
||||
mlog.String("teamID", teamID),
|
||||
mlog.Int("boardsCount", len(results)),
|
||||
)
|
||||
|
||||
data, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
// response
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
|
||||
auditRec.AddMeta("templatesCount", len(results))
|
||||
auditRec.Success()
|
||||
}
|
304
server/api/users.go
Normal file
304
server/api/users.go
Normal file
@ -0,0 +1,304 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/audit"
|
||||
"github.com/mattermost/focalboard/server/utils"
|
||||
)
|
||||
|
||||
func (a *API) registerUsersRoutes(r *mux.Router) {
|
||||
// Users APIs
|
||||
r.HandleFunc("/users", a.sessionRequired(a.handleGetUsersList)).Methods("POST")
|
||||
r.HandleFunc("/users/me", a.sessionRequired(a.handleGetMe)).Methods("GET")
|
||||
r.HandleFunc("/users/me/memberships", a.sessionRequired(a.handleGetMyMemberships)).Methods("GET")
|
||||
r.HandleFunc("/users/{userID}", a.sessionRequired(a.handleGetUser)).Methods("GET")
|
||||
r.HandleFunc("/users/{userID}/config", a.sessionRequired(a.handleUpdateUserConfig)).Methods(http.MethodPut)
|
||||
}
|
||||
|
||||
func (a *API) handleGetUsersList(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /users getUser
|
||||
//
|
||||
// Returns a user[]
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: userID
|
||||
// in: path
|
||||
// description: User ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var userIDs []string
|
||||
if err = json.Unmarshal(requestBody, &userIDs); err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getUsersList", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
||||
|
||||
users, err := a.app.GetUsersList(userIDs)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
usersList, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonStringResponse(w, http.StatusOK, string(usersList))
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /users/me getMe
|
||||
//
|
||||
// Returns the currently logged-in user
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
var user *model.User
|
||||
var err error
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getMe", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
|
||||
if userID == model.SingleUser {
|
||||
ws, _ := a.app.GetRootTeam()
|
||||
now := utils.GetMillis()
|
||||
user = &model.User{
|
||||
ID: model.SingleUser,
|
||||
Username: model.SingleUser,
|
||||
Email: model.SingleUser,
|
||||
CreateAt: ws.UpdateAt,
|
||||
UpdateAt: now,
|
||||
Props: map[string]interface{}{},
|
||||
}
|
||||
} else {
|
||||
user, err = a.app.GetUser(userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
userData, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
jsonBytesResponse(w, http.StatusOK, userData)
|
||||
|
||||
auditRec.AddMeta("userID", user.ID)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetMyMemberships(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /users/me/memberships getMyMemberships
|
||||
//
|
||||
// Returns the currently users board memberships
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/BoardMember"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
userID := getUserID(r)
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "getMyBoardMemberships", audit.Fail)
|
||||
auditRec.AddMeta("userID", userID)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
|
||||
members, err := a.app.GetMembersForUser(userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
membersData, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, membersData)
|
||||
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleGetUser(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /users/{userID} getUser
|
||||
//
|
||||
// Returns a user
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: userID
|
||||
// in: path
|
||||
// description: User ID
|
||||
// required: true
|
||||
// type: string
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// schema:
|
||||
// "$ref": "#/definitions/User"
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
vars := mux.Vars(r)
|
||||
userID := vars["userID"]
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "postBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||
auditRec.AddMeta("userID", userID)
|
||||
|
||||
user, err := a.app.GetUser(userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
userData, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, userData)
|
||||
auditRec.Success()
|
||||
}
|
||||
|
||||
func (a *API) handleUpdateUserConfig(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation PATCH /users/{userID}/config updateUserConfig
|
||||
//
|
||||
// Updates user config
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: userID
|
||||
// in: path
|
||||
// description: User ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: User config patch to apply
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/UserPropPatch"
|
||||
// security:
|
||||
// - BearerAuth: []
|
||||
// responses:
|
||||
// '200':
|
||||
// description: success
|
||||
// default:
|
||||
// description: internal error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ErrorResponse"
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var patch *model.UserPropPatch
|
||||
err = json.Unmarshal(requestBody, &patch)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
userID := vars["userID"]
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "updateUserConfig", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
|
||||
// a user can update only own config
|
||||
if userID != session.UserID {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "", nil)
|
||||
return
|
||||
}
|
||||
|
||||
updatedConfig, err := a.app.UpdateUserConfig(userID, *patch)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(updatedConfig)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytesResponse(w, http.StatusOK, data)
|
||||
auditRec.Success()
|
||||
}
|
@ -64,6 +64,18 @@ func (a *App) GetUser(id string) (*model.User, error) {
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (a *App) GetUsersList(userIDs []string) ([]*model.User, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return nil, errors.New("No User IDs")
|
||||
}
|
||||
|
||||
users, err := a.store.GetUsersList(userIDs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to find users")
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
// Login create a new user session if the authentication data is valid.
|
||||
func (a *App) Login(username, email, password, mfaToken string) (string, error) {
|
||||
var user *model.User
|
||||
|
@ -65,10 +65,6 @@ func (a *App) DuplicateBlock(boardID string, blockID string, userID string, asTe
|
||||
return blocks, err
|
||||
}
|
||||
|
||||
func (a *App) GetBlocksWithBoardID(boardID string) ([]model.Block, error) {
|
||||
return a.store.GetBlocksWithBoardID(boardID)
|
||||
}
|
||||
|
||||
func (a *App) PatchBlock(blockID string, blockPatch *model.BlockPatch, modifiedByID string) error {
|
||||
oldBlock, err := a.store.GetBlock(blockID)
|
||||
if err != nil {
|
||||
|
@ -145,6 +145,36 @@ func (a *App) getBoardDescendantModifiedInfo(boardID string, latest bool) (int64
|
||||
return timestamp, modifiedBy, nil
|
||||
}
|
||||
|
||||
func (a *App) setBoardCategoryFromSource(sourceBoardID, destinationBoardID, userID, teamID string) error {
|
||||
// find source board's category ID for the user
|
||||
userCategoryBoards, err := a.GetUserCategoryBoards(userID, teamID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var destinationCategoryID string
|
||||
|
||||
for _, categoryBoard := range userCategoryBoards {
|
||||
for _, boardID := range categoryBoard.BoardIDs {
|
||||
if boardID == sourceBoardID {
|
||||
// category found!
|
||||
destinationCategoryID = categoryBoard.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if source board is not mapped to a category for this user,
|
||||
// then we have nothing more to do.
|
||||
if destinationCategoryID == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// now that we have source board's category,
|
||||
// we send destination board to the same category
|
||||
return a.AddUpdateUserCategoryBoard(teamID, userID, destinationCategoryID, destinationBoardID)
|
||||
}
|
||||
|
||||
func (a *App) DuplicateBoard(boardID, userID, toTeam string, asTemplate bool) (*model.BoardsAndBlocks, []*model.BoardMember, error) {
|
||||
bab, members, err := a.store.DuplicateBoard(boardID, userID, toTeam, asTemplate)
|
||||
if err != nil {
|
||||
@ -156,6 +186,12 @@ func (a *App) DuplicateBoard(boardID, userID, toTeam string, asTemplate bool) (*
|
||||
a.logger.Error("Could not copy files while duplicating board", mlog.String("BoardID", boardID), mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, board := range bab.Boards {
|
||||
if categoryErr := a.setBoardCategoryFromSource(boardID, board.ID, userID, board.TeamID); categoryErr != nil {
|
||||
return nil, nil, categoryErr
|
||||
}
|
||||
}
|
||||
|
||||
// bab.Blocks now has updated file ids for any blocks containing files. We need to store them.
|
||||
blockIDs := make([]string, 0)
|
||||
blockPatches := make([]model.BlockPatch, 0)
|
||||
@ -247,7 +283,15 @@ func (a *App) CreateBoard(board *model.Board, userID string, addMember bool) (*m
|
||||
a.blockChangeNotifier.Enqueue(func() error {
|
||||
a.wsAdapter.BroadcastBoardChange(newBoard.TeamID, newBoard)
|
||||
|
||||
if addMember {
|
||||
if newBoard.ChannelID != "" {
|
||||
members, err := a.GetMembersForBoard(board.ID)
|
||||
if err != nil {
|
||||
a.logger.Error("Unable to get the board members", mlog.Err(err))
|
||||
}
|
||||
for _, member := range members {
|
||||
a.wsAdapter.BroadcastMemberChange(newBoard.TeamID, member.BoardID, member)
|
||||
}
|
||||
} else if addMember {
|
||||
a.wsAdapter.BroadcastMemberChange(newBoard.TeamID, newBoard.ID, member)
|
||||
}
|
||||
return nil
|
||||
@ -257,6 +301,14 @@ func (a *App) CreateBoard(board *model.Board, userID string, addMember bool) (*m
|
||||
}
|
||||
|
||||
func (a *App) PatchBoard(patch *model.BoardPatch, boardID, userID string) (*model.Board, error) {
|
||||
var oldMembers []*model.BoardMember
|
||||
if patch.ChannelID != nil && *patch.ChannelID == "" {
|
||||
var err error
|
||||
oldMembers, err = a.GetMembersForBoard(boardID)
|
||||
if err != nil {
|
||||
a.logger.Error("Unable to get the board members", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
updatedBoard, err := a.store.PatchBoard(boardID, patch, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -264,6 +316,23 @@ func (a *App) PatchBoard(patch *model.BoardPatch, boardID, userID string) (*mode
|
||||
|
||||
a.blockChangeNotifier.Enqueue(func() error {
|
||||
a.wsAdapter.BroadcastBoardChange(updatedBoard.TeamID, updatedBoard)
|
||||
if patch.ChannelID != nil && *patch.ChannelID != "" {
|
||||
members, err := a.GetMembersForBoard(updatedBoard.ID)
|
||||
if err != nil {
|
||||
a.logger.Error("Unable to get the board members", mlog.Err(err))
|
||||
}
|
||||
for _, member := range members {
|
||||
if member.Synthetic {
|
||||
a.wsAdapter.BroadcastMemberChange(updatedBoard.TeamID, member.BoardID, member)
|
||||
}
|
||||
}
|
||||
} else if patch.ChannelID != nil && *patch.ChannelID == "" {
|
||||
for _, oldMember := range oldMembers {
|
||||
if oldMember.Synthetic {
|
||||
a.wsAdapter.BroadcastMemberDelete(updatedBoard.TeamID, boardID, oldMember.UserID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -326,7 +395,7 @@ func (a *App) AddMemberToBoard(member *model.BoardMember) (*model.BoardMember, e
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if existingMembership != nil {
|
||||
if existingMembership != nil && !existingMembership.Synthetic {
|
||||
return existingMembership, nil
|
||||
}
|
||||
|
||||
@ -433,7 +502,11 @@ func (a *App) DeleteBoardMember(boardID, userID string) error {
|
||||
}
|
||||
|
||||
a.blockChangeNotifier.Enqueue(func() error {
|
||||
a.wsAdapter.BroadcastMemberDelete(board.TeamID, boardID, userID)
|
||||
if synteticMember, _ := a.store.GetMemberForBoard(boardID, userID); synteticMember != nil {
|
||||
a.wsAdapter.BroadcastMemberChange(board.TeamID, boardID, synteticMember)
|
||||
} else {
|
||||
a.wsAdapter.BroadcastMemberDelete(board.TeamID, boardID, userID)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
107
server/app/boards_test.go
Normal file
107
server/app/boards_test.go
Normal file
@ -0,0 +1,107 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddMemberToBoard(t *testing.T) {
|
||||
th, tearDown := SetupTestHelper(t)
|
||||
defer tearDown()
|
||||
|
||||
t.Run("base case", func(t *testing.T) {
|
||||
const boardID = "board_id_1"
|
||||
const userID = "user_id_1"
|
||||
|
||||
boardMember := &model.BoardMember{
|
||||
BoardID: boardID,
|
||||
UserID: userID,
|
||||
SchemeEditor: true,
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetBoard(boardID).Return(&model.Board{
|
||||
TeamID: "team_id_1",
|
||||
}, nil)
|
||||
|
||||
th.Store.EXPECT().GetMemberForBoard(boardID, userID).Return(nil, nil)
|
||||
|
||||
th.Store.EXPECT().SaveMember(mock.MatchedBy(func(i interface{}) bool {
|
||||
p := i.(*model.BoardMember)
|
||||
return p.BoardID == boardID && p.UserID == userID
|
||||
})).Return(&model.BoardMember{
|
||||
BoardID: boardID,
|
||||
}, nil)
|
||||
|
||||
// for WS change broadcast
|
||||
th.Store.EXPECT().GetMembersForBoard(boardID).Return([]*model.BoardMember{}, nil)
|
||||
|
||||
addedBoardMember, err := th.App.AddMemberToBoard(boardMember)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, boardID, addedBoardMember.BoardID)
|
||||
})
|
||||
|
||||
t.Run("return existing non-synthetic membership if any", func(t *testing.T) {
|
||||
const boardID = "board_id_1"
|
||||
const userID = "user_id_1"
|
||||
|
||||
boardMember := &model.BoardMember{
|
||||
BoardID: boardID,
|
||||
UserID: userID,
|
||||
SchemeEditor: true,
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetBoard(boardID).Return(&model.Board{
|
||||
TeamID: "team_id_1",
|
||||
}, nil)
|
||||
|
||||
th.Store.EXPECT().GetMemberForBoard(boardID, userID).Return(&model.BoardMember{
|
||||
UserID: userID,
|
||||
BoardID: boardID,
|
||||
Synthetic: false,
|
||||
}, nil)
|
||||
|
||||
addedBoardMember, err := th.App.AddMemberToBoard(boardMember)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, boardID, addedBoardMember.BoardID)
|
||||
})
|
||||
|
||||
t.Run("should convert synthetic membership into natural membership", func(t *testing.T) {
|
||||
const boardID = "board_id_1"
|
||||
const userID = "user_id_1"
|
||||
|
||||
boardMember := &model.BoardMember{
|
||||
BoardID: boardID,
|
||||
UserID: userID,
|
||||
SchemeEditor: true,
|
||||
}
|
||||
|
||||
th.Store.EXPECT().GetBoard(boardID).Return(&model.Board{
|
||||
TeamID: "team_id_1",
|
||||
}, nil)
|
||||
|
||||
th.Store.EXPECT().GetMemberForBoard(boardID, userID).Return(&model.BoardMember{
|
||||
UserID: userID,
|
||||
BoardID: boardID,
|
||||
Synthetic: true,
|
||||
}, nil)
|
||||
|
||||
th.Store.EXPECT().SaveMember(mock.MatchedBy(func(i interface{}) bool {
|
||||
p := i.(*model.BoardMember)
|
||||
return p.BoardID == boardID && p.UserID == userID
|
||||
})).Return(&model.BoardMember{
|
||||
UserID: userID,
|
||||
BoardID: boardID,
|
||||
Synthetic: false,
|
||||
}, nil)
|
||||
|
||||
// for WS change broadcast
|
||||
th.Store.EXPECT().GetMembersForBoard(boardID).Return([]*model.BoardMember{}, nil)
|
||||
|
||||
addedBoardMember, err := th.App.AddMemberToBoard(boardMember)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, boardID, addedBoardMember.BoardID)
|
||||
})
|
||||
}
|
@ -82,7 +82,7 @@ func (a *App) writeArchiveBoard(zw *zip.Writer, board model.Board, opt model.Exp
|
||||
var files []string
|
||||
// write the board's blocks
|
||||
// TODO: paginate this
|
||||
blocks, err := a.GetBlocksWithBoardID(board.ID)
|
||||
blocks, err := a.GetBlocksForBoard(board.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
78
server/app/insights.go
Normal file
78
server/app/insights.go
Normal file
@ -0,0 +1,78 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (a *App) GetTeamBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) {
|
||||
// check if server is properly licensed, and user is not a guest
|
||||
userPermitted, err := insightPermissionGate(a, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !userPermitted {
|
||||
return nil, errors.New("User isn't authorized to access insights.")
|
||||
}
|
||||
boardIDs, err := getUserBoards(userID, teamID, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.store.GetTeamBoardsInsights(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage, boardIDs)
|
||||
}
|
||||
|
||||
func (a *App) GetUserBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) {
|
||||
// check if server is properly licensed, and user is not a guest
|
||||
userPermitted, err := insightPermissionGate(a, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !userPermitted {
|
||||
return nil, errors.New("User isn't authorized to access insights.")
|
||||
}
|
||||
boardIDs, err := getUserBoards(userID, teamID, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.store.GetUserBoardsInsights(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage, boardIDs)
|
||||
}
|
||||
|
||||
func insightPermissionGate(a *App, userID string) (bool, error) {
|
||||
licenseError := errors.New("invalid license/authorization to use insights API")
|
||||
guestError := errors.New("guests aren't authorized to use insights API")
|
||||
lic := a.store.GetLicense()
|
||||
if lic == nil {
|
||||
a.logger.Debug("Deployment doesn't have a license")
|
||||
return false, licenseError
|
||||
}
|
||||
user, err := a.store.GetUserByID(userID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if lic.SkuShortName != mmModel.LicenseShortSkuProfessional && lic.SkuShortName != mmModel.LicenseShortSkuEnterprise {
|
||||
return false, licenseError
|
||||
}
|
||||
if user.IsGuest {
|
||||
return false, guestError
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *App) GetUserTimezone(userID string) (string, error) {
|
||||
return a.store.GetUserTimezone(userID)
|
||||
}
|
||||
|
||||
func getUserBoards(userID string, teamID string, a *App) ([]string, error) {
|
||||
// get boards accessible by user and filter boardIDs
|
||||
boards, err := a.store.GetBoardsForUserAndTeam(userID, teamID)
|
||||
if err != nil {
|
||||
return nil, errors.New("error getting boards for user")
|
||||
}
|
||||
boardIDs := make([]string, 0, len(boards))
|
||||
|
||||
for _, board := range boards {
|
||||
boardIDs = append(boardIDs, board.ID)
|
||||
}
|
||||
return boardIDs, nil
|
||||
}
|
89
server/app/insights_test.go
Normal file
89
server/app/insights_test.go
Normal file
@ -0,0 +1,89 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var mockInsightsBoards = []*model.Board{
|
||||
{
|
||||
ID: "mock-user-workspace-id",
|
||||
Title: "MockUserWorkspace",
|
||||
},
|
||||
}
|
||||
|
||||
var mockTeamInsights = []*model.BoardInsight{
|
||||
{
|
||||
BoardID: "board-id-1",
|
||||
},
|
||||
{
|
||||
BoardID: "board-id-2",
|
||||
},
|
||||
}
|
||||
|
||||
var mockTeamInsightsList = &model.BoardInsightsList{
|
||||
InsightsListData: mmModel.InsightsListData{HasNext: false},
|
||||
Items: mockTeamInsights,
|
||||
}
|
||||
|
||||
type insightError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (ie insightError) Error() string {
|
||||
return ie.msg
|
||||
}
|
||||
|
||||
func TestGetTeamAndUserBoardsInsights(t *testing.T) {
|
||||
th, tearDown := SetupTestHelper(t)
|
||||
defer tearDown()
|
||||
|
||||
t.Run("success query", func(t *testing.T) {
|
||||
fakeLicense := &mmModel.License{Features: &mmModel.Features{}, SkuShortName: mmModel.LicenseShortSkuEnterprise}
|
||||
th.Store.EXPECT().GetLicense().Return(fakeLicense).AnyTimes()
|
||||
fakeUser := &model.User{
|
||||
ID: "user-id",
|
||||
IsGuest: false,
|
||||
}
|
||||
th.Store.EXPECT().GetUserByID("user-id").Return(fakeUser, nil).AnyTimes()
|
||||
th.Store.EXPECT().GetBoardsForUserAndTeam("user-id", "team-id").Return(mockInsightsBoards, nil).AnyTimes()
|
||||
th.Store.EXPECT().
|
||||
GetTeamBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
|
||||
Return(mockTeamInsightsList, nil)
|
||||
results, err := th.App.GetTeamBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results.Items, 2)
|
||||
th.Store.EXPECT().
|
||||
GetUserBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
|
||||
Return(mockTeamInsightsList, nil)
|
||||
results, err = th.App.GetUserBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results.Items, 2)
|
||||
})
|
||||
|
||||
t.Run("fail query", func(t *testing.T) {
|
||||
fakeLicense := &mmModel.License{Features: &mmModel.Features{}, SkuShortName: mmModel.LicenseShortSkuEnterprise}
|
||||
th.Store.EXPECT().GetLicense().Return(fakeLicense).AnyTimes()
|
||||
fakeUser := &model.User{
|
||||
ID: "user-id",
|
||||
IsGuest: false,
|
||||
}
|
||||
th.Store.EXPECT().GetUserByID("user-id").Return(fakeUser, nil).AnyTimes()
|
||||
th.Store.EXPECT().GetBoardsForUserAndTeam("user-id", "team-id").Return(mockInsightsBoards, nil).AnyTimes()
|
||||
th.Store.EXPECT().
|
||||
GetTeamBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
|
||||
Return(nil, insightError{"board-insight-error"})
|
||||
_, err := th.App.GetTeamBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, insightError{"board-insight-error"})
|
||||
th.Store.EXPECT().
|
||||
GetUserBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
|
||||
Return(nil, insightError{"board-insight-error"})
|
||||
_, err = th.App.GetUserBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, insightError{"board-insight-error"})
|
||||
})
|
||||
}
|
@ -50,6 +50,7 @@ func TestPrepareOnboardingTour(t *testing.T) {
|
||||
}
|
||||
|
||||
th.Store.EXPECT().PatchUserProps(userID, userPropPatch).Return(nil)
|
||||
th.Store.EXPECT().GetUserCategoryBoards(userID, "0").Return([]model.CategoryBoards{}, nil)
|
||||
|
||||
teamID, boardID, err := th.App.PrepareOnboardingTour(userID, teamID)
|
||||
assert.NoError(t, err)
|
||||
@ -86,6 +87,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
|
||||
}
|
||||
newType := model.BoardTypePrivate
|
||||
th.Store.EXPECT().PatchBoard("board_id_1", &model.BoardPatch{Type: &newType}, "user_id_1").Return(&privateWelcomeBoard, nil)
|
||||
th.Store.EXPECT().GetUserCategoryBoards(userID, "0")
|
||||
|
||||
boardID, err := th.App.createWelcomeBoard(userID, teamID)
|
||||
assert.Nil(t, err)
|
||||
|
@ -3,7 +3,7 @@
|
||||
{"type":"block","data":{"id":"chki1tsudciyiiffrkqbcmp71rh","parentId":"b7wnw9awd4pnefryhq51apbzb4c","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"mweioqznbife7p7aee7dr4wcxo","modifiedBy":"mweioqznbife7p7aee7dr4wcxo","schema":1,"type":"card","title":"Video production","fields":{"contentOrder":["a9ti13dqo8jfmjdmg97f5umfdyw","717fa85sx3f8f8m81f771s9hmwr","a4se5s4ozx3ry8ec57w6z6jpk7y","7n37rxrn9uffdzrfi1xajotzjey","7ifofmuwjzbdzppfxgtuai4i47h","7cfc4fkpz53gn9frciz9kui4p1c"],"icon":"📹","isTemplate":false,"properties":{"4cf1568d-530f-4028-8ffd-bdc65249187e":"b1abafbf-a038-4a19-8b68-56e0fd2319f7","d777ba3b-8728-40d1-87a6-59406bbbbfb0":"34eb9c25-d5bf-49d9-859e-f74f4e0030e7"}},"createAt":1641497048092,"updateAt":1643788318629,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"cmt5usr1mw3fom886t34ekjquay","parentId":"b7wnw9awd4pnefryhq51apbzb4c","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"mweioqznbife7p7aee7dr4wcxo","modifiedBy":"mweioqznbife7p7aee7dr4wcxo","schema":1,"type":"card","title":"Offsite plans","fields":{"contentOrder":["aw53ugkfq8pyi9fjh9j6i4kdeiw","7ni9593iz3pnb7xitoz3guwq5gh","agjkcro3x7irbxedyxrn8iuerrr","75zkot1f3sjb7ifysuzijitw91y","7is5m8apdu3g53c8f6cz6sq7bmh","7xsmzscbqn3ftudzqbb4w1q7t7e"],"icon":"🚙","isTemplate":false,"properties":{"4cf1568d-530f-4028-8ffd-bdc65249187e":"8b05c83e-a44a-4d04-831e-97f01d8e2003","d777ba3b-8728-40d1-87a6-59406bbbbfb0":"dabadd9b-adf1-4d9f-8702-805ac6cef602"}},"createAt":1641497048336,"updateAt":1643788318629,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"cnqsbzg4b7brfddtyh7fc66atrw","parentId":"b7wnw9awd4pnefryhq51apbzb4c","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"mweioqznbife7p7aee7dr4wcxo","modifiedBy":"mweioqznbife7p7aee7dr4wcxo","schema":1,"type":"card","title":"Social Media Strategy","fields":{"contentOrder":["ao57n1fbtmt8q8bfk8ieqgzqt3a","76h9y996sdj8sbrbpqjo9d8cwto","aco8iu5jp7jbyzmzegwxkeusgzr","7y6zcyofmsfrbt899ts1ixr3iey","7hudywfzcwirkpcp1p5jhsfs83r","7jzw67ngdgtns8mstsg9g614oac"],"icon":"🎉","isTemplate":false,"properties":{"4cf1568d-530f-4028-8ffd-bdc65249187e":"b1abafbf-a038-4a19-8b68-56e0fd2319f7","d777ba3b-8728-40d1-87a6-59406bbbbfb0":"d37a61f4-f332-4db9-8b2d-5e0a91aa20ed"}},"createAt":1641497048417,"updateAt":1643788318629,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vfs8sj79dt7n75bomn46fybxmfo","parentId":"b7wnw9awd4pnefryhq51apbzb4c","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"mweioqznbife7p7aee7dr4wcxo","modifiedBy":"mweioqznbife7p7aee7dr4wcxo","schema":1,"type":"view","title":"Discussion Items","fields":{"cardOrder":["cjpkiya33qsagr4f9hrdwhgiajc"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"ch798q5ucefyobf5bymgqjt4f3h","filter":{"filters":[],"operation":"and"},"groupById":"d777ba3b-8728-40d1-87a6-59406bbbbfb0","hiddenOptionIds":[""],"kanbanCalculations":{},"sortOptions":[{"propertyId":"4cf1568d-530f-4028-8ffd-bdc65249187e","reversed":false}],"viewType":"board","visibleOptionIds":[],"visiblePropertyIds":["4cf1568d-530f-4028-8ffd-bdc65249187e"]},"createAt":1641497048501,"updateAt":1643788318629,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vfs8sj79dt7n75bomn46fybxmfo","parentId":"b7wnw9awd4pnefryhq51apbzb4c","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"mweioqznbife7p7aee7dr4wcxo","modifiedBy":"mweioqznbife7p7aee7dr4wcxo","schema":1,"type":"view","title":"Discussion Items","fields":{"cardOrder":["cjpkiya33qsagr4f9hrdwhgiajc"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"groupById":"d777ba3b-8728-40d1-87a6-59406bbbbfb0","hiddenOptionIds":[""],"kanbanCalculations":{},"sortOptions":[{"propertyId":"4cf1568d-530f-4028-8ffd-bdc65249187e","reversed":false}],"viewType":"board","visibleOptionIds":[],"visiblePropertyIds":["4cf1568d-530f-4028-8ffd-bdc65249187e"]},"createAt":1641497048501,"updateAt":1643788318629,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"73dzfgistnbgzuekc6c8irou9wy","parentId":"cgwagmaw6gin7xcq7nwew8rsynr","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"","fields":{"value":false},"createAt":1641586451774,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"7b3njq5m3n78hdpe4bimzr34fic","parentId":"cgwagmaw6gin7xcq7nwew8rsynr","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"","fields":{"value":false},"createAt":1641586448934,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"7b7hsbkm6sifqfqi4gstxxaz7my","parentId":"cgwagmaw6gin7xcq7nwew8rsynr","rootId":"b7wnw9awd4pnefryhq51apbzb4c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"divider","title":"","fields":{},"createAt":1641586358664,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
|
@ -5,7 +5,7 @@
|
||||
{"type":"block","data":{"id":"cx7cki81xppd3pdgnyktwbgtzer","parentId":"bbn1888mprfrm5fjw9f1je9x3xo","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Feed Fluffy","fields":{"contentOrder":["as5kdrix3ibd3jrnqzz94dcqqba"],"icon":"🐱","isTemplate":false,"properties":{"a9zf59u8x1rf4ywctpcqama7tio":"an51dnkenmoog9cetapbc4uyt3y"}},"createAt":1640281433850,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"czowhma7rnpgb3eczbqo3t7fijo","parentId":"bbn1888mprfrm5fjw9f1je9x3xo","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Gardening","fields":{"contentOrder":[],"icon":"🌳","isTemplate":false,"properties":{"a9zf59u8x1rf4ywctpcqama7tio":"afpy8s7i45frggprmfsqngsocqh"}},"createAt":1640281433750,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vjq4piq89kbds5x5zq39zww7joo","parentId":"bbn1888mprfrm5fjw9f1je9x3xo","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"List View","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{"__title":280},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"table","visibleOptionIds":[],"visiblePropertyIds":["a9zf59u8x1rf4ywctpcqama7tio","abthng7baedhhtrwsdodeuincqy"]},"createAt":1641247999081,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vyeipq97iqbfjtd6fgcbxg6xbme","parentId":"bbn1888mprfrm5fjw9f1je9x3xo","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Board View","fields":{"cardOrder":["co6a88h6og3dm3kkub64kyb71jw","c5xamko6rpibhje3bjreenon7ce","cr7gz7sempbfqpq7sign4jaeyxc","cx7cki81xppd3pdgnyktwbgtzer","czowhma7rnpgb3eczbqo3t7fijo"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"cidrrzojxpfroicutox1hoyk91h","filter":{"filters":[],"operation":"and"},"groupById":"a9zf59u8x1rf4ywctpcqama7tio","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"board","visibleOptionIds":["an51dnkenmoog9cetapbc4uyt3y","afpy8s7i45frggprmfsqngsocqh","aj4jyekqqssatjcq7r7chmy19ey",""],"visiblePropertyIds":["a9zf59u8x1rf4ywctpcqama7tio"]},"createAt":1640281433698,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vyeipq97iqbfjtd6fgcbxg6xbme","parentId":"bbn1888mprfrm5fjw9f1je9x3xo","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Board View","fields":{"cardOrder":["co6a88h6og3dm3kkub64kyb71jw","c5xamko6rpibhje3bjreenon7ce","cr7gz7sempbfqpq7sign4jaeyxc","cx7cki81xppd3pdgnyktwbgtzer","czowhma7rnpgb3eczbqo3t7fijo"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"groupById":"a9zf59u8x1rf4ywctpcqama7tio","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"board","visibleOptionIds":["an51dnkenmoog9cetapbc4uyt3y","afpy8s7i45frggprmfsqngsocqh","aj4jyekqqssatjcq7r7chmy19ey",""],"visiblePropertyIds":["a9zf59u8x1rf4ywctpcqama7tio"]},"createAt":1640281433698,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"7fjacjgfxjfrf3psxc46wwsgqdo","parentId":"c5xamko6rpibhje3bjreenon7ce","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"Utilities","fields":{"value":true},"createAt":1640367568655,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"7gwsf4uxtftgjt841zgwydxeere","parentId":"c5xamko6rpibhje3bjreenon7ce","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"Mobile phone","fields":{"value":true},"createAt":1640367517692,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"7j6rbt87htj83bbssod76iumsja","parentId":"c5xamko6rpibhje3bjreenon7ce","rootId":"bbn1888mprfrm5fjw9f1je9x3xo","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"Internet","fields":{"value":true},"createAt":1640367560684,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
|
@ -5,7 +5,7 @@
|
||||
{"type":"block","data":{"id":"cfk8kwmuhcfd8m8qicz5aqw4mar","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Project budget approval","fields":{"contentOrder":["a9h4kfaurrprepefrw95i1raoxr","7btyuex8nji8jxn9yieaxgwoe6h","a34hy46bu8bngxcxpz9woui4afa","7ekrgkgq67fdofn9gskpe19bkrc","7ygi1kq3683ya5ydfttuc5rhasr","7qmjyww91rj8a38dsgu5b5wu7hr","7qmmpepfm4byqjqo9m16yp7m3no"],"icon":"💵","isTemplate":false,"properties":{"a8daz81s4xjgke1ww6cwik5w7ye":"16","a972dc7a-5f4c-45d2-8044-8c28c69717f1":"ayz81h9f3dwp7rzzbdebesc7ute","d3d682bf-e074-49d9-8df5-7320921c2d23":"d3bfb50f-f569-4bad-8a3a-dd15c3f60101"}},"createAt":1640281242677,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"ckcntrrmcjbywpciau57gw5suoo","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Conduct market analysis","fields":{"contentOrder":["a6gowxxpgijgip8qzrsp5rmjwqy","771bq4ja3ejfwbgaq78cdpgmjih","asdoj8ffhcirh3x3iys3joeox9o","7k975b49ni7yrfn3nqg7q4x4wde","7e9aj57zouidozb8sf8e1wybywe","71dm4jiu43byubx7pukjiy19pay","719y6x4tkiigd9nwarn1e6ek7ic"],"icon":"📈","isTemplate":false,"properties":{"a8daz81s4xjgke1ww6cwik5w7ye":"40","a972dc7a-5f4c-45d2-8044-8c28c69717f1":"ar6b8m3jxr3asyxhr8iucdbo6yc","d3d682bf-e074-49d9-8df5-7320921c2d23":"87f59784-b859-4c24-8ebe-17c766e081dd"}},"createAt":1640281242851,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vcuoise4b8jn1ffzujfuacymmmr","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Project Priorities","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"groupById":"d3d682bf-e074-49d9-8df5-7320921c2d23","hiddenOptionIds":[],"kanbanCalculations":{"":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"87f59784-b859-4c24-8ebe-17c766e081dd":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"98a57627-0f76-471d-850d-91f3ed9fd213":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"d3bfb50f-f569-4bad-8a3a-dd15c3f60101":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"}},"sortOptions":[],"viewType":"board","visibleOptionIds":["d3bfb50f-f569-4bad-8a3a-dd15c3f60101","87f59784-b859-4c24-8ebe-17c766e081dd","98a57627-0f76-471d-850d-91f3ed9fd213",""],"visiblePropertyIds":["a972dc7a-5f4c-45d2-8044-8c28c69717f1","a8daz81s4xjgke1ww6cwik5w7ye"]},"createAt":1640281242551,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vey61xzc6u38ptnpjqaik6ap91e","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Progress Tracker","fields":{"cardOrder":["cfk8kwmuhcfd8m8qicz5aqw4mar","cdwqxf4b3utbbxdrgbwtmk9y9eo","c68gyx34srjgjxmrs1z8pj7nbce","ckcntrrmcjbywpciau57gw5suoo","c6w7rxrootfdw7j4fsftc5gsyoo","coxnjt3ro1in19dd1e3awdt338r"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"czw9es1e89fdpjr7cqptr1xq7qh","filter":{"filters":[],"operation":"and"},"groupById":"a972dc7a-5f4c-45d2-8044-8c28c69717f1","hiddenOptionIds":[],"kanbanCalculations":{"":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"adeo5xuwne3qjue83fcozekz8ko":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"afi4o5nhnqc3smtzs1hs3ij34dh":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ahpyxfnnrzynsw3im1psxpkgtpe":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ar6b8m3jxr3asyxhr8iucdbo6yc":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ayz81h9f3dwp7rzzbdebesc7ute":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"}},"sortOptions":[],"viewType":"board","visibleOptionIds":["ayz81h9f3dwp7rzzbdebesc7ute","ar6b8m3jxr3asyxhr8iucdbo6yc","afi4o5nhnqc3smtzs1hs3ij34dh","adeo5xuwne3qjue83fcozekz8ko","ahpyxfnnrzynsw3im1psxpkgtpe",""],"visiblePropertyIds":["d3d682bf-e074-49d9-8df5-7320921c2d23","a8daz81s4xjgke1ww6cwik5w7ye"]},"createAt":1640281242788,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vey61xzc6u38ptnpjqaik6ap91e","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Progress Tracker","fields":{"cardOrder":["cfk8kwmuhcfd8m8qicz5aqw4mar","cdwqxf4b3utbbxdrgbwtmk9y9eo","c68gyx34srjgjxmrs1z8pj7nbce","ckcntrrmcjbywpciau57gw5suoo","c6w7rxrootfdw7j4fsftc5gsyoo","coxnjt3ro1in19dd1e3awdt338r"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"groupById":"a972dc7a-5f4c-45d2-8044-8c28c69717f1","hiddenOptionIds":[],"kanbanCalculations":{"":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"adeo5xuwne3qjue83fcozekz8ko":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"afi4o5nhnqc3smtzs1hs3ij34dh":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ahpyxfnnrzynsw3im1psxpkgtpe":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ar6b8m3jxr3asyxhr8iucdbo6yc":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"},"ayz81h9f3dwp7rzzbdebesc7ute":{"calculation":"sum","propertyId":"a8daz81s4xjgke1ww6cwik5w7ye"}},"sortOptions":[],"viewType":"board","visibleOptionIds":["ayz81h9f3dwp7rzzbdebesc7ute","ar6b8m3jxr3asyxhr8iucdbo6yc","afi4o5nhnqc3smtzs1hs3ij34dh","adeo5xuwne3qjue83fcozekz8ko","ahpyxfnnrzynsw3im1psxpkgtpe",""],"visiblePropertyIds":["d3d682bf-e074-49d9-8df5-7320921c2d23","a8daz81s4xjgke1ww6cwik5w7ye"]},"createAt":1640281242788,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vfztxwjnegbdh38nfccu3bq1auc","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Task Overview","fields":{"cardOrder":["c6w7rxrootfdw7j4fsftc5gsyoo","ckcntrrmcjbywpciau57gw5suoo","c68gyx34srjgjxmrs1z8pj7nbce","cfk8kwmuhcfd8m8qicz5aqw4mar","cdwqxf4b3utbbxdrgbwtmk9y9eo","cz8p8gofakfby8kzz83j97db8ph","ce1jm5q5i54enhuu4h3kkay1hcc"],"collapsedOptionIds":[],"columnCalculations":{"a8daz81s4xjgke1ww6cwik5w7ye":"sum"},"columnWidths":{"2a5da320-735c-4093-8787-f56e15cdfeed":196,"__title":280,"a8daz81s4xjgke1ww6cwik5w7ye":139,"a972dc7a-5f4c-45d2-8044-8c28c69717f1":141,"d3d682bf-e074-49d9-8df5-7320921c2d23":110},"defaultTemplateId":"czw9es1e89fdpjr7cqptr1xq7qh","filter":{"filters":[],"operation":"and"},"groupById":"","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"table","visibleOptionIds":[],"visiblePropertyIds":["a972dc7a-5f4c-45d2-8044-8c28c69717f1","d3d682bf-e074-49d9-8df5-7320921c2d23","2a5da320-735c-4093-8787-f56e15cdfeed","a3zsw7xs8sxy7atj8b6totp3mby","axkhqa4jxr3jcqe4k87g8bhmary","a7gdnz8ff8iyuqmzddjgmgo9ery","a8daz81s4xjgke1ww6cwik5w7ye"]},"createAt":1640281242734,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vi49i1138jpnbiqhyd81beme9zy","parentId":"bc41mwxg9ybb69pn9j5zna6d36c","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Task Calendar","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"dateDisplayPropertyId":"a3zsw7xs8sxy7atj8b6totp3mby","defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"calendar","visibleOptionIds":[],"visiblePropertyIds":["__title"]},"createAt":1640361708030,"updateAt":1643788318630,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"76q9tmzey4byqdpimsdxeg1gx3h","parentId":"c68gyx34srjgjxmrs1z8pj7nbce","rootId":"bc41mwxg9ybb69pn9j5zna6d36c","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"checkbox","title":"[Subtask 1]","fields":{"value":false},"createAt":1641247437494,"updateAt":1643788318632,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
|
@ -6,7 +6,7 @@
|
||||
{"type":"block","data":{"id":"cp1m1wrpfatdxikhwkf58oo5k3o","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Review API design","fields":{"contentOrder":["ahsamufik97nsfxjgx9cs6cmzme"],"icon":"🛣️","isTemplate":false,"properties":{"20717ad3-5741-4416-83f1-6f133fff3d11":"424ea5e3-9aa1-4075-8c5c-01b44b66e634","50117d52-bcc7-4750-82aa-831a351c44a0":"8c557f69-b0ed-46ec-83a3-8efab9d47ef5","60985f46-3e41-486e-8213-2b987440ea1c":"14892380-1a32-42dd-8034-a0cea32bc7e6","ai7ajsdk14w7x5s8up3dwir77te":"https://mattermost.com/boards/","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e":"c62172ea-5da7-4dec-8186-37267d8ee9a7"}},"createAt":1640363550754,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"cqfy6g434pigk3p7j3gq55trq9o","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"card","title":"Icons don't display","fields":{"contentOrder":["axfkn6tuy4igubj3ka99tbymb8o","acbpep9wxdtyg8gg3fi6h1hgoro","7tedfdyq4p7g77dmkrebryh4jor"],"icon":"💻","isTemplate":false,"properties":{"20717ad3-5741-4416-83f1-6f133fff3d11":"1fdbb515-edd2-4af5-80fc-437ed2211a49","50117d52-bcc7-4750-82aa-831a351c44a0":"8c557f69-b0ed-46ec-83a3-8efab9d47ef5","60985f46-3e41-486e-8213-2b987440ea1c":"ed4a5340-460d-461b-8838-2c56e8ee59fe","ai7ajsdk14w7x5s8up3dwir77te":"https://mattermost.com/boards/","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e":"e6a7f297-4440-4783-8ab3-3af5ba62ca11"}},"createAt":1640363550868,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"v1uubwdzrw7fsxnd6pss1dyhh5e","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Calendar View","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"dateDisplayPropertyId":"a4378omyhmgj3bex13sj4wbpfiy","defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[],"viewType":"calendar","visibleOptionIds":[],"visiblePropertyIds":["__title"]},"createAt":1640379248049,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"v7n4sc9cre7gsbq9yydsuekpg8a","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Board: Sprints","fields":{"cardOrder":["c3jawn6e4fbr3jctthy9xxkdsqe","c5trb4319wi8n3x4r4f7f83ytdc","c9p4bdasriifc7qgihzhjm63ugy","cqfy6g434pigk3p7j3gq55trq9o","chfrdo1nb3p8ofnbftyinr6949o","cp1m1wrpfatdxikhwkf58oo5k3o"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"cidz4imnqhir48brz6e8hxhfrhy","filter":{"filters":[],"operation":"and"},"groupById":"60985f46-3e41-486e-8213-2b987440ea1c","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[{"propertyId":"f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e","reversed":false}],"viewType":"board","visibleOptionIds":["c01676ca-babf-4534-8be5-cce2287daa6c","ed4a5340-460d-461b-8838-2c56e8ee59fe","14892380-1a32-42dd-8034-a0cea32bc7e6",""],"visiblePropertyIds":["20717ad3-5741-4416-83f1-6f133fff3d11","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e"]},"createAt":1640363550811,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"v7n4sc9cre7gsbq9yydsuekpg8a","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Board: Sprints","fields":{"cardOrder":["c3jawn6e4fbr3jctthy9xxkdsqe","c5trb4319wi8n3x4r4f7f83ytdc","c9p4bdasriifc7qgihzhjm63ugy","cqfy6g434pigk3p7j3gq55trq9o","chfrdo1nb3p8ofnbftyinr6949o","cp1m1wrpfatdxikhwkf58oo5k3o"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"","filter":{"filters":[],"operation":"and"},"groupById":"60985f46-3e41-486e-8213-2b987440ea1c","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[{"propertyId":"f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e","reversed":false}],"viewType":"board","visibleOptionIds":["c01676ca-babf-4534-8be5-cce2287daa6c","ed4a5340-460d-461b-8838-2c56e8ee59fe","14892380-1a32-42dd-8034-a0cea32bc7e6",""],"visiblePropertyIds":["20717ad3-5741-4416-83f1-6f133fff3d11","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e"]},"createAt":1640363550811,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"v8sa3mo81d38rbmd8bz4n6dg7qc","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"List: Tasks 🔨","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{"50117d52-bcc7-4750-82aa-831a351c44a0":139,"__title":280},"defaultTemplateId":"","filter":{"filters":[{"condition":"includes","propertyId":"20717ad3-5741-4416-83f1-6f133fff3d11","values":["6eea96c9-4c61-4968-8554-4b7537e8f748"]}],"operation":"and"},"hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[{"propertyId":"50117d52-bcc7-4750-82aa-831a351c44a0","reversed":true}],"viewType":"table","visibleOptionIds":[],"visiblePropertyIds":["50117d52-bcc7-4750-82aa-831a351c44a0","20717ad3-5741-4416-83f1-6f133fff3d11","60985f46-3e41-486e-8213-2b987440ea1c","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e"]},"createAt":1640363550980,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vi43bqxsho3fmjbu1oa8qafwo4c","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"Board: Status","fields":{"cardOrder":["c3jawn6e4fbr3jctthy9xxkdsqe","cm4w7cc3aac6s9jdcujbs4j8f4r","c6egh6cpnj137ixdoitsoxq17oo","cct9u78utsdyotmejbmwwg66ihr","cmft87it1q7yebbd51ij9k65xbw","c9fe77j9qcruxf4itzib7ag6f1c","coup7afjknqnzbdwghiwbsq541w","c5ex1hndz8qyc8gx6ofbfeksftc"],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{},"defaultTemplateId":"cidz4imnqhir48brz6e8hxhfrhy","filter":{"filters":[],"operation":"and"},"groupById":"50117d52-bcc7-4750-82aa-831a351c44a0","hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[{"propertyId":"f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e","reversed":false}],"viewType":"board","visibleOptionIds":["8c557f69-b0ed-46ec-83a3-8efab9d47ef5","ec6d2bc5-df2b-4f77-8479-e59ceb039946","849766ba-56a5-48d1-886f-21672f415395",""],"visiblePropertyIds":["20717ad3-5741-4416-83f1-6f133fff3d11","60985f46-3e41-486e-8213-2b987440ea1c","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e"]},"createAt":1640363551099,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
{"type":"block","data":{"id":"vod5de87tz7nxpji31oou4ine3c","parentId":"bui5izho7dtn77xg3thkiqprc9r","rootId":"bui5izho7dtn77xg3thkiqprc9r","createdBy":"edrkkih4cinzf8ueeszh6rmfoo","modifiedBy":"edrkkih4cinzf8ueeszh6rmfoo","schema":1,"type":"view","title":"List: Bugs 🐞","fields":{"cardOrder":[],"collapsedOptionIds":[],"columnCalculations":{},"columnWidths":{"50117d52-bcc7-4750-82aa-831a351c44a0":145,"__title":280},"defaultTemplateId":"","filter":{"filters":[{"condition":"includes","propertyId":"20717ad3-5741-4416-83f1-6f133fff3d11","values":["1fdbb515-edd2-4af5-80fc-437ed2211a49"]}],"operation":"and"},"hiddenOptionIds":[],"kanbanCalculations":{},"sortOptions":[{"propertyId":"f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e","reversed":false}],"viewType":"table","visibleOptionIds":[],"visiblePropertyIds":["50117d52-bcc7-4750-82aa-831a351c44a0","20717ad3-5741-4416-83f1-6f133fff3d11","60985f46-3e41-486e-8213-2b987440ea1c","f7f3ad42-b31a-4ac2-81f0-28ea80c5b34e"]},"createAt":1640363550690,"updateAt":1643788318631,"deleteAt":0,"workspaceId":"855b3j34ojn5p8f36yhu8336fe"}}
|
||||
|
@ -206,6 +206,36 @@ func (c *Client) GetTeam(teamID string) (*model.Team, *Response) {
|
||||
return model.TeamFromJSON(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) GetTeamBoardsInsights(teamID string, userID string, timeRange string, page int, perPage int) (*model.BoardInsightsList, *Response) {
|
||||
query := fmt.Sprintf("?time_range=%v&page=%v&per_page=%v", timeRange, page, perPage)
|
||||
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/boards/insights"+query, "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
var boardInsightsList *model.BoardInsightsList
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&boardInsightsList); jsonErr != nil {
|
||||
return nil, BuildErrorResponse(r, jsonErr)
|
||||
}
|
||||
return boardInsightsList, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) GetUserBoardsInsights(teamID string, userID string, timeRange string, page int, perPage int) (*model.BoardInsightsList, *Response) {
|
||||
query := fmt.Sprintf("?time_range=%v&page=%v&per_page=%v&team_id=%v", timeRange, page, perPage, teamID)
|
||||
r, err := c.DoAPIGet(c.GetMeRoute()+"/boards/insights"+query, "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
var boardInsightsList *model.BoardInsightsList
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&boardInsightsList); jsonErr != nil {
|
||||
return nil, BuildErrorResponse(r, jsonErr)
|
||||
}
|
||||
return boardInsightsList, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) GetBlocksForBoard(boardID string) ([]model.Block, *Response) {
|
||||
r, err := c.DoAPIGet(c.GetBlocksRoute(boardID), "")
|
||||
if err != nil {
|
||||
@ -318,6 +348,38 @@ func (c *Client) CreateBoardsAndBlocks(bab *model.BoardsAndBlocks) (*model.Board
|
||||
return model.BoardsAndBlocksFromJSON(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) CreateCategory(category model.Category) (*model.Category, *Response) {
|
||||
r, err := c.DoAPIPost(c.GetTeamRoute(category.TeamID)+"/categories", toJSON(category))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
return model.CategoryFromJSON(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCategoryBoard(teamID, categoryID, boardID string) *Response {
|
||||
r, err := c.DoAPIPost(fmt.Sprintf("%s/categories/%s/boards/%s", c.GetTeamRoute(teamID), categoryID, boardID), "")
|
||||
if err != nil {
|
||||
return BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
return BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) GetUserCategoryBoards(teamID string) ([]model.CategoryBoards, *Response) {
|
||||
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/categories", "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
var categoryBoards []model.CategoryBoards
|
||||
_ = json.NewDecoder(r.Body).Decode(&categoryBoards)
|
||||
return categoryBoards, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) PatchBoardsAndBlocks(pbab *model.PatchBoardsAndBlocks) (*model.BoardsAndBlocks, *Response) {
|
||||
r, err := c.DoAPIPatch(c.GetBoardsAndBlocksRoute(), toJSON(pbab))
|
||||
if err != nil {
|
||||
@ -369,7 +431,7 @@ func (c *Client) GetRegisterRoute() string {
|
||||
return "/register"
|
||||
}
|
||||
|
||||
func (c *Client) Register(request *api.RegisterRequest) (bool, *Response) {
|
||||
func (c *Client) Register(request *model.RegisterRequest) (bool, *Response) {
|
||||
r, err := c.DoAPIPost(c.GetRegisterRoute(), toJSON(&request))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
@ -383,14 +445,14 @@ func (c *Client) GetLoginRoute() string {
|
||||
return "/login"
|
||||
}
|
||||
|
||||
func (c *Client) Login(request *api.LoginRequest) (*api.LoginResponse, *Response) {
|
||||
func (c *Client) Login(request *model.LoginRequest) (*model.LoginResponse, *Response) {
|
||||
r, err := c.DoAPIPost(c.GetLoginRoute(), toJSON(&request))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
data, err := api.LoginResponseFromJSON(r.Body)
|
||||
data, err := model.LoginResponseFromJSON(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -450,7 +512,7 @@ func (c *Client) GetUserChangePasswordRoute(id string) string {
|
||||
return fmt.Sprintf("/users/%s/changepassword", id)
|
||||
}
|
||||
|
||||
func (c *Client) UserChangePassword(id string, data *api.ChangePasswordRequest) (bool, *Response) {
|
||||
func (c *Client) UserChangePassword(id string, data *model.ChangePasswordRequest) (bool, *Response) {
|
||||
r, err := c.DoAPIPost(c.GetUserChangePasswordRoute(id), toJSON(&data))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
|
@ -4,23 +4,23 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.2
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/krolaw/zipstream v0.0.0-20180621105154-0a2661891f94
|
||||
github.com/lib/pq v1.10.6
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.28-0.20220623051512-0afd85e854d4
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220711175838-7ee7523729e6
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.29-0.20220801143717-73008cfda2fb
|
||||
github.com/mattermost/mattermost-server/v6 v6.0.0-20220802151854-f07c31c5d933
|
||||
github.com/mattermost/morph v0.0.0-20220401091636-39f834798da8
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/mgdelacroix/foundation v0.0.0-20220812143423-0bfc18f73538
|
||||
github.com/oklog/run v1.1.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.12.1
|
||||
github.com/rudderlabs/analytics-go v3.3.2+incompatible
|
||||
github.com/sergi/go-diff v1.2.0
|
||||
github.com/spf13/viper v1.10.1
|
||||
github.com/stretchr/testify v1.7.2
|
||||
github.com/stretchr/testify v1.8.0
|
||||
github.com/wiggin77/merror v1.0.3
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
|
||||
)
|
||||
@ -28,14 +28,17 @@ require (
|
||||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||
github.com/blang/semver/v4 v4.0.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
|
||||
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/francoispqt/gojay v1.2.13 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/golang-migrate/migrate/v4 v4.15.2 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/graph-gophers/graphql-go v1.4.0 // indirect
|
||||
@ -43,6 +46,7 @@ require (
|
||||
github.com/hashicorp/go-plugin v1.4.4 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.15.6 // indirect
|
||||
@ -53,6 +57,7 @@ require (
|
||||
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
|
||||
github.com/mattermost/logr/v2 v2.0.15 // indirect
|
||||
github.com/mattermost/squirrel v0.2.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
@ -92,6 +97,7 @@ require (
|
||||
github.com/yuin/goldmark v1.4.12 // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022 // indirect
|
||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
||||
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.11 // indirect
|
||||
|
317
server/go.sum
317
server/go.sum
File diff suppressed because it is too large
Load Diff
@ -1936,6 +1936,108 @@ func TestDuplicateBoard(t *testing.T) {
|
||||
require.Equal(t, duplicateBoard.ID, members[0].BoardID)
|
||||
require.True(t, members[0].SchemeAdmin)
|
||||
})
|
||||
|
||||
t.Run("create and duplicate public board from a custom category", func(t *testing.T) {
|
||||
th := SetupTestHelper(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
me := th.GetUser1()
|
||||
teamID := testTeamID
|
||||
|
||||
category := model.Category{
|
||||
Name: "My Category",
|
||||
UserID: me.ID,
|
||||
TeamID: teamID,
|
||||
}
|
||||
createdCategory, resp := th.Client.CreateCategory(category)
|
||||
th.CheckOK(resp)
|
||||
require.NoError(t, resp.Error)
|
||||
require.NotNil(t, createdCategory)
|
||||
require.Equal(t, "My Category", createdCategory.Name)
|
||||
require.Equal(t, me.ID, createdCategory.UserID)
|
||||
require.Equal(t, teamID, createdCategory.TeamID)
|
||||
|
||||
title := "Public board"
|
||||
newBoard := &model.Board{
|
||||
Title: title,
|
||||
Type: model.BoardTypeOpen,
|
||||
TeamID: teamID,
|
||||
}
|
||||
board, resp := th.Client.CreateBoard(newBoard)
|
||||
th.CheckOK(resp)
|
||||
require.NoError(t, resp.Error)
|
||||
require.NotNil(t, board)
|
||||
require.NotNil(t, board.ID)
|
||||
require.Equal(t, title, board.Title)
|
||||
require.Equal(t, model.BoardTypeOpen, board.Type)
|
||||
require.Equal(t, teamID, board.TeamID)
|
||||
require.Equal(t, me.ID, board.CreatedBy)
|
||||
require.Equal(t, me.ID, board.ModifiedBy)
|
||||
|
||||
// move board to custom category
|
||||
resp = th.Client.UpdateCategoryBoard(teamID, createdCategory.ID, board.ID)
|
||||
th.CheckOK(resp)
|
||||
require.NoError(t, resp.Error)
|
||||
|
||||
newBlocks := []model.Block{
|
||||
{
|
||||
ID: utils.NewID(utils.IDTypeBlock),
|
||||
BoardID: board.ID,
|
||||
CreateAt: 1,
|
||||
UpdateAt: 1,
|
||||
Title: "View 1",
|
||||
Type: model.TypeView,
|
||||
},
|
||||
}
|
||||
|
||||
newBlocks, resp = th.Client.InsertBlocks(board.ID, newBlocks)
|
||||
require.NoError(t, resp.Error)
|
||||
require.Len(t, newBlocks, 1)
|
||||
|
||||
newUserMember := &model.BoardMember{
|
||||
UserID: th.GetUser2().ID,
|
||||
BoardID: board.ID,
|
||||
SchemeEditor: true,
|
||||
}
|
||||
th.Client.AddMemberToBoard(newUserMember)
|
||||
|
||||
members, err := th.Server.App().GetMembersForBoard(board.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, members, 2)
|
||||
|
||||
// Duplicate the board
|
||||
rBoardsAndBlock, resp := th.Client.DuplicateBoard(board.ID, false, teamID)
|
||||
th.CheckOK(resp)
|
||||
require.NotNil(t, rBoardsAndBlock)
|
||||
require.Equal(t, len(rBoardsAndBlock.Boards), 1)
|
||||
require.Equal(t, len(rBoardsAndBlock.Blocks), 1)
|
||||
|
||||
duplicateBoard := rBoardsAndBlock.Boards[0]
|
||||
require.Equal(t, duplicateBoard.Type, model.BoardTypePrivate, "Duplicated board should be private")
|
||||
require.Equal(t, "Public board copy", duplicateBoard.Title)
|
||||
|
||||
members, err = th.Server.App().GetMembersForBoard(duplicateBoard.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, members, 1, "Duplicated board should only have one member")
|
||||
require.Equal(t, me.ID, members[0].UserID)
|
||||
require.Equal(t, duplicateBoard.ID, members[0].BoardID)
|
||||
require.True(t, members[0].SchemeAdmin)
|
||||
|
||||
// verify duplicated board is in the same custom category
|
||||
userCategoryBoards, resp := th.Client.GetUserCategoryBoards(teamID)
|
||||
th.CheckOK(resp)
|
||||
require.NotNil(t, rBoardsAndBlock)
|
||||
|
||||
var duplicateBoardCategoryID string
|
||||
for _, categoryBoard := range userCategoryBoards {
|
||||
for _, boardID := range categoryBoard.BoardIDs {
|
||||
if boardID == duplicateBoard.ID {
|
||||
duplicateBoardCategoryID = categoryBoard.Category.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
require.Equal(t, createdCategory.ID, duplicateBoardCategoryID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestJoinBoard(t *testing.T) {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/focalboard/server/api"
|
||||
"github.com/mattermost/focalboard/server/client"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/server"
|
||||
@ -363,7 +362,7 @@ func (th *TestHelper) TearDown() {
|
||||
}
|
||||
|
||||
func (th *TestHelper) RegisterAndLogin(client *client.Client, username, email, password, token string) {
|
||||
req := &api.RegisterRequest{
|
||||
req := &model.RegisterRequest{
|
||||
Username: username,
|
||||
Email: email,
|
||||
Password: password,
|
||||
@ -378,7 +377,7 @@ func (th *TestHelper) RegisterAndLogin(client *client.Client, username, email, p
|
||||
}
|
||||
|
||||
func (th *TestHelper) Login(client *client.Client, username, password string) {
|
||||
req := &api.LoginRequest{
|
||||
req := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: username,
|
||||
Password: password,
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/api"
|
||||
"github.com/mattermost/focalboard/server/client"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -370,6 +369,43 @@ func TestPermissionsSearchTeamBoards(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestPermissionsSearchTeamLinkableBoards(t *testing.T) {
|
||||
t.Run("plugin", func(t *testing.T) {
|
||||
th := SetupTestHelperPluginMode(t)
|
||||
defer th.TearDown()
|
||||
clients := setupClients(th)
|
||||
testData := setupData(t, th)
|
||||
ttCases := []TestCase{
|
||||
// Search boards
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userAnon, http.StatusUnauthorized, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userNoTeamMember, http.StatusForbidden, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userTeamMember, http.StatusOK, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userViewer, http.StatusOK, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userCommenter, http.StatusOK, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userEditor, http.StatusOK, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userAdmin, http.StatusOK, 2},
|
||||
}
|
||||
runTestCases(t, ttCases, testData, clients)
|
||||
})
|
||||
t.Run("local", func(t *testing.T) {
|
||||
th := SetupTestHelperLocalMode(t)
|
||||
defer th.TearDown()
|
||||
clients := setupLocalClients(th)
|
||||
testData := setupData(t, th)
|
||||
ttCases := []TestCase{
|
||||
// Search boards
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userAnon, http.StatusUnauthorized, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userNoTeamMember, http.StatusNotImplemented, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userTeamMember, http.StatusNotImplemented, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userViewer, http.StatusNotImplemented, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userCommenter, http.StatusNotImplemented, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userEditor, http.StatusNotImplemented, 0},
|
||||
{"/teams/test-team/boards/search/linkable?q=b", methodGet, "", userAdmin, http.StatusNotImplemented, 0},
|
||||
}
|
||||
runTestCases(t, ttCases, testData, clients)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPermissionsGetTeamTemplates(t *testing.T) {
|
||||
extraSetup := func(t *testing.T, th *TestHelper) {
|
||||
err := th.Server.App().InitTemplates()
|
||||
@ -2304,7 +2340,7 @@ func TestPermissionsGetUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPermissionsUserChangePassword(t *testing.T) {
|
||||
postBody := toJSON(t, api.ChangePasswordRequest{
|
||||
postBody := toJSON(t, model.ChangePasswordRequest{
|
||||
OldPassword: password,
|
||||
NewPassword: "newpa$$word123",
|
||||
})
|
||||
@ -2512,7 +2548,7 @@ func TestPermissionsDeleteBoardsAndBlocks(t *testing.T) {
|
||||
|
||||
func TestPermissionsLogin(t *testing.T) {
|
||||
loginReq := func(username, password string) string {
|
||||
return toJSON(t, api.LoginRequest{
|
||||
return toJSON(t, model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: username,
|
||||
Password: password,
|
||||
@ -2591,7 +2627,7 @@ func TestPermissionsRegister(t *testing.T) {
|
||||
require.NotNil(th.T, team)
|
||||
require.NotNil(th.T, team.SignupToken)
|
||||
|
||||
postData := toJSON(t, api.RegisterRequest{
|
||||
postData := toJSON(t, model.RegisterRequest{
|
||||
Username: "newuser",
|
||||
Email: "newuser@test.com",
|
||||
Password: password,
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/api"
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/utils"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -21,7 +20,7 @@ func TestUserRegister(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// register
|
||||
registerRequest := &api.RegisterRequest{
|
||||
registerRequest := &model.RegisterRequest{
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
Password: utils.NewID(utils.IDTypeNone),
|
||||
@ -41,7 +40,7 @@ func TestUserLogin(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("with nonexist user", func(t *testing.T) {
|
||||
loginRequest := &api.LoginRequest{
|
||||
loginRequest := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: "nonexistuser",
|
||||
Email: "",
|
||||
@ -55,7 +54,7 @@ func TestUserLogin(t *testing.T) {
|
||||
t.Run("with registered user", func(t *testing.T) {
|
||||
password := utils.NewID(utils.IDTypeNone)
|
||||
// register
|
||||
registerRequest := &api.RegisterRequest{
|
||||
registerRequest := &model.RegisterRequest{
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
Password: password,
|
||||
@ -65,7 +64,7 @@ func TestUserLogin(t *testing.T) {
|
||||
require.True(t, success)
|
||||
|
||||
// login
|
||||
loginRequest := &api.LoginRequest{
|
||||
loginRequest := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
@ -91,7 +90,7 @@ func TestGetMe(t *testing.T) {
|
||||
t.Run("logged in", func(t *testing.T) {
|
||||
// register
|
||||
password := utils.NewID(utils.IDTypeNone)
|
||||
registerRequest := &api.RegisterRequest{
|
||||
registerRequest := &model.RegisterRequest{
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
Password: password,
|
||||
@ -100,7 +99,7 @@ func TestGetMe(t *testing.T) {
|
||||
require.NoError(t, resp.Error)
|
||||
require.True(t, success)
|
||||
// login
|
||||
loginRequest := &api.LoginRequest{
|
||||
loginRequest := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
@ -126,7 +125,7 @@ func TestGetUser(t *testing.T) {
|
||||
|
||||
// register
|
||||
password := utils.NewID(utils.IDTypeNone)
|
||||
registerRequest := &api.RegisterRequest{
|
||||
registerRequest := &model.RegisterRequest{
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
Password: password,
|
||||
@ -135,7 +134,7 @@ func TestGetUser(t *testing.T) {
|
||||
require.NoError(t, resp.Error)
|
||||
require.True(t, success)
|
||||
// login
|
||||
loginRequest := &api.LoginRequest{
|
||||
loginRequest := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
@ -171,7 +170,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
|
||||
// register
|
||||
password := utils.NewID(utils.IDTypeNone)
|
||||
registerRequest := &api.RegisterRequest{
|
||||
registerRequest := &model.RegisterRequest{
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
Password: password,
|
||||
@ -180,7 +179,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
require.NoError(t, resp.Error)
|
||||
require.True(t, success)
|
||||
// login
|
||||
loginRequest := &api.LoginRequest{
|
||||
loginRequest := &model.LoginRequest{
|
||||
Type: "normal",
|
||||
Username: fakeUsername,
|
||||
Email: fakeEmail,
|
||||
@ -196,7 +195,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
require.NotNil(t, originalMe)
|
||||
|
||||
// change password
|
||||
success, resp = th.Client.UserChangePassword(originalMe.ID, &api.ChangePasswordRequest{
|
||||
success, resp = th.Client.UserChangePassword(originalMe.ID, &model.ChangePasswordRequest{
|
||||
OldPassword: password,
|
||||
NewPassword: utils.NewID(utils.IDTypeNone),
|
||||
})
|
||||
|
@ -53,16 +53,6 @@ func monitorPid(pid int, logger *mlog.Logger) {
|
||||
}()
|
||||
}
|
||||
|
||||
func logInfo(logger *mlog.Logger) {
|
||||
logger.Info("FocalBoard Server",
|
||||
mlog.String("version", model.CurrentVersion),
|
||||
mlog.String("edition", model.Edition),
|
||||
mlog.String("build_number", model.BuildNumber),
|
||||
mlog.String("build_date", model.BuildDate),
|
||||
mlog.String("build_hash", model.BuildHash),
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Command line args
|
||||
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
|
||||
@ -101,7 +91,7 @@ func main() {
|
||||
defer restore()
|
||||
}
|
||||
|
||||
logInfo(logger)
|
||||
model.LogServerInfo(logger)
|
||||
|
||||
singleUser := false
|
||||
if pSingleUser != nil {
|
||||
@ -214,7 +204,7 @@ func startServer(webPath string, filesPath string, port int, singleUserToken, db
|
||||
return
|
||||
}
|
||||
|
||||
logInfo(logger)
|
||||
model.LogServerInfo(logger)
|
||||
|
||||
if len(filesPath) > 0 {
|
||||
config.FilesPath = filesPath
|
||||
|
129
server/model/auth.go
Normal file
129
server/model/auth.go
Normal file
@ -0,0 +1,129 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/focalboard/server/services/auth"
|
||||
)
|
||||
|
||||
const (
|
||||
MinimumPasswordLength = 8
|
||||
)
|
||||
|
||||
type AuthParamError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (pe AuthParamError) Error() string {
|
||||
return pe.msg
|
||||
}
|
||||
|
||||
// LoginRequest is a login request
|
||||
// swagger:model
|
||||
type LoginRequest struct {
|
||||
// Type of login, currently must be set to "normal"
|
||||
// required: true
|
||||
Type string `json:"type"`
|
||||
|
||||
// If specified, login using username
|
||||
// required: false
|
||||
Username string `json:"username"`
|
||||
|
||||
// If specified, login using email
|
||||
// required: false
|
||||
Email string `json:"email"`
|
||||
|
||||
// Password
|
||||
// required: true
|
||||
Password string `json:"password"`
|
||||
|
||||
// MFA token
|
||||
// required: false
|
||||
// swagger:ignore
|
||||
MfaToken string `json:"mfa_token"`
|
||||
}
|
||||
|
||||
// LoginResponse is a login response
|
||||
// swagger:model
|
||||
type LoginResponse struct {
|
||||
// Session token
|
||||
// required: true
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func LoginResponseFromJSON(data io.Reader) (*LoginResponse, error) {
|
||||
var resp LoginResponse
|
||||
if err := json.NewDecoder(data).Decode(&resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// RegisterRequest is a user registration request
|
||||
// swagger:model
|
||||
type RegisterRequest struct {
|
||||
// User name
|
||||
// required: true
|
||||
Username string `json:"username"`
|
||||
|
||||
// User's email
|
||||
// required: true
|
||||
Email string `json:"email"`
|
||||
|
||||
// Password
|
||||
// required: true
|
||||
Password string `json:"password"`
|
||||
|
||||
// Registration authorization token
|
||||
// required: true
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func (rd *RegisterRequest) IsValid() error {
|
||||
if strings.TrimSpace(rd.Username) == "" {
|
||||
return AuthParamError{"username is required"}
|
||||
}
|
||||
if strings.TrimSpace(rd.Email) == "" {
|
||||
return AuthParamError{"email is required"}
|
||||
}
|
||||
if !auth.IsEmailValid(rd.Email) {
|
||||
return AuthParamError{"invalid email format"}
|
||||
}
|
||||
if rd.Password == "" {
|
||||
return AuthParamError{"password is required"}
|
||||
}
|
||||
return isValidPassword(rd.Password)
|
||||
}
|
||||
|
||||
// ChangePasswordRequest is a user password change request
|
||||
// swagger:model
|
||||
type ChangePasswordRequest struct {
|
||||
// Old password
|
||||
// required: true
|
||||
OldPassword string `json:"oldPassword"`
|
||||
|
||||
// New password
|
||||
// required: true
|
||||
NewPassword string `json:"newPassword"`
|
||||
}
|
||||
|
||||
// IsValid validates a password change request.
|
||||
func (rd *ChangePasswordRequest) IsValid() error {
|
||||
if rd.OldPassword == "" {
|
||||
return AuthParamError{"old password is required"}
|
||||
}
|
||||
if rd.NewPassword == "" {
|
||||
return AuthParamError{"new password is required"}
|
||||
}
|
||||
return isValidPassword(rd.NewPassword)
|
||||
}
|
||||
|
||||
func isValidPassword(password string) error {
|
||||
if len(password) < MinimumPasswordLength {
|
||||
return AuthParamError{fmt.Sprintf("password must be at least %d characters", MinimumPasswordLength)}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -94,10 +94,6 @@ type BlockPatch struct {
|
||||
// The block removed fields
|
||||
// required: false
|
||||
DeletedFields []string `json:"deletedFields"`
|
||||
|
||||
// The board id that the block belongs to
|
||||
// required: false
|
||||
BoardID *string `json:"boardId"`
|
||||
}
|
||||
|
||||
// BlockPatchBatch is a batch of IDs and patches for modify blocks
|
||||
@ -149,10 +145,6 @@ func (p *BlockPatch) Patch(block *Block) *Block {
|
||||
block.ParentID = *p.ParentID
|
||||
}
|
||||
|
||||
if p.BoardID != nil {
|
||||
block.BoardID = *p.BoardID
|
||||
}
|
||||
|
||||
if p.Schema != nil {
|
||||
block.Schema = *p.Schema
|
||||
}
|
||||
|
@ -253,6 +253,46 @@ func TestGenerateBlockIDs(t *testing.T) {
|
||||
require.Equal(t, blocks[1].ID, block4ContentOrder[1].([]interface{})[0])
|
||||
require.Equal(t, blocks[2].ID, block4ContentOrder[1].([]interface{})[1])
|
||||
})
|
||||
|
||||
t.Run("Should update Id of default template view", func(t *testing.T) {
|
||||
blockID1 := utils.NewID(utils.IDTypeBlock)
|
||||
boardID1 := utils.NewID(utils.IDTypeBlock)
|
||||
parentID1 := utils.NewID(utils.IDTypeBlock)
|
||||
block1 := Block{
|
||||
ID: blockID1,
|
||||
BoardID: boardID1,
|
||||
ParentID: parentID1,
|
||||
}
|
||||
|
||||
blockID2 := utils.NewID(utils.IDTypeBlock)
|
||||
boardID2 := utils.NewID(utils.IDTypeBlock)
|
||||
parentID2 := utils.NewID(utils.IDTypeBlock)
|
||||
block2 := Block{
|
||||
ID: blockID2,
|
||||
BoardID: boardID2,
|
||||
ParentID: parentID2,
|
||||
Fields: map[string]interface{}{
|
||||
"defaultTemplateId": blockID1,
|
||||
},
|
||||
}
|
||||
|
||||
blocks := []Block{block1, block2}
|
||||
|
||||
blocks = GenerateBlockIDs(blocks, &mlog.Logger{})
|
||||
|
||||
require.NotEqual(t, blockID1, blocks[0].ID)
|
||||
require.Equal(t, boardID1, blocks[0].BoardID)
|
||||
require.Equal(t, parentID1, blocks[0].ParentID)
|
||||
|
||||
require.NotEqual(t, blockID2, blocks[1].ID)
|
||||
require.Equal(t, boardID2, blocks[1].BoardID)
|
||||
require.Equal(t, parentID2, blocks[1].ParentID)
|
||||
|
||||
block2DefaultTemplateID, ok := block2.Fields["defaultTemplateId"].(string)
|
||||
require.True(t, ok)
|
||||
require.NotEqual(t, blockID1, block2DefaultTemplateID)
|
||||
require.Equal(t, blocks[0].ID, block2DefaultTemplateID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestStampModificationMetadata(t *testing.T) {
|
||||
|
@ -52,6 +52,21 @@ func GenerateBlockIDs(blocks []Block, logger mlog.LoggerIFace) []Block {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := block.Fields["defaultTemplateId"]; ok {
|
||||
defaultTemplateID, typeOk := block.Fields["defaultTemplateId"].(string)
|
||||
if !typeOk {
|
||||
logger.Warn(
|
||||
"type assertion failed for default template ID when saving reference block IDs",
|
||||
mlog.String("blockID", block.ID),
|
||||
mlog.String("actionType", fmt.Sprintf("%T", block.Fields["defaultTemplateId"])),
|
||||
mlog.String("expectedType", "string"),
|
||||
mlog.String("defaultTemplateId", fmt.Sprintf("%v", block.Fields["defaultTemplateId"])),
|
||||
)
|
||||
continue
|
||||
}
|
||||
referenceIDs[defaultTemplateID] = true
|
||||
}
|
||||
}
|
||||
|
||||
newIDs := map[string]string{}
|
||||
@ -93,6 +108,21 @@ func GenerateBlockIDs(blocks []Block, logger mlog.LoggerIFace) []Block {
|
||||
fixFieldIDs(&blockMod, "cardOrder", getExistingOrOldID, logger)
|
||||
}
|
||||
|
||||
if _, ok := blockMod.Fields["defaultTemplateId"]; ok {
|
||||
defaultTemplateID, typeOk := blockMod.Fields["defaultTemplateId"].(string)
|
||||
if !typeOk {
|
||||
logger.Warn(
|
||||
"type assertion failed for default template ID when saving reference block IDs",
|
||||
mlog.String("blockID", blockMod.ID),
|
||||
mlog.String("actionType", fmt.Sprintf("%T", blockMod.Fields["defaultTemplateId"])),
|
||||
mlog.String("expectedType", "string"),
|
||||
mlog.String("defaultTemplateId", fmt.Sprintf("%v", blockMod.Fields["defaultTemplateId"])),
|
||||
)
|
||||
} else {
|
||||
blockMod.Fields["defaultTemplateId"] = getExistingOrOldID(defaultTemplateID)
|
||||
}
|
||||
}
|
||||
|
||||
newBlocks[i] = blockMod
|
||||
}
|
||||
|
||||
|
62
server/model/board_insights.go
Normal file
62
server/model/board_insights.go
Normal file
@ -0,0 +1,62 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
|
||||
// BoardInsightsList is a response type with pagination support.
|
||||
type BoardInsightsList struct {
|
||||
mmModel.InsightsListData
|
||||
Items []*BoardInsight `json:"items"`
|
||||
}
|
||||
|
||||
// BoardInsight gives insight into activities in a Board
|
||||
// swagger:model
|
||||
type BoardInsight struct {
|
||||
// ID of the board
|
||||
// required: true
|
||||
BoardID string `json:"boardID"`
|
||||
|
||||
// icon of the board
|
||||
// required: false
|
||||
Icon string `json:"icon"`
|
||||
|
||||
// Title of the board
|
||||
// required: false
|
||||
Title string `json:"title"`
|
||||
|
||||
// Metric of how active the board is
|
||||
// required: true
|
||||
ActivityCount string `json:"activityCount"`
|
||||
|
||||
// IDs of users active on the board
|
||||
// required: true
|
||||
ActiveUsers string `json:"activeUsers"`
|
||||
|
||||
// ID of user who created the board
|
||||
// required: true
|
||||
CreatedBy string `json:"createdBy"`
|
||||
}
|
||||
|
||||
func BoardInsightsFromJSON(data io.Reader) []BoardInsight {
|
||||
var boardInsights []BoardInsight
|
||||
_ = json.NewDecoder(data).Decode(&boardInsights)
|
||||
return boardInsights
|
||||
}
|
||||
|
||||
// GetTopBoardInsightsListWithPagination adds a rank to each item in the given list of BoardInsight and checks if there is
|
||||
// another page that can be fetched based on the given limit and offset. The given list of BoardInsight is assumed to be
|
||||
// sorted by ActivityCount(score). Returns a BoardInsightsList.
|
||||
func GetTopBoardInsightsListWithPagination(boards []*BoardInsight, limit int) *BoardInsightsList {
|
||||
// Add pagination support
|
||||
var hasNext bool
|
||||
if limit != 0 && len(boards) == limit+1 {
|
||||
hasNext = true
|
||||
boards = boards[:len(boards)-1]
|
||||
}
|
||||
|
||||
return &BoardInsightsList{InsightsListData: mmModel.InsightsListData{HasNext: hasNext}, Items: boards}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/focalboard/server/utils"
|
||||
@ -36,6 +38,10 @@ type Category struct {
|
||||
// The deleted time in miliseconds since the current epoch. Set to indicate this category is deleted
|
||||
// required: false
|
||||
DeleteAt int64 `json:"deleteAt"`
|
||||
|
||||
// Category's state in client side
|
||||
// required: true
|
||||
Collapsed bool `json:"collapsed"`
|
||||
}
|
||||
|
||||
func (c *Category) Hydrate() {
|
||||
@ -77,3 +83,9 @@ func newErrInvalidCategory(msg string) *ErrInvalidCategory {
|
||||
func (e *ErrInvalidCategory) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func CategoryFromJSON(data io.Reader) *Category {
|
||||
var category *Category
|
||||
_ = json.NewDecoder(data).Decode(&category)
|
||||
return category
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
apierrors "github.com/mattermost/mattermost-plugin-api/errors"
|
||||
pluginapi "github.com/mattermost/mattermost-plugin-api"
|
||||
)
|
||||
|
||||
// ErrBlocksFromDifferentBoards is an error type that can be returned
|
||||
@ -32,7 +32,7 @@ func (nf *ErrNotFound) Error() string {
|
||||
// IsErrNotFound returns true if `err` is or wraps one of:
|
||||
// - model.ErrNotFound
|
||||
// - sql.ErrNoRows
|
||||
// - mattermost-plugin-api/errors/ErrNotFound.
|
||||
// - mattermost-plugin-api/ErrNotFound.
|
||||
func IsErrNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
@ -50,7 +50,7 @@ func IsErrNotFound(err error) bool {
|
||||
}
|
||||
|
||||
// check if this is a plugin API error
|
||||
return errors.Is(err, apierrors.ErrNotFound)
|
||||
return errors.Is(err, pluginapi.ErrNotFound)
|
||||
}
|
||||
|
||||
// ErrNotAllFound is an error type that can be returned by store APIs
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
mux "github.com/gorilla/mux"
|
||||
model "github.com/mattermost/mattermost-server/v6/model"
|
||||
mlog "github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
@ -386,6 +387,18 @@ func (mr *MockServicesAPIMockRecorder) PublishWebSocketEvent(arg0, arg1, arg2 in
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishWebSocketEvent", reflect.TypeOf((*MockServicesAPI)(nil).PublishWebSocketEvent), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// RegisterRouter mocks base method.
|
||||
func (m *MockServicesAPI) RegisterRouter(arg0 *mux.Router) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterRouter", arg0)
|
||||
}
|
||||
|
||||
// RegisterRouter indicates an expected call of RegisterRouter.
|
||||
func (mr *MockServicesAPIMockRecorder) RegisterRouter(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRouter", reflect.TypeOf((*MockServicesAPI)(nil).RegisterRouter), arg0)
|
||||
}
|
||||
|
||||
// UpdateUser mocks base method.
|
||||
func (m *MockServicesAPI) UpdateUser(arg0 *model.User) (*model.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -8,6 +8,8 @@ package model
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
@ -67,4 +69,7 @@ type ServicesAPI interface {
|
||||
|
||||
// System service
|
||||
GetDiagnosticID() string
|
||||
|
||||
// Router service
|
||||
RegisterRouter(sub *mux.Router)
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
// This is a list of all the current versions including any patches.
|
||||
// It should be maintained in chronological order with most current
|
||||
// release at the front of the list.
|
||||
@ -41,3 +45,14 @@ var (
|
||||
BuildHash string
|
||||
Edition string
|
||||
)
|
||||
|
||||
// LogServerInfo logs information about the server instance.
|
||||
func LogServerInfo(logger mlog.LoggerIFace) {
|
||||
logger.Info("FocalBoard Server",
|
||||
mlog.String("version", CurrentVersion),
|
||||
mlog.String("edition", Edition),
|
||||
mlog.String("build_number", BuildNumber),
|
||||
mlog.String("build_date", BuildDate),
|
||||
mlog.String("build_hash", BuildHash),
|
||||
)
|
||||
}
|
||||
|
@ -681,21 +681,6 @@ func (mr *MockAPIMockRecorder) GetChannelsForTeamForUser(arg0, arg1, arg2 interf
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannelsForTeamForUser", reflect.TypeOf((*MockAPI)(nil).GetChannelsForTeamForUser), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// GetCloudLimits mocks base method.
|
||||
func (m *MockAPI) GetCloudLimits() (*model.ProductLimits, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetCloudLimits")
|
||||
ret0, _ := ret[0].(*model.ProductLimits)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetCloudLimits indicates an expected call of GetCloudLimits.
|
||||
func (mr *MockAPIMockRecorder) GetCloudLimits() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCloudLimits", reflect.TypeOf((*MockAPI)(nil).GetCloudLimits))
|
||||
}
|
||||
|
||||
// GetCommand mocks base method.
|
||||
func (m *MockAPI) GetCommand(arg0 string) (*model.Command, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -275,8 +275,8 @@ func (s *MattermostAuthLayer) GetUsersByTeam(teamID string) ([]*model.User, erro
|
||||
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.props", "u.CreateAt as create_at", "u.UpdateAt as update_at",
|
||||
"u.DeleteAt as delete_at", "b.UserId IS NOT NULL AS is_bot").
|
||||
From("Users as u").
|
||||
Join("TeamMembers as tm ON tm.UserID = u.ID").
|
||||
LeftJoin("Bots b ON ( b.UserId = Users.ID )").
|
||||
Join("TeamMembers as tm ON tm.UserID = u.id").
|
||||
LeftJoin("Bots b ON ( b.UserID = u.id )").
|
||||
Where(sq.Eq{"u.deleteAt": 0}).
|
||||
Where(sq.NotEq{"u.roles": "system_guest"}).
|
||||
Where(sq.Eq{"tm.TeamId": teamID})
|
||||
@ -295,6 +295,28 @@ func (s *MattermostAuthLayer) GetUsersByTeam(teamID string) ([]*model.User, erro
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) GetUsersList(userIDs []string) ([]*model.User, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.props", "u.CreateAt as create_at", "u.UpdateAt as update_at",
|
||||
"u.DeleteAt as delete_at", "b.UserId IS NOT NULL AS is_bot").
|
||||
From("Users as u").
|
||||
LeftJoin("Bots b ON ( b.UserId = u.id )").
|
||||
Where(sq.Eq{"u.id": userIDs})
|
||||
|
||||
rows, err := query.Query()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
users, err := s.usersFromRows(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery string) ([]*model.User, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.props", "u.CreateAt as create_at", "u.UpdateAt as update_at",
|
||||
@ -546,6 +568,7 @@ func (s *MattermostAuthLayer) SearchBoardsForUser(term, userID string) ([]*model
|
||||
From(s.tablePrefix + "boards as b").
|
||||
LeftJoin(s.tablePrefix + "board_members as bm on b.id=bm.board_id").
|
||||
LeftJoin("TeamMembers as tm on tm.teamid=b.team_id").
|
||||
LeftJoin("ChannelMembers as cm on cm.channelId=b.channel_id").
|
||||
Where(sq.Eq{"b.is_template": false}).
|
||||
Where(sq.Eq{"tm.userID": userID}).
|
||||
Where(sq.Eq{"tm.deleteAt": 0}).
|
||||
@ -553,18 +576,21 @@ func (s *MattermostAuthLayer) SearchBoardsForUser(term, userID string) ([]*model
|
||||
sq.Eq{"b.type": model.BoardTypeOpen},
|
||||
sq.And{
|
||||
sq.Eq{"b.type": model.BoardTypePrivate},
|
||||
sq.Eq{"bm.user_id": userID},
|
||||
sq.Or{
|
||||
sq.Eq{"bm.user_id": userID},
|
||||
sq.Eq{"cm.userId": userID},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if term != "" {
|
||||
// break search query into space separated words
|
||||
// and search for each word.
|
||||
// and search for all words.
|
||||
// This should later be upgraded to industrial-strength
|
||||
// word tokenizer, that uses much more than space
|
||||
// to break words.
|
||||
|
||||
conditions := sq.Or{}
|
||||
conditions := sq.And{}
|
||||
|
||||
for _, word := range strings.Split(strings.TrimSpace(term), " ") {
|
||||
conditions = append(conditions, sq.Like{"lower(b.title)": "%" + strings.ToLower(word) + "%"})
|
||||
@ -662,15 +688,23 @@ func (s *MattermostAuthLayer) implicitBoardMembershipsFromRows(rows *sql.Rows) (
|
||||
func (s *MattermostAuthLayer) GetMemberForBoard(boardID, userID string) (*model.BoardMember, error) {
|
||||
bm, err := s.Store.GetMemberForBoard(boardID, userID)
|
||||
if model.IsErrNotFound(err) {
|
||||
b, err := s.Store.GetBoard(boardID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
b, boardErr := s.Store.GetBoard(boardID)
|
||||
if boardErr != nil {
|
||||
return nil, boardErr
|
||||
}
|
||||
if b.ChannelID != "" {
|
||||
_, err := s.servicesAPI.GetChannelMember(b.ChannelID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
_, memberErr := s.servicesAPI.GetChannelMember(b.ChannelID, userID)
|
||||
if memberErr != nil {
|
||||
var appErr *mmModel.AppError
|
||||
if errors.As(memberErr, &appErr) && appErr.StatusCode == http.StatusNotFound {
|
||||
// Plugin API returns error if channel member doesn't exist.
|
||||
// We're fine if it doesn't exist, so its not an error for us.
|
||||
return nil, model.NewErrNotFound(userID)
|
||||
}
|
||||
|
||||
return nil, memberErr
|
||||
}
|
||||
|
||||
return &model.BoardMember{
|
||||
BoardID: boardID,
|
||||
UserID: userID,
|
||||
@ -683,6 +717,9 @@ func (s *MattermostAuthLayer) GetMemberForBoard(boardID, userID string) (*model.
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bm, nil
|
||||
}
|
||||
|
||||
@ -789,13 +826,14 @@ func (s *MattermostAuthLayer) SearchUserChannels(teamID, userID, query string) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lowerQuery := strings.ToLower(query)
|
||||
|
||||
result := []*mmModel.Channel{}
|
||||
count := 0
|
||||
for _, channel := range channels {
|
||||
if channel.Type != mmModel.ChannelTypeDirect &&
|
||||
channel.Type != mmModel.ChannelTypeGroup &&
|
||||
(strings.Contains(channel.Name, query) || strings.Contains(channel.DisplayName, query)) {
|
||||
(strings.Contains(strings.ToLower(channel.Name), lowerQuery) || strings.Contains(strings.ToLower(channel.DisplayName), lowerQuery)) {
|
||||
result = append(result, channel)
|
||||
count++
|
||||
if count >= 10 {
|
||||
@ -861,3 +899,12 @@ func (s *MattermostAuthLayer) SendMessage(message, postType string, receipts []s
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) GetUserTimezone(userID string) (string, error) {
|
||||
user, err := s.servicesAPI.GetUserByID(userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
timezone := user.Timezone
|
||||
return mmModel.GetPreferredTimezone(timezone), nil
|
||||
}
|
||||
|
@ -925,6 +925,21 @@ func (mr *MockStoreMockRecorder) GetTeam(arg0 interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTeam", reflect.TypeOf((*MockStore)(nil).GetTeam), arg0)
|
||||
}
|
||||
|
||||
// GetTeamBoardsInsights mocks base method.
|
||||
func (m *MockStore) GetTeamBoardsInsights(arg0, arg1 string, arg2 int64, arg3, arg4 int, arg5 []string) (*model.BoardInsightsList, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetTeamBoardsInsights", arg0, arg1, arg2, arg3, arg4, arg5)
|
||||
ret0, _ := ret[0].(*model.BoardInsightsList)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetTeamBoardsInsights indicates an expected call of GetTeamBoardsInsights.
|
||||
func (mr *MockStoreMockRecorder) GetTeamBoardsInsights(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTeamBoardsInsights", reflect.TypeOf((*MockStore)(nil).GetTeamBoardsInsights), arg0, arg1, arg2, arg3, arg4, arg5)
|
||||
}
|
||||
|
||||
// GetTeamCount mocks base method.
|
||||
func (m *MockStore) GetTeamCount() (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -985,6 +1000,21 @@ func (mr *MockStoreMockRecorder) GetUsedCardsCount() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsedCardsCount", reflect.TypeOf((*MockStore)(nil).GetUsedCardsCount))
|
||||
}
|
||||
|
||||
// GetUserBoardsInsights mocks base method.
|
||||
func (m *MockStore) GetUserBoardsInsights(arg0, arg1 string, arg2 int64, arg3, arg4 int, arg5 []string) (*model.BoardInsightsList, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUserBoardsInsights", arg0, arg1, arg2, arg3, arg4, arg5)
|
||||
ret0, _ := ret[0].(*model.BoardInsightsList)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUserBoardsInsights indicates an expected call of GetUserBoardsInsights.
|
||||
func (mr *MockStoreMockRecorder) GetUserBoardsInsights(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserBoardsInsights", reflect.TypeOf((*MockStore)(nil).GetUserBoardsInsights), arg0, arg1, arg2, arg3, arg4, arg5)
|
||||
}
|
||||
|
||||
// GetUserByEmail mocks base method.
|
||||
func (m *MockStore) GetUserByEmail(arg0 string) (*model.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -1045,6 +1075,21 @@ func (mr *MockStoreMockRecorder) GetUserCategoryBoards(arg0, arg1 interface{}) *
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserCategoryBoards", reflect.TypeOf((*MockStore)(nil).GetUserCategoryBoards), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetUserTimezone mocks base method.
|
||||
func (m *MockStore) GetUserTimezone(arg0 string) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUserTimezone", arg0)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUserTimezone indicates an expected call of GetUserTimezone.
|
||||
func (mr *MockStoreMockRecorder) GetUserTimezone(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserTimezone", reflect.TypeOf((*MockStore)(nil).GetUserTimezone), arg0)
|
||||
}
|
||||
|
||||
// GetUsersByTeam mocks base method.
|
||||
func (m *MockStore) GetUsersByTeam(arg0 string) ([]*model.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -1060,6 +1105,21 @@ func (mr *MockStoreMockRecorder) GetUsersByTeam(arg0 interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersByTeam", reflect.TypeOf((*MockStore)(nil).GetUsersByTeam), arg0)
|
||||
}
|
||||
|
||||
// GetUsersList mocks base method.
|
||||
func (m *MockStore) GetUsersList(arg0 []string) ([]*model.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUsersList", arg0)
|
||||
ret0, _ := ret[0].([]*model.User)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUsersList indicates an expected call of GetUsersList.
|
||||
func (mr *MockStoreMockRecorder) GetUsersList(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersList", reflect.TypeOf((*MockStore)(nil).GetUsersList), arg0)
|
||||
}
|
||||
|
||||
// InsertBlock mocks base method.
|
||||
func (m *MockStore) InsertBlock(arg0 *model.Block, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -126,23 +126,6 @@ func (s *SQLStore) getBlocksByIDs(db sq.BaseRunner, ids []string) ([]model.Block
|
||||
return blocks, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithBoardID(db sq.BaseRunner, boardID string) ([]model.Block, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select(s.blockFields()...).
|
||||
From(s.tablePrefix + "blocks").
|
||||
Where(sq.Eq{"board_id": boardID})
|
||||
|
||||
rows, err := query.Query()
|
||||
if err != nil {
|
||||
s.logger.Error(`GetBlocksWithBoardID ERROR`, mlog.Err(err))
|
||||
|
||||
return nil, err
|
||||
}
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
return s.blocksFromRows(rows)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithType(db sq.BaseRunner, boardID, blockType string) ([]model.Block, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select(s.blockFields()...).
|
||||
|
@ -660,12 +660,12 @@ func (s *SQLStore) searchBoardsForUser(db sq.BaseRunner, term, userID string) ([
|
||||
|
||||
if term != "" {
|
||||
// break search query into space separated words
|
||||
// and search for each word.
|
||||
// and search for all words.
|
||||
// This should later be upgraded to industrial-strength
|
||||
// word tokenizer, that uses much more than space
|
||||
// to break words.
|
||||
|
||||
conditions := sq.Or{}
|
||||
conditions := sq.And{}
|
||||
|
||||
for _, word := range strings.Split(strings.TrimSpace(term), " ") {
|
||||
conditions = append(conditions, sq.Like{"lower(b.title)": "%" + strings.ToLower(word) + "%"})
|
||||
@ -706,12 +706,12 @@ func (s *SQLStore) searchBoardsForUserInTeam(db sq.BaseRunner, teamID, term, use
|
||||
|
||||
if term != "" {
|
||||
// break search query into space separated words
|
||||
// and search for each word.
|
||||
// and search for all words.
|
||||
// This should later be upgraded to industrial-strength
|
||||
// word tokenizer, that uses much more than space
|
||||
// to break words.
|
||||
|
||||
conditions := sq.Or{}
|
||||
conditions := sq.And{}
|
||||
|
||||
for _, word := range strings.Split(strings.TrimSpace(term), " ") {
|
||||
conditions = append(conditions, sq.Like{"lower(b.title)": "%" + strings.ToLower(word) + "%"})
|
||||
|
147
server/services/store/sqlstore/board_insights.go
Normal file
147
server/services/store/sqlstore/board_insights.go
Normal file
@ -0,0 +1,147 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (s *SQLStore) getTeamBoardsInsights(db sq.BaseRunner, teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
|
||||
boardsHistoryQuery := s.getQueryBuilder(db).
|
||||
Select("boards.id, boards.icon, boards.title, count(boards_history.id) as count, boards_history.modified_by, boards.created_by").
|
||||
From(s.tablePrefix + "boards_history as boards_history").
|
||||
Join(s.tablePrefix + "boards as boards on boards_history.id = boards.id").
|
||||
Where(sq.Gt{"boards_history.insert_at": mmModel.GetTimeForMillis(since).Format(time.RFC3339)}).
|
||||
Where(sq.Eq{"boards.team_id": teamID}).
|
||||
Where(sq.Eq{"boards.id": boardIDs}).
|
||||
Where(sq.NotEq{"boards_history.modified_by": "system"}).
|
||||
Where(sq.Eq{"boards.delete_at": 0}).
|
||||
GroupBy("boards.id, boards_history.id, boards_history.modified_by")
|
||||
|
||||
blocksHistoryQuery := s.getQueryBuilder(db).
|
||||
Select("boards.id, boards.icon, boards.title, count(blocks_history.id) as count, blocks_history.modified_by, boards.created_by").
|
||||
Prefix("UNION ALL").
|
||||
From(s.tablePrefix + "blocks_history as blocks_history").
|
||||
Join(s.tablePrefix + "boards as boards on blocks_history.board_id = boards.id").
|
||||
Where(sq.Gt{"blocks_history.insert_at": mmModel.GetTimeForMillis(since).Format(time.RFC3339)}).
|
||||
Where(sq.Eq{"boards.team_id": teamID}).
|
||||
Where(sq.Eq{"boards.id": boardIDs}).
|
||||
Where(sq.NotEq{"blocks_history.modified_by": "system"}).
|
||||
Where(sq.Eq{"boards.delete_at": 0}).
|
||||
GroupBy("boards.id, blocks_history.board_id, blocks_history.modified_by")
|
||||
|
||||
boardsActivity := boardsHistoryQuery.SuffixExpr(blocksHistoryQuery)
|
||||
|
||||
insightsQuery := s.getQueryBuilder(db).Select(
|
||||
fmt.Sprintf("id, title, icon, sum(count) as activity_count, %s as active_users, created_by", s.concatenationSelector("distinct modified_by", ",")),
|
||||
).
|
||||
FromSelect(boardsActivity, "boards_and_blocks_history").
|
||||
GroupBy("id, title, icon, created_by").
|
||||
OrderBy("activity_count desc").
|
||||
Offset(uint64(offset)).
|
||||
Limit(uint64(limit))
|
||||
|
||||
rows, err := insightsQuery.Query()
|
||||
if err != nil {
|
||||
s.logger.Error(`Team insights query ERROR`, mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
boardsInsights, err := boardsInsightsFromRows(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
boardInsightsPaginated := model.GetTopBoardInsightsListWithPagination(boardsInsights, limit)
|
||||
|
||||
return boardInsightsPaginated, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getUserBoardsInsights(db sq.BaseRunner, teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
|
||||
boardsHistoryQuery := s.getQueryBuilder(db).
|
||||
Select("boards.id, boards.icon, boards.title, count(boards_history.id) as count, boards_history.modified_by, boards.created_by").
|
||||
From(s.tablePrefix + "boards_history as boards_history").
|
||||
Join(s.tablePrefix + "boards as boards on boards_history.id = boards.id").
|
||||
Where(sq.Gt{"boards_history.insert_at": mmModel.GetTimeForMillis(since).Format(time.RFC3339)}).
|
||||
Where(sq.Eq{"boards.team_id": teamID}).
|
||||
Where(sq.Eq{"boards.id": boardIDs}).
|
||||
Where(sq.NotEq{"boards_history.modified_by": "system"}).
|
||||
Where(sq.Eq{"boards.delete_at": 0}).
|
||||
GroupBy("boards.id, boards_history.id, boards_history.modified_by")
|
||||
|
||||
blocksHistoryQuery := s.getQueryBuilder(db).
|
||||
Select("boards.id, boards.icon, boards.title, count(blocks_history.id) as count, blocks_history.modified_by, boards.created_by").
|
||||
Prefix("UNION ALL").
|
||||
From(s.tablePrefix + "blocks_history as blocks_history").
|
||||
Join(s.tablePrefix + "boards as boards on blocks_history.board_id = boards.id").
|
||||
Where(sq.Gt{"blocks_history.insert_at": mmModel.GetTimeForMillis(since).Format(time.RFC3339)}).
|
||||
Where(sq.Eq{"boards.team_id": teamID}).
|
||||
Where(sq.Eq{"boards.id": boardIDs}).
|
||||
Where(sq.NotEq{"blocks_history.modified_by": "system"}).
|
||||
Where(sq.Eq{"boards.delete_at": 0}).
|
||||
GroupBy("boards.id, blocks_history.board_id, blocks_history.modified_by")
|
||||
|
||||
boardsActivity := boardsHistoryQuery.SuffixExpr(blocksHistoryQuery)
|
||||
|
||||
insightsQuery := s.getQueryBuilder(db).Select(
|
||||
fmt.Sprintf("id, title, icon, sum(count) as activity_count, %s as active_users, created_by", s.concatenationSelector("distinct modified_by", ",")),
|
||||
).
|
||||
FromSelect(boardsActivity, "boards_and_blocks_history").
|
||||
GroupBy("id, title, icon, created_by").
|
||||
OrderBy("activity_count desc")
|
||||
|
||||
userQuery := s.getQueryBuilder(db).Select("*").
|
||||
FromSelect(insightsQuery, "boards_and_blocks_history_for_user").
|
||||
Where(sq.Or{
|
||||
sq.Eq{
|
||||
"created_by": userID,
|
||||
},
|
||||
sq.Expr(s.elementInColumn("active_users"), userID),
|
||||
}).
|
||||
Offset(uint64(offset)).
|
||||
Limit(uint64(limit))
|
||||
|
||||
rows, err := userQuery.Query()
|
||||
|
||||
if err != nil {
|
||||
s.logger.Error(`Team insights query ERROR`, mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
boardsInsights, err := boardsInsightsFromRows(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
boardInsightsPaginated := model.GetTopBoardInsightsListWithPagination(boardsInsights, limit)
|
||||
|
||||
return boardInsightsPaginated, nil
|
||||
}
|
||||
|
||||
func boardsInsightsFromRows(rows *sql.Rows) ([]*model.BoardInsight, error) {
|
||||
boardsInsights := []*model.BoardInsight{}
|
||||
for rows.Next() {
|
||||
var boardInsight model.BoardInsight
|
||||
|
||||
err := rows.Scan(
|
||||
&boardInsight.BoardID,
|
||||
&boardInsight.Title,
|
||||
&boardInsight.Icon,
|
||||
&boardInsight.ActivityCount,
|
||||
&boardInsight.ActiveUsers,
|
||||
&boardInsight.CreatedBy,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
boardsInsights = append(boardsInsights, &boardInsight)
|
||||
}
|
||||
return boardsInsights, nil
|
||||
}
|
@ -161,7 +161,7 @@ func (s *SQLStore) duplicateBoard(db sq.BaseRunner, boardID string, userID strin
|
||||
}
|
||||
|
||||
bab.Boards = []*model.Board{board}
|
||||
blocks, err := s.getBlocksWithBoardID(db, boardID)
|
||||
blocks, err := s.getBlocksForBoard(db, boardID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func (s *SQLStore) getCategory(db sq.BaseRunner, id string) (*model.Category, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at").
|
||||
Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at", "collapsed").
|
||||
From(s.tablePrefix + "categories").
|
||||
Where(sq.Eq{"id": id})
|
||||
|
||||
@ -46,6 +46,7 @@ func (s *SQLStore) createCategory(db sq.BaseRunner, category model.Category) err
|
||||
"create_at",
|
||||
"update_at",
|
||||
"delete_at",
|
||||
"collapsed",
|
||||
).
|
||||
Values(
|
||||
category.ID,
|
||||
@ -55,6 +56,7 @@ func (s *SQLStore) createCategory(db sq.BaseRunner, category model.Category) err
|
||||
category.CreateAt,
|
||||
category.UpdateAt,
|
||||
category.DeleteAt,
|
||||
category.Collapsed,
|
||||
)
|
||||
|
||||
_, err := query.Exec()
|
||||
@ -70,6 +72,7 @@ func (s *SQLStore) updateCategory(db sq.BaseRunner, category model.Category) err
|
||||
Update(s.tablePrefix+"categories").
|
||||
Set("name", category.Name).
|
||||
Set("update_at", category.UpdateAt).
|
||||
Set("collapsed", category.Collapsed).
|
||||
Where(sq.Eq{"id": category.ID})
|
||||
|
||||
_, err := query.Exec()
|
||||
@ -106,7 +109,7 @@ func (s *SQLStore) deleteCategory(db sq.BaseRunner, categoryID, userID, teamID s
|
||||
|
||||
func (s *SQLStore) getUserCategories(db sq.BaseRunner, userID, teamID string) ([]model.Category, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at").
|
||||
Select("id", "name", "user_id", "team_id", "create_at", "update_at", "delete_at", "collapsed").
|
||||
From(s.tablePrefix + "categories").
|
||||
Where(sq.Eq{
|
||||
"user_id": userID,
|
||||
@ -136,6 +139,7 @@ func (s *SQLStore) categoriesFromRows(rows *sql.Rows) ([]model.Category, error)
|
||||
&category.CreateAt,
|
||||
&category.UpdateAt,
|
||||
&category.DeleteAt,
|
||||
&category.Collapsed,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -14,10 +14,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TemplatesToTeamsMigrationKey = "TemplatesToTeamsMigrationComplete"
|
||||
UniqueIDsMigrationKey = "UniqueIDsMigrationComplete"
|
||||
CategoryUUIDIDMigrationKey = "CategoryUuidIdMigrationComplete"
|
||||
TeamLessBoardsMigrationKey = "TeamLessBoardsMigrationComplete"
|
||||
// we group the inserts on batches of 1000 because PostgreSQL
|
||||
// supports a limit of around 64K values (not rows) on an insert
|
||||
// query, so we want to stay safely below.
|
||||
CategoryInsertBatch = 1000
|
||||
|
||||
TemplatesToTeamsMigrationKey = "TemplatesToTeamsMigrationComplete"
|
||||
UniqueIDsMigrationKey = "UniqueIDsMigrationComplete"
|
||||
CategoryUUIDIDMigrationKey = "CategoryUuidIdMigrationComplete"
|
||||
TeamLessBoardsMigrationKey = "TeamLessBoardsMigrationComplete"
|
||||
DeletedMembershipBoardsMigrationKey = "DeletedMembershipBoardsMigrationComplete"
|
||||
)
|
||||
|
||||
func (s *SQLStore) getBlocksWithSameID(db sq.BaseRunner) ([]model.Block, error) {
|
||||
@ -59,7 +65,7 @@ func (s *SQLStore) getBlocksWithSameID(db sq.BaseRunner) ([]model.Block, error)
|
||||
return s.blocksFromRows(rows)
|
||||
}
|
||||
|
||||
func (s *SQLStore) runUniqueIDsMigration() error {
|
||||
func (s *SQLStore) RunUniqueIDsMigration() error {
|
||||
setting, err := s.GetSystemSetting(UniqueIDsMigrationKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get migration state: %w", err)
|
||||
@ -122,7 +128,11 @@ func (s *SQLStore) runUniqueIDsMigration() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) runCategoryUUIDIDMigration() error {
|
||||
// RunCategoryUUIDIDMigration takes care of deriving the categories
|
||||
// from the boards and its memberships. The name references UUID
|
||||
// because of the preexisting purpose of this migration, and has been
|
||||
// preserved for compatibility with already migrated instances.
|
||||
func (s *SQLStore) RunCategoryUUIDIDMigration() error {
|
||||
setting, err := s.GetSystemSetting(CategoryUUIDIDMigrationKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get migration state: %w", err)
|
||||
@ -140,159 +150,197 @@ func (s *SQLStore) runCategoryUUIDIDMigration() error {
|
||||
return txErr
|
||||
}
|
||||
|
||||
if err := s.updateCategoryIDs(tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.isPlugin {
|
||||
if err := s.createCategories(tx); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
s.logger.Error("category UUIDs insert categories transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.updateCategoryBlocksIDs(tx); err != nil {
|
||||
return err
|
||||
if err := s.createCategoryBoards(tx); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
s.logger.Error("category UUIDs insert category boards transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.setSystemSetting(tx, CategoryUUIDIDMigrationKey, strconv.FormatBool(true)); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
s.logger.Error("category IDs transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
|
||||
s.logger.Error("category UUIDs transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
|
||||
}
|
||||
return fmt.Errorf("cannot mark migration as completed: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("cannot commit category IDs transaction: %w", err)
|
||||
return fmt.Errorf("cannot commit category UUIDs transaction: %w", err)
|
||||
}
|
||||
|
||||
s.logger.Debug("category IDs migration finished successfully")
|
||||
s.logger.Debug("category UUIDs migration finished successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) updateCategoryIDs(db sq.BaseRunner) error {
|
||||
// fetch all category IDs
|
||||
oldCategoryIDs, err := s.getIDs(db, "categories")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// map old category ID to new ID
|
||||
categoryIDs := map[string]string{}
|
||||
for _, oldID := range oldCategoryIDs {
|
||||
newID := utils.NewID(utils.IDTypeNone)
|
||||
categoryIDs[oldID] = newID
|
||||
}
|
||||
|
||||
// update for each category ID.
|
||||
// Update the new ID in category table,
|
||||
// and update corresponding rows in category boards table.
|
||||
for oldID, newID := range categoryIDs {
|
||||
if err := s.updateCategoryID(db, oldID, newID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getIDs(db sq.BaseRunner, table string) ([]string, error) {
|
||||
func (s *SQLStore) createCategories(db sq.BaseRunner) error {
|
||||
rows, err := s.getQueryBuilder(db).
|
||||
Select("id").
|
||||
From(s.tablePrefix + table).
|
||||
Select("c.DisplayName, cm.UserId, c.TeamId, cm.ChannelId").
|
||||
From(s.tablePrefix + "boards boards").
|
||||
Join("ChannelMembers cm on boards.channel_id = cm.ChannelId").
|
||||
Join("Channels c on cm.ChannelId = c.id and (c.Type = 'O' or c.Type = 'P')").
|
||||
GroupBy("cm.UserId, c.TeamId, cm.ChannelId, c.DisplayName").
|
||||
Query()
|
||||
|
||||
if err != nil {
|
||||
s.logger.Error("getIDs error", mlog.String("table", table), mlog.Err(err))
|
||||
return nil, err
|
||||
s.logger.Error("get boards data error", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
defer s.CloseRows(rows)
|
||||
var categoryIDs []string
|
||||
|
||||
initQuery := func() sq.InsertBuilder {
|
||||
return s.getQueryBuilder(db).
|
||||
Insert(s.tablePrefix+"categories").
|
||||
Columns(
|
||||
"id",
|
||||
"name",
|
||||
"user_id",
|
||||
"team_id",
|
||||
"channel_id",
|
||||
"create_at",
|
||||
"update_at",
|
||||
"delete_at",
|
||||
)
|
||||
}
|
||||
// query will accumulate the insert values until the limit is
|
||||
// reached, and then it will be stored and reset
|
||||
query := initQuery()
|
||||
// queryList stores those queries that already reached the limit
|
||||
// to be run when all the data is processed
|
||||
queryList := []sq.InsertBuilder{}
|
||||
counter := 0
|
||||
now := model.GetMillis()
|
||||
|
||||
for rows.Next() {
|
||||
var id string
|
||||
err := rows.Scan(&id)
|
||||
var displayName string
|
||||
var userID string
|
||||
var teamID string
|
||||
var channelID string
|
||||
|
||||
err := rows.Scan(
|
||||
&displayName,
|
||||
&userID,
|
||||
&teamID,
|
||||
&channelID,
|
||||
)
|
||||
if err != nil {
|
||||
s.logger.Error("getIDs scan row error", mlog.String("table", table), mlog.Err(err))
|
||||
return nil, err
|
||||
return fmt.Errorf("cannot scan result while trying to create categories: %w", err)
|
||||
}
|
||||
|
||||
categoryIDs = append(categoryIDs, id)
|
||||
query = query.Values(
|
||||
utils.NewID(utils.IDTypeNone),
|
||||
displayName,
|
||||
userID,
|
||||
teamID,
|
||||
channelID,
|
||||
now,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
|
||||
counter++
|
||||
if counter%CategoryInsertBatch == 0 {
|
||||
queryList = append(queryList, query)
|
||||
query = initQuery()
|
||||
}
|
||||
}
|
||||
|
||||
return categoryIDs, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) updateCategoryID(db sq.BaseRunner, oldID, newID string) error {
|
||||
// update in category table
|
||||
rows, err := s.getQueryBuilder(db).
|
||||
Update(s.tablePrefix+"categories").
|
||||
Set("id", newID).
|
||||
Where(sq.Eq{"id": oldID}).
|
||||
Query()
|
||||
|
||||
if err != nil {
|
||||
s.logger.Error("updateCategoryID update category error", mlog.Err(err))
|
||||
return err
|
||||
if counter%CategoryInsertBatch != 0 {
|
||||
queryList = append(queryList, query)
|
||||
}
|
||||
|
||||
if err = rows.Close(); err != nil {
|
||||
s.logger.Error("updateCategoryID error closing rows after updating categories table IDs", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// update category boards table
|
||||
|
||||
rows, err = s.getQueryBuilder(db).
|
||||
Update(s.tablePrefix+"category_boards").
|
||||
Set("category_id", newID).
|
||||
Where(sq.Eq{"category_id": oldID}).
|
||||
Query()
|
||||
|
||||
if err != nil {
|
||||
s.logger.Error("updateCategoryID update category boards error", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if err := rows.Close(); err != nil {
|
||||
s.logger.Error("updateCategoryID error closing rows after updating category boards table IDs", mlog.Err(err))
|
||||
return err
|
||||
for _, q := range queryList {
|
||||
if _, err := q.Exec(); err != nil {
|
||||
return fmt.Errorf("cannot create category values: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) updateCategoryBlocksIDs(db sq.BaseRunner) error {
|
||||
// fetch all category IDs
|
||||
oldCategoryIDs, err := s.getIDs(db, "category_boards")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// map old category ID to new ID
|
||||
categoryIDs := map[string]string{}
|
||||
for _, oldID := range oldCategoryIDs {
|
||||
newID := utils.NewID(utils.IDTypeNone)
|
||||
categoryIDs[oldID] = newID
|
||||
}
|
||||
|
||||
// update for each category ID.
|
||||
// Update the new ID in category table,
|
||||
// and update corresponding rows in category boards table.
|
||||
for oldID, newID := range categoryIDs {
|
||||
if err := s.updateCategoryBlocksID(db, oldID, newID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) updateCategoryBlocksID(db sq.BaseRunner, oldID, newID string) error {
|
||||
// update in category table
|
||||
func (s *SQLStore) createCategoryBoards(db sq.BaseRunner) error {
|
||||
rows, err := s.getQueryBuilder(db).
|
||||
Update(s.tablePrefix+"category_boards").
|
||||
Set("id", newID).
|
||||
Where(sq.Eq{"id": oldID}).
|
||||
Select("categories.user_id, categories.id, boards.id").
|
||||
From(s.tablePrefix + "categories categories").
|
||||
Join(s.tablePrefix + "boards boards on categories.channel_id = boards.channel_id AND boards.is_template = false").
|
||||
Query()
|
||||
|
||||
if err != nil {
|
||||
s.logger.Error("updateCategoryBlocksID update category error", mlog.Err(err))
|
||||
s.logger.Error("get categories data error", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
rows.Close()
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
initQuery := func() sq.InsertBuilder {
|
||||
return s.getQueryBuilder(db).
|
||||
Insert(s.tablePrefix+"category_boards").
|
||||
Columns(
|
||||
"id",
|
||||
"user_id",
|
||||
"category_id",
|
||||
"board_id",
|
||||
"create_at",
|
||||
"update_at",
|
||||
"delete_at",
|
||||
)
|
||||
}
|
||||
// query will accumulate the insert values until the limit is
|
||||
// reached, and then it will be stored and reset
|
||||
query := initQuery()
|
||||
// queryList stores those queries that already reached the limit
|
||||
// to be run when all the data is processed
|
||||
queryList := []sq.InsertBuilder{}
|
||||
counter := 0
|
||||
now := model.GetMillis()
|
||||
|
||||
for rows.Next() {
|
||||
var userID string
|
||||
var categoryID string
|
||||
var boardID string
|
||||
|
||||
err := rows.Scan(
|
||||
&userID,
|
||||
&categoryID,
|
||||
&boardID,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan result while trying to create category boards: %w", err)
|
||||
}
|
||||
|
||||
query = query.Values(
|
||||
utils.NewID(utils.IDTypeNone),
|
||||
userID,
|
||||
categoryID,
|
||||
boardID,
|
||||
now,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
|
||||
counter++
|
||||
if counter%CategoryInsertBatch == 0 {
|
||||
queryList = append(queryList, query)
|
||||
query = initQuery()
|
||||
}
|
||||
}
|
||||
|
||||
if counter%CategoryInsertBatch != 0 {
|
||||
queryList = append(queryList, query)
|
||||
}
|
||||
|
||||
for _, q := range queryList {
|
||||
if _, err := q.Exec(); err != nil {
|
||||
return fmt.Errorf("cannot create category boards values: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -300,7 +348,7 @@ func (s *SQLStore) updateCategoryBlocksID(db sq.BaseRunner, oldID, newID string)
|
||||
// We no longer support boards existing in DMs and private
|
||||
// group messages. This function migrates all boards
|
||||
// belonging to a DM to the best possible team.
|
||||
func (s *SQLStore) migrateTeamLessBoards() error {
|
||||
func (s *SQLStore) RunTeamLessBoardsMigration() error {
|
||||
if !s.isPlugin {
|
||||
return nil
|
||||
}
|
||||
@ -329,7 +377,7 @@ func (s *SQLStore) migrateTeamLessBoards() error {
|
||||
|
||||
tx, err := s.db.BeginTx(context.Background(), nil)
|
||||
if err != nil {
|
||||
s.logger.Error("error starting transaction in migrateTeamLessBoards", mlog.Err(err))
|
||||
s.logger.Error("error starting transaction in runTeamLessBoardsMigration", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -343,6 +391,7 @@ func (s *SQLStore) migrateTeamLessBoards() error {
|
||||
if err != nil {
|
||||
// don't let one board's error spoil
|
||||
// the mood for others
|
||||
s.logger.Error("could not find the best team for board during team less boards migration. Continuing", mlog.String("boardID", boards[i].ID))
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -364,13 +413,13 @@ func (s *SQLStore) migrateTeamLessBoards() error {
|
||||
|
||||
if err := s.setSystemSetting(tx, TeamLessBoardsMigrationKey, strconv.FormatBool(true)); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
s.logger.Error("transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "migrateTeamLessBoards"))
|
||||
s.logger.Error("transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "runTeamLessBoardsMigration"))
|
||||
}
|
||||
return fmt.Errorf("cannot mark migration as completed: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
s.logger.Error("failed to commit migrateTeamLessBoards transaction", mlog.Err(err))
|
||||
s.logger.Error("failed to commit runTeamLessBoardsMigration transaction", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -467,10 +516,15 @@ func (s *SQLStore) getBestTeamForBoard(tx sq.BaseRunner, board *model.Board) (st
|
||||
|
||||
func (s *SQLStore) getBoardUserTeams(tx sq.BaseRunner, board *model.Board) (map[string][]string, error) {
|
||||
query := s.getQueryBuilder(tx).
|
||||
Select("TeamMembers.UserId", "TeamMembers.TeamId").
|
||||
From("ChannelMembers").
|
||||
Join("TeamMembers ON ChannelMembers.UserId = TeamMembers.UserId").
|
||||
Where(sq.Eq{"ChannelId": board.ChannelID})
|
||||
Select("tm.UserId", "tm.TeamId").
|
||||
From("ChannelMembers cm").
|
||||
Join("TeamMembers tm ON cm.UserId = tm.UserId").
|
||||
Join("Teams t ON tm.TeamId = t.Id").
|
||||
Where(sq.Eq{
|
||||
"cm.ChannelId": board.ChannelID,
|
||||
"t.DeleteAt": 0,
|
||||
"tm.DeleteAt": 0,
|
||||
})
|
||||
|
||||
rows, err := query.Query()
|
||||
if err != nil {
|
||||
@ -495,3 +549,99 @@ func (s *SQLStore) getBoardUserTeams(tx sq.BaseRunner, board *model.Board) (map[
|
||||
|
||||
return userTeams, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) RunDeletedMembershipBoardsMigration() error {
|
||||
if !s.isPlugin {
|
||||
return nil
|
||||
}
|
||||
|
||||
setting, err := s.GetSystemSetting(DeletedMembershipBoardsMigrationKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get deleted membership boards migration state: %w", err)
|
||||
}
|
||||
|
||||
// If the migration is already completed, do not run it again.
|
||||
if hasAlreadyRun, _ := strconv.ParseBool(setting); hasAlreadyRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
boards, err := s.getDeletedMembershipBoards(s.db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(boards) == 0 {
|
||||
s.logger.Debug("No boards with owner not anymore on their team found, marking runDeletedMembershipBoardsMigration as done")
|
||||
if sErr := s.SetSystemSetting(DeletedMembershipBoardsMigrationKey, strconv.FormatBool(true)); sErr != nil {
|
||||
return fmt.Errorf("cannot mark migration as completed: %w", sErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
s.logger.Debug("Migrating boards with owner not anymore on their team", mlog.Int("count", len(boards)))
|
||||
|
||||
tx, err := s.db.BeginTx(context.Background(), nil)
|
||||
if err != nil {
|
||||
s.logger.Error("error starting transaction in runDeletedMembershipBoardsMigration", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range boards {
|
||||
teamID, err := s.getBestTeamForBoard(s.db, boards[i])
|
||||
if err != nil {
|
||||
// don't let one board's error spoil
|
||||
// the mood for others
|
||||
s.logger.Error("could not find the best team for board during deleted membership boards migration. Continuing", mlog.String("boardID", boards[i].ID))
|
||||
continue
|
||||
}
|
||||
|
||||
boards[i].TeamID = teamID
|
||||
|
||||
query := s.getQueryBuilder(tx).
|
||||
Update(s.tablePrefix+"boards").
|
||||
Set("team_id", teamID).
|
||||
Where(sq.Eq{"id": boards[i].ID})
|
||||
|
||||
if _, err := query.Exec(); err != nil {
|
||||
s.logger.Error("failed to set team id for board", mlog.String("board_id", boards[i].ID), mlog.String("team_id", teamID), mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.setSystemSetting(tx, DeletedMembershipBoardsMigrationKey, strconv.FormatBool(true)); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
s.logger.Error("transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "runDeletedMembershipBoardsMigration"))
|
||||
}
|
||||
return fmt.Errorf("cannot mark migration as completed: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
s.logger.Error("failed to commit runDeletedMembershipBoardsMigration transaction", mlog.Err(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getDeletedMembershipBoards retrieves those boards whose creator is
|
||||
// associated to the board's team with a deleted team membership.
|
||||
func (s *SQLStore) getDeletedMembershipBoards(tx sq.BaseRunner) ([]*model.Board, error) {
|
||||
rows, err := s.getQueryBuilder(tx).
|
||||
Select(legacyBoardFields("b.")...).
|
||||
From(s.tablePrefix + "boards b").
|
||||
Join("TeamMembers tm ON b.created_by = tm.UserId").
|
||||
Where("b.team_id = tm.TeamId").
|
||||
Where(sq.NotEq{"tm.DeleteAt": 0}).
|
||||
Query()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.CloseRows(rows)
|
||||
|
||||
boards, err := s.boardsFromRows(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return boards, err
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ func TestRunUniqueIDsMigration(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
err := sqlStore.runUniqueIDsMigration()
|
||||
err := sqlStore.RunUniqueIDsMigration()
|
||||
require.NoError(t, err)
|
||||
|
||||
// blocks from workspace 1 haven't changed, so we can simply fetch them
|
||||
|
@ -31,7 +31,7 @@ func SetupTests(t *testing.T) (store.Store, func()) {
|
||||
IsPlugin: false,
|
||||
}
|
||||
store, err := New(storeParams)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
tearDown := func() {
|
||||
defer func() { _ = logger.Shutdown() }()
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user