Skip to content

Commit

Permalink
Added user:list group:permission-list tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Nov 21, 2018
1 parent 612a3c8 commit 0a4cc9e
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

54 changes: 54 additions & 0 deletions lib/task/sfGuardGroupPermissionListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* 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 <[email protected]>
*/
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()));
}
}
}
14 changes: 1 addition & 13 deletions lib/task/sfGuardPermissionDeleteTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
*/

/**
* Create a new Permission.
* Delete a group-permission.
*
* @package symfony
* @subpackage task
* @author Emanuele Panzeri <[email protected]>
*/
class sfGuardPermissionDeleteTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
Expand All @@ -35,17 +32,8 @@ protected function configure()
$this->namespace = 'guard';
$this->name = 'permission:delete';
$this->briefDescription = 'Delete a Permission';

$this->detailedDescription = <<<EOF
The [guard:permission:delete|INFO] task deletes a Permission:
[./symfony guard:permission:delete PermissionName"|INFO]
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
Expand Down
20 changes: 3 additions & 17 deletions lib/task/sfGuardPermissionListTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
*/

/**
* Add a group to a user.
* List the available Permissions.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @version SVN: $Id$
* @author Emanuele Panzeri <[email protected]>
*/
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'),
Expand All @@ -36,17 +31,8 @@ protected function configure()
$this->namespace = 'guard';
$this->name = 'permission:list';
$this->briefDescription = 'List Permissions';

$this->detailedDescription = <<<EOF
The [guard:permission:list|INFO] list permissions:
[./symfony guard:list-groups|INFO]
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
Expand Down
16 changes: 1 addition & 15 deletions lib/task/sfGuardUserGroupsListTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

/**
* Add a permission to a user.
* List the group associated to a user.
*
* @package symfony
* @subpackage task
Expand All @@ -18,9 +18,6 @@
*/
class sfGuardUserGroupsListTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
Expand All @@ -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 = <<<EOF
The [guard:user:groups-list|INFO] task adds a permission to a user:
[./symfony guard:user:group-list fabien|INFO]
The user must exist in the database.
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
Expand Down
44 changes: 44 additions & 0 deletions lib/task/sfGuardUserListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* 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 <[email protected]>
*/
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()));
}
}
}

0 comments on commit 0a4cc9e

Please sign in to comment.