diff --git a/lib/task/sfGuardGroupListTask.class.php b/lib/task/sfGuardGroupListTask.class.php new file mode 100644 index 0000000..44aeb93 --- /dev/null +++ b/lib/task/sfGuardGroupListTask.class.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Lists sfGuard groups. + * + * @package symfony + * @subpackage task + * @author Fabien Potencier + * @version SVN: $Id$ + */ +class sfGuardGroupListTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure() + { + $this->addArguments(array( + )); + + $this->addOptions(array( + new sfCommandOption('with-perm', null, sfCommandOption::PARAMETER_NONE, 'Join with Permissions'), + new sfCommandOption('with-users', null, sfCommandOption::PARAMETER_NONE, 'Join with Users'), + )); + + $this->namespace = 'guard'; + $this->name = 'group:list'; + $this->briefDescription = 'List groups'; + + $this->detailedDescription = <<configuration); + + $groupTable = Doctrine_Core::getTable('sfGuardGroup'); + + $groups = $groupTable->findAll(); + + $this->logSection('guard', sprintf('Found %d Groups', $groups->count())); + + /** @var sfGuardGroup $group */ + foreach($groups as $group) { + $this->logSection('guard', sprintf('%d : %s', $group->getPrimaryKey(), $group->getName())); + + if ($options['with-perm']) { + /** @var sfGuardPermission $permission */ + foreach ($group->getPermissions() as $permission) { + $this->logSection('guard', sprintf(' - Permission: %s', $permission->getName())); + } + } + } + if ($options['with-users']) { + /** @var sfGuardUser $user */ + foreach ($group->getUsers() as $user) { + $this->logSection('guard', sprintf(' - User %d: %s', $user->getPrimaryKey(), $user->getName())); + } + } + + } +} diff --git a/lib/task/sfGuardPermissionListTask.class.php b/lib/task/sfGuardPermissionListTask.class.php new file mode 100644 index 0000000..15a1956 --- /dev/null +++ b/lib/task/sfGuardPermissionListTask.class.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Add a group to a user. + * + * @package symfony + * @subpackage task + * @author Fabien Potencier + * @version SVN: $Id$ + */ +class sfGuardPermissionListTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure() + { + $this->addArguments(array( + )); + + $this->addOptions(array( + new sfCommandOption('with-groups', null, sfCommandOption::PARAMETER_NONE, 'Join with Groups'), + new sfCommandOption('with-users', null, sfCommandOption::PARAMETER_NONE, 'Join with Users'), + )); + + $this->namespace = 'guard'; + $this->name = 'permission:list'; + $this->briefDescription = 'List Permissions'; + + $this->detailedDescription = <<configuration); + + $permTable = Doctrine_Core::getTable('sfGuardPermission'); + + $perms = $permTable->findAll(); + + $this->logSection('guard', sprintf('Found %d Permissions', $perms->count())); + + /** @var sfGuardGroup $perm */ + foreach($perms as $perm) { + $this->logSection('guard', sprintf(' - %s', $perm->getName())); + if ($options['with-groups']) { + foreach ($perm->getPermissions() as $permission) { + $this->logSection('guard', sprintf(' - Permission: %s', $permission->getName())); + } + } + } + if ($options['with-users']) { + foreach ($perm->getUsers() as $user) { + $this->logSection('guard', sprintf(' - User: %s', $user->getName())); + } + } + + } +} diff --git a/lib/task/sfGuardUserGroupsListTask.class.php b/lib/task/sfGuardUserGroupsListTask.class.php new file mode 100644 index 0000000..b980a5c --- /dev/null +++ b/lib/task/sfGuardUserGroupsListTask.class.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Add a permission to a user. + * + * @package symfony + * @subpackage task + * @author Fabien Potencier + * @version SVN: $Id$ + */ +class sfGuardUserGroupsListTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure() + { + $this->addArguments(array( + new sfCommandArgument('username', sfCommandArgument::REQUIRED, 'The user 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->name = 'user:groups-list'; + $this->namespace = 'guard'; + $this->briefDescription = 'List the Groups associated to a user'; + + $this->detailedDescription = <<configuration); + + $model = sfConfig::get('app_sf_guard_user_model', 'sfGuardUser'); + + /** @var sfGuardUser $user */ + $user = Doctrine_Core::getTable($model)->findOneByUsername($arguments['username']); + if (!$user) + { + throw new sfCommandException(sprintf('User "%s" does not exist.', $arguments['username'])); + } + + $this->logSection('guard', sprintf('Listing groups associated to user %s', $arguments['username'])); + foreach ($user->getGroupNames() as $groupName) { + $this->logSection('guard', sprintf(' - %s', $groupName)); + } + } +} diff --git a/lib/task/sfGuardUserUserPermissionAddTask.class.php b/lib/task/sfGuardUserPermissionAddTask.class.php similarity index 100% rename from lib/task/sfGuardUserUserPermissionAddTask.class.php rename to lib/task/sfGuardUserPermissionAddTask.class.php