Moved admin checking into seperate function
Этот коммит содержится в:
@@ -265,6 +265,16 @@ func (c *Context) IsSystemAdmin() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Context) IsTeamAdmin() bool {
|
||||
if uresult := <-Srv.Store.User().Get(c.Session.UserId); uresult.Err != nil {
|
||||
c.Err = uresult.Err
|
||||
return false
|
||||
} else {
|
||||
user := uresult.Data.(*model.User)
|
||||
return strings.Contains(user.Roles, model.ROLE_ADMIN) && user.TeamId == c.Session.TeamId
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) RemoveSessionCookie(w http.ResponseWriter) {
|
||||
|
||||
sessionCache.Remove(c.Session.Id)
|
||||
|
||||
20
api/post.go
20
api/post.go
@@ -619,23 +619,17 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
|
||||
pchan := Srv.Store.Post().Get(postId)
|
||||
uchan := Srv.Store.User().Get(c.Session.UserId)
|
||||
|
||||
if uresult := <-uchan; uresult.Err != nil {
|
||||
c.Err = uresult.Err
|
||||
if !c.HasPermissionsToChannel(cchan, "deletePost") && !c.IsTeamAdmin(){
|
||||
return
|
||||
} else if presult := <-pchan; presult.Err != nil {
|
||||
c.Err = presult.Err
|
||||
}
|
||||
|
||||
if result := <-pchan; result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "deletePost") && !strings.Contains(user.Roles,"admin"){
|
||||
return
|
||||
}
|
||||
|
||||
post := presult.Data.(*model.PostList).Posts[postId]
|
||||
post := result.Data.(*model.PostList).Posts[postId]
|
||||
|
||||
if post == nil {
|
||||
c.SetInvalidParam("deletePost", "postId")
|
||||
@@ -648,7 +642,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if post.UserId != c.Session.UserId && !strings.Contains(user.Roles,"admin") {
|
||||
if post.UserId != c.Session.UserId && !strings.Contains(c.Session.Roles,model.ROLE_ADMIN) {
|
||||
c.Err = model.NewAppError("deletePost", "You do not have the appropriate permissions", "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
|
||||
Ссылка в новой задаче
Block a user