summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorcpanato <ctadeu@gmail.com>2018-07-10 19:27:14 +0200
committercpanato <ctadeu@gmail.com>2018-07-10 19:27:14 +0200
commitc042ffa460296587579aff54b157a5109e022f7e (patch)
tree9e7f77fbc83b6d06204db099066be8999dbb22d9 /api4
parent9470564d355c201155f6fcb123152b8ac954f812 (diff)
parentdccd95bc67779a5b83a2660aec0cf4622cd56550 (diff)
downloadchat-c042ffa460296587579aff54b157a5109e022f7e.tar.gz
chat-c042ffa460296587579aff54b157a5109e022f7e.tar.bz2
chat-c042ffa460296587579aff54b157a5109e022f7e.zip
Merge remote-tracking branch 'upstream/release-5.1' into release-5.1-daily-merge-20180710
Diffstat (limited to 'api4')
-rw-r--r--api4/channel.go63
-rw-r--r--api4/channel_test.go58
-rw-r--r--api4/emoji.go4
-rw-r--r--api4/team_test.go9
4 files changed, 113 insertions, 21 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 1afadf39b..7505d899b 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -96,12 +96,28 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if _, err = c.App.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
- c.Err = err
- return
- }
+ switch oldChannel.Type {
+ case model.CHANNEL_OPEN:
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
+ return
+ }
- if !CanManageChannel(c, channel) {
+ case model.CHANNEL_PRIVATE:
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
+ return
+ }
+
+ case model.CHANNEL_GROUP, model.CHANNEL_DIRECT:
+ // Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
+ if _, err := c.App.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
+ c.Err = model.NewAppError("updateChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
+ return
+ }
+
+ default:
+ c.Err = model.NewAppError("updateChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
return
}
@@ -205,7 +221,28 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !CanManageChannel(c, oldChannel) {
+ switch oldChannel.Type {
+ case model.CHANNEL_OPEN:
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
+ return
+ }
+
+ case model.CHANNEL_PRIVATE:
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
+ return
+ }
+
+ case model.CHANNEL_GROUP, model.CHANNEL_DIRECT:
+ // Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
+ if _, err := c.App.GetChannelMember(c.Params.ChannelId, c.Session.UserId); err != nil {
+ c.Err = model.NewAppError("patchChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
+ return
+ }
+
+ default:
+ c.Err = model.NewAppError("patchChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
return
}
@@ -255,20 +292,6 @@ func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
-func CanManageChannel(c *Context, channel *model.Channel) bool {
- if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
- c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
- return false
- }
-
- if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
- c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
- return false
- }
-
- return true
-}
-
func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
userIds := model.ArrayFromJson(r.Body)
allowed := false
diff --git a/api4/channel_test.go b/api4/channel_test.go
index ab751f151..43223d060 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -209,8 +209,34 @@ func TestUpdateChannel(t *testing.T) {
channel.DisplayName = "Should not update"
_, resp = Client.UpdateChannel(channel)
- CheckNotFoundStatus(t, resp)
+ CheckForbiddenStatus(t, resp)
+
+ // Test updating the header of someone else's GM channel.
+ user1 := th.CreateUser()
+ user2 := th.CreateUser()
+ user3 := th.CreateUser()
+
+ groupChannel, resp := Client.CreateGroupChannel([]string{user1.Id, user2.Id})
+ CheckNoError(t, resp)
+
+ groupChannel.Header = "lolololol"
+ Client.Logout()
+ Client.Login(user3.Email, user3.Password)
+ _, resp = Client.UpdateChannel(groupChannel)
+ CheckForbiddenStatus(t, resp)
+ // Test updating the header of someone else's GM channel.
+ Client.Logout()
+ Client.Login(user.Email, user.Password)
+
+ directChannel, resp := Client.CreateDirectChannel(user.Id, user1.Id)
+ CheckNoError(t, resp)
+
+ directChannel.Header = "lolololol"
+ Client.Logout()
+ Client.Login(user3.Email, user3.Password)
+ _, resp = Client.UpdateChannel(directChannel)
+ CheckForbiddenStatus(t, resp)
}
func TestPatchChannel(t *testing.T) {
@@ -267,6 +293,36 @@ func TestPatchChannel(t *testing.T) {
_, resp = th.SystemAdminClient.PatchChannel(th.BasicPrivateChannel.Id, patch)
CheckNoError(t, resp)
+
+ // Test updating the header of someone else's GM channel.
+ user1 := th.CreateUser()
+ user2 := th.CreateUser()
+ user3 := th.CreateUser()
+
+ groupChannel, resp := Client.CreateGroupChannel([]string{user1.Id, user2.Id})
+ CheckNoError(t, resp)
+
+ Client.Logout()
+ Client.Login(user3.Email, user3.Password)
+
+ channelPatch := &model.ChannelPatch{}
+ channelPatch.Header = new(string)
+ *channelPatch.Header = "lolololol"
+
+ _, resp = Client.PatchChannel(groupChannel.Id, channelPatch)
+ CheckForbiddenStatus(t, resp)
+
+ // Test updating the header of someone else's GM channel.
+ Client.Logout()
+ Client.Login(user.Email, user.Password)
+
+ directChannel, resp := Client.CreateDirectChannel(user.Id, user1.Id)
+ CheckNoError(t, resp)
+
+ Client.Logout()
+ Client.Login(user3.Email, user3.Password)
+ _, resp = Client.PatchChannel(directChannel.Id, channelPatch)
+ CheckForbiddenStatus(t, resp)
}
func TestCreateDirectChannel(t *testing.T) {
diff --git a/api4/emoji.go b/api4/emoji.go
index 42f66a22a..750f4b6e9 100644
--- a/api4/emoji.go
+++ b/api4/emoji.go
@@ -4,6 +4,8 @@
package api4
import (
+ "io"
+ "io/ioutil"
"net/http"
"strings"
@@ -28,6 +30,8 @@ func (api *API) InitEmoji() {
}
func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
+ defer io.Copy(ioutil.Discard, r.Body)
+
if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
return
diff --git a/api4/team_test.go b/api4/team_test.go
index 48e3404eb..307e91635 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -1935,6 +1935,15 @@ func TestInviteUsersToTeam(t *testing.T) {
utils.DeleteMailBox(user1)
utils.DeleteMailBox(user2)
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableEmailInvitations = false })
+
+ _, resp := th.SystemAdminClient.InviteUsersToTeam(th.BasicTeam.Id, emailList)
+ if resp.Error == nil {
+ t.Fatal("Should be disabled")
+ }
+
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableEmailInvitations = true })
+
okMsg, resp := th.SystemAdminClient.InviteUsersToTeam(th.BasicTeam.Id, emailList)
CheckNoError(t, resp)
if !okMsg {