From 67c0efae1bfcf6e53c4eaa5cb9966348134973ab Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 23 Mar 2018 16:49:18 +0300 Subject: Allow to get the team icon for open teams (#8499) * Allow to get the team icon for open teams * feedback review --- api4/team.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'api4') 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) { -- cgit v1.2.3-1-g7c22 From 4a69c277a620308959ad6870d4e7c8240f9a166d Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 26 Mar 2018 12:41:06 -0700 Subject: Adding go client support and basic unit tests for channel autocomplete. (#8510) --- api4/channel_test.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'api4') diff --git a/api4/channel_test.go b/api4/channel_test.go index 51c32cf71..427607dc5 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) { @@ -2015,3 +2016,75 @@ func TestRemoveChannelMember(t *testing.T) { _, resp = th.SystemAdminClient.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) + } + } + } + } + } +} -- cgit v1.2.3-1-g7c22 From 8491ba5740e2d9942b2612ce06aef90bb10ad4c0 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Mon, 26 Mar 2018 17:55:35 -0400 Subject: Relax 4k post message limit (#8478) * MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1 * MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests * MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2 * MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000) This is safe to do in a production instance since the underyling type is not changing. We explicitly don't do this automatically for MySQL, but also don't need to since the ORM would have already created a TEXT column for MySQL in that case. * MM-9661: emit MaxPostSize in client config This value remains unconfigurable at this time, but exposes the current limit to the client. The limit remains at 4k in this commit. * MM-9661: introduce and use SqlPostStore.GetMaxPostSize Enforce a byte limitation in the database, and use 1/4 of that value as the rune count limitation (assuming a worst case UTF-8 representation). * move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore * address feedback from code review: * ensure sqlstore unit tests are actually being run * move global caches into SqlPostStore * leverage sync.Once to address a race condition * modify upgrade semantics to match new db semantics gorp's behaviour on creating columns with a maximum length on Postgres differs from MySQL: * Postgres * gorp uses TEXT for string columns without a maximum length * gorp uses VARCHAR(N) for string columns with a maximum length of N * MySQL * gorp uses TEXT for string columns with a maximum length >= 256 * gorp uses VARCHAR(N) for string columns with a maximum length of N * gorp defaults to a maximum length of 255, implying VARCHAR(255) So the Message column has been TEXT on MySQL but VARCHAR(4000) on Postgres. With the new, longer limits of 65535, and without changes to gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on Postgres. This commit makes the upgrade semantics match the new database semantics. Ideally, we'd revisit the gorp behaviour at a later time. * allow TestMaxPostSize test cases to actually run in parallel * default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics * fix casting error * MM-9661: skip the schema migration for Postgres It turns out resizing VARCHAR requires a rewrite in some versions of Postgres, but migrating VARCHAR to TEXT does not. Given the increasing complexity, let's defer the migration to the enduser instead. --- api4/system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api4') 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) { -- cgit v1.2.3-1-g7c22