Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions lib/task/sfGuardGroupListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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.
*/

/**
* Lists sfGuard groups.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @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 = <<<EOF
The [guard:group:list|INFO] list groups:

[./symfony guard:group:list|INFO]
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->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()));
}
}

}
}
74 changes: 74 additions & 0 deletions lib/task/sfGuardPermissionListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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.
*/

/**
* Add a group to a user.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @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 = <<<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);

$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()));
}
}

}
}
69 changes: 69 additions & 0 deletions lib/task/sfGuardUserGroupsListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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.
*/

/**
* Add a permission to a user.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @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 = <<<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);

$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));
}
}
}