From 0332e1545d7b82fd352e439553d89294908606c1 Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Mon, 27 Sep 2021 21:01:16 -0400 Subject: [PATCH] [MM-38579] Removing some town square permissions stuff (#18464) * removing some town square permissions stuff * fixing error * adding back in channel leave check * removing tests Co-authored-by: Benjamin Cooke --- api4/post.go | 20 -------------------- app/post.go | 31 ------------------------------- app/reaction.go | 23 ----------------------- app/webhook.go | 7 ------- i18n/en.json | 12 ------------ 5 files changed, 93 deletions(-) diff --git a/api4/post.go b/api4/post.go index 218b0f8ef4..869d335262 100644 --- a/api4/post.go +++ b/api4/post.go @@ -713,13 +713,6 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) { return } - // Restrict pinning if the experimental read-only-town-square setting is on. - user, err := c.App.GetUser(c.AppContext.Session().UserId) - if err != nil { - c.Err = err - return - } - post, err := c.App.GetSinglePost(c.Params.PostId) if err != nil { c.Err = err @@ -727,19 +720,6 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) { } auditRec.AddMeta("post", post) - channel, err := c.App.GetChannel(post.ChannelId) - if err != nil { - c.Err = err - return - } - - if c.App.Srv().License() != nil && - channel.Name == model.DefaultChannelName && - !c.App.RolesGrantPermission(user.GetRoles(), model.PermissionManageSystem.Id) { - c.Err = model.NewAppError("saveIsPinnedPost", "api.post.save_is_pinned_post.town_square_read_only", nil, "", http.StatusForbidden) - return - } - patch := &model.PostPatch{} patch.IsPinned = model.NewBool(isPinned) diff --git a/app/post.go b/app/post.go index 4255e6967a..d0c0114294 100644 --- a/app/post.go +++ b/app/post.go @@ -57,30 +57,6 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess err.StatusCode = http.StatusBadRequest } - if err.Id == "api.post.create_post.town_square_read_only" { - user, nErr := a.Srv().Store.User().Get(context.Background(), post.UserId) - if nErr != nil { - var nfErr *store.ErrNotFound - switch { - case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreatePostAsUser", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) - default: - return nil, model.NewAppError("CreatePostAsUser", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) - } - } - - T := i18n.GetUserTranslations(user.Locale) - a.SendEphemeralPost( - post.UserId, - &model.Post{ - ChannelId: channel.Id, - RootId: post.RootId, - UserId: post.UserId, - Message: T("api.post.create_post.town_square_read_only"), - CreateAt: model.GetMillis() + 1, - }, - ) - } return nil, err } @@ -213,13 +189,6 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch post.AddProp("from_bot", "true") } - if a.Srv().License() != nil && - !post.IsSystemMessage() && - channel.Name == model.DefaultChannelName && - !a.RolesGrantPermission(user.GetRoles(), model.PermissionManageSystem.Id) { - return nil, model.NewAppError("createPost", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden) - } - var ephemeralPost *model.Post if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PermissionUseChannelMentions) { mention := post.DisableMentionHighlights() diff --git a/app/reaction.go b/app/reaction.go index f3293bfc36..c6a80c61f6 100644 --- a/app/reaction.go +++ b/app/reaction.go @@ -29,18 +29,6 @@ func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction) return nil, model.NewAppError("deleteReactionForPost", "api.reaction.save.archived_channel.app_error", nil, "", http.StatusForbidden) } - if a.Srv().License() != nil && channel.Name == model.DefaultChannelName { - var user *model.User - user, err = a.GetUser(reaction.UserId) - if err != nil { - return nil, err - } - - if !a.RolesGrantPermission(user.GetRoles(), model.PermissionManageSystem.Id) { - return nil, model.NewAppError("saveReactionForPost", "api.reaction.town_square_read_only", nil, "", http.StatusForbidden) - } - } - reaction, nErr := a.Srv().Store.Reaction().Save(reaction) if nErr != nil { var appErr *model.AppError @@ -123,17 +111,6 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction return model.NewAppError("DeleteReactionForPost", "api.reaction.delete.archived_channel.app_error", nil, "", http.StatusForbidden) } - if a.Srv().License() != nil && channel.Name == model.DefaultChannelName { - user, err := a.GetUser(reaction.UserId) - if err != nil { - return err - } - - if !a.RolesGrantPermission(user.GetRoles(), model.PermissionManageSystem.Id) { - return model.NewAppError("DeleteReactionForPost", "api.reaction.town_square_read_only", nil, "", http.StatusForbidden) - } - } - if _, err := a.Srv().Store.Reaction().Delete(reaction); err != nil { return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError) } diff --git a/app/webhook.go b/app/webhook.go index ec58cfed4d..ebb4870fac 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -770,17 +770,10 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden) } - var user *model.User result = <-uchan if result.NErr != nil { return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, result.NErr.Error(), http.StatusForbidden) } - user = result.Data.(*model.User) - - if a.Srv().License() != nil && - channel.Name == model.DefaultChannelName && !a.RolesGrantPermission(user.GetRoles(), model.PermissionManageSystem.Id) { - return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden) - } if channel.Type != model.ChannelTypeOpen && !a.HasPermissionToChannel(hook.UserId, channel.Id, model.PermissionReadChannel) { return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "", http.StatusForbidden) diff --git a/i18n/en.json b/i18n/en.json index 512d79b28a..8dc5d9d6cf 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2149,10 +2149,6 @@ "id": "api.post.create_post.root_id.app_error", "translation": "Invalid RootId parameter." }, - { - "id": "api.post.create_post.town_square_read_only", - "translation": "This channel is read-only. Only members with permission can post here." - }, { "id": "api.post.create_webhook_post.creating.app_error", "translation": "Error creating post." @@ -2215,10 +2211,6 @@ "id": "api.post.patch_post.can_not_update_post_in_deleted.error", "translation": "Can not update a post in a deleted channel." }, - { - "id": "api.post.save_is_pinned_post.town_square_read_only", - "translation": "This channel is read-only. Only members with permission can pin or unpin posts here." - }, { "id": "api.post.search_files.invalid_body.app_error", "translation": "Unable to parse the request body." @@ -2359,10 +2351,6 @@ "id": "api.reaction.save_reaction.user_id.app_error", "translation": "You cannot save reaction for the other user." }, - { - "id": "api.reaction.town_square_read_only", - "translation": "Reacting to posts is not possible in read-only channels." - }, { "id": "api.remote_cluster.delete.app_error", "translation": "We encountered an error deleting the secure connection."