Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #18356: [security] User with only user update allowed can…
… set/remove any role to any user (#2625) * Fix part of #18355: make sure a user can only assign permissions to it's own child users --------- Co-authored-by: encuestabizdevgit <devgit@encuesta.biz> Co-authored-by: lapiudevgit <devgit@lapiu.biz>
- Loading branch information
1 parent
5ff8650
commit a2eece7
Showing
5 changed files
with
130 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
* | ||
*/ | ||
|
||
use LimeSurvey\Models\Services\UserManager; | ||
|
||
/** | ||
* Class User | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace LimeSurvey\Models\Services; | ||
|
||
use LSWebUser; | ||
use Permission; | ||
use User; | ||
|
||
/** | ||
* Service class for managing users and their permissions | ||
*/ | ||
class UserManager | ||
{ | ||
/** @var LSWebUser the user managing other users */ | ||
private $managingUser; | ||
|
||
/** @var User the user being handled */ | ||
private $targetUser; | ||
|
||
/** | ||
* @param LSWebUser $managingUser | ||
* @param User|null $targetUser | ||
*/ | ||
public function __construct( | ||
LSWebUser $managingUser, | ||
User $targetUser = null | ||
) { | ||
$this->managingUser = $managingUser; | ||
$this->targetUser = $targetUser; | ||
} | ||
|
||
/** | ||
* Returns true if the managing user can assign permissions to the target user. | ||
* @return boolean | ||
*/ | ||
public function canAssignPermissions() | ||
{ | ||
if (empty($this->managingUser) || empty($this->targetUser)) { | ||
return false; | ||
} | ||
|
||
if ( | ||
Permission::model()->hasGlobalPermission('superadmin', 'read', $this->managingUser->id) | ||
|| ( | ||
Permission::model()->hasGlobalPermission('users', 'update', $this->managingUser->id) | ||
&& $this->targetUser->parent_id == $this->managingUser->id | ||
) | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Returns true if the managing user can assign roles to the target user. | ||
* @return boolean | ||
*/ | ||
public function canAssignRole() | ||
{ | ||
if (empty($this->managingUser)) { | ||
return false; | ||
} | ||
|
||
return Permission::model()->hasGlobalPermission('superadmin', 'read', $this->managingUser->id); | ||
} | ||
|
||
/** | ||
* Returns true if the managing user can edit the target user | ||
* @return bool | ||
*/ | ||
public function canEdit() | ||
{ | ||
if (empty($this->managingUser) || empty($this->targetUser)) { | ||
return false; | ||
} | ||
|
||
return | ||
Permission::model()->hasGlobalPermission('superadmin', 'read', $this->managingUser->id) | ||
|| $this->targetUser->uid == $this->managingUser->id | ||
|| ( | ||
Permission::model()->hasGlobalPermission('users', 'update', $this->managingUser->id) | ||
&& $this->targetUser->parent_id == $this->managingUser->id | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters