[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>
Этот коммит содержится в:
Ben Cooke
2021-09-27 21:01:16 -04:00
коммит произвёл GitHub
родитель 74054c74bf
Коммит 0332e1545d
5 изменённых файлов: 0 добавлений и 93 удалений

Просмотреть файл

@@ -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()

Просмотреть файл

@@ -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)
}

Просмотреть файл

@@ -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)