[PLT-7362] Add post' root ID to APIv4 addChannelMember to render added user (as system post) at RHS (#7730)
* add post' root ID to apiv4 addChannelMember to render added user (as system post) at RHS * add check to post_root_id parameter * add AddChannelMemberWithRootId function for backward compatibility
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
3024525c3b
Коммит
709ef99eca
@@ -783,21 +783,36 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
member := model.ChannelMemberFromJson(r.Body)
|
||||
if member == nil {
|
||||
c.SetInvalidParam("channel_member")
|
||||
return
|
||||
}
|
||||
|
||||
if len(member.UserId) != 26 {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
userId, ok := props["user_id"].(string)
|
||||
if !ok || len(userId) != 26 {
|
||||
c.SetInvalidParam("user_id")
|
||||
return
|
||||
}
|
||||
|
||||
member.ChannelId = c.Params.ChannelId
|
||||
member := &model.ChannelMember{
|
||||
ChannelId: c.Params.ChannelId,
|
||||
UserId: userId,
|
||||
}
|
||||
|
||||
postRootId, ok := props["post_root_id"].(string)
|
||||
if ok && len(postRootId) != 0 && len(postRootId) != 26 {
|
||||
c.SetInvalidParam("post_root_id")
|
||||
return
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
if ok && len(postRootId) == 26 {
|
||||
if rootPost, err := c.App.GetSinglePost(postRootId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if rootPost.ChannelId != member.ChannelId {
|
||||
c.SetInvalidParam("post_root_id")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = c.App.GetChannel(member.ChannelId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -828,7 +843,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if cm, err := c.App.AddChannelMember(member.UserId, channel, c.Session.UserId); err != nil {
|
||||
if cm, err := c.App.AddChannelMember(member.UserId, channel, c.Session.UserId, postRootId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -1740,6 +1740,24 @@ func TestAddChannelMember(t *testing.T) {
|
||||
t.Fatal("should have returned exact user added to private channel")
|
||||
}
|
||||
|
||||
post := &model.Post{ChannelId: publicChannel.Id, Message: "a" + GenerateTestId() + "a"}
|
||||
rpost, err := Client.CreatePost(post)
|
||||
if err == nil {
|
||||
t.Fatal("should have created a post")
|
||||
}
|
||||
|
||||
Client.RemoveUserFromChannel(publicChannel.Id, user.Id)
|
||||
_, resp = Client.AddChannelMemberWithRootId(publicChannel.Id, user.Id, rpost.Id)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
Client.RemoveUserFromChannel(publicChannel.Id, user.Id)
|
||||
_, resp = Client.AddChannelMemberWithRootId(publicChannel.Id, user.Id, "junk")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.AddChannelMemberWithRootId(publicChannel.Id, user.Id, GenerateTestId())
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
Client.RemoveUserFromChannel(publicChannel.Id, user.Id)
|
||||
_, resp = Client.AddChannelMember(publicChannel.Id, user.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user