From 860989e2ca9c409ceff18f4db53f965d7177928c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ossi=20V=C3=A4=C3=A4n=C3=A4nen?= <4111915+oh6hay@users.noreply.github.com> Date: Mon, 28 Nov 2022 18:12:41 +0200 Subject: [PATCH] [MM-47982] [MM-47983] Honor the ShowEmailAddress setting (#21707) * Honor the ShowEmailAddress setting for the `/api/v4/teams/[teamid]/regenerate_invite_id` and `/api/v4/users/me/teams` API paths. Fixes MM-47982 and MM-47983 * Fix linter error in test code * MM-48186: Add a new API endpoint to add a user to their default GroupChannels and GroupTeams. (#21591) * MM-48186: Add a new API endpoint to add a user to their default GroupChannels and GroupTeams. * MM-48186: Removed unrelated lint fixes. * MM-48186: Removed variable from previous iteration. * MM-48186: Adds translation. * MM-48186: Not upgrading golang.org/x/text in this pr. * MM-48186: Validate user ID and auth service. * MM-48186: Use user id from struct. * MM-48186: Added basic client test. * MM-48186: Adds empty translation. * MM-48186: Added translations. Co-authored-by: Mattermod * [MM-47384] Make OpenID Connect free for all (#21556) * wip: make OpenID Connect free-for-all * Deprecation note: GoogleOAuth, Office365OAuth * Improve deprecation comments Co-authored-by: Martin Kraft * Lint fix * Add model/oauthproviders, move google, openid, office365 from enterprise * Vet fixes * Remove redundant log Co-authored-by: Martin Kraft Co-authored-by: Mattermod Co-authored-by: Martin Kraft Co-authored-by: Mattermod Co-authored-by: Shivashis Padhi --- api4/team.go | 10 ++++++++++ api4/team_test.go | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/api4/team.go b/api4/team.go index a4d687f1ff..08b520ebe2 100644 --- a/api4/team.go +++ b/api4/team.go @@ -407,6 +407,10 @@ func regenerateTeamInviteId(c *Context, w http.ResponseWriter, r *http.Request) c.App.SanitizeTeam(*c.AppContext.Session(), patchedTeam) + if !*c.App.Config().PrivacySettings.ShowEmailAddress && !c.IsSystemAdmin() { + patchedTeam.Email = "" + } + auditRec.Success() auditRec.AddEventResultState(patchedTeam) auditRec.AddEventObjectType("team") @@ -493,6 +497,12 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) { c.App.SanitizeTeams(*c.AppContext.Session(), teams) + if !*c.App.Config().PrivacySettings.ShowEmailAddress && !c.IsSystemAdmin() { + for _, team := range teams { + team.Email = "" + } + } + js, err := json.Marshal(teams) if err != nil { c.Err = model.NewAppError("getTeamsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) diff --git a/api4/team_test.go b/api4/team_test.go index 04cca44f71..c1eef6e6ac 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -871,11 +871,21 @@ func TestRegenerateTeamInviteId(t *testing.T) { assert.NotEqual(t, team.InviteId, "") assert.NotEqual(t, team.InviteId, "inviteid0") + *th.App.Config().PrivacySettings.ShowEmailAddress = true rteam, _, err := client.RegenerateTeamInviteId(team.Id) require.NoError(t, err) assert.NotEqual(t, team.InviteId, rteam.InviteId) assert.NotEqual(t, team.InviteId, "") + assert.NotEqual(t, rteam.Email, "") + + *th.App.Config().PrivacySettings.ShowEmailAddress = false + rteam, _, err = client.RegenerateTeamInviteId(team.Id) + require.NoError(t, err) + + assert.NotEqual(t, team.InviteId, rteam.InviteId) + assert.NotEqual(t, team.InviteId, "") + assert.Equal(t, rteam.Email, "") } func TestSoftDeleteTeam(t *testing.T) { @@ -1819,6 +1829,17 @@ func TestGetTeamsForUserSanitization(t *testing.T) { require.NotEmpty(t, rteam.Email, "should not have sanitized email") require.NotEmpty(t, rteam.InviteId, "should have not sanitized inviteid") } + *th.App.Config().PrivacySettings.ShowEmailAddress = false + rteams, _, err2 := th.Client.GetTeamsForUser(th.BasicUser.Id, "") + require.NoError(t, err2) + for _, rteam := range rteams { + if rteam.Id != team.Id && rteam.Id != team2.Id { + continue + } + + require.Empty(t, rteam.Email, "should have sanitized email") + require.NotEmpty(t, rteam.InviteId, "should have not sanitized inviteid") + } }) t.Run("system admin", func(t *testing.T) {