Merge pull request #184 from nickago/MM-1278
MM-1278 Team admin can now delete any post
Этот коммит содержится в:
@@ -265,6 +265,16 @@ func (c *Context) IsSystemAdmin() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) IsTeamAdmin(userId string) bool {
|
||||||
|
if uresult := <-Srv.Store.User().Get(userId); uresult.Err != nil {
|
||||||
|
c.Err = uresult.Err
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
user := uresult.Data.(*model.User)
|
||||||
|
return strings.Contains(c.Session.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)
|
||||||
|
|||||||
11
api/post.go
11
api/post.go
@@ -634,16 +634,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)
|
||||||
|
|
||||||
if !c.HasPermissionsToChannel(cchan, "deletePost") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if result := <-pchan; result.Err != nil {
|
if result := <-pchan; result.Err != nil {
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
post := result.Data.(*model.PostList).Posts[postId]
|
post := result.Data.(*model.PostList).Posts[postId]
|
||||||
|
|
||||||
|
if !c.HasPermissionsToChannel(cchan, "deletePost") && !c.IsTeamAdmin(post.UserId){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if post == nil {
|
if post == nil {
|
||||||
c.SetInvalidParam("deletePost", "postId")
|
c.SetInvalidParam("deletePost", "postId")
|
||||||
return
|
return
|
||||||
@@ -655,7 +656,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if post.UserId != c.Session.UserId {
|
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
|
||||||
|
|||||||
@@ -483,6 +483,10 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
team := &model.Team{Name: "Name", Domain: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
team := &model.Team{Name: "Name", Domain: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||||
|
|
||||||
|
userAdmin := &model.User{TeamId: team.Id, Email: team.Email, FullName: "Corey Hulen", Password: "pwd"}
|
||||||
|
userAdmin = Client.Must(Client.CreateUser(userAdmin, "")).Data.(*model.User)
|
||||||
|
store.Must(Srv.Store.User().VerifyEmail(userAdmin.Id))
|
||||||
|
|
||||||
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", FullName: "Corey Hulen", Password: "pwd"}
|
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", FullName: "Corey Hulen", Password: "pwd"}
|
||||||
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
||||||
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
|
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
|
||||||
@@ -521,8 +525,16 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
r2 := Client.Must(Client.GetPosts(channel1.Id, 0, 10, "")).Data.(*model.PostList)
|
r2 := Client.Must(Client.GetPosts(channel1.Id, 0, 10, "")).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r2.Posts) != 4 {
|
if len(r2.Posts) != 4 {
|
||||||
t.Fatal("should have returned 5 items")
|
t.Fatal("should have returned 4 items")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
post4 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
|
||||||
|
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||||
|
|
||||||
|
Client.LoginByEmail(team.Domain, userAdmin.Email, "pwd")
|
||||||
|
|
||||||
|
Client.Must(Client.DeletePost(channel1.Id, post4.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmailMention(t *testing.T) {
|
func TestEmailMention(t *testing.T) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ module.exports = React.createClass({
|
|||||||
render: function() {
|
render: function() {
|
||||||
var post = this.props.post;
|
var post = this.props.post;
|
||||||
var isOwner = UserStore.getCurrentId() == post.user_id;
|
var isOwner = UserStore.getCurrentId() == post.user_id;
|
||||||
|
var isAdmin = UserStore.getCurrentUser().roles.indexOf("admin") > -1
|
||||||
|
|
||||||
var type = "Post"
|
var type = "Post"
|
||||||
if (post.root_id.length > 0) {
|
if (post.root_id.length > 0) {
|
||||||
@@ -36,7 +37,7 @@ module.exports = React.createClass({
|
|||||||
<ul className="dropdown-menu" role="menu">
|
<ul className="dropdown-menu" role="menu">
|
||||||
{ isOwner ? <li role="presentation"><a href="#" role="menuitem" data-toggle="modal" data-target="#edit_post" data-title={type} data-message={post.message} data-postid={post.id} data-channelid={post.channel_id} data-comments={type === "Post" ? this.props.commentCount : 0}>Edit</a></li>
|
{ isOwner ? <li role="presentation"><a href="#" role="menuitem" data-toggle="modal" data-target="#edit_post" data-title={type} data-message={post.message} data-postid={post.id} data-channelid={post.channel_id} data-comments={type === "Post" ? this.props.commentCount : 0}>Edit</a></li>
|
||||||
: "" }
|
: "" }
|
||||||
{ isOwner ? <li role="presentation"><a href="#" role="menuitem" data-toggle="modal" data-target="#delete_post" data-title={type} data-postid={post.id} data-channelid={post.channel_id} data-comments={type === "Post" ? this.props.commentCount : 0}>Delete</a></li>
|
{ isOwner || isAdmin ? <li role="presentation"><a href="#" role="menuitem" data-toggle="modal" data-target="#delete_post" data-title={type} data-postid={post.id} data-channelid={post.channel_id} data-comments={type === "Post" ? this.props.commentCount : 0}>Delete</a></li>
|
||||||
: "" }
|
: "" }
|
||||||
{ this.props.allowReply === "true" ? <li role="presentation"><a className="reply-link theme" href="#" onClick={this.props.handleCommentClick}>Reply</a></li>
|
{ this.props.allowReply === "true" ? <li role="presentation"><a className="reply-link theme" href="#" onClick={this.props.handleCommentClick}>Reply</a></li>
|
||||||
: "" }
|
: "" }
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user