From c84df535b6bdc7260144872fc4e0c241a5a5ad61 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 11 Sep 2016 18:32:47 -0400 Subject: Improve column restrictions --- app/Helper/ProjectRoleHelper.php | 55 ++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'app/Helper') diff --git a/app/Helper/ProjectRoleHelper.php b/app/Helper/ProjectRoleHelper.php index 34905b52..99fa82bc 100644 --- a/app/Helper/ProjectRoleHelper.php +++ b/app/Helper/ProjectRoleHelper.php @@ -26,25 +26,45 @@ class ProjectRoleHelper extends Base } /** - * Return true if the task can be moved by the connected user + * Return true if the task can be moved by the logged user * * @param array $task * @return bool */ - public function isDraggable(array $task) + public function isDraggable(array &$task) { if ($task['is_active'] == 1 && $this->helper->user->hasProjectAccess('BoardViewController', 'save', $task['project_id'])) { - $role = $this->getProjectUserRole($task['project_id']); + return $this->isSortableColumn($task['project_id'], $task['column_id'], 'src_column_id'); + } + + return false; + } + + /** + * Return true is the column is sortable + * + * @param int $project_id + * @param int $column_id + * @param string $field + * @return bool + */ + public function isSortableColumn($project_id, $column_id, $field) + { + $role = $this->getProjectUserRole($project_id); + + if ($this->role->isCustomProjectRole($role)) { + $sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($project_id, $role); - if ($this->role->isCustomProjectRole($role)) { - $srcColumnIds = $this->columnMoveRestrictionCacheDecorator->getAllSrcColumns($task['project_id'], $role); - return isset($srcColumnIds[$task['column_id']]); + foreach ($sortableColumns as $column) { + if ($column[$field] == $column_id) { + return true; + } } - return true; + return empty($sortableColumns); } - return false; + return true; } /** @@ -60,12 +80,19 @@ class ProjectRoleHelper extends Base $role = $this->getProjectUserRole($project_id); if ($this->role->isCustomProjectRole($role)) { - return $this->columnMoveRestrictionModel->isAllowed( - $project_id, - $role, - $src_column_id, - $dst_column_id - ); + if ($src_column_id == $dst_column_id) { + return true; + } + + $sortableColumns = $this->columnMoveRestrictionCacheDecorator->getSortableColumns($project_id, $role); + + foreach ($sortableColumns as $column) { + if ($column['src_column_id'] == $src_column_id && $column['dst_column_id'] == $dst_column_id) { + return true; + } + } + + return empty($sortableColumns); } return true; -- cgit v1.2.3