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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"name": "Fabien Potencier",
"email": "[email protected]",
"role": "Creator"
},
{
"name": "Emanuele Panzeri",
"email": "[email protected]",
"role": "Contributor"
}
],
"require": {
Expand Down
2 changes: 2 additions & 0 deletions lib/task/sfGuardAddPermissionTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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)
{
Expand Down
66 changes: 66 additions & 0 deletions lib/task/sfGuardGroupCreateTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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.
*/

/**
* Create a new user.
*
* @package symfony
* @subpackage task
* @author Emanuele Panzeri <[email protected]>
*/
class sfGuardGroupCreateTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The group name'),
));

$this->addOptions(array(
new sfCommandOption('description', null, sfCommandOption::PARAMETER_REQUIRED, 'The Group description', null),
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:create';
$this->briefDescription = 'Creates a Group';

$this->detailedDescription = <<<EOF
The [guard:group:create|INFO] task creates a group:

[./symfony guard:group:create GroupName --description="This is a nice Group description"|INFO]
EOF;
}

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

$table = Doctrine_Core::getTable('sfGuardGroup');
if ($ret = $table->findOneBy('name', $arguments['name'])) {
$this->logSection('guard', sprintf('Group "%s" already exists!', $arguments['name']), null, 'ERROR');
return -1;
}

$group = new sfGuardGroup();
$group->setName($arguments['name']);
$group->setDescription($options['description']);
$group->save();

$this->logSection('guard', sprintf('Created group "%s"', $arguments['name']));
}
}
67 changes: 67 additions & 0 deletions lib/task/sfGuardGroupDeleteTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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.
*/

/**
* Delete a sfGuard Group.
*
* @package symfony
* @subpackage task
* @author Emanuele Panzeri <[email protected]>
*/
class sfGuardGroupDeleteTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The group name'),
));

$this->addOptions(array(
new sfCommandOption('description', null, sfCommandOption::PARAMETER_REQUIRED, 'The Group description', null),
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:delete';
$this->briefDescription = 'Deletes a Group';

$this->detailedDescription = <<<EOF
The [guard:group:delete|INFO] task deletes a group:

[./symfony guard:group:delete GroupName --description="This is a nice Group description"|INFO]
EOF;
}

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

$table = Doctrine_Core::getTable('sfGuardGroup');
$entity = $table->findOneBy('name', $arguments['name']);
if (!$entity) {
$this->logSection('guard', sprintf('Group "%s" does exists!', $arguments['name']), null, 'ERROR');
return -1;
}

if (!$entity->delete()) {
$this->logSection('guard', sprintf('Group "%s" was not deleted', $arguments['name']), 'ERROR');
return -1;
}

$this->logSection('guard', sprintf('Group "%s" deleted', $arguments['name']));
}
}
86 changes: 86 additions & 0 deletions lib/task/sfGuardGroupPermissionAddTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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 sfGuardGroupPermissionAddTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('group', sfCommandArgument::REQUIRED, 'The group name'),
new sfCommandArgument('permission', sfCommandArgument::REQUIRED, 'The permission name'),
));

$this->addOptions(array(
new sfCommandOption('description', null, sfCommandOption::PARAMETER_REQUIRED, 'The Group description', null),
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-add';
$this->briefDescription = 'Associated a Group with a Permission';

$this->detailedDescription = <<<EOF
The [guard:group:permission-add|INFO] task add a group with a permission:

[./symfony guard:group:permission-add GroupName PermissionName|INFO]
EOF;
}

/**
* @see sfTask
*/
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;
}

/** @var sfGuardPermission $permission */
$permission = Doctrine_Core::getTable('sfGuardPermission')->findOneByName($arguments['permission']);
if (!$permission) {
$this->logSection('guard', sprintf('Permission "%s" not found!', $arguments['permission']), null, 'ERROR');
return -1;
}

/** @var sfGuardGroupPermission $groupPermission */
$groupPermission = Doctrine_Core::getTable('sfGuardGroupPermission')->find(array(
$group->getPrimaryKey(),
$permission->getPrimaryKey(),
));
if ($groupPermission) {
$this->logSection('guard', 'Group Permission already exists', null, 'ERROR');
return -1;
}

$groupPermission = new sfGuardGroupPermission();
$groupPermission
->setGroup($group)
->setPermission($permission);
$groupPermission->save();

$this->logSection('guard', sprintf('Associated group "%s" with permission "%s".', $group->getName(), $permission->getName()));
}
}
86 changes: 86 additions & 0 deletions lib/task/sfGuardGroupPermissionRemoveTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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 sfGuardGroupPermissionRemoveTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('group', sfCommandArgument::REQUIRED, 'The group name'),
new sfCommandArgument('permission', sfCommandArgument::REQUIRED, 'The permission name'),
));

$this->addOptions(array(
new sfCommandOption('description', null, sfCommandOption::PARAMETER_REQUIRED, 'The Group description', null),
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-remove';
$this->briefDescription = 'Removes a permission from a group';

$this->detailedDescription = <<<EOF
The [guard:group:permission-remove|INFO] task remove a permission from a group:

[./symfony guard:group:permission-remove GroupName PermissionName|INFO]
EOF;
}

/**
* @see sfTask
*/
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;
}

/** @var sfGuardPermission $permission */
$permission = Doctrine_Core::getTable('sfGuardPermission')->findOneByName($arguments['permission']);
if (!$permission) {
$this->logSection('guard', sprintf('Permission "%s" not found!', $arguments['permission']), null, 'ERROR');
return -1;
}

/** @var sfGuardGroupPermission $entity */
$entity = Doctrine_Core::getTable('sfGuardGroupPermission')->find(array(
$group->getPrimaryKey(),
$permission->getPrimaryKey(),
));
if (!$entity) {
$this->logSection('guard', 'Group Permission does not exists', null, 'ERROR');
return -1;
}


if (!$entity->delete()) {
$this->logSection('guard', sprintf('Can not remove permission "%s" from group "%s"', $group->getName(), $permission->getName()), 'ERROR');
return -1;
}

$this->logSection('guard', sprintf('Permission "%s" removed from group "%s"', $group->getName(), $permission->getName()));
}
}
67 changes: 67 additions & 0 deletions lib/task/sfGuardPermissionCreateTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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.
*/

/**
* Create a new sfGuard permission.
*
* @package symfony
* @subpackage task
* @author Emanuele Panzeri <[email protected]>
*/
class sfGuardPermissionCreateTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The permission name'),
));

$this->addOptions(array(
new sfCommandOption('description', null, sfCommandOption::PARAMETER_REQUIRED, 'The Permission description', null),
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 = 'permission:create';
$this->briefDescription = 'Creates a Permission';

$this->detailedDescription = <<<EOF
The [guard:permission:create|INFO] task creates a Permission:

[./symfony guard:permission:create PermissionName --description="This is a nice Permission description"|INFO]
EOF;
}

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

$table = Doctrine_Core::getTable('sfGuardPermission');
if ($ret = $table->findOneBy('name', $arguments['name'])) {
$this->logSection('guard', sprintf('Permission "%s" already exists!', $arguments['name']), null, 'ERROR');
return -1;
}

$permission = new sfGuardPermission();

$permission->setName($arguments['name']);
$permission->setDescription($options['description']);
$permission->save();

$this->logSection('guard', sprintf('Created Permission "%s"', $arguments['name']));
}
}
Loading