From 134be30dbc4406471af50c8b0e4e8a15fad39c73 Mon Sep 17 00:00:00 2001 From: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com> Date: Wed, 31 May 2023 19:08:30 +0530 Subject: [PATCH] Fixing failed CP (#4752) * Fixing failed CP * fixing some tests --- .github/workflows/ci.yml | 4 ++-- .github/workflows/dev-release.yml | 4 ++-- .github/workflows/lint-server.yml | 4 ++-- .github/workflows/prod-release.yml | 4 ++-- server/app/boards_test.go | 10 +++++----- server/app/helper_test.go | 11 +++++++++++ server/model/permission.go | 13 ++++++++----- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecb8834a6..f87708c0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ env: jobs: ci-ubuntu-server: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: @@ -54,7 +54,7 @@ jobs: run: cd focalboard; make server-test-${{matrix['db']}} ci-ubuntu-webapp: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index 69b95d7ba..54c589088 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -14,7 +14,7 @@ env: jobs: ubuntu: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -218,7 +218,7 @@ jobs: path: ${{ github.workspace }}/focalboard/win-wpf/dist/focalboard-win.zip plugin: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/lint-server.yml b/.github/workflows/lint-server.yml index 65f93c864..f47caefb7 100644 --- a/.github/workflows/lint-server.yml +++ b/.github/workflows/lint-server.yml @@ -13,7 +13,7 @@ env: jobs: down-migrations: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 with: @@ -26,7 +26,7 @@ jobs: golangci: name: plugin - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/setup-go@v3 with: diff --git a/.github/workflows/prod-release.yml b/.github/workflows/prod-release.yml index 1144b47f8..dd355df2c 100644 --- a/.github/workflows/prod-release.yml +++ b/.github/workflows/prod-release.yml @@ -9,7 +9,7 @@ env: jobs: ubuntu: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Checkout @@ -216,7 +216,7 @@ jobs: path: ${{ github.workspace }}/focalboard/win-wpf/dist/focalboard-win.zip plugin-release: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Checkout diff --git a/server/app/boards_test.go b/server/app/boards_test.go index d7e585d9b..dba337fe4 100644 --- a/server/app/boards_test.go +++ b/server/app/boards_test.go @@ -184,7 +184,6 @@ func TestPatchBoard(t *testing.T) { // Type not null will retrieve team members th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{}, nil) - th.Store.EXPECT().GetUserByID(userID).Return(&model.User{ID: userID, Username: "UserName"}, nil) th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( &model.Board{ @@ -412,8 +411,8 @@ func TestPatchBoard(t *testing.T) { TeamID: teamID, IsTemplate: true, }, nil).Times(1) - th.API.EXPECT().HasPermissionToChannel(userID, channelID, model.PermissionCreatePost).Return(false).Times(1) + _, err := th.App.PatchBoard(patch, boardID, userID) require.Error(t, err) }) @@ -433,7 +432,7 @@ func TestPatchBoard(t *testing.T) { th.Store.EXPECT().GetBoard(boardID).Return(&model.Board{ ID: boardID, TeamID: teamID, - }, nil).Times(2) + }, nil).Times(1) th.API.EXPECT().HasPermissionToChannel(userID, channelID, model.PermissionCreatePost).Return(true).Times(1) @@ -444,6 +443,8 @@ func TestPatchBoard(t *testing.T) { }, nil) + th.Store.EXPECT().GetUserByID(userID).Return(&model.User{ID: userID, Username: "UserName"}, nil) + // Should call GetMembersForBoard 2 times // - for WS BroadcastBoardChange // - for AddTeamMembers check @@ -476,11 +477,10 @@ func TestPatchBoard(t *testing.T) { TeamID: teamID, IsTemplate: true, ChannelID: channelID, - }, nil).Times(2) + }, nil).Times(1) th.API.EXPECT().HasPermissionToChannel(userID, channelID, model.PermissionCreatePost).Return(false).Times(1) - th.API.EXPECT().HasPermissionToTeam(userID, teamID, model.PermissionManageTeam).Return(false).Times(1) // Should call GetMembersForBoard 2 times // for WS BroadcastBoardChange // for AddTeamMembers check diff --git a/server/app/helper_test.go b/server/app/helper_test.go index b471ace1e..9aeda4cc3 100644 --- a/server/app/helper_test.go +++ b/server/app/helper_test.go @@ -5,6 +5,10 @@ package app import ( "testing" + "github.com/mattermost/focalboard/server/services/permissions/mmpermissions" + mmpermissionsMocks "github.com/mattermost/focalboard/server/services/permissions/mmpermissions/mocks" + permissionsMocks "github.com/mattermost/focalboard/server/services/permissions/mocks" + "github.com/golang/mock/gomock" "github.com/mattermost/focalboard/server/auth" @@ -23,6 +27,7 @@ type TestHelper struct { Store *mockstore.MockStore FilesBackend *mocks.FileBackend logger mlog.LoggerIFace + API *mmpermissionsMocks.MockAPI } func SetupTestHelper(t *testing.T) (*TestHelper, func()) { @@ -37,6 +42,10 @@ func SetupTestHelper(t *testing.T) (*TestHelper, func()) { webhook := webhook.NewClient(&cfg, logger) metricsService := metrics.NewMetrics(metrics.InstanceInfo{}) + mockStore := permissionsMocks.NewMockStore(ctrl) + mockAPI := mmpermissionsMocks.NewMockAPI(ctrl) + permissions := mmpermissions.New(mockStore, mockAPI, mlog.CreateConsoleTestLogger(true, mlog.LvlError)) + appServices := Services{ Auth: auth, Store: store, @@ -45,6 +54,7 @@ func SetupTestHelper(t *testing.T) (*TestHelper, func()) { Metrics: metricsService, Logger: logger, SkipTemplateInit: true, + Permissions: permissions, } app2 := New(&cfg, wsserver, appServices) @@ -60,5 +70,6 @@ func SetupTestHelper(t *testing.T) (*TestHelper, func()) { Store: store, FilesBackend: filesBackend, logger: logger, + API: mockAPI, }, tearDown } diff --git a/server/model/permission.go b/server/model/permission.go index 7d3d773f1..03b4136e2 100644 --- a/server/model/permission.go +++ b/server/model/permission.go @@ -5,11 +5,14 @@ import ( ) var ( - PermissionViewTeam = mmModel.PermissionViewTeam - PermissionReadChannel = mmModel.PermissionReadChannel - PermissionViewMembers = mmModel.PermissionViewMembers - PermissionCreatePublicChannel = mmModel.PermissionCreatePublicChannel - PermissionCreatePrivateChannel = mmModel.PermissionCreatePrivateChannel + PermissionViewTeam = mmModel.PermissionViewTeam + PermissionReadChannel = mmModel.PermissionReadChannel + PermissionViewMembers = mmModel.PermissionViewMembers + PermissionCreatePublicChannel = mmModel.PermissionCreatePublicChannel + PermissionCreatePrivateChannel = mmModel.PermissionCreatePrivateChannel + + PermissionCreatePost = mmModel.PermissionCreatePost + PermissionManageTeam = mmModel.PermissionManageTeam PermissionManageBoardType = &mmModel.Permission{Id: "manage_board_type", Name: "", Description: "", Scope: ""} PermissionDeleteBoard = &mmModel.Permission{Id: "delete_board", Name: "", Description: "", Scope: ""} PermissionViewBoard = &mmModel.Permission{Id: "view_board", Name: "", Description: "", Scope: ""}