N°4036 - User edition controls : a user cannot change his own status

This commit is contained in:
Eric
2021-07-27 13:57:54 +02:00
parent 25f3c1cbc4
commit ace2eb6dab
3 changed files with 42 additions and 26 deletions

View File

@@ -352,6 +352,11 @@ abstract class User extends cmdbAbstractObject
}
}
}
if ($this->IsCurrentUser()) {
if (isset($aChanges['status'])) {
$this->m_aCheckIssues[] = Dict::S('Class:User/Error:StatusChangeIsNotAllowed');
}
}
// Check that this user has at least one profile assigned when profiles have changed
if (array_key_exists('profile_list', $aChanges))
{
@@ -362,7 +367,7 @@ abstract class User extends cmdbAbstractObject
}
// A user cannot add a profile denying the access to the backoffice
$aForbiddenProfiles = PortalDispatcherData::GetData('backoffice')['deny'];
if (UserRights::GetUserId() == $this->GetKey()) {
if ($this->IsCurrentUser()) {
$oSet->Rewind();
while ($oUserProfile = $oSet->Fetch()) {
$sProfile = $oUserProfile->Get('profile');
@@ -429,7 +434,7 @@ abstract class User extends cmdbAbstractObject
parent::DoCheckToDelete($oDeletionPlan);
// A user cannot suppress himself
if (UserRights::GetUserId() == $this->GetKey()) {
if ($this->IsCurrentUser()) {
$this->m_bSecurityIssue = true;
$this->m_aDeleteIssues[] = Dict::S('UI:Delete:NotAllowedToDelete');
}
@@ -547,6 +552,15 @@ abstract class User extends cmdbAbstractObject
}
parent::DBDeleteSingleObject();
}
/**
* @return bool
* @throws \OQLException
*/
private function IsCurrentUser(): bool
{
return UserRights::GetUserId() == $this->GetKey();
}
}
/**

View File

@@ -104,35 +104,36 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:User/Attribute:last_name' => 'Last name',
'Class:User/Attribute:last_name+' => 'Name of the corresponding contact',
'Class:User/Attribute:first_name' => 'First name',
'Class:User/Attribute:first_name+' => 'First name of the corresponding contact',
'Class:User/Attribute:email' => 'Email',
'Class:User/Attribute:email+' => 'Email of the corresponding contact',
'Class:User/Attribute:login' => 'Login',
'Class:User/Attribute:login+' => 'user identification string',
'Class:User/Attribute:language' => 'Language',
'Class:User/Attribute:language+' => 'User language',
'Class:User/Attribute:language/Value:EN US' => 'English',
'Class:User/Attribute:first_name+' => 'First name of the corresponding contact',
'Class:User/Attribute:email' => 'Email',
'Class:User/Attribute:email+' => 'Email of the corresponding contact',
'Class:User/Attribute:login' => 'Login',
'Class:User/Attribute:login+' => 'user identification string',
'Class:User/Attribute:language' => 'Language',
'Class:User/Attribute:language+' => 'User language',
'Class:User/Attribute:language/Value:EN US' => 'English',
'Class:User/Attribute:language/Value:EN US+' => 'English (U.S.)',
'Class:User/Attribute:language/Value:FR FR' => 'French',
'Class:User/Attribute:language/Value:FR FR' => 'French',
'Class:User/Attribute:language/Value:FR FR+' => 'French (France)',
'Class:User/Attribute:profile_list' => 'Profiles',
'Class:User/Attribute:profile_list+' => 'Roles, granting rights for that person',
'Class:User/Attribute:allowed_org_list' => 'Allowed Organizations',
'Class:User/Attribute:allowed_org_list+' => 'The end user is allowed to see data belonging to the following organizations. If no organization is specified, there is no restriction.',
'Class:User/Attribute:status' => 'Status',
'Class:User/Attribute:status+' => 'Whether the user account is enabled or disabled.',
'Class:User/Attribute:status/Value:enabled' => 'Enabled',
'Class:User/Attribute:profile_list' => 'Profiles',
'Class:User/Attribute:profile_list+' => 'Roles, granting rights for that person',
'Class:User/Attribute:allowed_org_list' => 'Allowed Organizations',
'Class:User/Attribute:allowed_org_list+' => 'The end user is allowed to see data belonging to the following organizations. If no organization is specified, there is no restriction.',
'Class:User/Attribute:status' => 'Status',
'Class:User/Attribute:status+' => 'Whether the user account is enabled or disabled.',
'Class:User/Attribute:status/Value:enabled' => 'Enabled',
'Class:User/Attribute:status/Value:disabled' => 'Disabled',
'Class:User/Error:LoginMustBeUnique' => 'Login must be unique - "%1$s" is already being used.',
'Class:User/Error:AtLeastOneProfileIsNeeded' => 'At least one profile must be assigned to this user.',
'Class:User/Error:ProfileNotAllowed' => 'Profile "%1$s" cannot be added it will deny the access to backoffice',
'Class:User/Error:LoginMustBeUnique' => 'Login must be unique - "%1$s" is already being used.',
'Class:User/Error:AtLeastOneProfileIsNeeded' => 'At least one profile must be assigned to this user.',
'Class:User/Error:ProfileNotAllowed' => 'Profile "%1$s" cannot be added it will deny the access to backoffice',
'Class:User/Error:StatusChangeIsNotAllowed' => 'Changing status is not allowed for your own User',
'Class:User/Error:AtLeastOneOrganizationIsNeeded' => 'At least one organization must be assigned to this user.',
'Class:User/Error:OrganizationNotAllowed' => 'Organization not allowed.',
'Class:User/Error:UserOrganizationNotAllowed' => 'The user account does not belong to your allowed organizations.',
'Class:User/Error:PersonIsMandatory' => 'The Contact is mandatory.',
'Class:UserInternal' => 'User Internal',
'Class:UserInternal+' => 'User defined within '.ITOP_APPLICATION_SHORT,
'Class:User/Error:OrganizationNotAllowed' => 'Organization not allowed.',
'Class:User/Error:UserOrganizationNotAllowed' => 'The user account does not belong to your allowed organizations.',
'Class:User/Error:PersonIsMandatory' > 'The Contact is mandatory.',
'Class:UserInternal' => 'User Internal',
'Class:UserInternal+' => 'User defined within '.ITOP_APPLICATION_SHORT,
));
//

View File

@@ -111,6 +111,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
'Class:User/Error:LoginMustBeUnique' => 'Le login doit être unique - "%1s" est déjà utilisé.',
'Class:User/Error:AtLeastOneProfileIsNeeded' => 'L\'utilisateur doit avoir au moins un profil.',
'Class:User/Error:ProfileNotAllowed' => 'Le profil "%1$s" ne peux pas être ajouté à son propre utilisateur, il interdit l\'accès à la console',
'Class:User/Error:StatusChangeIsNotAllowed' => 'Impossible de changer l\'état de son propre utilisateur',
'Class:User/Error:AtLeastOneOrganizationIsNeeded' => 'L\'utilisateur doit avoir au moins une organisation.',
'Class:User/Error:OrganizationNotAllowed' => 'Organisation non autorisée.',
'Class:User/Error:UserOrganizationNotAllowed' => 'L\'utilisateur n\'appartient pas à vos organisations.',