permissions and roles added

This commit is contained in:
Benjamin Takats
2022-11-30 16:28:01 +01:00
parent e8edd349f2
commit 7767482f4d
14 changed files with 516 additions and 21 deletions

View File

@@ -8,16 +8,16 @@ created:
- database/factories/VenueFactory.php - database/factories/VenueFactory.php
- database/factories/EventFactory.php - database/factories/EventFactory.php
- database/factories/RegistrationFactory.php - database/factories/RegistrationFactory.php
- database/migrations/2022_11_30_135656_create_countries_table.php - database/migrations/2022_11_30_152002_create_countries_table.php
- database/migrations/2022_11_30_135657_create_cities_table.php - database/migrations/2022_11_30_152003_create_cities_table.php
- database/migrations/2022_11_30_135658_create_lecturers_table.php - database/migrations/2022_11_30_152004_create_lecturers_table.php
- database/migrations/2022_11_30_135659_create_participants_table.php - database/migrations/2022_11_30_152005_create_participants_table.php
- database/migrations/2022_11_30_135700_create_categories_table.php - database/migrations/2022_11_30_152006_create_categories_table.php
- database/migrations/2022_11_30_135701_create_courses_table.php - database/migrations/2022_11_30_152007_create_courses_table.php
- database/migrations/2022_11_30_135702_create_venues_table.php - database/migrations/2022_11_30_152008_create_venues_table.php
- database/migrations/2022_11_30_135703_create_events_table.php - database/migrations/2022_11_30_152009_create_events_table.php
- database/migrations/2022_11_30_135704_create_registrations_table.php - database/migrations/2022_11_30_152010_create_registrations_table.php
- database/migrations/2022_11_30_135705_create_category_course_table.php - database/migrations/2022_11_30_152011_create_category_course_table.php
- app/Models/Country.php - app/Models/Country.php
- app/Models/City.php - app/Models/City.php
- app/Models/Lecturer.php - app/Models/Lecturer.php

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Spatie\Permission\Models\Permission;
class PermissionPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(User $user)
{
return true;
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Permission $permission
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, Permission $permission)
{
//
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
//
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Permission $permission
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, Permission $permission)
{
//
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Permission $permission
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(User $user, Permission $permission)
{
//
}
/**
* Determine whether the user can restore the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Permission $permission
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(User $user, Permission $permission)
{
//
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Permission $permission
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(User $user, Permission $permission)
{
//
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Spatie\Permission\Models\Role;
class RolePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(User $user)
{
return true;
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Role $role
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, Role $role)
{
//
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
//
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Role $role
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, Role $role)
{
//
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Role $role
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(User $user, Role $role)
{
//
}
/**
* Determine whether the user can restore the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Role $role
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(User $user, Role $role)
{
//
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\User $user
* @param \Spatie\Permission\Models\Role $role
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(User $user, Role $role)
{
//
}
}

View File

@@ -3,23 +3,27 @@
namespace App\Providers; namespace App\Providers;
use App\Models\Team; use App\Models\Team;
use App\Policies\PermissionPolicy;
use App\Policies\RolePolicy;
use App\Policies\TeamPolicy; use App\Policies\TeamPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class AuthServiceProvider extends ServiceProvider class AuthServiceProvider extends ServiceProvider
{ {
/** /**
* The policy mappings for the application. * The policy mappings for the application.
*
* @var array * @var array
*/ */
protected $policies = [ protected $policies = [
Team::class => TeamPolicy::class, Team::class => TeamPolicy::class,
Role::class => RolePolicy::class,
Permission::class => PermissionPolicy::class,
]; ];
/** /**
* Register any authentication / authorization services. * Register any authentication / authorization services.
*
* @return void * @return void
*/ */
public function boot() public function boot()

View File

@@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Itsmejoshua\Novaspatiepermissions\Novaspatiepermissions;
use Laravel\Nova\Nova; use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider; use Laravel\Nova\NovaApplicationServiceProvider;
@@ -38,7 +39,9 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
*/ */
public function tools() public function tools()
{ {
return []; return [
Novaspatiepermissions::make(),
];
} }
/** /**

View File

@@ -10,6 +10,7 @@
"require": { "require": {
"php": "^8.1", "php": "^8.1",
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"itsmejoshua/novaspatiepermissions": "^1.0",
"laravel/framework": "^9.19", "laravel/framework": "^9.19",
"laravel/jetstream": "^2.12", "laravel/jetstream": "^2.12",
"laravel/nova": "~4.0", "laravel/nova": "~4.0",

134
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "06518b5d3d774a669c86ea4b334482a0", "content-hash": "d24618febd9e2bd450aeeb6d229e565c",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@@ -1463,6 +1463,56 @@
], ],
"time": "2022-11-08T12:44:02+00:00" "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", "name": "jaybizzle/crawler-detect",
"version": "v1.2.112", "version": "v1.2.112",
@@ -4507,6 +4557,88 @@
], ],
"time": "2022-11-15T09:10:09+00:00" "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", "name": "spatie/laravel-sluggable",
"version": "3.4.0", "version": "3.4.0",

View File

@@ -103,6 +103,7 @@ return [
HandleInertiaRequests::class, HandleInertiaRequests::class,
DispatchServingNovaEvent::class, DispatchServingNovaEvent::class,
BootTools::class, BootTools::class,
\Itsmejoshua\Novaspatiepermissions\ForgetCachedPermissions::class,
], ],
'api_middleware' => [ 'api_middleware' => [

161
config/permission.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
return [
'models' => [
/*
* 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',
],
];

View File

@@ -16,6 +16,7 @@ use App\Models\User;
use App\Models\Venue; use App\Models\Venue;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Spatie\Permission\Models\Role;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
@@ -25,6 +26,10 @@ class DatabaseSeeder extends Seeder
*/ */
public function run() public function run()
{ {
Role::create([
'name' => 'super-admin',
'guard_name' => 'web',
]);
$user = User::create([ $user = User::create([
'name' => 'Admin', 'name' => 'Admin',
'email' => 'admin@einundzwanzig.space', 'email' => 'admin@einundzwanzig.space',

View File

@@ -17,7 +17,7 @@
</head> </head>
<body class="font-sans antialiased bg-21gray dark"> <body class="font-sans antialiased bg-21gray dark">
<x-jet-banner /> <x-jet-banner />
<div class="min-h-screen bg-white"> <div class="min-h-screen">
@livewire('navigation-menu') @livewire('navigation-menu')
<!-- Page Heading --> <!-- Page Heading -->
@if (isset($header)) @if (isset($header))

View File

@@ -96,7 +96,7 @@
</div> </div>
</section> </section>
{{-- FOOTER --}} {{-- FOOTER --}}
<section class="py-10 bg-gray-900"> <section class="sticky bottom-0 py-10 bg-gray-900">
<div class="px-10 mx-auto max-w-7xl"> <div class="px-10 mx-auto max-w-7xl">
<div class="flex flex-col items-center md:flex-row md:justify-between"> <div class="flex flex-col items-center md:flex-row md:justify-between">
<a href="#_"> <a href="#_">

View File

@@ -1,4 +1,4 @@
<nav x-data="{ open: false }" class="border-b border-gray-100"> <nav x-data="{ open: false }" class="border-b border-gray-100 bg-white">
<!-- Primary Navigation Menu --> <!-- Primary Navigation Menu -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16"> <div class="flex justify-between h-16">
@@ -19,7 +19,7 @@
{{ __('Mein Profil') }} {{ __('Mein Profil') }}
</x-jet-nav-link> </x-jet-nav-link>
<x-jet-nav-link href="{{ route('welcome') }}" :active="request()->routeIs('welcome')"> <x-jet-nav-link href="{{ route('welcome') }}" :active="request()->routeIs('welcome')">
{{ __('Mein Profil') }} {{ __('Meine Termine') }}
</x-jet-nav-link> </x-jet-nav-link>
</div> </div>
</div> </div>

View File

@@ -1,8 +1,8 @@
<div class="md:col-span-1 flex justify-between"> <div class="md:col-span-1 flex justify-between">
<div class="px-4 sm:px-0"> <div class="px-4 sm:px-0">
<h3 class="text-lg font-medium text-gray-900">{{ $title }}</h3> <h3 class="text-lg font-medium text-gray-200">{{ $title }}</h3>
<p class="mt-1 text-sm text-gray-600"> <p class="mt-1 text-sm text-gray-200">
{{ $description }} {{ $description }}
</p> </p>
</div> </div>