Skip to content

Commit

Permalink
Added command to remove rules. Not yet complete, can only remove ALL …
Browse files Browse the repository at this point in the history
…rules
  • Loading branch information
christeredvartsen committed Jul 13, 2011
1 parent 39c4952 commit a5c3e2b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
19 changes: 11 additions & 8 deletions library/PHSA/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ public function __construct() {
parent::__construct('PHSA', Version::getVersionNumber());

// Register commands
$this->add(new Command\ListReposes());
$this->add(new Command\ListAcls());
$this->add(new Command\AllowUser());
$this->add(new Command\AllowGroup());
$this->add(new Command\DenyUser());
$this->add(new Command\DenyGroup());
$this->add(new Command\Dump());
$this->add(new Command\Import());
$this->addCommands(array(
new Command\ListReposes(),
new Command\ListAcls(),
new Command\AllowUser(),
new Command\AllowGroup(),
new Command\DenyUser(),
new Command\DenyGroup(),
new Command\Dump(),
new Command\Import(),
new Command\Remove(),
));

// Add global options
$this->getDefinition()->addOption(
Expand Down
60 changes: 60 additions & 0 deletions library/PHSA/Command/Remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace PHSA\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

/**
* Command used to remove rules from the database
*/
class Remove extends BaseCommand {
/**
* Class constructor
*/
public function __construct() {
parent::__construct('remove');
$this->setDescription('Remove rules');
$this->setHelp('Remove rules from the database based on one or more options. Several options can be combined to remove more rules');

$this->addOption('all', null, InputOption::VALUE_NONE, 'Remove all rules');

$this->addOption('repos', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of repositories to remove rules from');
$this->addOption('user', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of users to remove rules from');
$this->addOption('group', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of groups to remove rules from');
$this->addOption('rule', null, InputOption::VALUE_OPTIONAL, 'Remove rules of this type. "allow" or "deny"');
$this->addOption('role', null, InputOption::VALUE_OPTIONAL, 'Remove rules with this role. "user" or "group"');
$this->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of paths to remove');
}

/**
* Execute the command
*
* @see \Symfony\Components\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$dialog = $this->getHelper('dialog');
$result = $dialog->askConfirmation($output, 'Are you sure you want to remove rules? ', false);

if (!$result) {
$output->writeln('Command aborted');
return;
}

$database = $this->configuration['database']['driver'];

if ($input->getOption('all')) {
$result = $dialog->askConfirmation($output, 'Are you REALLY sure you want to remove ALL rules? ', false);

if ($result) {
$database->removeAllRules();
$output->writeln('All rules have been removed');
return;
} else {
$output->writeln('Command aborted');
return;
}
}
}
}

0 comments on commit a5c3e2b

Please sign in to comment.