Implement PUT /channels/{channel_id}/members/{user_id}/notify_props for APIv4 (#5901)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
ea17e8d004
Коммит
4e224c2996
@@ -43,6 +43,7 @@ func InitChannel() {
|
|||||||
BaseRoutes.ChannelMember.Handle("", ApiSessionRequired(getChannelMember)).Methods("GET")
|
BaseRoutes.ChannelMember.Handle("", ApiSessionRequired(getChannelMember)).Methods("GET")
|
||||||
BaseRoutes.ChannelMember.Handle("", ApiSessionRequired(removeChannelMember)).Methods("DELETE")
|
BaseRoutes.ChannelMember.Handle("", ApiSessionRequired(removeChannelMember)).Methods("DELETE")
|
||||||
BaseRoutes.ChannelMember.Handle("/roles", ApiSessionRequired(updateChannelMemberRoles)).Methods("PUT")
|
BaseRoutes.ChannelMember.Handle("/roles", ApiSessionRequired(updateChannelMemberRoles)).Methods("PUT")
|
||||||
|
BaseRoutes.ChannelMember.Handle("/notify_props", ApiSessionRequired(updateChannelMemberNotifyProps)).Methods("PUT")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -660,6 +661,32 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
|
|||||||
ReturnStatusOK(w)
|
ReturnStatusOK(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateChannelMemberNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
c.RequireChannelId().RequireUserId()
|
||||||
|
if c.Err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
props := model.MapFromJson(r.Body)
|
||||||
|
if props == nil {
|
||||||
|
c.SetInvalidParam("notify_props")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.SessionHasPermissionToUser(c.Session, c.Params.UserId) {
|
||||||
|
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := app.UpdateChannelMemberNotifyProps(props, c.Params.ChannelId, c.Params.UserId)
|
||||||
|
if err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnStatusOK(w)
|
||||||
|
}
|
||||||
|
|
||||||
func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
c.RequireChannelId()
|
c.RequireChannelId()
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
|
|||||||
@@ -1440,6 +1440,56 @@ func TestUpdateChannelRoles(t *testing.T) {
|
|||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateChannelNotifyProps(t *testing.T) {
|
||||||
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
|
defer TearDown()
|
||||||
|
Client := th.Client
|
||||||
|
|
||||||
|
props := map[string]string{}
|
||||||
|
props[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
|
||||||
|
props[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
|
||||||
|
|
||||||
|
pass, resp := Client.UpdateChannelNotifyProps(th.BasicChannel.Id, th.BasicUser.Id, props)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if !pass {
|
||||||
|
t.Fatal("should have passed")
|
||||||
|
}
|
||||||
|
|
||||||
|
member, err := app.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if member.NotifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
|
||||||
|
t.Fatal("bad update")
|
||||||
|
} else if member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_MENTION {
|
||||||
|
t.Fatal("bad update")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps("junk", th.BasicUser.Id, props)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps(th.BasicChannel.Id, "junk", props)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps(model.NewId(), th.BasicUser.Id, props)
|
||||||
|
CheckNotFoundStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps(th.BasicChannel.Id, model.NewId(), props)
|
||||||
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps(th.BasicChannel.Id, th.BasicUser.Id, map[string]string{})
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
Client.Logout()
|
||||||
|
_, resp = Client.UpdateChannelNotifyProps(th.BasicChannel.Id, th.BasicUser.Id, props)
|
||||||
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = th.SystemAdminClient.UpdateChannelNotifyProps(th.BasicChannel.Id, th.BasicUser.Id, props)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddChannelMember(t *testing.T) {
|
func TestAddChannelMember(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer TearDown()
|
defer TearDown()
|
||||||
|
|||||||
@@ -1186,6 +1186,16 @@ func (c *Client4) UpdateChannelRoles(channelId, userId, roles string) (bool, *Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateChannelNotifyProps will update the notification properties on a channel for a user.
|
||||||
|
func (c *Client4) UpdateChannelNotifyProps(channelId, userId string, props map[string]string) (bool, *Response) {
|
||||||
|
if r, err := c.DoApiPut(c.GetChannelMemberRoute(channelId, userId)+"/notify_props", MapToJson(props)); err != nil {
|
||||||
|
return false, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return CheckStatusOK(r), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AddChannelMember adds user to channel and return a channel member.
|
// AddChannelMember adds user to channel and return a channel member.
|
||||||
func (c *Client4) AddChannelMember(channelId, userId string) (*ChannelMember, *Response) {
|
func (c *Client4) AddChannelMember(channelId, userId string) (*ChannelMember, *Response) {
|
||||||
requestBody := map[string]string{"user_id": userId}
|
requestBody := map[string]string{"user_id": userId}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user