MM-11713: Does not require edit_own_posts to edit_others_posts. (#14787)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
53ef4d120b
Коммит
7c4c038a96
20
api4/post.go
20
api4/post.go
@@ -595,11 +595,6 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
// Updating the file_ids of a post is not a supported operation and will be ignored
|
// Updating the file_ids of a post is not a supported operation and will be ignored
|
||||||
post.FileIds = nil
|
post.FileIds = nil
|
||||||
|
|
||||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_POST) {
|
|
||||||
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
originalPost, err := c.App.GetSinglePost(c.Params.PostId)
|
originalPost, err := c.App.GetSinglePost(c.Params.PostId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
||||||
@@ -607,11 +602,16 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
auditRec.AddMeta("post", originalPost)
|
auditRec.AddMeta("post", originalPost)
|
||||||
|
|
||||||
if c.App.Session().UserId != originalPost.UserId {
|
var permission *model.Permission
|
||||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
|
if c.App.Session().UserId == originalPost.UserId {
|
||||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
|
permission = model.PERMISSION_EDIT_POST
|
||||||
return
|
} else {
|
||||||
}
|
permission = model.PERMISSION_EDIT_OTHERS_POSTS
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, permission) {
|
||||||
|
c.SetPermissionError(permission)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
patchedPost, err := c.App.PatchPost(c.Params.PostId, c.App.PostPatchWithProxyRemovedFromImageURLs(post))
|
patchedPost, err := c.App.PatchPost(c.Params.PostId, c.App.PostPatchWithProxyRemovedFromImageURLs(post))
|
||||||
|
|||||||
@@ -938,6 +938,21 @@ func TestPatchPost(t *testing.T) {
|
|||||||
_, resp := th.SystemAdminClient.PatchPost(post.Id, patch)
|
_, resp := th.SystemAdminClient.PatchPost(post.Id, patch)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("edit others posts permission can function independently of edit own post", func(t *testing.T) {
|
||||||
|
th.LoginBasic2()
|
||||||
|
patch := &model.PostPatch{}
|
||||||
|
_, resp := Client.PatchPost(post.Id, patch)
|
||||||
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
// Add permission to edit others'
|
||||||
|
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||||
|
th.RemovePermissionFromRole(model.PERMISSION_EDIT_POST.Id, model.CHANNEL_USER_ROLE_ID)
|
||||||
|
th.AddPermissionToRole(model.PERMISSION_EDIT_OTHERS_POSTS.Id, model.CHANNEL_USER_ROLE_ID)
|
||||||
|
|
||||||
|
_, resp = Client.PatchPost(post.Id, patch)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPinPost(t *testing.T) {
|
func TestPinPost(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user