Add restriction to disable task drag and drop for a project

This commit is contained in:
Frederic Guillot
2016-10-07 08:45:18 -04:00
parent 4cc856344f
commit 096b000c59
28 changed files with 50 additions and 3 deletions

View File

@@ -62,7 +62,7 @@ class ProjectRoleHelper extends Base
} }
} }
return empty($sortableColumns); return empty($sortableColumns) && $this->isAllowedToMoveTask($project_id, $role);
} }
return true; return true;
@@ -97,7 +97,7 @@ class ProjectRoleHelper extends Base
} }
} }
return empty($sortableColumns); return empty($sortableColumns) && $this->isAllowedToMoveTask($project_id, $role);
} }
return true; return true;
@@ -263,4 +263,24 @@ class ProjectRoleHelper extends Base
return true; return true;
} }
/**
* Check if the role can move task in the given project
*
* @param int $project_id
* @param string $role
* @return bool
*/
protected function isAllowedToMoveTask($project_id, $role)
{
$projectRestrictions = $this->projectRoleRestrictionCacheDecorator->getAllByRole($project_id, $role);
foreach ($projectRestrictions as $restriction) {
if ($restriction['rule'] == ProjectRoleRestrictionModel::RULE_TASK_MOVE) {
return false;
}
}
return true;
}
} }

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
'Do you really want to remove this project restriction: "%s"?' => 'Voulez-vous vraiment supprimer cette restriction de projet : « %s » ?', 'Do you really want to remove this project restriction: "%s"?' => 'Voulez-vous vraiment supprimer cette restriction de projet : « %s » ?',
'Duplicate to multiple projects' => 'Dupliquer vers plusieurs projets', 'Duplicate to multiple projects' => 'Dupliquer vers plusieurs projets',
'This field is required' => 'Ce champ est requis', 'This field is required' => 'Ce champ est requis',
'Moving a task is not permitted' => 'Déplaçer une tâche n\'est pas autorisé',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
'Do you really want to remove this project restriction: "%s"?' => 'Tem a certeza que quer remover a restrição de projeto: "%s"?', 'Do you really want to remove this project restriction: "%s"?' => 'Tem a certeza que quer remover a restrição de projeto: "%s"?',
'Duplicate to multiple projects' => 'Duplicar para vários projetos', 'Duplicate to multiple projects' => 'Duplicar para vários projetos',
'This field is required' => 'Este campo é obrigatório', 'This field is required' => 'Este campo é obrigatório',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -1275,4 +1275,5 @@ return array(
// 'Do you really want to remove this project restriction: "%s"?' => '', // 'Do you really want to remove this project restriction: "%s"?' => '',
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '',
); );

View File

@@ -16,6 +16,7 @@ class ProjectRoleRestrictionModel extends Base
const RULE_TASK_CREATION = 'task_creation'; const RULE_TASK_CREATION = 'task_creation';
const RULE_TASK_OPEN_CLOSE = 'task_open_close'; const RULE_TASK_OPEN_CLOSE = 'task_open_close';
const RULE_TASK_MOVE = 'task_move';
/** /**
* Get rules * Get rules
@@ -27,6 +28,7 @@ class ProjectRoleRestrictionModel extends Base
return array( return array(
self::RULE_TASK_CREATION => t('Task creation is not permitted'), self::RULE_TASK_CREATION => t('Task creation is not permitted'),
self::RULE_TASK_OPEN_CLOSE => t('Closing or opening a task is not permitted'), self::RULE_TASK_OPEN_CLOSE => t('Closing or opening a task is not permitted'),
self::RULE_TASK_MOVE => t('Moving a task is not permitted'),
); );
} }

View File

@@ -90,7 +90,7 @@ class ProjectRoleRestrictionModelTest extends Base
$projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container); $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
$rules = $projectRoleRestrictionModel->getRules(); $rules = $projectRoleRestrictionModel->getRules();
$this->assertCount(2, $rules); $this->assertCount(3, $rules);
$this->assertArrayHasKey(ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE, $rules); $this->assertArrayHasKey(ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE, $rules);
} }
} }