Skip to content

Commit

Permalink
Add props and edit permission
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril committed Mar 28, 2017
1 parent 1cb4942 commit d541903
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions api4/post.go
Expand Up @@ -259,8 +259,8 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
c.SetPermissionError(model.PERMISSION_EDIT_POST)
if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
return
}

Expand Down
9 changes: 9 additions & 0 deletions api4/post_test.go
Expand Up @@ -194,6 +194,7 @@ func TestPatchPost(t *testing.T) {
ChannelId: channel.Id,
IsPinned: true,
Message: "#hashtag a message",
Props: model.StringInterface{"channel_header": "old_header"},
FileIds: model.StringArray{"file1", "file2"},
HasReactions: true,
}
Expand All @@ -205,6 +206,8 @@ func TestPatchPost(t *testing.T) {
*patch.IsPinned = false
patch.Message = new(string)
*patch.Message = "#otherhashtag other message"
patch.Props = new(model.StringInterface)
*patch.Props = model.StringInterface{"channel_header": "new_header"}
patch.FileIds = new(model.StringArray)
*patch.FileIds = model.StringArray{"file1", "otherfile2", "otherfile3"}
patch.HasReactions = new(bool)
Expand All @@ -219,6 +222,12 @@ func TestPatchPost(t *testing.T) {
if rpost.Message != "#otherhashtag other message" {
t.Fatal("Message did not update properly")
}
if len(rpost.Props) != 1 {
t.Fatal("Props did not update properly")
}
if !reflect.DeepEqual(rpost.Props, *patch.Props) {
t.Fatal("Props did not update properly")
}
if rpost.Hashtags != "#otherhashtag" {
t.Fatal("Message did not update properly")
}
Expand Down
1 change: 1 addition & 0 deletions app/post.go
Expand Up @@ -299,6 +299,7 @@ func UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
*newPost = *oldPost

newPost.Message = post.Message
newPost.Props = post.Props
newPost.EditAt = model.GetMillis()
newPost.Hashtags, _ = model.ParseHashtags(post.Message)
newPost.IsPinned = post.IsPinned
Expand Down
13 changes: 9 additions & 4 deletions model/post.go
Expand Up @@ -55,10 +55,11 @@ type Post struct {
}

type PostPatch struct {
IsPinned *bool `json:"is_pinned"`
Message *string `json:"message"`
FileIds *StringArray `json:"file_ids"`
HasReactions *bool `json:"has_reactions"`
IsPinned *bool `json:"is_pinned"`
Message *string `json:"message"`
Props *StringInterface `json:"props"`
FileIds *StringArray `json:"file_ids"`
HasReactions *bool `json:"has_reactions"`
}

func (o *Post) ToJson() string {
Expand Down Expand Up @@ -207,6 +208,10 @@ func (p *Post) Patch(patch *PostPatch) {
p.Message = *patch.Message
}

if patch.Props != nil {
p.Props = *patch.Props
}

if patch.FileIds != nil {
p.FileIds = *patch.FileIds
}
Expand Down

0 comments on commit d541903

Please sign in to comment.