From abdf6f97800e7e838b5841820815385b183bab67 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 16 May 2016 20:19:07 -0400 Subject: Improve group controllers and views --- app/Controller/Group.php | 256 ------------------------- app/Controller/GroupAjaxController.php | 26 +++ app/Controller/GroupCreationController.php | 49 +++++ app/Controller/GroupHelper.php | 26 --- app/Controller/GroupListController.php | 173 +++++++++++++++++ app/Controller/GroupModificationController.php | 53 +++++ app/ServiceProvider/AuthenticationProvider.php | 4 +- app/ServiceProvider/RouteProvider.php | 9 +- app/Template/group/associate.php | 41 ++-- app/Template/group/create.php | 19 -- app/Template/group/dissociate.php | 25 +-- app/Template/group/edit.php | 22 --- app/Template/group/index.php | 12 +- app/Template/group/remove.php | 25 +-- app/Template/group/users.php | 7 +- app/Template/group_creation/show.php | 15 ++ app/Template/group_modification/show.php | 18 ++ app/Template/header.php | 2 +- app/Template/project_permission/index.php | 2 +- app/Template/user/index.php | 2 +- app/Template/user/layout.php | 2 +- 21 files changed, 391 insertions(+), 397 deletions(-) delete mode 100644 app/Controller/Group.php create mode 100644 app/Controller/GroupAjaxController.php create mode 100644 app/Controller/GroupCreationController.php delete mode 100644 app/Controller/GroupHelper.php create mode 100644 app/Controller/GroupListController.php create mode 100644 app/Controller/GroupModificationController.php delete mode 100644 app/Template/group/create.php delete mode 100644 app/Template/group/edit.php create mode 100644 app/Template/group_creation/show.php create mode 100644 app/Template/group_modification/show.php (limited to 'app') diff --git a/app/Controller/Group.php b/app/Controller/Group.php deleted file mode 100644 index 2f91e72a..00000000 --- a/app/Controller/Group.php +++ /dev/null @@ -1,256 +0,0 @@ -paginator - ->setUrl('group', 'index') - ->setMax(30) - ->setOrder('name') - ->setQuery($this->group->getQuery()) - ->calculate(); - - $this->response->html($this->helper->layout->app('group/index', array( - 'title' => t('Groups').' ('.$paginator->getTotal().')', - 'paginator' => $paginator, - ))); - } - - /** - * List all users - * - * @access public - */ - public function users() - { - $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); - - $paginator = $this->paginator - ->setUrl('group', 'users', array('group_id' => $group_id)) - ->setMax(30) - ->setOrder('username') - ->setQuery($this->groupMember->getQuery($group_id)) - ->calculate(); - - $this->response->html($this->helper->layout->app('group/users', array( - 'title' => t('Members of %s', $group['name']).' ('.$paginator->getTotal().')', - 'paginator' => $paginator, - 'group' => $group, - ))); - } - - /** - * Display a form to create a new group - * - * @access public - * @param array $values - * @param array $errors - */ - public function create(array $values = array(), array $errors = array()) - { - $this->response->html($this->helper->layout->app('group/create', array( - 'errors' => $errors, - 'values' => $values, - 'title' => t('New group') - ))); - } - - /** - * Validate and save a new group - * - * @access public - */ - public function save() - { - $values = $this->request->getValues(); - list($valid, $errors) = $this->groupValidator->validateCreation($values); - - if ($valid) { - if ($this->group->create($values['name']) !== false) { - $this->flash->success(t('Group created successfully.')); - return $this->response->redirect($this->helper->url->to('group', 'index')); - } else { - $this->flash->failure(t('Unable to create your group.')); - } - } - - return $this->create($values, $errors); - } - - /** - * Display a form to update a group - * - * @access public - * @param array $values - * @param array $errors - */ - public function edit(array $values = array(), array $errors = array()) - { - if (empty($values)) { - $values = $this->group->getById($this->request->getIntegerParam('group_id')); - } - - $this->response->html($this->helper->layout->app('group/edit', array( - 'errors' => $errors, - 'values' => $values, - 'title' => t('Edit group') - ))); - } - - /** - * Validate and save a group - * - * @access public - */ - public function update() - { - $values = $this->request->getValues(); - list($valid, $errors) = $this->groupValidator->validateModification($values); - - if ($valid) { - if ($this->group->update($values) !== false) { - $this->flash->success(t('Group updated successfully.')); - return $this->response->redirect($this->helper->url->to('group', 'index')); - } else { - $this->flash->failure(t('Unable to update your group.')); - } - } - - return $this->edit($values, $errors); - } - - /** - * Form to associate a user to a group - * - * @access public - * @param array $values - * @param array $errors - */ - public function associate(array $values = array(), array $errors = array()) - { - $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); - - if (empty($values)) { - $values['group_id'] = $group_id; - } - - $this->response->html($this->helper->layout->app('group/associate', array( - 'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)), - 'group' => $group, - 'errors' => $errors, - 'values' => $values, - 'title' => t('Add group member to "%s"', $group['name']), - ))); - } - - /** - * Add user to a group - * - * @access public - */ - public function addUser() - { - $values = $this->request->getValues(); - - if (isset($values['group_id']) && isset($values['user_id'])) { - if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) { - $this->flash->success(t('Group member added successfully.')); - return $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $values['group_id']))); - } else { - $this->flash->failure(t('Unable to add group member.')); - } - } - - return $this->associate($values); - } - - /** - * Confirmation dialog to remove a user from a group - * - * @access public - */ - public function dissociate() - { - $group_id = $this->request->getIntegerParam('group_id'); - $user_id = $this->request->getIntegerParam('user_id'); - $group = $this->group->getById($group_id); - $user = $this->user->getById($user_id); - - $this->response->html($this->helper->layout->app('group/dissociate', array( - 'group' => $group, - 'user' => $user, - 'title' => t('Remove user from group "%s"', $group['name']), - ))); - } - - /** - * Remove a user from a group - * - * @access public - */ - public function removeUser() - { - $this->checkCSRFParam(); - $group_id = $this->request->getIntegerParam('group_id'); - $user_id = $this->request->getIntegerParam('user_id'); - - if ($this->groupMember->removeUser($group_id, $user_id)) { - $this->flash->success(t('User removed successfully from this group.')); - } else { - $this->flash->failure(t('Unable to remove this user from the group.')); - } - - $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $group_id))); - } - - /** - * Confirmation dialog to remove a group - * - * @access public - */ - public function confirm() - { - $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); - - $this->response->html($this->helper->layout->app('group/remove', array( - 'group' => $group, - 'title' => t('Remove group'), - ))); - } - - /** - * Remove a group - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $group_id = $this->request->getIntegerParam('group_id'); - - if ($this->group->remove($group_id)) { - $this->flash->success(t('Group removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this group.')); - } - - $this->response->redirect($this->helper->url->to('group', 'index')); - } -} diff --git a/app/Controller/GroupAjaxController.php b/app/Controller/GroupAjaxController.php new file mode 100644 index 00000000..496e9ef2 --- /dev/null +++ b/app/Controller/GroupAjaxController.php @@ -0,0 +1,26 @@ +request->getStringParam('term'); + $formatter = new GroupAutoCompleteFormatter($this->groupManager->find($search)); + $this->response->json($formatter->format()); + } +} diff --git a/app/Controller/GroupCreationController.php b/app/Controller/GroupCreationController.php new file mode 100644 index 00000000..7d0bb93c --- /dev/null +++ b/app/Controller/GroupCreationController.php @@ -0,0 +1,49 @@ +response->html($this->template->render('group_creation/show', array( + 'errors' => $errors, + 'values' => $values, + ))); + } + + /** + * Validate and save a new group + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->groupValidator->validateCreation($values); + + if ($valid) { + if ($this->group->create($values['name']) !== false) { + $this->flash->success(t('Group created successfully.')); + return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true); + } else { + $this->flash->failure(t('Unable to create your group.')); + } + } + + return $this->show($values, $errors); + } +} diff --git a/app/Controller/GroupHelper.php b/app/Controller/GroupHelper.php deleted file mode 100644 index 06e5ec71..00000000 --- a/app/Controller/GroupHelper.php +++ /dev/null @@ -1,26 +0,0 @@ -request->getStringParam('term'); - $formatter = new GroupAutoCompleteFormatter($this->groupManager->find($search)); - $this->response->json($formatter->format()); - } -} diff --git a/app/Controller/GroupListController.php b/app/Controller/GroupListController.php new file mode 100644 index 00000000..17f3b2a9 --- /dev/null +++ b/app/Controller/GroupListController.php @@ -0,0 +1,173 @@ +paginator + ->setUrl('GroupListController', 'index') + ->setMax(30) + ->setOrder('name') + ->setQuery($this->group->getQuery()) + ->calculate(); + + $this->response->html($this->helper->layout->app('group/index', array( + 'title' => t('Groups').' ('.$paginator->getTotal().')', + 'paginator' => $paginator, + ))); + } + + /** + * List all users + * + * @access public + */ + public function users() + { + $group_id = $this->request->getIntegerParam('group_id'); + $group = $this->group->getById($group_id); + + $paginator = $this->paginator + ->setUrl('GroupListController', 'users', array('group_id' => $group_id)) + ->setMax(30) + ->setOrder('username') + ->setQuery($this->groupMember->getQuery($group_id)) + ->calculate(); + + $this->response->html($this->helper->layout->app('group/users', array( + 'title' => t('Members of %s', $group['name']).' ('.$paginator->getTotal().')', + 'paginator' => $paginator, + 'group' => $group, + ))); + } + + /** + * Form to associate a user to a group + * + * @access public + * @param array $values + * @param array $errors + */ + public function associate(array $values = array(), array $errors = array()) + { + $group_id = $this->request->getIntegerParam('group_id'); + $group = $this->group->getById($group_id); + + if (empty($values)) { + $values['group_id'] = $group_id; + } + + $this->response->html($this->template->render('group/associate', array( + 'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)), + 'group' => $group, + 'errors' => $errors, + 'values' => $values, + ))); + } + + /** + * Add user to a group + * + * @access public + */ + public function addUser() + { + $values = $this->request->getValues(); + + if (isset($values['group_id']) && isset($values['user_id'])) { + if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) { + $this->flash->success(t('Group member added successfully.')); + return $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $values['group_id'])), true); + } else { + $this->flash->failure(t('Unable to add group member.')); + } + } + + return $this->associate($values); + } + + /** + * Confirmation dialog to remove a user from a group + * + * @access public + */ + public function dissociate() + { + $group_id = $this->request->getIntegerParam('group_id'); + $user_id = $this->request->getIntegerParam('user_id'); + $group = $this->group->getById($group_id); + $user = $this->user->getById($user_id); + + $this->response->html($this->template->render('group/dissociate', array( + 'group' => $group, + 'user' => $user, + ))); + } + + /** + * Remove a user from a group + * + * @access public + */ + public function removeUser() + { + $this->checkCSRFParam(); + $group_id = $this->request->getIntegerParam('group_id'); + $user_id = $this->request->getIntegerParam('user_id'); + + if ($this->groupMember->removeUser($group_id, $user_id)) { + $this->flash->success(t('User removed successfully from this group.')); + } else { + $this->flash->failure(t('Unable to remove this user from the group.')); + } + + $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $group_id)), true); + } + + /** + * Confirmation dialog to remove a group + * + * @access public + */ + public function confirm() + { + $group_id = $this->request->getIntegerParam('group_id'); + $group = $this->group->getById($group_id); + + $this->response->html($this->template->render('group/remove', array( + 'group' => $group, + ))); + } + + /** + * Remove a group + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $group_id = $this->request->getIntegerParam('group_id'); + + if ($this->group->remove($group_id)) { + $this->flash->success(t('Group removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this group.')); + } + + $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true); + } +} diff --git a/app/Controller/GroupModificationController.php b/app/Controller/GroupModificationController.php new file mode 100644 index 00000000..1f225a14 --- /dev/null +++ b/app/Controller/GroupModificationController.php @@ -0,0 +1,53 @@ +group->getById($this->request->getIntegerParam('group_id')); + } + + $this->response->html($this->template->render('group_modification/show', array( + 'errors' => $errors, + 'values' => $values, + ))); + } + + /** + * Validate and save a group + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->groupValidator->validateModification($values); + + if ($valid) { + if ($this->group->update($values) !== false) { + $this->flash->success(t('Group updated successfully.')); + return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true); + } else { + $this->flash->failure(t('Unable to update your group.')); + } + } + + return $this->show($values, $errors); + } +} diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index 82f61e11..5540bf88 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -132,7 +132,9 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('Config', '*', Role::APP_ADMIN); $acl->add('Currency', '*', Role::APP_ADMIN); $acl->add('Gantt', array('projects', 'saveProjectDate'), Role::APP_MANAGER); - $acl->add('Group', '*', Role::APP_ADMIN); + $acl->add('GroupListController', '*', Role::APP_ADMIN); + $acl->add('GroupCreationController', '*', Role::APP_ADMIN); + $acl->add('GroupModificationController', '*', Role::APP_ADMIN); $acl->add('Link', '*', Role::APP_ADMIN); $acl->add('ProjectCreation', 'create', Role::APP_MANAGER); $acl->add('Projectuser', '*', Role::APP_MANAGER); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index 2788e3a7..a6d6abef 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -161,13 +161,8 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('user/:user_id/avatar', 'AvatarFile', 'show'); // Groups - $container['route']->addRoute('groups', 'group', 'index'); - $container['route']->addRoute('groups/create', 'group', 'create'); - $container['route']->addRoute('group/:group_id/associate', 'group', 'associate'); - $container['route']->addRoute('group/:group_id/dissociate/:user_id', 'group', 'dissociate'); - $container['route']->addRoute('group/:group_id/edit', 'group', 'edit'); - $container['route']->addRoute('group/:group_id/members', 'group', 'users'); - $container['route']->addRoute('group/:group_id/remove', 'group', 'confirm'); + $container['route']->addRoute('groups', 'GroupListController', 'index'); + $container['route']->addRoute('group/:group_id/members', 'GroupListController', 'users'); // Config $container['route']->addRoute('settings', 'config', 'index'); diff --git a/app/Template/group/associate.php b/app/Template/group/associate.php index 9de46f35..87787568 100644 --- a/app/Template/group/associate.php +++ b/app/Template/group/associate.php @@ -1,25 +1,20 @@ -
- - -

- -
- form->csrf() ?> - form->hidden('group_id', $values) ?> + + +

+ + + form->csrf() ?> + form->hidden('group_id', $values) ?> - form->label(t('User'), 'user_id') ?> - form->select('user_id', $users, $values, $errors, array('required'), 'chosen-select') ?> + form->label(t('User'), 'user_id') ?> + form->select('user_id', $users, $values, $errors, array('required'), 'chosen-select') ?> -
- - - url->link(t('cancel'), 'group', 'index') ?> -
-
- -
+
+ + + url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?> +
+ + diff --git a/app/Template/group/create.php b/app/Template/group/create.php deleted file mode 100644 index 4ce6b1f3..00000000 --- a/app/Template/group/create.php +++ /dev/null @@ -1,19 +0,0 @@ -
- -
- form->csrf() ?> - - form->label(t('Name'), 'name') ?> - form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?> - -
- - - url->link(t('cancel'), 'group', 'index') ?> -
-
-
diff --git a/app/Template/group/dissociate.php b/app/Template/group/dissociate.php index e1c60764..50ef6d61 100644 --- a/app/Template/group/dissociate.php +++ b/app/Template/group/dissociate.php @@ -1,17 +1,12 @@ -
- -
-

+ +
+

-
- url->link(t('Yes'), 'group', 'removeUser', array('group_id' => $group['id'], 'user_id' => $user['id']), true, 'btn btn-red') ?> - - url->link(t('cancel'), 'group', 'users', array('group_id' => $group['id'])) ?> -
+
+ url->link(t('Yes'), 'GroupListController', 'removeUser', array('group_id' => $group['id'], 'user_id' => $user['id']), true, 'btn btn-red') ?> + + url->link(t('cancel'), 'GroupListController', 'users', array('group_id' => $group['id']), false, 'close-popover') ?>
-
+ diff --git a/app/Template/group/edit.php b/app/Template/group/edit.php deleted file mode 100644 index e9d9dd5a..00000000 --- a/app/Template/group/edit.php +++ /dev/null @@ -1,22 +0,0 @@ -
- -
- form->csrf() ?> - - form->hidden('id', $values) ?> - form->hidden('external_id', $values) ?> - - form->label(t('Name'), 'name') ?> - form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?> - -
- - - url->link(t('cancel'), 'group', 'index') ?> -
-
-
diff --git a/app/Template/group/index.php b/app/Template/group/index.php index 8302e5a8..74e074c3 100644 --- a/app/Template/group/index.php +++ b/app/Template/group/index.php @@ -2,7 +2,7 @@ isEmpty()): ?> @@ -24,16 +24,16 @@ text->e($group['external_id']) ?> - text->e($group['name']) ?> + url->link($this->text->e($group['name']), 'GroupListController', 'users', array('group_id' => $group['id'])) ?> diff --git a/app/Template/group/remove.php b/app/Template/group/remove.php index 1cb007b1..408b3d83 100644 --- a/app/Template/group/remove.php +++ b/app/Template/group/remove.php @@ -1,17 +1,12 @@ -
- -
-

+ +
+

-
- url->link(t('Yes'), 'group', 'remove', array('group_id' => $group['id']), true, 'btn btn-red') ?> - - url->link(t('cancel'), 'group', 'index') ?> -
+
+ url->link(t('Yes'), 'GroupListController', 'remove', array('group_id' => $group['id']), true, 'btn btn-red') ?> + + url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?>
-
+ diff --git a/app/Template/group/users.php b/app/Template/group/users.php index bbd41525..0f802146 100644 --- a/app/Template/group/users.php +++ b/app/Template/group/users.php @@ -1,8 +1,8 @@
isEmpty()): ?> @@ -31,7 +31,8 @@ text->e($user['email']) ?> - url->link(t('Remove this user'), 'group', 'dissociate', array('group_id' => $group['id'], 'user_id' => $user['id'])) ?> + + url->link(t('Remove this user'), 'GroupListController', 'dissociate', array('group_id' => $group['id'], 'user_id' => $user['id']), false, 'popover') ?> diff --git a/app/Template/group_creation/show.php b/app/Template/group_creation/show.php new file mode 100644 index 00000000..b219bd70 --- /dev/null +++ b/app/Template/group_creation/show.php @@ -0,0 +1,15 @@ + +
+ form->csrf() ?> + + form->label(t('Name'), 'name') ?> + form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?> + +
+ + + url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?> +
+
diff --git a/app/Template/group_modification/show.php b/app/Template/group_modification/show.php new file mode 100644 index 00000000..ddf07369 --- /dev/null +++ b/app/Template/group_modification/show.php @@ -0,0 +1,18 @@ + +
+ form->csrf() ?> + + form->hidden('id', $values) ?> + form->hidden('external_id', $values) ?> + + form->label(t('Name'), 'name') ?> + form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?> + +
+ + + url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?> +
+
diff --git a/app/Template/header.php b/app/Template/header.php index f47b270f..bac026d3 100644 --- a/app/Template/header.php +++ b/app/Template/header.php @@ -80,7 +80,7 @@
  • - url->link(t('Groups management'), 'group', 'index') ?> + url->link(t('Groups management'), 'GroupListController', 'index') ?>
  • diff --git a/app/Template/project_permission/index.php b/app/Template/project_permission/index.php index a7d666a6..6d1fc15c 100644 --- a/app/Template/project_permission/index.php +++ b/app/Template/project_permission/index.php @@ -113,7 +113,7 @@ 'title="'.t('Enter group name...').'"', 'data-dst-field="group_id"', 'data-dst-extra-field="external_id"', - 'data-search-url="'.$this->url->href('GroupHelper', 'autocomplete').'"', + 'data-search-url="'.$this->url->href('GroupAjaxController', 'autocomplete').'"', ), 'autocomplete') ?> diff --git a/app/Template/user/index.php b/app/Template/user/index.php index b810373f..15923e84 100644 --- a/app/Template/user/index.php +++ b/app/Template/user/index.php @@ -5,7 +5,7 @@
  • url->link(t('New local user'), 'UserCreationController', 'show', array(), false, 'popover') ?>
  • url->link(t('New remote user'), 'UserCreationController', 'show', array('remote' => 1), false, 'popover') ?>
  • url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?>
  • -
  • url->link(t('View all groups'), 'group', 'index') ?>
  • +
  • url->link(t('View all groups'), 'GroupListController', 'index') ?>
  • diff --git a/app/Template/user/layout.php b/app/Template/user/layout.php index 47df2997..2c4bb7be 100644 --- a/app/Template/user/layout.php +++ b/app/Template/user/layout.php @@ -6,7 +6,7 @@
  • url->link(t('New local user'), 'UserCreationController', 'show', array(), false, 'popover') ?>
  • url->link(t('New remote user'), 'UserCreationController', 'show', array('remote' => 1), false, 'popover') ?>
  • url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?>
  • -
  • url->link(t('View all groups'), 'group', 'index') ?>
  • +
  • url->link(t('View all groups'), 'GroupListController', 'index') ?>
  • -- cgit v1.2.3