From 0a4cc9e14065989acaf9ccdf1a2b6f7df0976e55 Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 21 Nov 2018 20:14:46 +0100 Subject: [PATCH] Added user:list group:permission-list tasks --- .gitignore | 1 + .../sfGuardGroupPermissionListTask.class.php | 54 +++++++++++++++++++ .../sfGuardPermissionDeleteTask.class.php | 14 +---- lib/task/sfGuardPermissionListTask.class.php | 20 ++----- lib/task/sfGuardUserGroupsListTask.class.php | 16 +----- lib/task/sfGuardUserListTask.class.php | 44 +++++++++++++++ 6 files changed, 104 insertions(+), 45 deletions(-) create mode 100644 .gitignore create mode 100644 lib/task/sfGuardGroupPermissionListTask.class.php create mode 100644 lib/task/sfGuardUserListTask.class.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ + diff --git a/lib/task/sfGuardGroupPermissionListTask.class.php b/lib/task/sfGuardGroupPermissionListTask.class.php new file mode 100644 index 0000000..d20455a --- /dev/null +++ b/lib/task/sfGuardGroupPermissionListTask.class.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Associates a sfGuard group with a permission. + * + * @package symfony + * @subpackage task + * @author Emanuele Panzeri + */ +class sfGuardGroupPermissionListTask extends sfBaseTask +{ + protected function configure() + { + $this->addArguments(array( + new sfCommandArgument('group', sfCommandArgument::REQUIRED, 'The group name'), + )); + + $this->addOptions(array( + new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), + )); + + $this->namespace = 'guard'; + $this->name = 'group:permission-list'; + $this->briefDescription = 'List the group permissions'; + } + + protected function execute($arguments = array(), $options = array()) + { + $databaseManager = new sfDatabaseManager($this->configuration); + + /** @var sfGuardGroup $group */ + $group = Doctrine_Core::getTable('sfGuardGroup')->findOneByName($arguments['group']); + if (!$group) { + $this->logSection('guard', sprintf('Group "%s" not found!', $arguments['group']), null, 'ERROR'); + return -1; + } + + $this->logSection('guard', sprintf('Listing permissions for Group "%s"', $group->getName())); + + /** @var sfGuardPermission $permission */ + foreach ($group->getPermissions() as $permission) { + $this->logSection('guard', sprintf(' - %s', $permission->getName())); + } + } +} diff --git a/lib/task/sfGuardPermissionDeleteTask.class.php b/lib/task/sfGuardPermissionDeleteTask.class.php index 4799414..ef43b22 100644 --- a/lib/task/sfGuardPermissionDeleteTask.class.php +++ b/lib/task/sfGuardPermissionDeleteTask.class.php @@ -9,7 +9,7 @@ */ /** - * Create a new Permission. + * Delete a group-permission. * * @package symfony * @subpackage task @@ -17,9 +17,6 @@ */ class sfGuardPermissionDeleteTask extends sfBaseTask { - /** - * @see sfTask - */ protected function configure() { $this->addArguments(array( @@ -35,17 +32,8 @@ protected function configure() $this->namespace = 'guard'; $this->name = 'permission:delete'; $this->briefDescription = 'Delete a Permission'; - - $this->detailedDescription = <<configuration); diff --git a/lib/task/sfGuardPermissionListTask.class.php b/lib/task/sfGuardPermissionListTask.class.php index db8f972..4dac5e4 100644 --- a/lib/task/sfGuardPermissionListTask.class.php +++ b/lib/task/sfGuardPermissionListTask.class.php @@ -9,22 +9,17 @@ */ /** - * Add a group to a user. + * List the available Permissions. * * @package symfony * @subpackage task - * @author Fabien Potencier - * @version SVN: $Id$ + * @author Emanuele Panzeri */ class sfGuardPermissionListTask extends sfBaseTask { - /** - * @see sfTask - */ protected function configure() { - $this->addArguments(array( - )); + $this->addArguments(array()); $this->addOptions(array( new sfCommandOption('with-groups', null, sfCommandOption::PARAMETER_NONE, 'Join with Groups'), @@ -36,17 +31,8 @@ protected function configure() $this->namespace = 'guard'; $this->name = 'permission:list'; $this->briefDescription = 'List Permissions'; - - $this->detailedDescription = <<configuration); diff --git a/lib/task/sfGuardUserGroupsListTask.class.php b/lib/task/sfGuardUserGroupsListTask.class.php index b980a5c..fbb1167 100644 --- a/lib/task/sfGuardUserGroupsListTask.class.php +++ b/lib/task/sfGuardUserGroupsListTask.class.php @@ -9,7 +9,7 @@ */ /** - * Add a permission to a user. + * List the group associated to a user. * * @package symfony * @subpackage task @@ -18,9 +18,6 @@ */ class sfGuardUserGroupsListTask extends sfBaseTask { - /** - * @see sfTask - */ protected function configure() { $this->addArguments(array( @@ -35,19 +32,8 @@ protected function configure() $this->name = 'user:groups-list'; $this->namespace = 'guard'; $this->briefDescription = 'List the Groups associated to a user'; - - $this->detailedDescription = <<configuration); diff --git a/lib/task/sfGuardUserListTask.class.php b/lib/task/sfGuardUserListTask.class.php new file mode 100644 index 0000000..45c4814 --- /dev/null +++ b/lib/task/sfGuardUserListTask.class.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * List the sfGuard users. + * + * @package symfony + * @subpackage task + * @author Emanuele Panzeri + */ +class sfGuardUserListTask extends sfBaseTask +{ + protected function configure() + { + $this->addArguments(array()); + + $this->addOptions(array( + new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), + )); + + $this->namespace = 'guard'; + $this->name = 'user:list'; + $this->briefDescription = 'List users'; + } + + protected function execute($arguments = array(), $options = array()) + { + $databaseManager = new sfDatabaseManager($this->configuration); + + $model = sfConfig::get('app_sf_guard_user_model', 'sfGuardUser'); + $users = Doctrine_Core::getTable($model)->findAll(); + /** @var sfGuardUser $user */ + foreach ($users as $user) { + $this->logSection('guard', sprintf('%s (name: "%s", email: "%s")', $user->getUsername(), $user->getName(), $user->getEmailAddress())); + } + } +}