Add project restrictions for custom roles
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace Kanboard\Helper;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
/**
|
||||
* User helpers
|
||||
@@ -133,66 +132,14 @@ class UserHelper extends Base
|
||||
*/
|
||||
public function hasProjectAccess($controller, $action, $project_id)
|
||||
{
|
||||
if (! $this->userSession->isLogged()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->userSession->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->hasAccess($controller, $action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = 'project_access:'.$controller.$action.$project_id;
|
||||
$result = $this->memoryCache->get($key);
|
||||
|
||||
if ($result === null) {
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
$role = Role::PROJECT_MEMBER;
|
||||
}
|
||||
|
||||
$result = $this->projectAuthorization->isAllowed($controller, $action, $role);
|
||||
$result = $this->helper->projectRole->checkProjectAccess($controller, $action, $project_id);
|
||||
$this->memoryCache->set($key, $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get project role for the current user
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectUserRole($project_id)
|
||||
{
|
||||
return $this->memoryCache->proxy($this->projectUserRoleModel, 'getUserRole', $project_id, $this->userSession->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the user can remove a task
|
||||
*
|
||||
* Regular users can't remove tasks from other people
|
||||
*
|
||||
* @public
|
||||
* @param array $task
|
||||
* @return bool
|
||||
*/
|
||||
public function canRemoveTask(array $task)
|
||||
{
|
||||
if (isset($task['creator_id']) && $task['creator_id'] == $this->userSession->getId()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->userSession->isAdmin() || $this->getProjectUserRole($task['project_id']) === Role::PROJECT_MANAGER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user