Skip to content

Commit 8da282a

Browse files
committed
Group for CLI.
1 parent c0d052c commit 8da282a

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

docs/Authorization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ If you need to build a navigation that includes publicly accessible actions, you
594594
The plugin offers a convenience CLI command to sync ACL for any new controller. It will automatically skip controllers that are whitelisted as public (non authenticated).
595595

596596
```
597-
bin/cake tiny_auth_sync {your default roles, comma separated}
597+
bin/cake tiny_auth sync {your default roles, comma separated}
598598
```
599599

600600
This will then add any missing controller with `* = ...` for all actions and you can then manually fine-tune.
@@ -606,7 +606,7 @@ This will then add any missing controller with `* = ...` for all actions and you
606606
Add any role to any command and action:
607607

608608
```
609-
bin/cake tiny_auth_add {Controller} {Action} {roles, comma separated}
609+
bin/cake tiny_auth add {Controller} {Action} {roles, comma separated}
610610
```
611611

612612
It will skip if the roles are already present for this controller and action.

src/Command/TinyAuthAddCommand.php renamed to src/Command/AddCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
* or updating specific controller/action permissions for given roles.
1818
*
1919
* Usage examples:
20-
* - `bin/cake tiny_auth_add Articles index user,admin` - Allow users and admins to access Articles::index
21-
* - `bin/cake tiny_auth_add Articles` - Interactive mode, prompts for action and roles
22-
* - `bin/cake tiny_auth_add Articles "*" "*"` - Allow all roles to access all Articles actions
20+
* - `bin/cake tiny_auth add Articles index user,admin` - Allow users and admins to access Articles::index
21+
* - `bin/cake tiny_auth add Articles` - Interactive mode, prompts for action and roles
22+
* - `bin/cake tiny_auth add Articles "*" "*"` - Allow all roles to access all Articles actions
2323
*
2424
* @see config/auth_acl.ini - The file that gets modified by this command
2525
*/
26-
class TinyAuthAddCommand extends Command {
26+
class AddCommand extends Command {
2727

2828
/**
2929
* @inheritDoc
@@ -96,13 +96,13 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
9696
. 'This command modifies: config/auth_acl.ini (or custom path via TinyAuth.aclFilePath)' . PHP_EOL
9797
. PHP_EOL
9898
. 'Examples:' . PHP_EOL
99-
. ' bin/cake tiny_auth_add Articles index user,admin' . PHP_EOL
99+
. ' bin/cake tiny_auth add Articles index user,admin' . PHP_EOL
100100
. ' → Adds: [Articles] index = user, admin' . PHP_EOL
101101
. PHP_EOL
102-
. ' bin/cake tiny_auth_add Articles "*" admin' . PHP_EOL
102+
. ' bin/cake tiny_auth add Articles "*" admin' . PHP_EOL
103103
. ' → Adds: [Articles] * = admin' . PHP_EOL
104104
. PHP_EOL
105-
. ' bin/cake tiny_auth_add MyPlugin.Admin/Articles edit admin' . PHP_EOL
105+
. ' bin/cake tiny_auth add MyPlugin.Admin/Articles edit admin' . PHP_EOL
106106
. ' → Adds: [MyPlugin.Admin/Articles] edit = admin',
107107
)->addArgument('controller', [
108108
'help' => 'Controller name (Plugin.Prefix/Name) without Controller suffix.',

src/Command/TinyAuthSyncCommand.php renamed to src/Command/SyncCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
* have entries in the ACL INI file (default: config/auth_acl.ini).
1818
*
1919
* Usage examples:
20-
* - `bin/cake tiny_auth_sync user,admin` - Add all controllers with access for user and admin roles
21-
* - `bin/cake tiny_auth_sync "*" -p all` - Add all controllers (including plugins) with access for all roles
22-
* - `bin/cake tiny_auth_sync user -d` - Dry run, shows what would be added without modifying files
20+
* - `bin/cake tiny_auth sync user,admin` - Add all controllers with access for user and admin roles
21+
* - `bin/cake tiny_auth sync "*" -p all` - Add all controllers (including plugins) with access for all roles
22+
* - `bin/cake tiny_auth sync user -d` - Dry run, shows what would be added without modifying files
2323
*
2424
* @see config/auth_acl.ini - The file that gets modified by this command
2525
*/
26-
class TinyAuthSyncCommand extends Command {
26+
class SyncCommand extends Command {
2727

2828
/**
2929
* @inheritDoc
@@ -88,13 +88,13 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
8888
. ' 3. Preserve existing entries (never overwrites)' . PHP_EOL
8989
. PHP_EOL
9090
. 'Examples:' . PHP_EOL
91-
. ' bin/cake tiny_auth_sync user,admin' . PHP_EOL
91+
. ' bin/cake tiny_auth sync user,admin' . PHP_EOL
9292
. ' → Adds all missing controllers with: * = user, admin' . PHP_EOL
9393
. PHP_EOL
94-
. ' bin/cake tiny_auth_sync "*" -p all' . PHP_EOL
94+
. ' bin/cake tiny_auth sync "*" -p all' . PHP_EOL
9595
. ' → Adds all missing controllers (including plugins) with: * = *' . PHP_EOL
9696
. PHP_EOL
97-
. ' bin/cake tiny_auth_sync admin -d' . PHP_EOL
97+
. ' bin/cake tiny_auth sync admin -d' . PHP_EOL
9898
. ' → Dry run - shows what would be added without modifying files',
9999
)->addArgument('roles', [
100100
'help' => 'Role names, comma separated, e.g. `user,admin`.' . ($roles ? PHP_EOL . 'Available roles: ' . implode(', ', $roles) . '.' : ''),

src/Sync/Adder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Helper class for adding specific ACL entries to the INI configuration file.
1515
*
16-
* Used by TinyAuthAddCommand to modify auth_acl.ini file with new or updated
16+
* Used by AddCommand to modify auth_acl.ini file with new or updated
1717
* controller/action/role mappings.
1818
*
1919
* @internal

src/TinyAuthPlugin.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace TinyAuth;
44

5+
use Cake\Console\CommandCollection;
56
use Cake\Core\BasePlugin;
7+
use TinyAuth\Command\AddCommand;
8+
use TinyAuth\Command\SyncCommand;
69

710
/**
811
* Plugin for TinyAuth
@@ -24,4 +27,15 @@ class TinyAuthPlugin extends BasePlugin {
2427
*/
2528
protected bool $routesEnabled = false;
2629

30+
/**
31+
* @param \Cake\Console\CommandCollection $commands The command collection to add to.
32+
* @return \Cake\Console\CommandCollection
33+
*/
34+
public function console(CommandCollection $commands): CommandCollection {
35+
$commands->add('tiny_auth add', AddCommand::class);
36+
$commands->add('tiny_auth sync', SyncCommand::class);
37+
38+
return $commands;
39+
}
40+
2741
}

tests/TestCase/Command/TinyAuthAddCommandTest.php renamed to tests/TestCase/Command/AddCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Cake\TestSuite\TestCase;
99
use TinyAuth\Filesystem\Folder;
1010

11-
class TinyAuthAddCommandTest extends TestCase {
11+
class AddCommandTest extends TestCase {
1212

1313
use ConsoleIntegrationTestTrait;
1414

@@ -40,7 +40,7 @@ public function testAdd() {
4040
$folder = new Folder();
4141
$folder->copy('/tmp' . DS . 'src' . DS . 'Controller' . DS, ['from' => TESTS . 'test_app' . DS . 'Controller' . DS]);
4242

43-
$this->exec('tiny_auth_add Some action foo,bar -d -v');
43+
$this->exec('tiny_auth add Some action foo,bar -d -v');
4444

4545
$this->assertExitCode(Command::CODE_SUCCESS);
4646
$this->assertOutputContains('[Some]');

tests/TestCase/Command/TinyAuthSyncCommandTest.php renamed to tests/TestCase/Command/SyncCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Cake\TestSuite\TestCase;
99
use TinyAuth\Filesystem\Folder;
1010

11-
class TinyAuthSyncCommandTest extends TestCase {
11+
class SyncCommandTest extends TestCase {
1212

1313
use ConsoleIntegrationTestTrait;
1414

@@ -40,7 +40,7 @@ public function testSync() {
4040
$folder = new Folder();
4141
$folder->copy('/tmp' . DS . 'src' . DS . 'Controller' . DS, ['from' => TESTS . 'test_app' . DS . 'Controller' . DS]);
4242

43-
$this->exec('tiny_auth_sync foo,bar -d -v');
43+
$this->exec('tiny_auth sync foo,bar -d -v');
4444

4545
$this->assertExitCode(Command::CODE_SUCCESS);
4646
$this->assertOutputContains('index = admin');

0 commit comments

Comments
 (0)