From f2cce5ade869420bb73d5af2ad17907b1c3bb3da Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 25 May 2016 22:46:21 -0400 Subject: Rename ProjectEdit controller --- app/Controller/ProjectEdit.php | 133 ------------------------- app/Controller/ProjectEditController.php | 133 +++++++++++++++++++++++++ app/ServiceProvider/AuthenticationProvider.php | 2 +- app/ServiceProvider/RouteProvider.php | 8 +- app/Template/custom_filter/add.php | 4 +- app/Template/custom_filter/edit.php | 4 +- app/Template/project/dropdown.php | 2 +- app/Template/project/sidebar.php | 8 +- app/Template/project_edit/dates.php | 10 +- app/Template/project_edit/description.php | 10 +- app/Template/project_edit/general.php | 10 +- app/Template/project_edit/task_priority.php | 10 +- app/Template/project_header/dropdown.php | 2 +- app/Template/project_overview/description.php | 4 +- tests/units/Helper/UserHelperTest.php | 22 ++-- 15 files changed, 181 insertions(+), 181 deletions(-) delete mode 100644 app/Controller/ProjectEdit.php create mode 100644 app/Controller/ProjectEditController.php diff --git a/app/Controller/ProjectEdit.php b/app/Controller/ProjectEdit.php deleted file mode 100644 index e3ba74c3..00000000 --- a/app/Controller/ProjectEdit.php +++ /dev/null @@ -1,133 +0,0 @@ -renderView('project_edit/general', $values, $errors); - } - - /** - * Change start and end dates - * - * @access public - * @param array $values - * @param array $errors - */ - public function dates(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/dates', $values, $errors); - } - - /** - * Change project description - * - * @access public - * @param array $values - * @param array $errors - */ - public function description(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/description', $values, $errors); - } - - /** - * Change task priority - * - * @access public - * @param array $values - * @param array $errors - */ - public function priority(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/task_priority', $values, $errors); - } - - /** - * Validate and update a project - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - $redirect = $this->request->getStringParam('redirect', 'edit'); - - $values = $this->prepareValues($redirect, $project, $values); - list($valid, $errors) = $this->projectValidator->validateModification($values); - - if ($valid) { - if ($this->project->update($values)) { - $this->flash->success(t('Project updated successfully.')); - return $this->response->redirect($this->helper->url->to('ProjectEdit', $redirect, array('project_id' => $project['id'])), true); - } else { - $this->flash->failure(t('Unable to update this project.')); - } - } - - return $this->$redirect($values, $errors); - } - - /** - * Prepare form values - * - * @access private - * @param string $redirect - * @param array $project - * @param array $values - * @return array - */ - private function prepareValues($redirect, array $project, array $values) - { - if ($redirect === 'edit') { - if (isset($values['is_private'])) { - if (! $this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { - unset($values['is_private']); - } - } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { - if ($this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { - $values += array('is_private' => 0); - } - } - } - - return $values; - } - - /** - * Common metthod to render different views - * - * @access private - * @param string $template - * @param array $values - * @param array $errors - */ - private function renderView($template, array $values, array $errors) - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project($template, array( - 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true), - 'values' => empty($values) ? $project : $values, - 'errors' => $errors, - 'project' => $project, - 'title' => t('Edit project') - ))); - } -} diff --git a/app/Controller/ProjectEditController.php b/app/Controller/ProjectEditController.php new file mode 100644 index 00000000..774c6909 --- /dev/null +++ b/app/Controller/ProjectEditController.php @@ -0,0 +1,133 @@ +renderView('project_edit/general', $values, $errors); + } + + /** + * Change start and end dates + * + * @access public + * @param array $values + * @param array $errors + */ + public function dates(array $values = array(), array $errors = array()) + { + $this->renderView('project_edit/dates', $values, $errors); + } + + /** + * Change project description + * + * @access public + * @param array $values + * @param array $errors + */ + public function description(array $values = array(), array $errors = array()) + { + $this->renderView('project_edit/description', $values, $errors); + } + + /** + * Change task priority + * + * @access public + * @param array $values + * @param array $errors + */ + public function priority(array $values = array(), array $errors = array()) + { + $this->renderView('project_edit/task_priority', $values, $errors); + } + + /** + * Validate and update a project + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + $redirect = $this->request->getStringParam('redirect', 'edit'); + + $values = $this->prepareValues($redirect, $project, $values); + list($valid, $errors) = $this->projectValidator->validateModification($values); + + if ($valid) { + if ($this->project->update($values)) { + $this->flash->success(t('Project updated successfully.')); + return $this->response->redirect($this->helper->url->to('ProjectEditController', $redirect, array('project_id' => $project['id'])), true); + } else { + $this->flash->failure(t('Unable to update this project.')); + } + } + + return $this->$redirect($values, $errors); + } + + /** + * Prepare form values + * + * @access private + * @param string $redirect + * @param array $project + * @param array $values + * @return array + */ + private function prepareValues($redirect, array $project, array $values) + { + if ($redirect === 'edit') { + if (isset($values['is_private'])) { + if (! $this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { + unset($values['is_private']); + } + } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { + if ($this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { + $values += array('is_private' => 0); + } + } + } + + return $values; + } + + /** + * Common method to render different views + * + * @access private + * @param string $template + * @param array $values + * @param array $errors + */ + private function renderView($template, array $values, array $errors) + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project($template, array( + 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true), + 'values' => empty($values) ? $project : $values, + 'errors' => $errors, + 'project' => $project, + 'title' => t('Edit project') + ))); + } +} diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index fe9cee3c..051dcc30 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -83,7 +83,7 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('Gantt', '*', Role::PROJECT_MANAGER); $acl->add('ProjectViewController', array('share', 'updateSharing', 'integrations', 'updateIntegrations', 'notifications', 'updateNotifications', 'duplicate', 'doDuplication'), Role::PROJECT_MANAGER); $acl->add('ProjectPermissionController', '*', Role::PROJECT_MANAGER); - $acl->add('ProjectEdit', '*', Role::PROJECT_MANAGER); + $acl->add('ProjectEditController', '*', Role::PROJECT_MANAGER); $acl->add('ProjectFile', '*', Role::PROJECT_MEMBER); $acl->add('Projectuser', '*', Role::PROJECT_MANAGER); $acl->add('ProjectStatusController', '*', Role::PROJECT_MANAGER); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index e52b0762..2d705217 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -65,10 +65,10 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('project/:project_id/overview', 'ProjectOverview', 'show'); // ProjectEdit routes - $container['route']->addRoute('project/:project_id/edit', 'ProjectEdit', 'edit'); - $container['route']->addRoute('project/:project_id/edit/dates', 'ProjectEdit', 'dates'); - $container['route']->addRoute('project/:project_id/edit/description', 'ProjectEdit', 'description'); - $container['route']->addRoute('project/:project_id/edit/priority', 'ProjectEdit', 'priority'); + $container['route']->addRoute('project/:project_id/edit', 'ProjectEditController', 'edit'); + $container['route']->addRoute('project/:project_id/edit/dates', 'ProjectEditController', 'dates'); + $container['route']->addRoute('project/:project_id/edit/description', 'ProjectEditController', 'description'); + $container['route']->addRoute('project/:project_id/edit/priority', 'ProjectEditController', 'priority'); // ProjectUser routes $container['route']->addRoute('projects/managers/:user_id', 'projectuser', 'managers'); diff --git a/app/Template/custom_filter/add.php b/app/Template/custom_filter/add.php index e3e144ae..56f7921c 100644 --- a/app/Template/custom_filter/add.php +++ b/app/Template/custom_filter/add.php @@ -12,7 +12,7 @@ form->label(t('Filter'), 'filter') ?> form->text('filter', $values, $errors, array('required', 'maxlength="100"')) ?> - user->hasProjectAccess('ProjectEdit', 'edit', $project['id'])): ?> + user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])): ?> form->checkbox('is_shared', t('Share with all project members'), 1) ?> @@ -21,4 +21,4 @@
- \ No newline at end of file + diff --git a/app/Template/custom_filter/edit.php b/app/Template/custom_filter/edit.php index 5d07e8c2..051a5062 100644 --- a/app/Template/custom_filter/edit.php +++ b/app/Template/custom_filter/edit.php @@ -16,7 +16,7 @@ form->label(t('Filter'), 'filter') ?> form->text('filter', $values, $errors, array('required', 'maxlength="100"')) ?> - user->hasProjectAccess('ProjectEdit', 'edit', $project['id'])): ?> + user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])): ?> form->checkbox('is_shared', t('Share with all project members'), 1, $values['is_shared'] == 1) ?> form->hidden('is_shared', $values) ?> @@ -29,4 +29,4 @@ url->link(t('cancel'), 'customfilter', 'index', array('project_id' => $project['id']), false, 'close-popover') ?> - \ No newline at end of file + diff --git a/app/Template/project/dropdown.php b/app/Template/project/dropdown.php index 02bc4c02..edebdd65 100644 --- a/app/Template/project/dropdown.php +++ b/app/Template/project/dropdown.php @@ -34,7 +34,7 @@ hook->render('template:project:dropdown', array('project' => $project)) ?> - user->hasProjectAccess('ProjectEdit', 'edit', $project['id'])): ?> + user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])): ?>
  • url->link(t('Settings'), 'ProjectViewController', 'show', array('project_id' => $project['id'])) ?> diff --git a/app/Template/project/sidebar.php b/app/Template/project/sidebar.php index 2d49ca58..1071e78b 100644 --- a/app/Template/project/sidebar.php +++ b/app/Template/project/sidebar.php @@ -10,9 +10,9 @@
  • - user->hasProjectAccess('ProjectEdit', 'edit', $project['id'])): ?> -
  • app->checkMenuSelection('ProjectEdit') ?>> - url->link(t('Edit project'), 'ProjectEdit', 'edit', array('project_id' => $project['id'])) ?> + user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])): ?> +
  • app->checkMenuSelection('ProjectEditController') ?>> + url->link(t('Edit project'), 'ProjectEditController', 'edit', array('project_id' => $project['id'])) ?>
  • app->checkMenuSelection('ProjectViewController', 'share') ?>> url->link(t('Public access'), 'ProjectViewController', 'share', array('project_id' => $project['id'])) ?> @@ -33,7 +33,7 @@ url->link(t('Categories'), 'category', 'index', array('project_id' => $project['id'])) ?>
  • -
  • app->checkMenuSelection('ProjectPermission') ?>> +
  • app->checkMenuSelection('ProjectPermissionController') ?>> url->link(t('Permissions'), 'ProjectPermissionController', 'index', array('project_id' => $project['id'])) ?>
  • diff --git a/app/Template/project_edit/dates.php b/app/Template/project_edit/dates.php index f77b7260..48135ddc 100644 --- a/app/Template/project_edit/dates.php +++ b/app/Template/project_edit/dates.php @@ -1,13 +1,13 @@ -
    + form->csrf() ?> form->hidden('id', $values) ?> form->hidden('name', $values) ?> diff --git a/app/Template/project_edit/description.php b/app/Template/project_edit/description.php index e6c42caf..f7e7be46 100644 --- a/app/Template/project_edit/description.php +++ b/app/Template/project_edit/description.php @@ -1,13 +1,13 @@ - + form->csrf() ?> form->hidden('id', $values) ?> form->hidden('name', $values) ?> diff --git a/app/Template/project_edit/general.php b/app/Template/project_edit/general.php index 6c3fa68d..b817bcd4 100644 --- a/app/Template/project_edit/general.php +++ b/app/Template/project_edit/general.php @@ -1,13 +1,13 @@ - + form->csrf() ?> form->hidden('id', $values) ?> diff --git a/app/Template/project_edit/task_priority.php b/app/Template/project_edit/task_priority.php index 56c25753..3ef4b3cb 100644 --- a/app/Template/project_edit/task_priority.php +++ b/app/Template/project_edit/task_priority.php @@ -1,13 +1,13 @@ - + form->csrf() ?> form->hidden('id', $values) ?> form->hidden('name', $values) ?> diff --git a/app/Template/project_header/dropdown.php b/app/Template/project_header/dropdown.php index 7dffcb85..5a27e981 100644 --- a/app/Template/project_header/dropdown.php +++ b/app/Template/project_header/dropdown.php @@ -72,7 +72,7 @@ - user->hasProjectAccess('ProjectEdit', 'edit', $project['id'])): ?> + user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])): ?>
  • url->link(t('Settings'), 'ProjectViewController', 'show', array('project_id' => $project['id'])) ?> diff --git a/app/Template/project_overview/description.php b/app/Template/project_overview/description.php index 72ccf06a..0c2027ed 100644 --- a/app/Template/project_overview/description.php +++ b/app/Template/project_overview/description.php @@ -3,9 +3,9 @@

    - user->hasProjectAccess('ProjectEdit', 'description', $project['id'])): ?> + user->hasProjectAccess('ProjectEditController', 'description', $project['id'])): ?>
    - url->button('fa-edit', t('Edit description'), 'ProjectEdit', 'description', array('project_id' => $project['id']), 'popover') ?> + url->button('fa-edit', t('Edit description'), 'ProjectEditController', 'description', array('project_id' => $project['id']), 'popover') ?>
    diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index c5e5903f..0b339422 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -85,7 +85,7 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); } @@ -101,7 +101,7 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } @@ -117,7 +117,7 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } @@ -138,12 +138,12 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('taskcreationcontroller', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); @@ -166,12 +166,12 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); @@ -194,12 +194,12 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); @@ -222,12 +222,12 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); -- cgit v1.2.3