MM-27572 permissions regression (#15215)

* Fix regression in HasPermissionToTeam

* Removing unessisary special case + verify system admins always have permissions.

* Fixing testing and bad cleanup.
Этот коммит содержится в:
Christopher Speller
2020-08-10 12:50:16 -07:00
коммит произвёл GitHub
родитель 8138600dd1
Коммит 4492549d80
2 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@@ -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)
}

Просмотреть файл

@@ -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))
}