diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-09-10 22:37:57 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-09-10 22:37:57 -0400 |
commit | 44f680cf2f1463721eb5bdb7eda4d3b339e63ba9 (patch) | |
tree | ed4aeef8b32dbd76277dacf864b028677bc10809 /app/Controller | |
parent | 75470c72428c8d8f278d160369558ab31b137fb1 (diff) |
Add ui to create new custom project roles and column restrictions
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/ColumnController.php | 5 | ||||
-rw-r--r-- | app/Controller/ColumnMoveRestrictionController.php | 102 | ||||
-rw-r--r-- | app/Controller/ProjectOverviewController.php | 2 | ||||
-rw-r--r-- | app/Controller/ProjectPermissionController.php | 2 | ||||
-rw-r--r-- | app/Controller/ProjectRoleController.php | 107 | ||||
-rw-r--r-- | app/Controller/ProjectUserOverviewController.php | 4 |
6 files changed, 214 insertions, 8 deletions
diff --git a/app/Controller/ColumnController.php b/app/Controller/ColumnController.php index d3f0e36e..8c366c6e 100644 --- a/app/Controller/ColumnController.php +++ b/app/Controller/ColumnController.php @@ -25,7 +25,7 @@ class ColumnController extends BaseController $this->response->html($this->helper->layout->project('column/index', array( 'columns' => $columns, 'project' => $project, - 'title' => t('Edit board') + 'title' => t('Edit columns') ))); } @@ -49,7 +49,6 @@ class ColumnController extends BaseController 'values' => $values, 'errors' => $errors, 'project' => $project, - 'title' => t('Add a new column') ))); } @@ -102,7 +101,6 @@ class ColumnController extends BaseController 'values' => $values ?: $column, 'project' => $project, 'column' => $column, - 'title' => t('Edit column "%s"', $column['title']) ))); } @@ -168,7 +166,6 @@ class ColumnController extends BaseController $this->response->html($this->helper->layout->project('column/remove', array( 'column' => $this->columnModel->getById($this->request->getIntegerParam('column_id')), 'project' => $project, - 'title' => t('Remove a column from a board') ))); } diff --git a/app/Controller/ColumnMoveRestrictionController.php b/app/Controller/ColumnMoveRestrictionController.php new file mode 100644 index 00000000..3f1b878f --- /dev/null +++ b/app/Controller/ColumnMoveRestrictionController.php @@ -0,0 +1,102 @@ +<?php + +namespace Kanboard\Controller; + +use Kanboard\Core\Controller\AccessForbiddenException; + +/** + * Class ColumnMoveRestrictionController + * + * @package Kanboard\Controller + * @author Frederic Guillot + */ +class ColumnMoveRestrictionController extends BaseController +{ + /** + * Show form to create a new column restriction + * + * @param array $values + * @param array $errors + * @throws AccessForbiddenException + */ + public function create(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $role_id = $this->request->getIntegerParam('role_id'); + $role = $this->projectRoleModel->getById($project['id'], $role_id); + + $this->response->html($this->template->render('column_move_restriction/create', array( + 'project' => $project, + 'role' => $role, + 'columns' => $this->columnModel->getList($project['id']), + 'values' => $values + array('project_id' => $project['id'], 'role_id' => $role['role_id']), + 'errors' => $errors, + ))); + } + + /** + * Save new column restriction + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->columnMoveRestrictionValidator->validateCreation($values); + + if ($valid) { + $role_id = $this->columnMoveRestrictionModel->create( + $project['id'], + $values['role_id'], + $values['src_column_id'], + $values['dst_column_id'] + ); + + if ($role_id !== false) { + $this->flash->success(t('The column restriction has been created successfully.')); + } else { + $this->flash->failure(t('Unable to create this column restriction.')); + } + + $this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id']))); + } else { + $this->create($values, $errors); + } + } + + /** + * Confirm suppression + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $restriction_id = $this->request->getIntegerParam('restriction_id'); + + $this->response->html($this->helper->layout->project('column_move_restriction/remove', array( + 'project' => $project, + 'restriction' => $this->columnMoveRestrictionModel->getById($project['id'], $restriction_id), + ))); + } + + /** + * Remove a restriction + * + * @access public + */ + public function remove() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + $restriction_id = $this->request->getIntegerParam('restriction_id'); + + if ($this->columnMoveRestrictionModel->remove($restriction_id)) { + $this->flash->success(t('Column restriction removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this restriction.')); + } + + $this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/ProjectOverviewController.php b/app/Controller/ProjectOverviewController.php index abdff657..eb002936 100644 --- a/app/Controller/ProjectOverviewController.php +++ b/app/Controller/ProjectOverviewController.php @@ -23,7 +23,7 @@ class ProjectOverviewController extends BaseController 'title' => $project['name'], 'description' => $this->helper->projectHeader->getDescription($project), 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), - 'roles' => $this->role->getProjectRoles(), + 'roles' => $this->projectRoleModel->getList($project['id']), 'events' => $this->helper->projectActivity->getProjectEvents($project['id'], 10), 'images' => $this->projectFileModel->getAllImages($project['id']), 'files' => $this->projectFileModel->getAllDocuments($project['id']), diff --git a/app/Controller/ProjectPermissionController.php b/app/Controller/ProjectPermissionController.php index 99f556e8..1aa59c6d 100644 --- a/app/Controller/ProjectPermissionController.php +++ b/app/Controller/ProjectPermissionController.php @@ -52,7 +52,7 @@ class ProjectPermissionController extends BaseController 'project' => $project, 'users' => $this->projectUserRoleModel->getUsers($project['id']), 'groups' => $this->projectGroupRoleModel->getGroups($project['id']), - 'roles' => $this->role->getProjectRoles(), + 'roles' => $this->projectRoleModel->getList($project['id']), 'values' => $values, 'errors' => $errors, 'title' => t('Project Permissions'), diff --git a/app/Controller/ProjectRoleController.php b/app/Controller/ProjectRoleController.php new file mode 100644 index 00000000..87868748 --- /dev/null +++ b/app/Controller/ProjectRoleController.php @@ -0,0 +1,107 @@ +<?php + +namespace Kanboard\Controller; + +use Kanboard\Core\Controller\AccessForbiddenException; + +/** + * Class ProjectRoleController + * + * @package Kanboard\Controller + * @author Frederic Guillot + */ +class ProjectRoleController extends BaseController +{ + /** + * Show roles and permissions + */ + public function show() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('project_role/show', array( + 'project' => $project, + 'roles' => $this->projectRoleModel->getAllWithRestrictions($project['id']), + 'title' => t('Custom Project Roles'), + ))); + } + + /** + * Show form to create new role + * + * @param array $values + * @param array $errors + * @throws AccessForbiddenException + */ + public function create(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + $this->response->html($this->template->render('project_role/create', array( + 'project' => $project, + 'values' => $values + array('project_id' => $project['id']), + 'errors' => $errors, + ))); + } + + /** + * Save new role + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->projectRoleValidator->validateCreation($values); + + if ($valid) { + $role_id = $this->projectRoleModel->create($project['id'], $values['role']); + + if ($role_id !== false) { + $this->flash->success(t('Your custom project role has been created successfully.')); + } else { + $this->flash->failure(t('Unable to create custom project role.')); + } + + $this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id']))); + } else { + $this->create($values, $errors); + } + } + + /** + * Confirm suppression + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $role_id = $this->request->getIntegerParam('role_id'); + + $this->response->html($this->helper->layout->project('project_role/remove', array( + 'project' => $project, + 'role' => $this->projectRoleModel->getById($project['id'], $role_id), + ))); + } + + /** + * Remove a custom role + * + * @access public + */ + public function remove() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + $role_id = $this->request->getIntegerParam('role_id'); + + if ($this->projectRoleModel->remove($project['id'], $role_id)) { + $this->flash->success(t('Custom project role removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this project role.')); + } + + $this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/ProjectUserOverviewController.php b/app/Controller/ProjectUserOverviewController.php index 686de830..5faf5790 100644 --- a/app/Controller/ProjectUserOverviewController.php +++ b/app/Controller/ProjectUserOverviewController.php @@ -122,9 +122,9 @@ class ProjectUserOverviewController extends BaseController { $project = $this->getProject(); - return $this->response->html($this->template->render('project_user_overview/tooltip_users', array( + $this->response->html($this->template->render('project_user_overview/tooltip_users', array( 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), - 'roles' => $this->role->getProjectRoles(), + 'roles' => $this->projectRoleModel->getList($project['id']), ))); } } |