From 4492549d802b8ffaef8fa501e1e6138c6af3c2f8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 10 Aug 2020 12:50:16 -0700 Subject: [PATCH] MM-27572 permissions regression (#15215) * Fix regression in HasPermissionToTeam * Removing unessisary special case + verify system admins always have permissions. * Fixing testing and bad cleanup. --- app/authorization.go | 4 +++- app/authorization_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/authorization.go b/app/authorization.go index 4218823bf1..ca24c977b2 100644 --- a/app/authorization.go +++ b/app/authorization.go @@ -148,7 +148,9 @@ func (a *App) HasPermissionToTeam(askingUserId string, teamId string, permission } teamMember, _ := a.GetTeamMember(teamId, askingUserId) if teamMember != nil && teamMember.DeleteAt == 0 { - return a.RolesGrantPermission(teamMember.GetRoles(), permission.Id) + if a.RolesGrantPermission(teamMember.GetRoles(), permission.Id) { + return true + } } return a.HasPermissionTo(askingUserId, permission) } diff --git a/app/authorization_test.go b/app/authorization_test.go index 23af424d72..59a159c6bd 100644 --- a/app/authorization_test.go +++ b/app/authorization_test.go @@ -48,14 +48,14 @@ func TestHasPermissionToTeam(t *testing.T) { defer th.TearDown() assert.True(t, th.App.HasPermissionToTeam(th.BasicUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) - th.RemoveUserFromTeam(th.BasicUser, th.BasicTeam) - assert.False(t, th.App.HasPermissionToTeam(th.BasicUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) + assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam) assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) + th.RemovePermissionFromRole(model.PERMISSION_LIST_TEAM_CHANNELS.Id, model.TEAM_USER_ROLE_ID) + assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) th.RemoveUserFromTeam(th.SystemAdminUser, th.BasicTeam) - // This used to fail before MM-26015 assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PERMISSION_LIST_TEAM_CHANNELS)) }