Add new project role restriction to block task suppression
This commit is contained in:
@@ -19,12 +19,12 @@ class ProjectRoleHelper extends Base
|
||||
* Get project role for the current user
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param integer $projectId
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectUserRole($project_id)
|
||||
public function getProjectUserRole($projectId)
|
||||
{
|
||||
return $this->memoryCache->proxy($this->projectUserRoleModel, 'getUserRole', $project_id, $this->userSession->getId());
|
||||
return $this->memoryCache->proxy($this->projectUserRoleModel, 'getUserRole', $projectId, $this->userSession->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,24 +45,24 @@ class ProjectRoleHelper extends Base
|
||||
/**
|
||||
* Return true is the column is sortable
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $column_id
|
||||
* @param int $projectId
|
||||
* @param int $columnId
|
||||
* @return bool
|
||||
*/
|
||||
public function isSortableColumn($project_id, $column_id)
|
||||
public function isSortableColumn($projectId, $columnId)
|
||||
{
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
$role = $this->getProjectUserRole($projectId);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
$sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($project_id, $role);
|
||||
$sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($projectId, $role);
|
||||
|
||||
foreach ($sortableColumns as $column) {
|
||||
if ($column['src_column_id'] == $column_id || $column['dst_column_id'] == $column_id) {
|
||||
if ($column['src_column_id'] == $columnId || $column['dst_column_id'] == $columnId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return empty($sortableColumns) && $this->isAllowedToMoveTask($project_id, $role);
|
||||
return empty($sortableColumns) && $this->isAllowedToMoveTask($projectId, $role);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -71,33 +71,33 @@ class ProjectRoleHelper extends Base
|
||||
/**
|
||||
* Check if the user can move a task
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $src_column_id
|
||||
* @param int $dst_column_id
|
||||
* @param int $projectId
|
||||
* @param int $srcColumnId
|
||||
* @param int $dstColumnId
|
||||
* @return bool|int
|
||||
*/
|
||||
public function canMoveTask($project_id, $src_column_id, $dst_column_id)
|
||||
public function canMoveTask($projectId, $srcColumnId, $dstColumnId)
|
||||
{
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
$role = $this->getProjectUserRole($projectId);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
if ($src_column_id == $dst_column_id) {
|
||||
if ($srcColumnId == $dstColumnId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($project_id, $role);
|
||||
$sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($projectId, $role);
|
||||
|
||||
foreach ($sortableColumns as $column) {
|
||||
if ($column['src_column_id'] == $src_column_id && $column['dst_column_id'] == $dst_column_id) {
|
||||
if ($column['src_column_id'] == $srcColumnId && $column['dst_column_id'] == $dstColumnId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($column['dst_column_id'] == $src_column_id && $column['src_column_id'] == $dst_column_id) {
|
||||
if ($column['dst_column_id'] == $srcColumnId && $column['src_column_id'] == $dstColumnId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return empty($sortableColumns) && $this->isAllowedToMoveTask($project_id, $role);
|
||||
return empty($sortableColumns) && $this->isAllowedToMoveTask($projectId, $role);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -106,41 +106,41 @@ class ProjectRoleHelper extends Base
|
||||
/**
|
||||
* Return true if the user can create a task for the given column
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $column_id
|
||||
* @param int $projectId
|
||||
* @param int $columnId
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreateTaskInColumn($project_id, $column_id)
|
||||
public function canCreateTaskInColumn($projectId, $columnId)
|
||||
{
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
$role = $this->getProjectUserRole($projectId);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
if (! $this->isAllowedToCreateTask($project_id, $column_id, $role)) {
|
||||
if (! $this->isAllowedToCreateTask($projectId, $columnId, $role)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->helper->user->hasProjectAccess('TaskCreationController', 'show', $project_id);
|
||||
return $this->helper->user->hasProjectAccess('TaskCreationController', 'show', $projectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the user can create a task for the given column
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $column_id
|
||||
* @param int $projectId
|
||||
* @param int $columnId
|
||||
* @return bool
|
||||
*/
|
||||
public function canChangeTaskStatusInColumn($project_id, $column_id)
|
||||
public function canChangeTaskStatusInColumn($projectId, $columnId)
|
||||
{
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
$role = $this->getProjectUserRole($projectId);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
if (! $this->isAllowedToChangeTaskStatus($project_id, $column_id, $role)) {
|
||||
if (! $this->isAllowedToChangeTaskStatus($projectId, $columnId, $role)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->helper->user->hasProjectAccess('TaskStatusController', 'close', $project_id);
|
||||
return $this->helper->user->hasProjectAccess('TaskStatusController', 'close', $projectId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,6 +154,12 @@ class ProjectRoleHelper extends Base
|
||||
*/
|
||||
public function canRemoveTask(array $task)
|
||||
{
|
||||
$role = $this->getProjectUserRole($task['project_id']);
|
||||
|
||||
if ($this->hasRestriction($task['project_id'], $role, ProjectRoleRestrictionModel::RULE_TASK_SUPPRESSION)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($task['creator_id']) && $task['creator_id'] == $this->userSession->getId()) {
|
||||
return true;
|
||||
}
|
||||
@@ -170,10 +176,10 @@ class ProjectRoleHelper extends Base
|
||||
*
|
||||
* @param string $controller
|
||||
* @param string $action
|
||||
* @param integer $project_id
|
||||
* @param integer $projectId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkProjectAccess($controller, $action, $project_id)
|
||||
public function checkProjectAccess($controller, $action, $projectId)
|
||||
{
|
||||
if (! $this->userSession->isLogged()) {
|
||||
return false;
|
||||
@@ -187,7 +193,7 @@ class ProjectRoleHelper extends Base
|
||||
return false;
|
||||
}
|
||||
|
||||
$role = $this->getProjectUserRole($project_id);
|
||||
$role = $this->getProjectUserRole($projectId);
|
||||
|
||||
if ($this->role->isCustomProjectRole($role)) {
|
||||
$result = $this->projectAuthorization->isAllowed($controller, $action, Role::PROJECT_MEMBER);
|
||||
@@ -201,17 +207,17 @@ class ProjectRoleHelper extends Base
|
||||
/**
|
||||
* Check authorization for a custom project role to change the task status
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $column_id
|
||||
* @param int $projectId
|
||||
* @param int $columnId
|
||||
* @param string $role
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAllowedToChangeTaskStatus($project_id, $column_id, $role)
|
||||
protected function isAllowedToChangeTaskStatus($projectId, $columnId, $role)
|
||||
{
|
||||
$columnRestrictions = $this->columnRestrictionCacheDecorator->getAllByRole($project_id, $role);
|
||||
$columnRestrictions = $this->columnRestrictionCacheDecorator->getAllByRole($projectId, $role);
|
||||
|
||||
foreach ($columnRestrictions as $restriction) {
|
||||
if ($restriction['column_id'] == $column_id) {
|
||||
if ($restriction['column_id'] == $columnId) {
|
||||
if ($restriction['rule'] == ColumnRestrictionModel::RULE_ALLOW_TASK_OPEN_CLOSE) {
|
||||
return true;
|
||||
} else if ($restriction['rule'] == ColumnRestrictionModel::RULE_BLOCK_TASK_OPEN_CLOSE) {
|
||||
@@ -220,31 +226,23 @@ class ProjectRoleHelper extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($project_id, $role);
|
||||
|
||||
foreach ($projectRestrictions as $restriction) {
|
||||
if ($restriction['rule'] == ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ! $this->hasRestriction($projectId, $role, ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authorization for a custom project role to create a task
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $column_id
|
||||
* @param int $projectId
|
||||
* @param int $columnId
|
||||
* @param string $role
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAllowedToCreateTask($project_id, $column_id, $role)
|
||||
protected function isAllowedToCreateTask($projectId, $columnId, $role)
|
||||
{
|
||||
$columnRestrictions = $this->columnRestrictionCacheDecorator->getAllByRole($project_id, $role);
|
||||
$columnRestrictions = $this->columnRestrictionCacheDecorator->getAllByRole($projectId, $role);
|
||||
|
||||
foreach ($columnRestrictions as $restriction) {
|
||||
if ($restriction['column_id'] == $column_id) {
|
||||
if ($restriction['column_id'] == $columnId) {
|
||||
if ($restriction['rule'] == ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION) {
|
||||
return true;
|
||||
} else if ($restriction['rule'] == ColumnRestrictionModel::RULE_BLOCK_TASK_CREATION) {
|
||||
@@ -253,27 +251,19 @@ class ProjectRoleHelper extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($project_id, $role);
|
||||
|
||||
foreach ($projectRestrictions as $restriction) {
|
||||
if ($restriction['rule'] == ProjectRoleRestrictionModel::RULE_TASK_CREATION) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ! $this->hasRestriction($projectId, $role, ProjectRoleRestrictionModel::RULE_TASK_CREATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the role can move task in the given project
|
||||
*
|
||||
* @param int $project_id
|
||||
* @param int $projectId
|
||||
* @param string $role
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAllowedToMoveTask($project_id, $role)
|
||||
protected function isAllowedToMoveTask($projectId, $role)
|
||||
{
|
||||
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($project_id, $role);
|
||||
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($projectId, $role);
|
||||
|
||||
foreach ($projectRestrictions as $restriction) {
|
||||
if ($restriction['rule'] == ProjectRoleRestrictionModel::RULE_TASK_MOVE) {
|
||||
@@ -283,4 +273,25 @@ class ProjectRoleHelper extends Base
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given role has a restriction
|
||||
*
|
||||
* @param integer $projectId
|
||||
* @param string $role
|
||||
* @param string $rule
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasRestriction($projectId, $role, $rule)
|
||||
{
|
||||
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($projectId, $role);
|
||||
|
||||
foreach ($projectRestrictions as $restriction) {
|
||||
if ($restriction['rule'] == $rule) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user