From 9d9fcd9ac5d10a6ff1050477d527385d6af2f6bf Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Mon, 16 Jul 2018 13:04:52 +0100 Subject: MM-11172: Don't allow reacting in read-only town square. (#9106) --- api4/reaction_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'api4') diff --git a/api4/reaction_test.go b/api4/reaction_test.go index ac1a49671..dda9a578a 100644 --- a/api4/reaction_test.go +++ b/api4/reaction_test.go @@ -172,6 +172,33 @@ func TestSaveReaction(t *testing.T) { } th.AddPermissionToRole(model.PERMISSION_ADD_REACTION.Id, model.CHANNEL_USER_ROLE_ID) }) + + t.Run("unable-to-react-in-read-only-town-square", func(t *testing.T) { + th.LoginBasic() + + channel, err := th.App.GetChannelByName("town-square", th.BasicTeam.Id) + assert.Nil(t, err) + post := th.CreatePostWithClient(th.Client, channel) + + th.App.SetLicense(model.NewTestLicense()) + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true }) + + reaction := &model.Reaction{ + UserId: userId, + PostId: post.Id, + EmojiName: "smile", + } + + _, resp := Client.SaveReaction(reaction) + CheckForbiddenStatus(t, resp) + + if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 3 { + t.Fatal("should have not created a reactions") + } + + th.App.RemoveLicense() + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = false }) + }) } func TestGetReactions(t *testing.T) { @@ -451,4 +478,39 @@ func TestDeleteReaction(t *testing.T) { } th.AddPermissionToRole(model.PERMISSION_REMOVE_OTHERS_REACTIONS.Id, model.SYSTEM_ADMIN_ROLE_ID) }) + + t.Run("unable-to-delete-reactions-in-read-only-town-square", func(t *testing.T) { + th.LoginBasic() + + channel, err := th.App.GetChannelByName("town-square", th.BasicTeam.Id) + assert.Nil(t, err) + post := th.CreatePostWithClient(th.Client, channel) + + th.App.SetLicense(model.NewTestLicense()) + + reaction := &model.Reaction{ + UserId: userId, + PostId: post.Id, + EmojiName: "smile", + } + + r1, resp := Client.SaveReaction(reaction) + CheckNoError(t, resp) + + if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 1 { + t.Fatal("should have created a reactions") + } + + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true }) + + _, resp = th.SystemAdminClient.DeleteReaction(r1) + CheckForbiddenStatus(t, resp) + + if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 1 { + t.Fatal("should have not deleted a reactions") + } + + th.App.RemoveLicense() + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = false }) + }) } -- cgit v1.2.3-1-g7c22