diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/ColumnMoveRestrictionModel.php | 46 | ||||
-rw-r--r-- | app/Model/ProjectRoleModel.php | 79 |
2 files changed, 118 insertions, 7 deletions
diff --git a/app/Model/ColumnMoveRestrictionModel.php b/app/Model/ColumnMoveRestrictionModel.php index 63e739bf..aae1a391 100644 --- a/app/Model/ColumnMoveRestrictionModel.php +++ b/app/Model/ColumnMoveRestrictionModel.php @@ -35,6 +35,35 @@ class ColumnMoveRestrictionModel extends Base } /** + * Fetch one restriction + * + * @param int $project_id + * @param int $restriction_id + * @return array|null + */ + public function getById($project_id, $restriction_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.restriction_id', + self::TABLE.'.project_id', + self::TABLE.'.role_id', + self::TABLE.'.src_column_id', + self::TABLE.'.dst_column_id', + 'pr.role', + 'sc.title as src_column_title', + 'dc.title as dst_column_title' + ) + ->left(ColumnModel::TABLE, 'sc', 'id', self::TABLE, 'src_column_id') + ->left(ColumnModel::TABLE, 'dc', 'id', self::TABLE, 'dst_column_id') + ->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id') + ->eq(self::TABLE.'.project_id', $project_id) + ->eq(self::TABLE.'.restriction_id', $restriction_id) + ->findOne(); + } + + /** * Get all project column restrictions * * @param int $project_id @@ -45,9 +74,11 @@ class ColumnMoveRestrictionModel extends Base return $this->db ->table(self::TABLE) ->columns( - 'restriction_id', - 'src_column_id', - 'dst_column_id', + self::TABLE.'.restriction_id', + self::TABLE.'.project_id', + self::TABLE.'.role_id', + self::TABLE.'.src_column_id', + self::TABLE.'.dst_column_id', 'pr.role', 'sc.title as src_column_title', 'dc.title as dst_column_title' @@ -61,15 +92,18 @@ class ColumnMoveRestrictionModel extends Base /** * Get all source column Ids - * - * @param int $project_id + * + * @param int $project_id + * @param string $role * @return array */ - public function getAllSrcColumns($project_id) + public function getAllSrcColumns($project_id, $role) { return $this->db ->hashtable(self::TABLE) + ->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id') ->eq(self::TABLE.'.project_id', $project_id) + ->eq('pr.role', $role) ->getAll('src_column_id', 'src_column_id'); } diff --git a/app/Model/ProjectRoleModel.php b/app/Model/ProjectRoleModel.php index 93fe1dcc..82f22806 100644 --- a/app/Model/ProjectRoleModel.php +++ b/app/Model/ProjectRoleModel.php @@ -3,6 +3,7 @@ namespace Kanboard\Model; use Kanboard\Core\Base; +use Kanboard\Core\Security\Role; /** * Class ProjectRoleModel @@ -15,6 +16,38 @@ class ProjectRoleModel extends Base const TABLE = 'project_has_roles'; /** + * Get list of project roles + * + * @param int $project_id + * @return array + */ + public function getList($project_id) + { + $defaultRoles = $this->role->getProjectRoles(); + $customRoles = $this->db + ->hashtable(self::TABLE) + ->eq('project_id', $project_id) + ->getAll('role', 'role'); + + return $defaultRoles + $customRoles; + } + + /** + * Get a role + * + * @param int $project_id + * @param int $role_id + * @return array|null + */ + public function getById($project_id, $role_id) + { + return $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('role_id', $role_id) + ->findOne(); + } + + /** * Get all project roles * * @param int $project_id @@ -29,6 +62,22 @@ class ProjectRoleModel extends Base } /** + * Get all project roles with restrictions + * + * @param int $project_id + * @return array + */ + public function getAllWithRestrictions($project_id) + { + $roles = $this->getAll($project_id); + $restrictions = $this->columnMoveRestrictionModel->getAll($project_id); + $restrictions = array_column_index($restrictions, 'role_id'); + array_merge_relation($roles, $restrictions, 'restrictions', 'role_id'); + + return $roles; + } + + /** * Create a new project role * * @param int $project_id @@ -73,10 +122,38 @@ class ProjectRoleModel extends Base */ public function remove($project_id, $role_id) { - return $this->db + $this->db->startTransaction(); + + $role = $this->getById($project_id, $role_id); + + $r1 = $this->db + ->table(ProjectUserRoleModel::TABLE) + ->eq('project_id', $project_id) + ->eq('role', $role['role']) + ->update(array( + 'role' => Role::PROJECT_MEMBER + )); + + $r2 = $this->db + ->table(ProjectGroupRoleModel::TABLE) + ->eq('project_id', $project_id) + ->eq('role', $role['role']) + ->update(array( + 'role' => Role::PROJECT_MEMBER + )); + + $r3 = $this->db ->table(self::TABLE) ->eq('project_id', $project_id) ->eq('role_id', $role_id) ->remove(); + + if ($r1 && $r2 && $r3) { + $this->db->closeTransaction(); + return true; + } + + $this->db->cancelTransaction(); + return false; } } |