Skip to content

Commit 0a4cc9e

Browse files
committed
Added user:list group:permission-list tasks
1 parent 612a3c8 commit 0a4cc9e

6 files changed

+104
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony package.
5+
* (c) Fabien Potencier <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
/**
12+
* Associates a sfGuard group with a permission.
13+
*
14+
* @package symfony
15+
* @subpackage task
16+
* @author Emanuele Panzeri <[email protected]>
17+
*/
18+
class sfGuardGroupPermissionListTask extends sfBaseTask
19+
{
20+
protected function configure()
21+
{
22+
$this->addArguments(array(
23+
new sfCommandArgument('group', sfCommandArgument::REQUIRED, 'The group name'),
24+
));
25+
26+
$this->addOptions(array(
27+
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null),
28+
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
29+
));
30+
31+
$this->namespace = 'guard';
32+
$this->name = 'group:permission-list';
33+
$this->briefDescription = 'List the group permissions';
34+
}
35+
36+
protected function execute($arguments = array(), $options = array())
37+
{
38+
$databaseManager = new sfDatabaseManager($this->configuration);
39+
40+
/** @var sfGuardGroup $group */
41+
$group = Doctrine_Core::getTable('sfGuardGroup')->findOneByName($arguments['group']);
42+
if (!$group) {
43+
$this->logSection('guard', sprintf('Group "%s" not found!', $arguments['group']), null, 'ERROR');
44+
return -1;
45+
}
46+
47+
$this->logSection('guard', sprintf('Listing permissions for Group "%s"', $group->getName()));
48+
49+
/** @var sfGuardPermission $permission */
50+
foreach ($group->getPermissions() as $permission) {
51+
$this->logSection('guard', sprintf(' - %s', $permission->getName()));
52+
}
53+
}
54+
}

lib/task/sfGuardPermissionDeleteTask.class.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
*/
1010

1111
/**
12-
* Create a new Permission.
12+
* Delete a group-permission.
1313
*
1414
* @package symfony
1515
* @subpackage task
1616
* @author Emanuele Panzeri <[email protected]>
1717
*/
1818
class sfGuardPermissionDeleteTask extends sfBaseTask
1919
{
20-
/**
21-
* @see sfTask
22-
*/
2320
protected function configure()
2421
{
2522
$this->addArguments(array(
@@ -35,17 +32,8 @@ protected function configure()
3532
$this->namespace = 'guard';
3633
$this->name = 'permission:delete';
3734
$this->briefDescription = 'Delete a Permission';
38-
39-
$this->detailedDescription = <<<EOF
40-
The [guard:permission:delete|INFO] task deletes a Permission:
41-
42-
[./symfony guard:permission:delete PermissionName"|INFO]
43-
EOF;
4435
}
4536

46-
/**
47-
* @see sfTask
48-
*/
4937
protected function execute($arguments = array(), $options = array())
5038
{
5139
$databaseManager = new sfDatabaseManager($this->configuration);

lib/task/sfGuardPermissionListTask.class.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@
99
*/
1010

1111
/**
12-
* Add a group to a user.
12+
* List the available Permissions.
1313
*
1414
* @package symfony
1515
* @subpackage task
16-
* @author Fabien Potencier <[email protected]>
17-
* @version SVN: $Id$
16+
* @author Emanuele Panzeri <[email protected]>
1817
*/
1918
class sfGuardPermissionListTask extends sfBaseTask
2019
{
21-
/**
22-
* @see sfTask
23-
*/
2420
protected function configure()
2521
{
26-
$this->addArguments(array(
27-
));
22+
$this->addArguments(array());
2823

2924
$this->addOptions(array(
3025
new sfCommandOption('with-groups', null, sfCommandOption::PARAMETER_NONE, 'Join with Groups'),
@@ -36,17 +31,8 @@ protected function configure()
3631
$this->namespace = 'guard';
3732
$this->name = 'permission:list';
3833
$this->briefDescription = 'List Permissions';
39-
40-
$this->detailedDescription = <<<EOF
41-
The [guard:permission:list|INFO] list permissions:
42-
43-
[./symfony guard:list-groups|INFO]
44-
EOF;
4534
}
4635

47-
/**
48-
* @see sfTask
49-
*/
5036
protected function execute($arguments = array(), $options = array())
5137
{
5238
$databaseManager = new sfDatabaseManager($this->configuration);

lib/task/sfGuardUserGroupsListTask.class.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
/**
12-
* Add a permission to a user.
12+
* List the group associated to a user.
1313
*
1414
* @package symfony
1515
* @subpackage task
@@ -18,9 +18,6 @@
1818
*/
1919
class sfGuardUserGroupsListTask extends sfBaseTask
2020
{
21-
/**
22-
* @see sfTask
23-
*/
2421
protected function configure()
2522
{
2623
$this->addArguments(array(
@@ -35,19 +32,8 @@ protected function configure()
3532
$this->name = 'user:groups-list';
3633
$this->namespace = 'guard';
3734
$this->briefDescription = 'List the Groups associated to a user';
38-
39-
$this->detailedDescription = <<<EOF
40-
The [guard:user:groups-list|INFO] task adds a permission to a user:
41-
42-
[./symfony guard:user:group-list fabien|INFO]
43-
44-
The user must exist in the database.
45-
EOF;
4635
}
4736

48-
/**
49-
* @see sfTask
50-
*/
5137
protected function execute($arguments = array(), $options = array())
5238
{
5339
$databaseManager = new sfDatabaseManager($this->configuration);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony package.
5+
* (c) Fabien Potencier <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
/**
11+
* List the sfGuard users.
12+
*
13+
* @package symfony
14+
* @subpackage task
15+
* @author Emanuele Panzeri <[email protected]>
16+
*/
17+
class sfGuardUserListTask extends sfBaseTask
18+
{
19+
protected function configure()
20+
{
21+
$this->addArguments(array());
22+
23+
$this->addOptions(array(
24+
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null),
25+
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
26+
));
27+
28+
$this->namespace = 'guard';
29+
$this->name = 'user:list';
30+
$this->briefDescription = 'List users';
31+
}
32+
33+
protected function execute($arguments = array(), $options = array())
34+
{
35+
$databaseManager = new sfDatabaseManager($this->configuration);
36+
37+
$model = sfConfig::get('app_sf_guard_user_model', 'sfGuardUser');
38+
$users = Doctrine_Core::getTable($model)->findAll();
39+
/** @var sfGuardUser $user */
40+
foreach ($users as $user) {
41+
$this->logSection('guard', sprintf('%s (name: "%s", email: "%s")', $user->getUsername(), $user->getName(), $user->getEmailAddress()));
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)