Skip to content

Commit f999094

Browse files
committed
permission package, remove user-session migration
1 parent a0d892e commit f999094

24 files changed

Lines changed: 316 additions & 1073 deletions

packages/full/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"moox/notifications": "dev-main",
6565
"moox/packagist": "dev-main",
6666
"moox/page": "dev-main",
67+
"moox/permission": "dev-main",
6768
"moox/post": "dev-main",
6869
"moox/press": "dev-main",
6970
"moox/press-trainings": "dev-main",

packages/permission/README.md

Lines changed: 13 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2,152 +2,32 @@
22

33
# Moox Permission
44

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.
66

7-
## Quick Installation
8-
9-
These two commmands are all you need to install the package:
7+
## Installation
108

119
```bash
1210
composer require moox/permission
13-
php artisan mooxpermission:install
11+
php artisan moox:install
1412
```
1513

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`).
6615

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.
13917

140-
## Changelog
18+
## Optional permissions
14119

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`:
14321

144-
## Security Vulnerabilities
22+
- Shield not installed / tables missing → allow
23+
- Permission not generated yet → allow
24+
- Permission exists → check `can()`
14525

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.
14727

148-
## Credits
28+
## Default Policy
14929

150-
- [All Contributors](../../contributors)
30+
`Moox\Permission\Policies\DefaultPolicy` is the shared fallback for Moox resources when no dedicated policy exists.
15131

15232
## License
15333

packages/permission/composer.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "moox/permission",
3-
"description": "This is my package permission",
3+
"description": "Moox layer for Filament Shield and shared authorization defaults.",
44
"keywords": [
55
"Laravel",
66
"Filament",
7-
"Filament plugin",
8-
"Laravel package"
7+
"permissions",
8+
"roles",
9+
"shield"
910
],
1011
"homepage": "https://moox.org/",
1112
"license": "MIT",
@@ -18,7 +19,7 @@
1819
],
1920
"require": {
2021
"moox/core": "dev-main",
21-
"spatie/laravel-permission": "^7.0"
22+
"bezhansalleh/filament-shield": "^4.0"
2223
},
2324
"require-dev": {
2425
"moox/devtools": "dev-main"
@@ -35,9 +36,14 @@
3536
]
3637
},
3738
"moox": {
38-
"stability": "stable"
39+
"stability": "stable",
40+
"install": {
41+
"plugins": [
42+
"BezhanSalleh\\FilamentShield\\FilamentShieldPlugin"
43+
]
44+
}
3945
}
4046
},
4147
"minimum-stability": "stable",
4248
"prefer-stable": true
43-
}
49+
}

0 commit comments

Comments
 (0)