[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 <benjamincooke@Benjamins-MacBook-Pro.local>
Этот коммит содержится в:
20
api4/post.go
20
api4/post.go
@@ -713,13 +713,6 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) {
|
|||||||
return
|
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)
|
post, err := c.App.GetSinglePost(c.Params.PostId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
@@ -727,19 +720,6 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) {
|
|||||||
}
|
}
|
||||||
auditRec.AddMeta("post", post)
|
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 := &model.PostPatch{}
|
||||||
patch.IsPinned = model.NewBool(isPinned)
|
patch.IsPinned = model.NewBool(isPinned)
|
||||||
|
|
||||||
|
|||||||
31
app/post.go
31
app/post.go
@@ -57,30 +57,6 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess
|
|||||||
err.StatusCode = http.StatusBadRequest
|
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
|
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")
|
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
|
var ephemeralPost *model.Post
|
||||||
if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PermissionUseChannelMentions) {
|
if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PermissionUseChannelMentions) {
|
||||||
mention := post.DisableMentionHighlights()
|
mention := post.DisableMentionHighlights()
|
||||||
|
|||||||
@@ -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)
|
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)
|
reaction, nErr := a.Srv().Store.Reaction().Save(reaction)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
var appErr *model.AppError
|
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)
|
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 {
|
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)
|
return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
var user *model.User
|
|
||||||
result = <-uchan
|
result = <-uchan
|
||||||
if result.NErr != nil {
|
if result.NErr != nil {
|
||||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, result.NErr.Error(), http.StatusForbidden)
|
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) {
|
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)
|
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "", http.StatusForbidden)
|
||||||
|
|||||||
12
i18n/en.json
12
i18n/en.json
@@ -2149,10 +2149,6 @@
|
|||||||
"id": "api.post.create_post.root_id.app_error",
|
"id": "api.post.create_post.root_id.app_error",
|
||||||
"translation": "Invalid RootId parameter."
|
"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",
|
"id": "api.post.create_webhook_post.creating.app_error",
|
||||||
"translation": "Error creating post."
|
"translation": "Error creating post."
|
||||||
@@ -2215,10 +2211,6 @@
|
|||||||
"id": "api.post.patch_post.can_not_update_post_in_deleted.error",
|
"id": "api.post.patch_post.can_not_update_post_in_deleted.error",
|
||||||
"translation": "Can not update a post in a deleted channel."
|
"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",
|
"id": "api.post.search_files.invalid_body.app_error",
|
||||||
"translation": "Unable to parse the request body."
|
"translation": "Unable to parse the request body."
|
||||||
@@ -2359,10 +2351,6 @@
|
|||||||
"id": "api.reaction.save_reaction.user_id.app_error",
|
"id": "api.reaction.save_reaction.user_id.app_error",
|
||||||
"translation": "You cannot save reaction for the other user."
|
"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",
|
"id": "api.remote_cluster.delete.app_error",
|
||||||
"translation": "We encountered an error deleting the secure connection."
|
"translation": "We encountered an error deleting the secure connection."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user