1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-12 09:04:14 +02:00
focalboard/server/integrationtests/board_test.go
Jesús Espino aa540e73ce
Permissions feature branch (#2578)
* wip

* Added data migration for populating categories

* wip

* Added data migration for populating categories

* Store WIP

* migration WIP

* category CRUD APIs complete

* category block API WIP

* block category update API done

* Fetcehed data into store

* Started displayting sidebar data

* sidebar WIP

* Dashboard - basic changes

* Sidebar dashboard btn and board switcher UI only

* Sidebar dashboard btn and board switcher UI only

* create category dialog WIP

* Create category webapp side done

* Integrated move card to other category

* board to block

* Disabled dashboard route for now as we'll implement it in phase 2

* WIP

* Added logic to open last board/view on per team level

* Add workspace to teams and boards migrations (#1986)

* Add workspace to teams and boards migrations

* Update json annotations on board models

* boards search dialog WIP

* Seach dialog WIP

* Implemented opening boiard from search results

* Boards switcher styliung

* Handled update category WS event

* Template support

* personal server support and styling fixes

* test fix WIP

* Fixed a bug causing boards to not be moved correctly beteen categories

* Fixed webapp tests

* fix

* Store changes (#2011)

* Permissions phase 1 - Websocket updates (#2014)

* Store changes

* Websockets changes

* Permissions phase 1 - Permissions service (#2015)

* Store changes

* Websockets changes

* Permissions service

* Api and app updates (#2016)

* Store changes

* Websockets changes

* Permissions service

* New API and App changes

* Delete and Patch boards and blocks endpoints

* Used correct variable

* Webapp changes WIP

* Open correct team URL

* Fixed get block API

* Used React context for workspace users

* WIP

* On load navigation sorted out

* WIP

* Nav fix

* categories WS broadcast

* Used real search API

* Fixed unfurl ppreview

* set active team in sidebar

* IMplemented navigation on changing team in sidebar

* Misc fixes

* close rows inside transaction (#2045)

* update syntax for mysql (#2044)

* Upadted mutator for new patchBlock API

* Updated patchBlock API to use new URL

* Listeining to correct event in plugin mode

* Implemented WS messages for category operations:

* Fix duplicated build tags on Makefile

* Sidebar enhancements

* Add missing prefix to SQLite migration and fix flaky tests

* Sidebar boards menu enhancement

* Fix board page interactions (#2144)

* Fix patch board card properties error

* Fix board interactions

* Fix insert blocks interactions

* Fix app tests (#2104)

* Add json1 tag to vscode launch (#2157)

* Fix add, delete and update boards and add board patch generation (#2146)

* Fix update boards and add board patch generation

* Make add board and add template work, as well as deleting a board

* Update the state on board deletion

* Delete unused variable

* Fix bad parenthesis

* Fix board creation inside plugin, options were coming null due websocket message serialization

* update property type mutators to use boards API (#2168)

* Add permissions modal (#2196)

* Initial integration

* Permissions modal, websocket updates and API tests implemented

* Avoid updating/removing user if there is only one admin left

* Fix duplicates on board search

* Adds integration test

* Addressing PR review comments

Co-authored-by: Jesús Espino <jespinog@gmail.com>

* Merge

* I'm able to compile now

* Some fixes around tests execution

* Fixing migrations

* Fixing migrations order

* WIP

* Fixing some other compilation problems on tests

* Some typescript tests fixed

* Fixing javascript tests

* Fixing compilation

* Fixing some problems to create boards

* Load the templates on initial load

* Improvements over initial team templates import

* Adding new fields in the database

* Working on adding duplicate board api

* Removing RootID concept entirely

* Improving a bit the subscriptions

* Fixing store tests for notificationHints

* Fixing more tests

* fixing tests

* Fixing tests

* Fixing tests

* Fixing some small bugs related to templates

* Fixing registration link generation/regeneration

* Fixing cypress tests

* Adding store tests for duplicateBoard and duplicateBlock

* Addressing some TODO comments

* Making the export api simpler

* Add redirect component for old workspace urls

* Removing Dashboard code

* Delete only the built-in templates on update

* fixing tests

* Adding users autocompletion

* Updating snapshots

* Fixing bad merge

* fix panic when creating new card in notifysubscriptions (#2352)

* fix lint errors (#2353)

* fix lint errors

* fix panic when creating new card in notifysubscriptions (#2352)

* fix lint errors

* fix unit test

* Revert "fix unit test"

This reverts commit 0ad78aed65.

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>

* fix sql syntax error for SearchUsersByTeam (#2357)

* Fix mentions delivery (#2358)

* fix sql syntax error for SearchUsersByTeam

* fix mentions delivery

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* update api for octoClient calls, pass correct variables to mutator (#2359)

* Fixing tests after merge

* Fix sidebar context menu UI issue (#2399)

* Fix notification diff for text blocks (#2386)

* fix notification diff for text blocks; fix various linter errors.

* fix URLs to cards

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* Permissions branch: Fix card links (#2391)

* fix notification diff for text blocks; fix various linter errors.

* fix URLs to cards

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* Fixing sqlite tests

* Fixing server tests

* Update migrations to create global templates. (#2397)

* fix duplicate templates

* revert migrate.go

* update UI for empty templates

* implement updating built-in templates as global (teamId = 0)

* handle error if board not found

* update unit test

* fix more tests

* Update blocks_test.go

Fix merge issue

* fix migration sql error (#2414)

* Fixing frontend tests

* Set target team ID when using a global template (#2419)

* Fix some server tests

* Fixing onboarding creation

* Permissions branch: Fix unit tests and CI errors (part 1) (#2425)

* Fixing some small memory leaks (#2400)

* Fixing some small memory leaks

* fixing tests

* passing the tags to all test targets

* Increasing the timeout of the tests

* Fix some type checkings

* Permissions branch: Fixes all the linter errors (#2429)

* fix linter errors

* Reestructuring the router and splitting in more subcomponents (#2403)

* Reestructuring the router and splitting in more subcomponents

* Removing console.log calls

* Removing unneeded selector

* Addressing PR comment

* Fix redirection to one team when you load directly the boards home path

* Using properly the lastTeamID to redirect the user if needed

* don't allow last admin change/deleted (#2416)

* don't allow last admin change/deleted

* update for i18-extract

* fixed en.json

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>

* Splitting BoardPage component into simpler/smaller components (#2435)

* Splitting BoardPage component into simpler/smaller components

* Removing unneeded import

* Replace go migrate with morph permissions (#2424)

* merge origin/replace-go-migrate-with-morph

* run go mod tidy on mattermost-plugin and increase test timeout

* fix merge issue temprorarily

* remove some debug changes

* fixing the linter

* Allow always team 0 (global) templates fetch (#2472)

* Fix problem with viewId 0 in the URL (#2473)

* Migrate from binddata to goembed (#2471)

* Adding join logic to the board switcher (#2434)

* Adding join logic to the board switcher

* Using already existing client function and removing the joinBoard one

* Adding support for autojoin based on url

* Fixing frontend tests

* fix webapp compile error, missing enableSharedBoards (#2501)

* Fixing duplication on postgres

* Adding back views to the sidebar (#2494)

* Fix #2507. Update Swagger comments (#2508)

* Fix the flash of the template selector on board/team switch (#2490)

* Fix the flash of the template selector on board/team switch

* More fixes specially around error handling

* Fixing the bot badge (#2487)

* simplifying a bit the team store sync between channels and focalboard (#2481)

* Fix menu tests (#2528)

* fix failing menu tests

* fix lint error

* Added keyboard shortcut for boards switcher (#2407)

* Added keyboard shortcut for boards switcher

* Fixed a type error

* Added some inline comments

* Fixed lint

* Fixed bug with scroll jumping when the card is opened: (#2477)

- avoid remounting of `ScrollingComponent` for each render of `Kanban` component
  - property `autoFocus` set to false for `CalculationOptions` because it triggers `blur` even for the button in Jest tests and closes the menu
  - snapshots for tests with `CalculationOptions` updated

* Adding the frontend support for permissions and applying it to a big part of the interface. (#2536)

* Initial work on permissions gates

* Applying permissions gates in more places

* Adding more checks to the interface

* Adding more permissions gates and keeping the store up to date

* fixing some tests

* Fixing some more tests

* Fixing another test

* Fixing all tests and adding some more

* Adding no-permission snapshot tests

* Addressing PR review comments

* Fixing invert behavior

* Permissions branch:  No sqlstore calls after app shutdown (#2530)

* fix webapp compile error, missing enableSharedBoards

* refactor app init wip

* - ensure all block change notifications are finished before shutting down app
- fix unit tests for mysql (insert_at only has 1 second resolution!)

* adjust logging

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* Fixed migrations to allow upgrading from previous version (#2535)

* Added mechanism to check if schema migration is needed

* WIP

* WIP

* WIP

* WIP

* Fixed migration

* Fixed for SQLite

* minor cleaniup

* Deleted old schema migration table after running migrations

* Removed a debug log

* Fixed a bug where the code always tried to delete a table which may or may not exist

* Show properly the user avatar in the ShareBoard component (#2542)

* Fixing the last CI problems from the permissions-branch (#2541)

* Fix history ordering

* Giving some times to avoid possible race conditions

* Empty

* Reverting accidental change in the config.json

* Optimizing table view (#2540)

* Optimizing table view

* Reducing the amount of rendering for tables

* Some other performance improvements

* Improve the activeView updates

* Some extra simplifications

* Another small improvement

* Fixing tests

* Fixing linter errors

* Reducing a bit the amount of dependency with big objects in the store

* Small simplification

* Removing Commenter role from the user role selector (#2561)

* Shareboard cleanup (#2550)

* Initial work on permissions gates

* Applying permissions gates in more places

* Adding more checks to the interface

* Adding more permissions gates and keeping the store up to date

* fixing some tests

* Fixing some more tests

* Fixing another test

* Fixing all tests and adding some more

* Adding no-permission snapshot tests

* Addressing PR review comments

* cleanup some shareboard settings

* remove unused property, fix for user items being displayed for non admin

* revert change, allow users to show

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* Fixing comments and cards with the new optimizations in the store (#2560)

* Fixing property creation (#2563)

* Fix user selection in table view (#2565)

* Fixing focus new row in table view (#2567)

* Permissions branch: Fix sqlite table lock (CI) (#2568)

* fix sqlite table lock

* remove test db on teardown

* revert .gitignore

* fix goimport on migration code

* fix typo

* more linter fixes

* clean up tmp db for sqlstore tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>

* Fixing snapshots

* Migrating center panel to functional component (#2562)

* Migrating center panel to functional component

* Fixing some tests

* Fixing another test

* Fixing linter errors

* Fixing types errors

* Fixing linter error

* Fixing cypress tests

* Fixing the last cypress test

* Simpliying a bit the code

* Making property insertion more robust

* Updating checkbox test

Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Chen-I Lim <46905241+chenilim@users.noreply.github.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: kamre <eremchenko@gmail.com>
2022-03-22 08:24:34 -06:00

1271 lines
34 KiB
Go

package integrationtests
import (
"testing"
"github.com/mattermost/focalboard/server/client"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/utils"
"github.com/stretchr/testify/require"
)
const (
testTeamID = "team-id"
)
func TestGetBoards(t *testing.T) {
t.Run("a non authenticated client should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
teamID := "0"
newBoard := &model.Board{
TeamID: teamID,
Type: model.BoardTypeOpen,
}
board, err := th.Server.App().CreateBoard(newBoard, "user-id", false)
require.NoError(t, err)
require.NotNil(t, board)
boards, resp := th.Client.GetBoardsForTeam(teamID)
th.CheckUnauthorized(resp)
require.Nil(t, boards)
})
t.Run("should only return the boards that the user is a member of", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := "0"
otherTeamID := "other-team-id"
user1 := th.GetUser1()
board1 := &model.Board{
TeamID: teamID,
Type: model.BoardTypeOpen,
}
rBoard1, err := th.Server.App().CreateBoard(board1, user1.ID, true)
require.NoError(t, err)
require.NotNil(t, rBoard1)
board2 := &model.Board{
TeamID: teamID,
Type: model.BoardTypeOpen,
}
rBoard2, err := th.Server.App().CreateBoard(board2, user1.ID, false)
require.NoError(t, err)
require.NotNil(t, rBoard2)
board3 := &model.Board{
TeamID: teamID,
Type: model.BoardTypePrivate,
}
rBoard3, err := th.Server.App().CreateBoard(board3, user1.ID, true)
require.NoError(t, err)
require.NotNil(t, rBoard3)
board4 := &model.Board{
TeamID: teamID,
Type: model.BoardTypePrivate,
}
rBoard4, err := th.Server.App().CreateBoard(board4, user1.ID, false)
require.NoError(t, err)
require.NotNil(t, rBoard4)
board5 := &model.Board{
TeamID: otherTeamID,
Type: model.BoardTypeOpen,
}
rBoard5, err := th.Server.App().CreateBoard(board5, user1.ID, true)
require.NoError(t, err)
require.NotNil(t, rBoard5)
boards, resp := th.Client.GetBoardsForTeam(teamID)
th.CheckOK(resp)
require.NotNil(t, boards)
require.Len(t, boards, 2)
boardIDs := []string{}
for _, board := range boards {
boardIDs = append(boardIDs, board.ID)
}
require.ElementsMatch(t, []string{rBoard1.ID, rBoard3.ID}, boardIDs)
boardsFromOtherTeam, resp := th.Client.GetBoardsForTeam(otherTeamID)
th.CheckOK(resp)
require.NotNil(t, boardsFromOtherTeam)
require.Len(t, boardsFromOtherTeam, 1)
require.Equal(t, rBoard5.ID, boardsFromOtherTeam[0].ID)
})
}
func TestCreateBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
newBoard := &model.Board{
Title: "board title",
Type: model.BoardTypeOpen,
TeamID: testTeamID,
}
board, resp := th.Client.CreateBoard(newBoard)
th.CheckUnauthorized(resp)
require.Nil(t, board)
})
t.Run("create public board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
me := th.GetUser1()
title := "board title 1"
teamID := testTeamID
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)
t.Run("creating a board should make the creator an admin", func(t *testing.T) {
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.Equal(t, me.ID, members[0].UserID)
require.Equal(t, board.ID, members[0].BoardID)
require.True(t, members[0].SchemeAdmin)
})
})
t.Run("create private board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
me := th.GetUser1()
title := "board title"
teamID := testTeamID
newBoard := &model.Board{
Title: title,
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, resp := th.Client.CreateBoard(newBoard)
th.CheckOK(resp)
require.NotNil(t, board)
require.NotNil(t, board.ID)
require.Equal(t, title, board.Title)
require.Equal(t, model.BoardTypePrivate, board.Type)
require.Equal(t, teamID, board.TeamID)
require.Equal(t, me.ID, board.CreatedBy)
require.Equal(t, me.ID, board.ModifiedBy)
t.Run("creating a board should make the creator an admin", func(t *testing.T) {
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.Equal(t, me.ID, members[0].UserID)
require.Equal(t, board.ID, members[0].BoardID)
require.True(t, members[0].SchemeAdmin)
})
})
t.Run("create invalid board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
title := "board title"
teamID := testTeamID
user1 := th.GetUser1()
t.Run("invalid board type", func(t *testing.T) {
var invalidBoardType model.BoardType = "invalid"
newBoard := &model.Board{
Title: title,
TeamID: testTeamID,
Type: invalidBoardType,
}
board, resp := th.Client.CreateBoard(newBoard)
th.CheckBadRequest(resp)
require.Nil(t, board)
boards, err := th.Server.App().GetBoardsForUserAndTeam(user1.ID, teamID)
require.NoError(t, err)
require.Empty(t, boards)
})
t.Run("no type", func(t *testing.T) {
newBoard := &model.Board{
Title: title,
TeamID: teamID,
}
board, resp := th.Client.CreateBoard(newBoard)
th.CheckBadRequest(resp)
require.Nil(t, board)
boards, err := th.Server.App().GetBoardsForUserAndTeam(user1.ID, teamID)
require.NoError(t, err)
require.Empty(t, boards)
})
t.Run("no team ID", func(t *testing.T) {
newBoard := &model.Board{
Title: title,
}
board, resp := th.Client.CreateBoard(newBoard)
// the request is unauthorized because the permission
// check fails on an empty teamID
th.CheckForbidden(resp)
require.Nil(t, board)
boards, err := th.Server.App().GetBoardsForUserAndTeam(user1.ID, teamID)
require.NoError(t, err)
require.Empty(t, boards)
})
})
}
func TestSearchBoards(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
boards, resp := th.Client.SearchBoardsForTeam(testTeamID, "term")
th.CheckUnauthorized(resp)
require.Nil(t, boards)
})
t.Run("all the matching private boards that the user is a member of and all matching public boards should be returned", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := testTeamID
user1 := th.GetUser1()
board1 := &model.Board{
Title: "public board where user1 is admin",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
rBoard1, err := th.Server.App().CreateBoard(board1, user1.ID, true)
require.NoError(t, err)
board2 := &model.Board{
Title: "public board where user1 is not member",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
rBoard2, err := th.Server.App().CreateBoard(board2, user1.ID, false)
require.NoError(t, err)
board3 := &model.Board{
Title: "private board where user1 is admin",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
rBoard3, err := th.Server.App().CreateBoard(board3, user1.ID, true)
require.NoError(t, err)
board4 := &model.Board{
Title: "private board where user1 is not member",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
_, err = th.Server.App().CreateBoard(board4, user1.ID, false)
require.NoError(t, err)
board5 := &model.Board{
Title: "public board where user1 is admin, but in other team",
Type: model.BoardTypePrivate,
TeamID: "other-team-id",
}
_, err = th.Server.App().CreateBoard(board5, user1.ID, true)
require.NoError(t, err)
testCases := []struct {
Name string
Client *client.Client
Term string
ExpectedIDs []string
}{
{
Name: "should return all boards where user1 is member or that are public",
Client: th.Client,
Term: "board",
ExpectedIDs: []string{rBoard1.ID, rBoard2.ID, rBoard3.ID},
},
{
Name: "matching a full word",
Client: th.Client,
Term: "admin",
ExpectedIDs: []string{rBoard1.ID, rBoard3.ID},
},
{
Name: "matching part of the word",
Client: th.Client,
Term: "ubli",
ExpectedIDs: []string{rBoard1.ID, rBoard2.ID},
},
{
Name: "case insensitive",
Client: th.Client,
Term: "UBLI",
ExpectedIDs: []string{rBoard1.ID, rBoard2.ID},
},
{
Name: "user2 can only see the public boards, as he's not a member of any",
Client: th.Client2,
Term: "board",
ExpectedIDs: []string{rBoard1.ID, rBoard2.ID},
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
boards, resp := tc.Client.SearchBoardsForTeam(teamID, tc.Term)
th.CheckOK(resp)
boardIDs := []string{}
for _, board := range boards {
boardIDs = append(boardIDs, board.ID)
}
require.ElementsMatch(t, tc.ExpectedIDs, boardIDs)
})
}
})
}
func TestGetBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
board, resp := th.Client.GetBoard("boar-id", "")
th.CheckUnauthorized(resp)
require.Nil(t, board)
})
t.Run("valid read token should be enough to get the board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Server.Config().EnablePublicSharedBoards = true
teamID := testTeamID
sharingToken := utils.NewID(utils.IDTypeToken)
board := &model.Board{
Title: "public board where user1 is admin",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
rBoard, err := th.Server.App().CreateBoard(board, th.GetUser1().ID, true)
require.NoError(t, err)
sharing := &model.Sharing{
ID: rBoard.ID,
Enabled: true,
Token: sharingToken,
UpdateAt: 1,
}
success, resp := th.Client.PostSharing(sharing)
th.CheckOK(resp)
require.True(t, success)
// the client logs out
th.Logout(th.Client)
// we make sure that the client cannot currently retrieve the
// board with no session
board, resp = th.Client.GetBoard(rBoard.ID, "")
th.CheckUnauthorized(resp)
require.Nil(t, board)
// it should be able to retrieve it with the read token
board, resp = th.Client.GetBoard(rBoard.ID, sharingToken)
th.CheckOK(resp)
require.NotNil(t, board)
})
t.Run("nonexisting board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
board, resp := th.Client.GetBoard("nonexistent board", "")
th.CheckNotFound(resp)
require.Nil(t, board)
})
t.Run("a user that doesn't have permissions to a private board cannot retrieve it", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := testTeamID
newBoard := &model.Board{
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, false)
require.NoError(t, err)
rBoard, resp := th.Client.GetBoard(board.ID, "")
th.CheckForbidden(resp)
require.Nil(t, rBoard)
})
t.Run("a user that has permissions to a private board can retrieve it", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := testTeamID
newBoard := &model.Board{
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
rBoard, resp := th.Client.GetBoard(board.ID, "")
th.CheckOK(resp)
require.NotNil(t, rBoard)
})
t.Run("a user that doesn't have permissions to a public board but have them to its team can retrieve it", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := testTeamID
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, false)
require.NoError(t, err)
rBoard, resp := th.Client.GetBoard(board.ID, "")
th.CheckOK(resp)
require.NotNil(t, rBoard)
})
}
func TestPatchBoard(t *testing.T) {
teamID := testTeamID
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
initialTitle := "title 1"
newBoard := &model.Board{
Title: initialTitle,
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, "user-id", false)
require.NoError(t, err)
newTitle := "a new title 1"
patch := &model.BoardPatch{Title: &newTitle}
rBoard, resp := th.Client.PatchBoard(board.ID, patch)
th.CheckUnauthorized(resp)
require.Nil(t, rBoard)
dbBoard, err := th.Server.App().GetBoard(board.ID)
require.NoError(t, err)
require.Equal(t, initialTitle, dbBoard.Title)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newTitle := "a new title 2"
patch := &model.BoardPatch{Title: &newTitle}
board, resp := th.Client.PatchBoard("non-existing-board", patch)
th.CheckNotFound(resp)
require.Nil(t, board)
})
t.Run("invalid patch on a board with permissions", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
user1 := th.GetUser1()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, user1.ID, true)
require.NoError(t, err)
var invalidPatchType model.BoardType = "invalid"
patch := &model.BoardPatch{Type: &invalidPatchType}
rBoard, resp := th.Client.PatchBoard(board.ID, patch)
th.CheckBadRequest(resp)
require.Nil(t, rBoard)
})
t.Run("valid patch on a board with permissions", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
user1 := th.GetUser1()
initialTitle := "title"
newBoard := &model.Board{
Title: initialTitle,
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, user1.ID, true)
require.NoError(t, err)
newTitle := "a new title"
patch := &model.BoardPatch{Title: &newTitle}
rBoard, resp := th.Client.PatchBoard(board.ID, patch)
th.CheckOK(resp)
require.NotNil(t, rBoard)
require.Equal(t, newTitle, rBoard.Title)
})
t.Run("valid patch on a board without permissions", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
user1 := th.GetUser1()
initialTitle := "title"
newBoard := &model.Board{
Title: initialTitle,
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, user1.ID, false)
require.NoError(t, err)
newTitle := "a new title"
patch := &model.BoardPatch{Title: &newTitle}
rBoard, resp := th.Client.PatchBoard(board.ID, patch)
th.CheckForbidden(resp)
require.Nil(t, rBoard)
dbBoard, err := th.Server.App().GetBoard(board.ID)
require.NoError(t, err)
require.Equal(t, initialTitle, dbBoard.Title)
})
}
func TestDeleteBoard(t *testing.T) {
teamID := testTeamID
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, "user-id", false)
require.NoError(t, err)
success, resp := th.Client.DeleteBoard(board.ID)
th.CheckUnauthorized(resp)
require.False(t, success)
dbBoard, err := th.Server.App().GetBoard(board.ID)
require.NoError(t, err)
require.NotNil(t, dbBoard)
})
t.Run("a user without permissions should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, "some-user-id", false)
require.NoError(t, err)
success, resp := th.Client.DeleteBoard(board.ID)
th.CheckForbidden(resp)
require.False(t, success)
dbBoard, err := th.Server.App().GetBoard(board.ID)
require.NoError(t, err)
require.NotNil(t, dbBoard)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
success, resp := th.Client.DeleteBoard("non-existing-board")
th.CheckForbidden(resp)
require.False(t, success)
})
t.Run("an existing board should be correctly deleted", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
success, resp := th.Client.DeleteBoard(board.ID)
th.CheckOK(resp)
require.True(t, success)
dbBoard, err := th.Server.App().GetBoard(board.ID)
require.NoError(t, err)
require.Nil(t, dbBoard)
})
}
func TestGetMembersForBoard(t *testing.T) {
teamID := testTeamID
createBoardWithUsers := func(th *TestHelper) *model.Board {
user1 := th.GetUser1()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, user1.ID, true)
require.NoError(t, err)
newUser2Member := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
user2Member, err := th.Server.App().AddMemberToBoard(newUser2Member)
require.NoError(t, err)
require.NotNil(t, user2Member)
return board
}
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
board := createBoardWithUsers(th)
th.Logout(th.Client)
members, resp := th.Client.GetMembersForBoard(board.ID)
th.CheckUnauthorized(resp)
require.Empty(t, members)
})
t.Run("a user without permissions should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
board := createBoardWithUsers(th)
_ = th.Server.App().DeleteBoardMember(board.ID, th.GetUser2().ID)
members, resp := th.Client2.GetMembersForBoard(board.ID)
th.CheckForbidden(resp)
require.Empty(t, members)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
members, resp := th.Client.GetMembersForBoard("non-existing-board")
th.CheckForbidden(resp)
require.Empty(t, members)
})
t.Run("should correctly return board members for a valid board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
board := createBoardWithUsers(th)
members, resp := th.Client.GetMembersForBoard(board.ID)
th.CheckOK(resp)
require.Len(t, members, 2)
})
}
func TestAddMember(t *testing.T) {
teamID := testTeamID
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, "user-id", false)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: "user1",
BoardID: board.ID,
SchemeEditor: true,
}
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckUnauthorized(resp)
require.Nil(t, member)
})
t.Run("a user without permissions should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, "user-id", false)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: "user1",
BoardID: board.ID,
SchemeEditor: true,
}
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckForbidden(resp)
require.Nil(t, member)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newMember := &model.BoardMember{
UserID: "user1",
BoardID: "non-existing-board-id",
SchemeEditor: true,
}
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckNotFound(resp)
require.Nil(t, member)
})
t.Run("should correctly add a new member for a valid board", func(t *testing.T) {
t.Run("a private board through an admin user", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckOK(resp)
require.Equal(t, newMember.UserID, member.UserID)
require.Equal(t, newMember.BoardID, member.BoardID)
require.Equal(t, newMember.SchemeAdmin, member.SchemeAdmin)
require.Equal(t, newMember.SchemeEditor, member.SchemeEditor)
require.False(t, member.SchemeCommenter)
require.False(t, member.SchemeViewer)
})
t.Run("a public board through a user that is not yet a member", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
member, resp := th.Client2.AddMemberToBoard(newMember)
th.CheckOK(resp)
require.Equal(t, newMember.UserID, member.UserID)
require.Equal(t, newMember.BoardID, member.BoardID)
require.Equal(t, newMember.SchemeAdmin, member.SchemeAdmin)
require.Equal(t, newMember.SchemeEditor, member.SchemeEditor)
require.False(t, member.SchemeCommenter)
require.False(t, member.SchemeViewer)
members, resp := th.Client.GetMembersForBoard(board.ID)
th.CheckOK(resp)
require.Len(t, members, 2)
})
t.Run("should always add a new member as an editor", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeAdmin: true,
SchemeEditor: false,
}
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckOK(resp)
require.Equal(t, newMember.UserID, member.UserID)
require.Equal(t, newMember.BoardID, member.BoardID)
require.False(t, member.SchemeAdmin)
require.True(t, member.SchemeEditor)
})
})
t.Run("should do nothing if the member already exists", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newMember := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
SchemeAdmin: false,
SchemeEditor: true,
}
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.True(t, members[0].SchemeAdmin)
require.True(t, members[0].SchemeEditor)
member, resp := th.Client.AddMemberToBoard(newMember)
th.CheckOK(resp)
require.True(t, member.SchemeAdmin)
require.True(t, member.SchemeEditor)
members, err = th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.True(t, members[0].SchemeAdmin)
require.True(t, members[0].SchemeEditor)
})
}
func TestUpdateMember(t *testing.T) {
teamID := testTeamID
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
updatedMember := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
SchemeEditor: true,
}
th.Logout(th.Client)
member, resp := th.Client.UpdateBoardMember(updatedMember)
th.CheckUnauthorized(resp)
require.Nil(t, member)
})
t.Run("a user without permissions should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
updatedMember := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
SchemeEditor: true,
}
member, resp := th.Client2.UpdateBoardMember(updatedMember)
th.CheckForbidden(resp)
require.Nil(t, member)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
updatedMember := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: "non-existent-board-id",
SchemeEditor: true,
}
member, resp := th.Client.UpdateBoardMember(updatedMember)
th.CheckForbidden(resp)
require.Nil(t, member)
})
t.Run("should correctly update a member for a valid board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newUser2Member := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
user2Member, err := th.Server.App().AddMemberToBoard(newUser2Member)
require.NoError(t, err)
require.NotNil(t, user2Member)
require.False(t, user2Member.SchemeAdmin)
require.True(t, user2Member.SchemeEditor)
memberUpdate := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeAdmin: true,
SchemeEditor: true,
}
updatedUser2Member, resp := th.Client.UpdateBoardMember(memberUpdate)
th.CheckOK(resp)
require.True(t, updatedUser2Member.SchemeAdmin)
require.True(t, updatedUser2Member.SchemeEditor)
})
t.Run("should not update a member if that means that a board will not have any admin", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
memberUpdate := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
SchemeEditor: true,
}
updatedUser1Member, resp := th.Client.UpdateBoardMember(memberUpdate)
th.CheckBadRequest(resp)
require.Nil(t, updatedUser1Member)
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.True(t, members[0].SchemeAdmin)
})
}
func TestDeleteMember(t *testing.T) {
teamID := testTeamID
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
member := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
}
th.Logout(th.Client)
success, resp := th.Client.DeleteBoardMember(member)
th.CheckUnauthorized(resp)
require.False(t, success)
})
t.Run("a user without permissions should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypeOpen,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
member := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
}
success, resp := th.Client2.DeleteBoardMember(member)
th.CheckForbidden(resp)
require.False(t, success)
})
t.Run("non existing board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
updatedMember := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: "non-existent-board-id",
}
success, resp := th.Client.DeleteBoardMember(updatedMember)
th.CheckNotFound(resp)
require.False(t, success)
})
t.Run("should correctly delete a member for a valid board", func(t *testing.T) {
//nolint:dupl
t.Run("admin removing a user", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newUser2Member := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
user2Member, err := th.Server.App().AddMemberToBoard(newUser2Member)
require.NoError(t, err)
require.NotNil(t, user2Member)
require.False(t, user2Member.SchemeAdmin)
require.True(t, user2Member.SchemeEditor)
memberToDelete := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
}
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 2)
success, resp := th.Client.DeleteBoardMember(memberToDelete)
th.CheckOK(resp)
require.True(t, success)
members, err = th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
})
//nolint:dupl
t.Run("user removing themselves", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newUser2Member := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
user2Member, err := th.Server.App().AddMemberToBoard(newUser2Member)
require.NoError(t, err)
require.NotNil(t, user2Member)
require.False(t, user2Member.SchemeAdmin)
require.True(t, user2Member.SchemeEditor)
memberToDelete := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
}
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 2)
success, resp := th.Client2.DeleteBoardMember(memberToDelete)
th.CheckOK(resp)
require.True(t, success)
members, err = th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
})
//nolint:dupl
t.Run("a non admin user should not be able to remove another user", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
newUser2Member := &model.BoardMember{
UserID: th.GetUser2().ID,
BoardID: board.ID,
SchemeEditor: true,
}
user2Member, err := th.Server.App().AddMemberToBoard(newUser2Member)
require.NoError(t, err)
require.NotNil(t, user2Member)
require.False(t, user2Member.SchemeAdmin)
require.True(t, user2Member.SchemeEditor)
memberToDelete := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
}
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 2)
success, resp := th.Client2.DeleteBoardMember(memberToDelete)
th.CheckForbidden(resp)
require.False(t, success)
members, err = th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 2)
})
})
t.Run("should not delete a member if that means that a board will not have any admin", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
newBoard := &model.Board{
Title: "title",
Type: model.BoardTypePrivate,
TeamID: teamID,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
memberToDelete := &model.BoardMember{
UserID: th.GetUser1().ID,
BoardID: board.ID,
}
success, resp := th.Client.DeleteBoardMember(memberToDelete)
th.CheckBadRequest(resp)
require.False(t, success)
members, err := th.Server.App().GetMembersForBoard(board.ID)
require.NoError(t, err)
require.Len(t, members, 1)
require.True(t, members[0].SchemeAdmin)
})
}