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) {