Add assignee restriction for custom project roles (dnd)

This commit is contained in:
Frederic Guillot 2017-04-08 11:18:58 -04:00
parent 9a8c6d6493
commit fe9f3ba707
6 changed files with 30 additions and 9 deletions

View File

@ -49,7 +49,8 @@ class ColumnMoveRestrictionController extends BaseController
$project['id'],
$values['role_id'],
$values['src_column_id'],
$values['dst_column_id']
$values['dst_column_id'],
isset($values['only_assigned']) && $values['only_assigned'] == 1
);
if ($restriction_id !== false) {

View File

@ -36,7 +36,7 @@ class ProjectRoleHelper extends Base
public function isDraggable(array &$task)
{
if ($task['is_active'] == 1 && $this->helper->user->hasProjectAccess('BoardAjaxController', 'save', $task['project_id'])) {
return $this->isSortableColumn($task['project_id'], $task['column_id']);
return $this->isSortableColumn($task['project_id'], $task['column_id'], $task['owner_id']);
}
return false;
@ -47,9 +47,10 @@ class ProjectRoleHelper extends Base
*
* @param int $projectId
* @param int $columnId
* @param int $assigneeId
* @return bool
*/
public function isSortableColumn($projectId, $columnId)
public function isSortableColumn($projectId, $columnId, $assigneeId = null)
{
$role = $this->getProjectUserRole($projectId);
@ -58,6 +59,10 @@ class ProjectRoleHelper extends Base
foreach ($sortableColumns as $column) {
if ($column['src_column_id'] == $columnId || $column['dst_column_id'] == $columnId) {
if ($column['only_assigned'] == 1 && $assigneeId !== null && $assigneeId != $this->userSession->getId()) {
return false;
}
return true;
}
}
@ -182,7 +187,7 @@ class ProjectRoleHelper extends Base
{
$role = $this->getProjectUserRole($task['project_id']);
if ($this->hasRestriction($task['project_id'], $role, ProjectRoleRestrictionModel::RULE_TASK_CHANGE_ASSIGNEE)) {
if ($this->role->isCustomProjectRole($role) && $this->hasRestriction($task['project_id'], $role, ProjectRoleRestrictionModel::RULE_TASK_CHANGE_ASSIGNEE)) {
return false;
}
@ -200,7 +205,7 @@ class ProjectRoleHelper extends Base
{
$role = $this->getProjectUserRole($task['project_id']);
if ($task['owner_id'] != $this->userSession->getId() && $this->hasRestriction($task['project_id'], $role, ProjectRoleRestrictionModel::RULE_TASK_UPDATE_ASSIGNED)) {
if ($this->role->isCustomProjectRole($role) && $task['owner_id'] != $this->userSession->getId() && $this->hasRestriction($task['project_id'], $role, ProjectRoleRestrictionModel::RULE_TASK_UPDATE_ASSIGNED)) {
return false;
}

View File

@ -31,6 +31,7 @@ class ColumnMoveRestrictionModel extends Base
self::TABLE.'.role_id',
self::TABLE.'.src_column_id',
self::TABLE.'.dst_column_id',
self::TABLE.'.only_assigned',
'pr.role',
'sc.title as src_column_title',
'dc.title as dst_column_title'
@ -59,6 +60,7 @@ class ColumnMoveRestrictionModel extends Base
self::TABLE.'.role_id',
self::TABLE.'.src_column_id',
self::TABLE.'.dst_column_id',
self::TABLE.'.only_assigned',
'pr.role',
'sc.title as src_column_title',
'dc.title as dst_column_title'
@ -81,7 +83,7 @@ class ColumnMoveRestrictionModel extends Base
{
return $this->db
->table(self::TABLE)
->columns(self::TABLE.'.src_column_id', self::TABLE.'.dst_column_id')
->columns(self::TABLE.'.src_column_id', self::TABLE.'.dst_column_id', self::TABLE.'.only_assigned')
->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id')
->eq(self::TABLE.'.project_id', $project_id)
->eq('pr.role', $role)
@ -95,9 +97,10 @@ class ColumnMoveRestrictionModel extends Base
* @param int $role_id
* @param int $src_column_id
* @param int $dst_column_id
* @param bool $only_assigned
* @return bool|int
*/
public function create($project_id, $role_id, $src_column_id, $dst_column_id)
public function create($project_id, $role_id, $src_column_id, $dst_column_id, $only_assigned = false)
{
return $this->db
->table(self::TABLE)
@ -106,6 +109,7 @@ class ColumnMoveRestrictionModel extends Base
'role_id' => $role_id,
'src_column_id' => $src_column_id,
'dst_column_id' => $dst_column_id,
'only_assigned' => (int) $only_assigned,
));
}

View File

@ -8,7 +8,12 @@ use Kanboard\Core\Security\Token;
use Kanboard\Core\Security\Role;
use PDO;
const VERSION = 113;
const VERSION = 114;
function version_114(PDO $pdo)
{
$pdo->exec('ALTER TABLE column_has_move_restrictions ADD COLUMN only_assigned INTEGER DEFAULT 0');
}
function version_113(PDO $pdo)
{

View File

@ -12,6 +12,8 @@
<?= $this->form->label(t('Destination column'), 'dst_column_id') ?>
<?= $this->form->select('dst_column_id', $columns, $values, $errors) ?>
<?= $this->form->checkbox('only_assigned', t('Only for tasks assigned to the current user'), 1, isset($values['only_assigned']) && $values['only_assigned'] == 1) ?>
<?= $this->modal->submitButtons() ?>
<p class="alert alert-info"><?= t('People belonging to this role will be able to move tasks only between the source and the destination column.') ?></p>

View File

@ -80,7 +80,11 @@
<i class="fa fa-check-circle-o fa-fw" aria-hidden="true"></i>
<strong><?= $this->text->e($restriction['src_column_title']) ?> / <?= $this->text->e($restriction['dst_column_title']) ?></strong>
<i class="fa fa-arrow-right fa-fw" aria-hidden="true"></i>
<?= t('Only moving task between those columns is permitted') ?>
<?php if ($restriction['only_assigned'] == 1): ?>
<?= t('Only moving task between those columns is permitted for tasks assigned to the current user') ?>
<?php else: ?>
<?= t('Only moving task between those columns is permitted') ?>
<?php endif ?>
</td>
<td>
<?= $this->modal->confirm('trash-o', t('Remove'), 'ColumnMoveRestrictionController', 'confirm', array('project_id' => $project['id'], 'restriction_id' => $restriction['restriction_id'])) ?>