mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-21 14:20:41 +08:00
[MM-66827] Omit invite_id from team creation response based on permissions (#34693)
This commit is contained in:
@@ -127,6 +127,12 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Don't sanitize the team here since the user will be a team admin and their session won't reflect that yet
|
||||
// instead check the scheme roles for the team and if the user has the permission to invite users
|
||||
_, schemeUserRole, schemeAdminRole, schemeErr := c.App.GetSchemeRolesForTeam(rteam.Id)
|
||||
if schemeErr != nil || !c.App.RolesGrantPermission([]string{schemeUserRole, schemeAdminRole}, model.PermissionInviteUser.Id) {
|
||||
// If we can't check permissions, fail secure by hiding the invite_id because the team is already created above
|
||||
rteam.InviteId = ""
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddEventResultState(&team)
|
||||
|
||||
@@ -233,6 +233,29 @@ func TestCreateTeamSanitization(t *testing.T) {
|
||||
}, "system admin")
|
||||
}
|
||||
|
||||
func TestCreateTeamInviteIdHiddenWithoutInvitePermission(t *testing.T) {
|
||||
th := Setup(t)
|
||||
|
||||
defaultRolePermissions := th.SaveDefaultRolePermissions(t)
|
||||
defer th.RestoreDefaultRolePermissions(t, defaultRolePermissions)
|
||||
|
||||
// Remove PermissionInviteUser from the default team user role
|
||||
th.RemovePermissionFromRole(t, model.PermissionInviteUser.Id, model.TeamUserRoleId)
|
||||
|
||||
// Regular user creates a team - InviteId should be hidden
|
||||
// since the team user role lacks invite permission
|
||||
rteam, _, err := th.Client.CreateTeam(context.Background(), &model.Team{
|
||||
DisplayName: "Team Without Invite Permission",
|
||||
Name: GenerateTestTeamName(),
|
||||
Email: th.GenerateTestEmail(),
|
||||
Type: model.TeamOpen,
|
||||
AllowedDomains: "simulator.amazonses.com,localhost",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, rteam.Email, "should not have sanitized email")
|
||||
require.Empty(t, rteam.InviteId, "should have hidden invite_id when user lacks invite permission")
|
||||
}
|
||||
|
||||
func TestGetTeam(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
|
||||
|
||||
@@ -375,6 +375,7 @@ func (a *App) sendTeamEvent(team *model.Team, event model.WebsocketEventType) *m
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSchemeRolesForTeam Gets the scheme roles for a team, they may be empty, default or custom permissions based on the scheme.
|
||||
func (a *App) GetSchemeRolesForTeam(teamID string) (string, string, string, *model.AppError) {
|
||||
team, err := a.GetTeam(teamID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user