Skip to content

Commit

Permalink
Merge branch 'dev' into feature/button-and-input
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrinsieboy committed Dec 14, 2023
2 parents 5663cb2 + 7cb2437 commit c06b3f8
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 3 deletions.
93 changes: 93 additions & 0 deletions src/app/Enums/Permissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Enums;

enum Permissions: string
{
// ACTIONS
case BORROW = 'borrow';
case RESERVE = 'reserve';
case RETURN = 'return';
case LOGIN_MANAGE = 'login_manage';

// LIBRARY PASSES
case VIEW_LIBRARY_PASS = 'view_library_pass';
case CREATE_LIBRARY_PASS = 'create_library_pass';
case EDIT_LIBRARY_PASS = 'edit_library_pass';
case DELETE_LIBRARY_PASS = 'delete_library_pass';

// ITEMS
case VIEW_ITEM = 'view_item';
case CREATE_ITEM = 'create_item';
case EDIT_ITEM = 'edit_item';
case DELETE_ITEM = 'delete_item';

// USERS
case VIEW_USER = 'view_user';
case CREATE_USER = 'create_user';
case EDIT_USER = 'edit_user';
case DELETE_USER = 'delete_user';

// GRANTS
case VIEW_GRANT = 'view_grant';
case CREATE_GRANT = 'create_grant';
case EDIT_GRANT = 'edit_grant';
case DELETE_GRANT = 'delete_grant';

// RESERVATIONS
case VIEW_RESERVATION = 'view_reservation';
case CREATE_RESERVATION = 'create_reservation';
case EDIT_RESERVATION = 'edit_reservation';
case DELETE_RESERVATION = 'delete_reservation';

// PAYMENTS
case VIEW_PAYMENT = 'view_payment';
case CREATE_PAYMENT = 'create_payment';
case EDIT_PAYMENT = 'edit_payment';

// FINES
case VIEW_FINE = 'view_fine';
CASE EDIT_FINE = 'manage_fine';

public function label(): string
{
return match ($this) {

static::BORROW => 'Borrow',
static::RESERVE => 'Reserve',
static::RETURN => 'Return',
static::LOGIN_MANAGE => 'Login Manage',

static::VIEW_LIBRARY_PASS => 'View Library Pass',
static::CREATE_LIBRARY_PASS => 'Create Library Pass',
static::EDIT_LIBRARY_PASS => 'Edit Library Pass',
static::DELETE_LIBRARY_PASS => 'Delete Library Pass',

static::VIEW_ITEM => 'View Item',
static::CREATE_ITEM => 'Create Item',
static::EDIT_ITEM => 'Edit Item',
static::DELETE_ITEM => 'Delete Item',

static::VIEW_USER => 'View User',
static::CREATE_USER => 'Create User',
static::DELETE_USER => 'Delete User',

static::VIEW_GRANT => 'View Grant',
static::CREATE_GRANT => 'Create Grant',
static::EDIT_GRANT => 'Edit Grant',
static::DELETE_GRANT => 'Delete Grant',

static::VIEW_RESERVATION => 'View Reservation',
static::CREATE_RESERVATION => 'Create Reservation',
static::EDIT_RESERVATION => 'Edit Reservation',
static::DELETE_RESERVATION => 'Delete Reservation',

static::VIEW_PAYMENT => 'View Payment',
static::CREATE_PAYMENT => 'Create Payment',
static::EDIT_PAYMENT => 'Edit Payment',

static::VIEW_FINE => 'View Fine',
static::EDIT_FINE => 'Manage Fine',
};
}
}
19 changes: 19 additions & 0 deletions src/app/Enums/Roles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Enums;

enum Roles: string
{
case SUPERADMIN = 'super_admin';
case COLLEAGUE = 'colleague';
case CUSTOMER = 'customer';

public function label(): string
{
return match ($this) {
static::SUPERADMIN => 'Super Admin',
static::COLLEAGUE => 'Colleague',
static::CUSTOMER => 'Customer',
};
}
}
8 changes: 6 additions & 2 deletions src/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Providers;

// use Illuminate\Support\Facades\Gate;
use App\Enums\Roles;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
Expand All @@ -21,6 +22,9 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot(): void
{
//
// Implicitly grant "Super Admin" role all permissions
Gate::before(function ($user, $ability) {
return $user->hasRole(Roles::SUPERADMIN) ? true : null;
});
}
}
104 changes: 104 additions & 0 deletions src/database/seeders/PermissionSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Database\Seeders;

