summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorMartin Kraft <martinkraft@gmail.com>2018-03-27 09:01:42 -0400
committerMartin Kraft <martinkraft@gmail.com>2018-03-27 09:01:42 -0400
commite13e64711f7a7e8ceadb8cbc6af72c4022c95b36 (patch)
treefe0e956b1d660cd08d41757d25c8adcb3463568c /api4
parentd8b42070186c12f6320fe54ea1c405149846404c (diff)
parent9e6db178b09387e21ac19ce85369cf1ca7a443e8 (diff)
downloadchat-e13e64711f7a7e8ceadb8cbc6af72c4022c95b36.tar.gz
chat-e13e64711f7a7e8ceadb8cbc6af72c4022c95b36.tar.bz2
chat-e13e64711f7a7e8ceadb8cbc6af72c4022c95b36.zip
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-1
Diffstat (limited to 'api4')
-rw-r--r--api4/channel_test.go73
-rw-r--r--api4/system.go2
-rw-r--r--api4/team.go11
3 files changed, 80 insertions, 6 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index b9ee5bc7d..4c27e040a 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/utils"
)
func TestCreateChannel(t *testing.T) {
@@ -1766,3 +1767,75 @@ func TestRemoveChannelMember(t *testing.T) {
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp)
}
+
+func TestAutocompleteChannels(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ // A private channel to make sure private channels are not used
+ utils.DisableDebugLogForTest()
+ ptown, _ := th.Client.CreateChannel(&model.Channel{
+ DisplayName: "Town",
+ Name: "town",
+ Type: model.CHANNEL_PRIVATE,
+ TeamId: th.BasicTeam.Id,
+ })
+ utils.EnableDebugLogForTest()
+ defer func() {
+ th.Client.DeleteChannel(ptown.Id)
+ }()
+
+ for _, tc := range []struct {
+ description string
+ teamId string
+ fragment string
+ expectedIncludes []string
+ expectedExcludes []string
+ }{
+ {
+ "Basic town-square",
+ th.BasicTeam.Id,
+ "town",
+ []string{"town-square"},
+ []string{"off-topic", "town"},
+ },
+ {
+ "Basic off-topic",
+ th.BasicTeam.Id,
+ "off-to",
+ []string{"off-topic"},
+ []string{"town-square", "town"},
+ },
+ {
+ "Basic town square and off topic",
+ th.BasicTeam.Id,
+ "to",
+ []string{"off-topic", "town-square"},
+ []string{"town"},
+ },
+ } {
+ if channels, resp := th.Client.AutocompleteChannelsForTeam(tc.teamId, tc.fragment); resp.Error != nil {
+ t.Fatal("Test case " + tc.description + " failed. Err: " + resp.Error.Error())
+ } else {
+ for _, expectedInclude := range tc.expectedIncludes {
+ found := false
+ for _, channel := range *channels {
+ if channel.Name == expectedInclude {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Fatal("Test case " + tc.description + " failed. Expected but didn't find channel: " + expectedInclude)
+ }
+ }
+ for _, expectedExclude := range tc.expectedExcludes {
+ for _, channel := range *channels {
+ if channel.Name == expectedExclude {
+ t.Fatal("Test case " + tc.description + " failed. Found channel we didn't want: " + expectedExclude)
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/api4/system.go b/api4/system.go
index 4ae8ee7b9..b34f2af6b 100644
--- a/api4/system.go
+++ b/api4/system.go
@@ -248,7 +248,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- w.Write([]byte(model.MapToJson(c.App.ClientConfigWithNoAccounts())))
+ w.Write([]byte(model.MapToJson(c.App.ClientConfigWithComputed())))
}
func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
diff --git a/api4/team.go b/api4/team.go
index f8a1c556c..33cd57fbb 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -741,15 +741,16 @@ func getTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
- c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
- return
- }
-
if team, err := c.App.GetTeam(c.Params.TeamId); err != nil {
c.Err = err
return
} else {
+ if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) &&
+ (team.Type != model.TEAM_OPEN || team.AllowOpenInvite) {
+ c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
+ return
+ }
+
etag := strconv.FormatInt(team.LastTeamIconUpdate, 10)
if c.HandleEtag(etag, "Get Team Icon", w, r) {