[MM-62687] Patch permission check to avoid modifying the system admin (#30292)
* [MM-62687] Patch permission check to avoid modifying the system admin * Check for manage system first * PR feedback * Add another test * Lint * Fix test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a732962f0a
Коммит
9f49403d0a
@@ -4237,6 +4237,14 @@ func TestSetDefaultProfileImage(t *testing.T) {
|
|||||||
_, err = th.SystemAdminClient.SetDefaultProfileImage(context.Background(), user.Id)
|
_, err = th.SystemAdminClient.SetDefaultProfileImage(context.Background(), user.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Check that a system admin can set the default profile image for another system admin
|
||||||
|
anotherAdmin := th.CreateUser()
|
||||||
|
_, appErr := th.App.UpdateUserRoles(th.Context, anotherAdmin.Id, model.SystemAdminRoleId+" "+model.SystemUserRoleId, false)
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
|
_, err = th.SystemAdminClient.SetDefaultProfileImage(context.Background(), anotherAdmin.Id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ruser, appErr := th.App.GetUser(user.Id)
|
ruser, appErr := th.App.GetUser(user.Id)
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
assert.Less(t, ruser.LastPictureUpdate, iuser.LastPictureUpdate, "LastPictureUpdate should be updated to a lower negative number")
|
assert.Less(t, ruser.LastPictureUpdate, iuser.LastPictureUpdate, "LastPictureUpdate should be updated to a lower negative number")
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ func (a *App) SessionHasPermissionToUser(session model.Session, userID string) b
|
|||||||
if userID == "" {
|
if userID == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if session.IsUnrestricted() {
|
if session.IsUnrestricted() || a.SessionHasPermissionTo(session, model.PermissionManageSystem) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,11 +210,20 @@ func (a *App) SessionHasPermissionToUser(session model.Session, userID string) b
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.SessionHasPermissionTo(session, model.PermissionEditOtherUsers) {
|
if !a.SessionHasPermissionTo(session, model.PermissionEditOtherUsers) {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
user, err := a.GetUser(userID)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.IsSystemAdmin() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SessionHasPermissionToUserOrBot(rctx request.CTX, session model.Session, userID string) bool {
|
func (a *App) SessionHasPermissionToUserOrBot(rctx request.CTX, session model.Session, userID string) bool {
|
||||||
|
|||||||
@@ -382,6 +382,7 @@ func TestSessionHasPermissionToUser(t *testing.T) {
|
|||||||
|
|
||||||
th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId)
|
th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId)
|
||||||
assert.True(t, th.App.SessionHasPermissionToUser(session, th.BasicUser2.Id))
|
assert.True(t, th.App.SessionHasPermissionToUser(session, th.BasicUser2.Id))
|
||||||
|
assert.False(t, th.App.SessionHasPermissionToUser(session, th.SystemAdminUser.Id))
|
||||||
th.RemovePermissionFromRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId)
|
th.RemovePermissionFromRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId)
|
||||||
|
|
||||||
bot, err := th.App.CreateBot(th.Context, &model.Bot{
|
bot, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user