From 4587913b49d1516f37932153309ae7788ae86609 Mon Sep 17 00:00:00 2001 From: Hossein Ahmadian-Yazdi Date: Mon, 24 Feb 2020 05:53:58 -0500 Subject: [PATCH] [MM-22071] Allow fetch all groups as a system admin (#13866) * Merge upstream * allow fetch all groups * Delete report.xml * update i18n stuffz * fix test cases * fix bug Co-authored-by: Jason Paul Deland <9366595+jaydeland@users.noreply.github.com> Co-authored-by: mattermod --- api4/group.go | 4 ++-- api4/group_test.go | 7 ++++++- i18n/en.json | 4 ---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api4/group.go b/api4/group.go index fe242c13b0..555e93b200 100644 --- a/api4/group.go +++ b/api4/group.go @@ -581,8 +581,8 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) { channelID = id } - if teamID == "" && channelID == "" { - c.Err = model.NewAppError("Api4.getGroups", "api.getGroups.invalid_or_missing_channel_or_team_id", nil, "", http.StatusBadRequest) + if teamID == "" && channelID == "" && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) return } diff --git a/api4/group_test.go b/api4/group_test.go index 4415bf97da..611159525d 100644 --- a/api4/group_test.go +++ b/api4/group_test.go @@ -801,7 +801,7 @@ func TestGetGroups(t *testing.T) { th.App.SetLicense(model.NewTestLicense("ldap")) _, response = th.SystemAdminClient.GetGroups(opts) - CheckBadRequestStatus(t, response) + require.Nil(t, response.Error) _, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "") require.Nil(t, response.Error) @@ -841,4 +841,9 @@ func TestGetGroups(t *testing.T) { _, response = th.Client.GetGroups(opts) assert.Nil(t, response.Error) + + opts.NotAssociatedToTeam = "" + opts.NotAssociatedToChannel = "" + _, response = th.Client.GetGroups(opts) + CheckForbiddenStatus(t, response) } diff --git a/i18n/en.json b/i18n/en.json index 934ebed196..4e2c1742f0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1392,10 +1392,6 @@ "id": "api.file.write_file_locally.writing.app_error", "translation": "Encountered an error writing to local server storage" }, - { - "id": "api.getGroups.invalid_or_missing_channel_or_team_id", - "translation": "Invalid/Missing channel ID or Team ID." - }, { "id": "api.incoming_webhook.disabled.app_error", "translation": "Incoming webhooks have been disabled by the system admin."