Add ui to create new custom project roles and column restrictions

This commit is contained in:
Frederic Guillot
2016-09-10 22:37:57 -04:00
parent 75470c7242
commit 44f680cf2f
25 changed files with 717 additions and 26 deletions

View File

@@ -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')
)));
}

View File

@@ -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'])));
}
}

View File

@@ -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']),

View File

@@ -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'),

View File

@@ -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'])));
}
}

View File

@@ -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']),
)));
}
}