Skip to content

Repository files navigation

Moox Permission

Moox Permission

This is my package permission

Quick Installation

These two commmands are all you need to install the package:

composer require moox/permission
php artisan mooxpermission:install

Curious what the install command does? See manual installation below.

What it does

Here are some things missing, like an overview with screenshots about this package, or simply a link to the package's docs.

Manual Installation

Instead of using the install-command php artisan mooxpermission:install you are able to install this package manually step by step:

// Publish and run the migrations:
php artisan vendor:publish --tag="permission-migrations"
php artisan migrate
// Publish the config file with:
php artisan vendor:publish --tag="permission-config"

Using the Default Policy

The default policy handles all defaults for Moox Resources in Filament:

<?phpnamespaceMoox\Permission\Policies;
useApp\Models\User;
class DefaultPolicy
{
publicfunctionviewAll(User$user)
{
return$user->hasPermissionTo('view all');
}
publicfunctioneditAll(User$user)
{
return$user->hasPermissionTo('edit all');
}
publicfunctiondeleteAll(User$user)
{
return$user->hasPermissionTo('delete all');
}
publicfunctioncreate(User$user)
{
return$user->hasPermissionTo('create');
}
publicfunctionviewOwn(User$user, $model)
{
return$user->hasPermissionTo('view own') && $model->user_id === $user->id;
}
publicfunctioneditOwn(User$user, $model)
{
return$user->hasPermissionTo('edit own') && $model->user_id === $user->id;
}
publicfunctiondeleteOwn(User$user, $model)
{
return$user->hasPermissionTo('delete own') && $model->user_id === $user->id;
}
publicfunctionemptyTrash(User$user)
{
return$user->hasPermissionTo('empty trash');
}
publicfunctionchangeSettings(User$user)
{
return$user->hasPermissionTo('change settings');
}
}

The default policy is used by most Moox packages.

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.

Extending the Default Policy

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.

useMoox\Permission\Policies\DefaultPolicy;
class ItemPolicy extends DefaultPolicy
{
// Custom logic for editing own itemspublicfunctioneditOwn(User$user, $item)
{
// Maybe add additional checks herereturnparent::editOwn($user, $item);
}
// Additional custom methods if needed
}

You then need to register the policy in the published Moox Core config (/config/core.php):

return [
'packages' => [
'audit' => [
'package' => 'Moox Audit',
'models' => [
'Audit' => [
'policy' => \Moox\Audit\Policies\AuditPolicy::class,
],
],
],
// more packages

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Roles and Permissions for Filament, Moox and Laravel

Topics

Resources

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

Generated from mooxphp/builder