diff --git a/.blueprint b/.blueprint index 6d7bf2b5..c005256d 100644 --- a/.blueprint +++ b/.blueprint @@ -8,16 +8,16 @@ created: - database/factories/VenueFactory.php - database/factories/EventFactory.php - database/factories/RegistrationFactory.php - - database/migrations/2022_11_30_135656_create_countries_table.php - - database/migrations/2022_11_30_135657_create_cities_table.php - - database/migrations/2022_11_30_135658_create_lecturers_table.php - - database/migrations/2022_11_30_135659_create_participants_table.php - - database/migrations/2022_11_30_135700_create_categories_table.php - - database/migrations/2022_11_30_135701_create_courses_table.php - - database/migrations/2022_11_30_135702_create_venues_table.php - - database/migrations/2022_11_30_135703_create_events_table.php - - database/migrations/2022_11_30_135704_create_registrations_table.php - - database/migrations/2022_11_30_135705_create_category_course_table.php + - database/migrations/2022_11_30_152002_create_countries_table.php + - database/migrations/2022_11_30_152003_create_cities_table.php + - database/migrations/2022_11_30_152004_create_lecturers_table.php + - database/migrations/2022_11_30_152005_create_participants_table.php + - database/migrations/2022_11_30_152006_create_categories_table.php + - database/migrations/2022_11_30_152007_create_courses_table.php + - database/migrations/2022_11_30_152008_create_venues_table.php + - database/migrations/2022_11_30_152009_create_events_table.php + - database/migrations/2022_11_30_152010_create_registrations_table.php + - database/migrations/2022_11_30_152011_create_category_course_table.php - app/Models/Country.php - app/Models/City.php - app/Models/Lecturer.php diff --git a/app/Policies/PermissionPolicy.php b/app/Policies/PermissionPolicy.php new file mode 100644 index 00000000..f5b993b0 --- /dev/null +++ b/app/Policies/PermissionPolicy.php @@ -0,0 +1,94 @@ + TeamPolicy::class, + Team::class => TeamPolicy::class, + Role::class => RolePolicy::class, + Permission::class => PermissionPolicy::class, ]; /** * Register any authentication / authorization services. - * * @return void */ public function boot() diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index 78606ef6..c5ccc971 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use Illuminate\Support\Facades\Gate; +use Itsmejoshua\Novaspatiepermissions\Novaspatiepermissions; use Laravel\Nova\Nova; use Laravel\Nova\NovaApplicationServiceProvider; @@ -38,7 +39,9 @@ class NovaServiceProvider extends NovaApplicationServiceProvider */ public function tools() { - return []; + return [ + Novaspatiepermissions::make(), + ]; } /** diff --git a/composer.json b/composer.json index 54438be3..6a0839b4 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "require": { "php": "^8.1", "guzzlehttp/guzzle": "^7.2", + "itsmejoshua/novaspatiepermissions": "^1.0", "laravel/framework": "^9.19", "laravel/jetstream": "^2.12", "laravel/nova": "~4.0", diff --git a/composer.lock b/composer.lock index 6db056dd..0f8da301 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "06518b5d3d774a669c86ea4b334482a0", + "content-hash": "d24618febd9e2bd450aeeb6d229e565c", "packages": [ { "name": "bacon/bacon-qr-code", @@ -1463,6 +1463,56 @@ ], "time": "2022-11-08T12:44:02+00:00" }, + { + "name": "itsmejoshua/novaspatiepermissions", + "version": "v1.0.7", + "source": { + "type": "git", + "url": "https://github.com/itsmejoshua/novaspatiepermissions.git", + "reference": "6d665c310586627802a4dd03a36bfd45b05eef33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/itsmejoshua/novaspatiepermissions/zipball/6d665c310586627802a4dd03a36bfd45b05eef33", + "reference": "6d665c310586627802a4dd03a36bfd45b05eef33", + "shasum": "" + }, + "require": { + "laravel/nova": "^4.0", + "php": "^8.0", + "spatie/laravel-permission": "^5.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Itsmejoshua\\Novaspatiepermissions\\ToolServiceProvider", + "Itsmejoshua\\Novaspatiepermissions\\NovaSpatiePermissionsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Itsmejoshua\\Novaspatiepermissions\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Laravel Nova tool for managing spaties roles/permissions in laravel's nova package.", + "keywords": [ + "laravel", + "nova", + "permissions", + "spatie" + ], + "support": { + "issues": "https://github.com/itsmejoshua/novaspatiepermissions/issues", + "source": "https://github.com/itsmejoshua/novaspatiepermissions/tree/v1.0.7" + }, + "time": "2022-05-16T01:34:26+00:00" + }, { "name": "jaybizzle/crawler-detect", "version": "v1.2.112", @@ -4507,6 +4557,88 @@ ], "time": "2022-11-15T09:10:09+00:00" }, + { + "name": "spatie/laravel-permission", + "version": "5.7.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-permission.git", + "reference": "3a9bc00e6d338a9c61f830af654aa5c326407632" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/3a9bc00e6d338a9c61f830af654aa5c326407632", + "reference": "3a9bc00e6d338a9c61f830af654aa5c326407632", + "shasum": "" + }, + "require": { + "illuminate/auth": "^7.0|^8.0|^9.0", + "illuminate/container": "^7.0|^8.0|^9.0", + "illuminate/contracts": "^7.0|^8.0|^9.0", + "illuminate/database": "^7.0|^8.0|^9.0", + "php": "^7.3|^8.0|^8.1" + }, + "require-dev": { + "orchestra/testbench": "^5.0|^6.0|^7.0", + "phpunit/phpunit": "^9.4", + "predis/predis": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Permission\\PermissionServiceProvider" + ] + }, + "branch-alias": { + "dev-main": "5.x-dev", + "dev-master": "5.x-dev" + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\Permission\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Permission handling for Laravel 6.0 and up", + "homepage": "https://github.com/spatie/laravel-permission", + "keywords": [ + "acl", + "laravel", + "permission", + "permissions", + "rbac", + "roles", + "security", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-permission/issues", + "source": "https://github.com/spatie/laravel-permission/tree/5.7.0" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-11-23T07:01:37+00:00" + }, { "name": "spatie/laravel-sluggable", "version": "3.4.0", diff --git a/config/nova.php b/config/nova.php index 0f1930c8..f2743e3a 100644 --- a/config/nova.php +++ b/config/nova.php @@ -103,6 +103,7 @@ return [ HandleInertiaRequests::class, DispatchServingNovaEvent::class, BootTools::class, + \Itsmejoshua\Novaspatiepermissions\ForgetCachedPermissions::class, ], 'api_middleware' => [ diff --git a/config/permission.php b/config/permission.php new file mode 100644 index 00000000..5b6e184c --- /dev/null +++ b/config/permission.php @@ -0,0 +1,161 @@ + [ + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => Spatie\Permission\Models\Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => Spatie\Permission\Models\Role::class, + + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + 'column_names' => [ + /* + * Change this if you want to name the related pivots other than defaults + */ + 'role_pivot_key' => null, //default 'role_id', + 'permission_pivot_key' => null, //default 'permission_id', + + /* + * Change this if you want to name the related model primary key other than + * `model_id`. + * + * For example, this would be nice if your primary keys are all UUIDs. In + * that case, name this `model_uuid`. + */ + + 'model_morph_key' => 'model_id', + + /* + * Change this if you want to use the teams feature and your related model's + * foreign key is other than `team_id`. + */ + + 'team_foreign_key' => 'team_id', + ], + + /* + * When set to true, the method for checking permissions will be registered on the gate. + * Set this to false, if you want to implement custom logic for checking permissions. + */ + + 'register_permission_check_method' => true, + + /* + * When set to true the package implements teams using the 'team_foreign_key'. If you want + * the migrations to register the 'team_foreign_key', you must set this to true + * before doing the migration. If you already did the migration then you must make a new + * migration to also add 'team_foreign_key' to 'roles', 'model_has_roles', and + * 'model_has_permissions'(view the latest version of package's migration file) + */ + + 'teams' => false, + + /* + * When set to true, the required permission names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_permission_in_exception' => false, + + /* + * When set to true, the required role names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_role_in_exception' => false, + + /* + * By default wildcard permission lookups are disabled. + */ + + 'enable_wildcard_permission' => false, + + 'cache' => [ + + /* + * By default all permissions are cached for 24 hours to speed up performance. + * When permissions or roles are updated the cache is flushed automatically. + */ + + 'expiration_time' => \DateInterval::createFromDateString('24 hours'), + + /* + * The cache key used to store all permissions. + */ + + 'key' => 'spatie.permission.cache', + + /* + * You may optionally indicate a specific cache driver to use for permission and + * role caching using any of the `store` drivers listed in the cache.php config + * file. Using 'default' here means to use the `default` set in cache.php. + */ + + 'store' => 'default', + ], +]; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index f41cd714..0059c783 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -16,6 +16,7 @@ use App\Models\User; use App\Models\Venue; use Illuminate\Database\Seeder; use Illuminate\Support\Str; +use Spatie\Permission\Models\Role; class DatabaseSeeder extends Seeder { @@ -25,6 +26,10 @@ class DatabaseSeeder extends Seeder */ public function run() { + Role::create([ + 'name' => 'super-admin', + 'guard_name' => 'web', + ]); $user = User::create([ 'name' => 'Admin', 'email' => 'admin@einundzwanzig.space', diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 77c84365..b93fa9dc 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -17,7 +17,7 @@