diff options
author | George Goldberg <george@gberg.me> | 2017-01-13 13:52:32 +0000 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-01-13 10:52:32 -0300 |
commit | 4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6 (patch) | |
tree | 3c5d0f13fb8b61dbb75b72852d5501ab6c9251d1 /api/channel.go | |
parent | e69809dce3708b7ba28a7475c8babbb429ca601c (diff) | |
download | chat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.tar.gz chat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.tar.bz2 chat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.zip |
PLT-5050 (Server). API to update channel member roles. (#5043)
Implements API reference proposal mattermost-api-reference:#66.
Diffstat (limited to 'api/channel.go')
-rw-r--r-- | api/channel.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/api/channel.go b/api/channel.go index ae92ab618..cc63edd07 100644 --- a/api/channel.go +++ b/api/channel.go @@ -45,6 +45,7 @@ func InitChannel() { BaseRoutes.NeedChannel.Handle("/delete", ApiUserRequired(deleteChannel)).Methods("POST") BaseRoutes.NeedChannel.Handle("/add", ApiUserRequired(addMember)).Methods("POST") BaseRoutes.NeedChannel.Handle("/remove", ApiUserRequired(removeMember)).Methods("POST") + BaseRoutes.NeedChannel.Handle("/update_member_roles", ApiUserRequired(updateChannelMemberRoles)).Methods("POST") } func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { @@ -1320,3 +1321,49 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) return } } + +func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + channelId := params["channel_id"] + + props := model.MapFromJson(r.Body) + + userId := props["user_id"] + if len(userId) != 26 { + c.SetInvalidParam("updateChannelMemberRoles", "user_id") + return + } + + mchan := Srv.Store.Channel().GetMember(channelId, userId) + + newRoles := props["new_roles"] + if !(model.IsValidUserRoles(newRoles)) { + c.SetInvalidParam("updateChannelMemberRoles", "new_roles") + return + } + + if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) { + return + } + + var member model.ChannelMember + if result := <-mchan; result.Err != nil { + c.Err = result.Err + return + } else { + member = result.Data.(model.ChannelMember) + } + + member.Roles = newRoles + + if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil { + c.Err = result.Err + return + } + + InvalidateCacheForUser(userId) + + rdata := map[string]string{} + rdata["status"] = "ok" + w.Write([]byte(model.MapToJson(rdata))) +} |