Skip to content

Commit 1daa2f8

Browse files
committed
docs: document CLI workflow and move seeding to consumer apps
1 parent 2377b27 commit 1daa2f8

10 files changed

Lines changed: 97 additions & 333 deletions

File tree

README.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,9 @@ Abac::addPermission('read', App\Models\Post::class, [
4545

4646
3. Request is allowed when actor/resource attributes satisfy the grant constraints.
4747

48-
---
49-
50-
## Documentation
51-
52-
Full docs: [https://zennit-dev.github.io/abac/](https://zennit-dev.github.io/abac/)
53-
54-
Local docs index: `docs/index.md`
55-
56-
---
57-
5848
## Artisan Commands
5949

60-
The package ships with helper commands for publishing ABAC assets and scaffolding policy payloads.
50+
The package registers utility commands for consumer setup:
6151

6252
```bash
6353
php artisan abac:publish
@@ -66,10 +56,48 @@ php artisan abac:publish-env
6656
php artisan abac:scaffold --from-routes
6757
```
6858

69-
- `abac:publish` publishes ABAC config and environment variables in one step.
70-
- `abac:publish-config` publishes the `config/abac.php` file (supports `--force`).
71-
- `abac:publish-env` writes missing ABAC environment variables to a target env-style file.
72-
- `abac:scaffold --from-routes` generates policy stubs from `abac.middleware.resource_patterns`.
59+
- `abac:publish` runs config + env publishing in one command.
60+
- `abac:publish-config` publishes `config/abac.php`.
61+
- `abac:publish-env` appends missing ABAC environment variables to a chosen env file.
62+
- `abac:scaffold --from-routes` generates a starter policy JSON scaffold from `abac.middleware.resource_patterns`.
63+
64+
## Seeding Permissions in Your App
65+
66+
Seed permissions from your consuming application's seeders instead of package-provided seeders:
67+
68+
```php
69+
<?php
70+
71+
namespace Database\Seeders;
72+
73+
use Illuminate\Database\Seeder;
74+
use zennit\ABAC\Facades\Abac;
75+
76+
class AbacPermissionSeeder extends Seeder
77+
{
78+
public function run(): void
79+
{
80+
Abac::addPermission('read', App\Models\Post::class, [
81+
'role' => 'editor',
82+
'resource.owner_id' => '123',
83+
]);
84+
85+
Abac::addPermission('update', App\Models\Post::class, [
86+
'actor.role' => 'admin',
87+
]);
88+
}
89+
}
90+
```
91+
92+
Then call your seeder from `DatabaseSeeder` as part of your normal app bootstrap.
93+
94+
---
95+
96+
## Documentation
97+
98+
Full docs: [https://zennit-dev.github.io/abac/](https://zennit-dev.github.io/abac/)
99+
100+
Local docs index: `docs/index.md`
73101

74102
---
75103

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zennit/abac",
33
"description": "Attribute-Based Access Control (ABAC) for Laravel",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"type": "library",
66
"license": "MIT",
77
"keywords": [
@@ -48,8 +48,7 @@
4848
"autoload": {
4949
"psr-4": {
5050
"zennit\\ABAC\\": "src/",
51-
"zennit\\ABAC\\Database\\Factories\\": "database/factories/",
52-
"zennit\\ABAC\\Database\\Seeders\\": "database/seeders/"
51+
"zennit\\ABAC\\Database\\Factories\\": "database/factories/"
5352
},
5453
"files": [
5554
"src/helpers.php"

config/abac.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@
6666
'default_policy_behavior' => env('ABAC_DEFAULT_POLICY_BEHAVIOR', AbacDefaults::DEFAULT_POLICY_BEHAVIOR),
6767
],
6868

69-
/*
70-
|--------------------------------------------------------------------------
71-
| ABAC Seeders Configuration
72-
|--------------------------------------------------------------------------
73-
|
74-
| This section defines the paths to the JSON files used by the ABAC seeders.
75-
| These paths are relative to the resources' directory.
76-
*/
77-
'seeders' => [
78-
'actor_attribute_path' => 'stubs/abac/actor_attribute_path.json',
79-
'resource_attribute_path' => 'stubs/abac/resource_attribute_path.json',
80-
'policy_file_path' => 'stubs/abac/abac_policy_file_path.json',
81-
],
82-
8369
'permissions' => [
8470
'resources' => [], // alias => model class
8571
],

database/seeders/ActorAttributeSeeder.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

database/seeders/DatabaseSeeder.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

database/seeders/PolicySeeder.php

Lines changed: 0 additions & 162 deletions
This file was deleted.

database/seeders/ResourceAttributeSeeder.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)