use App\Enums\Permissions;
use App\Enums\Roles;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class PermissionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Create all roles
$superAdmin = Role::create(['name' => Roles::SUPERADMIN]);
$colleague = Role::create(['name' => Roles::COLLEAGUE]);
$customer = Role::create(['name' => Roles::CUSTOMER]);

// Create all permissions

$borrow = Permission::create(['name' => Permissions::BORROW]);
$reserve = Permission::create(['name' => Permissions::RESERVE]);
$return = Permission::create(['name' => Permissions::RETURN]);
$loginManage = Permission::create(['name' => Permissions::LOGIN_MANAGE]);

$viewLibraryPass = Permission::create(['name' => Permissions::VIEW_LIBRARY_PASS]);
$createLibraryPass = Permission::create(['name' => Permissions::CREATE_LIBRARY_PASS]);
$editLibraryPass = Permission::create(['name' => Permissions::EDIT_LIBRARY_PASS]);
$deleteLibraryPass = Permission::create(['name' => Permissions::DELETE_LIBRARY_PASS]);

$viewItem = Permission::create(['name' => Permissions::VIEW_ITEM]);
$createItem = Permission::create(['name' => Permissions::CREATE_ITEM]);
$editItem = Permission::create(['name' => Permissions::EDIT_ITEM]);
$deleteItem = Permission::create(['name' => Permissions::DELETE_ITEM]);

$viewUser = Permission::create(['name' => Permissions::VIEW_USER]);
$createUser = Permission::create(['name' => Permissions::CREATE_USER]);
$editUser = Permission::create(['name' => Permissions::EDIT_USER]);
$deleteUser = Permission::create(['name' => Permissions::DELETE_USER]);

$viewGrant = Permission::create(['name' => Permissions::VIEW_GRANT]);
$createGrant = Permission::create(['name' => Permissions::CREATE_GRANT]);
$editGrant = Permission::create(['name' => Permissions::EDIT_GRANT]);
$deleteGrant = Permission::create(['name' => Permissions::DELETE_GRANT]);

$viewReservation = Permission::create(['name' => Permissions::VIEW_RESERVATION]);
$createReservation = Permission::create(['name' => Permissions::CREATE_RESERVATION]);
$editReservation = Permission::create(['name' => Permissions::EDIT_RESERVATION]);
$deleteReservation = Permission::create(['name' => Permissions::DELETE_RESERVATION]);

$viewPayment = Permission::create(['name' => Permissions::VIEW_PAYMENT]);
$createPayment = Permission::create(['name' => Permissions::CREATE_PAYMENT]);
$editPayment = Permission::create(['name' => Permissions::EDIT_PAYMENT]);

$viewFine = Permission::create(['name' => Permissions::VIEW_FINE]);
$editFine = Permission::create(['name' => Permissions::EDIT_FINE]);



// -- CUSTOMER
$customer->givePermissionTo($borrow);
$customer->givePermissionTo($reserve);
$customer->givePermissionTo($return);

// -- COLLEAGUE
$colleague->givePermissionTo($borrow);
$colleague->givePermissionTo($reserve);
$colleague->givePermissionTo($return);
$colleague->givePermissionTo($loginManage);

$colleague->givePermissionTo($viewLibraryPass);
$colleague->givePermissionTo($createLibraryPass);
$colleague->givePermissionTo($editLibraryPass);
$colleague->givePermissionTo($deleteLibraryPass);

$colleague->givePermissionTo($viewItem);
$colleague->givePermissionTo($createItem);
$colleague->givePermissionTo($editItem);
$colleague->givePermissionTo($deleteItem);

$colleague->givePermissionTo($viewUser);
$colleague->givePermissionTo($createUser);
$colleague->givePermissionTo($editUser);
$colleague->givePermissionTo($deleteUser);

$colleague->givePermissionTo($viewGrant);
$colleague->givePermissionTo($createGrant);
$colleague->givePermissionTo($editGrant);
$colleague->givePermissionTo($deleteGrant);

$colleague->givePermissionTo($viewReservation);
$colleague->givePermissionTo($createReservation);
$colleague->givePermissionTo($editReservation);
$colleague->givePermissionTo($deleteReservation);

$colleague->givePermissionTo($viewPayment);
$colleague->givePermissionTo($viewFine);
}
}
Loading

0 comments on commit c06b3f8

Please sign in to comment.