acl changes

This commit is contained in:
Yuri Kuznetsov
2020-06-29 17:23:07 +03:00
parent 5b74430751
commit e4138b894c
5 changed files with 35 additions and 12 deletions
+12 -2
View File
@@ -127,7 +127,7 @@ class Acl
}
/**
* Whether a user has an access to another user taking into account a specific permission.
* @deprecated
*/
public function checkUser(string $permission, User $entity) : bool
{
@@ -174,11 +174,21 @@ class Acl
return $this->getAclManager()->getScopeForbiddenLinkList($this->getUser(), $scope, $action, $thresholdLevel);
}
public function checkUserPermission($target, string $permissionType = 'userPermission') : bool
/**
* Whether a user has an access to another user over a specific permission.
*
* @param $target User|string User entity or user ID.
*/
public function checkUserPermission($target, string $permissionType = 'user') : bool
{
return $this->getAclManager()->checkUserPermission($this->getUser(), $target, $permissionType);
}
/**
* Whether a user can assign to another user.
*
* @param $target User|string User entity or user ID.
*/
public function checkAssignmentPermission($target) : bool
{
return $this->getAclManager()->checkAssignmentPermission($this->getUser(), $target);
+20 -7
View File
@@ -141,6 +141,9 @@ class AclManager
*/
public function get(User $user, string $permission) : ?string
{
if (substr($permission, -10) !== 'Permission') {
$permission .= 'Permission';
}
return $this->getTable($user)->get($permission);
}
@@ -248,21 +251,21 @@ class AclManager
}
/**
* Whether a user has an access to another user taking into account a specific permission.
* @deprecated
*/
public function checkUser(User $user, string $permission, User $entity) : bool
public function checkUser(User $user, string $permission, User $target) : bool
{
if ($user->isAdmin()) {
return true;
}
if ($this->get($user, $permission) === 'no') {
if ($entity->id !== $user->id) {
if ($target->id !== $user->id) {
return false;
}
} else if ($this->get($user, $permission) === 'team') {
if ($entity->id != $user->id) {
if ($target->id != $user->id) {
$teamIdList1 = $user->getTeamIdList();
$teamIdList2 = $entity->getTeamIdList();
$teamIdList2 = $target->getTeamIdList();
$inTeam = false;
foreach ($teamIdList1 as $id) {
@@ -366,7 +369,12 @@ class AclManager
return $list;
}
public function checkUserPermission(User $user, $target, string $permissionType = 'userPermission') : bool
/**
* Whether a user has an access to another user over a specific permission.
*
* @param $target User|string User entity or user ID.
*/
public function checkUserPermission(User $user, $target, string $permissionType = 'user') : bool
{
$permission = $this->get($user, $permissionType);
@@ -396,9 +404,14 @@ class AclManager
return true;
}
/**
* Whether a user can assign to another user.
*
* @param $target User|string User entity or user ID.
*/
public function checkAssignmentPermission(User $user, $target) : bool
{
return $this->checkUserPermission($user, $target, 'assignmentPermission');
return $this->checkUserPermission($user, $target, 'assignment');
}
/**
+1 -1
View File
@@ -89,7 +89,7 @@ class Mentions
$userName = substr($item, 1);
$user = $this->entityManager->getRepository('User')->where(['userName' => $userName])->findOne();
if ($user) {
if (!$this->acl->checkUser('assignmentPermission', $user)) {
if (!$this->acl->checkUserPermission($user, 'assignment')) {
continue;
}
$m = [
@@ -737,7 +737,7 @@ class Activities implements
protected function accessCheck($entity)
{
if ($entity->getEntityType() == 'User') {
if (!$this->getAcl()->checkUser('userPermission', $entity)) {
if (!$this->getAcl()->checkUserPermission($entity, 'user')) {
throw new Forbidden();
}
+1 -1
View File
@@ -352,7 +352,7 @@ class Stream
if (!$user) {
throw new NotFound();
}
if (!$this->acl->checkUser('userPermission', $user)) {
if (!$this->acl->checkUserPermission($user, 'user')) {
throw new Forbidden();
}
}