|
2 | 2 |
|
3 | 3 | # Moox Permission |
4 | 4 |
|
5 | | -This is my package permission |
| 5 | +Moox Permission is a thin layer around [Filament Shield](https://github.com/bezhanSalleh/filament-shield). It pulls in Shield via Composer and provides the shared `DefaultPolicy` used across Moox packages. |
6 | 6 |
|
7 | | -## Quick Installation |
8 | | - |
9 | | -These two commmands are all you need to install the package: |
| 7 | +## Installation |
10 | 8 |
|
11 | 9 | ```bash |
12 | 10 | composer require moox/permission |
13 | | -php artisan mooxpermission:install |
| 11 | +php artisan moox:install |
14 | 12 | ``` |
15 | 13 |
|
16 | | -Curious what the install command does? See manual installation below. |
17 | | - |
18 | | -## What it does |
19 | | - |
20 | | -<!--whatdoes--> |
21 | | - |
22 | | -Here are some things missing, like an overview with screenshots about this package, or simply a link to the package's docs. |
23 | | - |
24 | | -<!--/whatdoes--> |
25 | | - |
26 | | -## Manual Installation |
27 | | - |
28 | | -Instead of using the install-command `php artisan mooxpermission:install` you are able to install this package manually step by step: |
29 | | - |
30 | | -```bash |
31 | | -// Publish and run the migrations: |
32 | | -php artisan vendor:publish --provider="Moox\Permission\PermissionServiceProvider" --tag="moox-permission-migrations" |
33 | | -php artisan migrate |
34 | | - |
35 | | -// Publish the config file with: |
36 | | -php artisan vendor:publish --provider="Moox\Permission\PermissionServiceProvider" --tag="moox-permission-config" |
37 | | -``` |
38 | | - |
39 | | -## Using the Default Policy |
40 | | - |
41 | | -The default policy handles all defaults for Moox Resources in Filament: |
42 | | - |
43 | | -```php |
44 | | -<?php |
45 | | - |
46 | | -namespace Moox\Permission\Policies; |
47 | | - |
48 | | -use App\Models\User; |
49 | | - |
50 | | -class DefaultPolicy |
51 | | -{ |
52 | | - public function viewAll(User $user) |
53 | | - { |
54 | | - return $user->hasPermissionTo('view all'); |
55 | | - } |
56 | | - |
57 | | - public function editAll(User $user) |
58 | | - { |
59 | | - return $user->hasPermissionTo('edit all'); |
60 | | - } |
61 | | - |
62 | | - public function deleteAll(User $user) |
63 | | - { |
64 | | - return $user->hasPermissionTo('delete all'); |
65 | | - } |
| 14 | +The installer publishes Shield/Spatie configuration, runs the permission migrations, and registers `FilamentShieldPlugin` in your panel (via `composer.json` → `extra.moox.install.plugins`). |
66 | 15 |
|
67 | | - public function create(User $user) |
68 | | - { |
69 | | - return $user->hasPermissionTo('create'); |
70 | | - } |
71 | | - |
72 | | - public function viewOwn(User $user, $model) |
73 | | - { |
74 | | - return $user->hasPermissionTo('view own') && $model->user_id === $user->id; |
75 | | - } |
76 | | - |
77 | | - public function editOwn(User $user, $model) |
78 | | - { |
79 | | - return $user->hasPermissionTo('edit own') && $model->user_id === $user->id; |
80 | | - } |
81 | | - |
82 | | - public function deleteOwn(User $user, $model) |
83 | | - { |
84 | | - return $user->hasPermissionTo('delete own') && $model->user_id === $user->id; |
85 | | - } |
86 | | - |
87 | | - public function emptyTrash(User $user) |
88 | | - { |
89 | | - return $user->hasPermissionTo('empty trash'); |
90 | | - } |
91 | | - |
92 | | - public function changeSettings(User $user) |
93 | | - { |
94 | | - return $user->hasPermissionTo('change settings'); |
95 | | - } |
96 | | -} |
97 | | -``` |
98 | | - |
99 | | -The default policy is used by most Moox packages. |
100 | | - |
101 | | -If you use Moox Builder to create a package, the default policy works out of the box and all default permissions are pre-configured to sane defaults. |
102 | | - |
103 | | -## Extending the Default Policy |
104 | | - |
105 | | -If you need to create a policy for a specific resource, you can extend the DefaultPolicy and override any methods where custom logic is required. |
106 | | - |
107 | | -```php |
108 | | -use Moox\Permission\Policies\DefaultPolicy; |
109 | | - |
110 | | -class ItemPolicy extends DefaultPolicy |
111 | | -{ |
112 | | - // Custom logic for editing own items |
113 | | - public function editOwn(User $user, $item) |
114 | | - { |
115 | | - // Maybe add additional checks here |
116 | | - return parent::editOwn($user, $item); |
117 | | - } |
118 | | - |
119 | | - // Additional custom methods if needed |
120 | | -} |
121 | | - |
122 | | -``` |
123 | | - |
124 | | -You then need to register the policy in the published Moox Core config (/config/core.php): |
125 | | - |
126 | | -```php |
127 | | -return [ |
128 | | - 'packages' => [ |
129 | | - 'audit' => [ |
130 | | - 'package' => 'Moox Audit', |
131 | | - 'models' => [ |
132 | | - 'Audit' => [ |
133 | | - 'policy' => \Moox\Audit\Policies\AuditPolicy::class, |
134 | | - ], |
135 | | - ], |
136 | | - ], |
137 | | - // more packages |
138 | | -``` |
| 16 | +Shield-specific setup (`shield:generate`, roles, super admin) stays in Shield itself — not in this package. |
139 | 17 |
|
140 | | -## Changelog |
| 18 | +## Optional permissions |
141 | 19 |
|
142 | | -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 20 | +Moox policies follow the same pattern as `HasRolesTrait` in `moox/user`: |
143 | 21 |
|
144 | | -## Security Vulnerabilities |
| 22 | +- Shield not installed / tables missing → allow |
| 23 | +- Permission not generated yet → allow |
| 24 | +- Permission exists → check `can()` |
145 | 25 |
|
146 | | -Please review [our security policy](https://github.com/mooxphp/moox/security/policy) on how to report security vulnerabilities. |
| 26 | +That way resources stay usable after install until you explicitly generate and assign permissions. |
147 | 27 |
|
148 | | -## Credits |
| 28 | +## Default Policy |
149 | 29 |
|
150 | | -- [All Contributors](../../contributors) |
| 30 | +`Moox\Permission\Policies\DefaultPolicy` is the shared fallback for Moox resources when no dedicated policy exists. |
151 | 31 |
|
152 | 32 | ## License |
153 | 33 |
|
|
0 commit comments