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