Skip to content

Commit

Permalink
activity policy
Browse files Browse the repository at this point in the history
  • Loading branch information
fzldn committed Sep 17, 2024
1 parent ededf40 commit 4d08590
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Enums/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum Permission: string
case ROLES_DETACH = 'roles.detach';
case ROLES_DETACHANY = 'roles.detachAny';

case ACTIVITIES_VIEWANY = 'activities.viewAny';

public function label(): string
{
return match ($this) {
Expand All @@ -41,6 +43,8 @@ public function label(): string
self::ROLES_DETACH => __('Detach Role'),
self::ROLES_DETACHANY => __('Detach Any Roles'),

self::ACTIVITIES_VIEWANY => __('View Any Activities'),

default => $this->value,
};
}
Expand Down
75 changes: 75 additions & 0 deletions app/Policies/ActivityPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Policies;

use App\Enums\Permission;
use App\Models\Activity;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class ActivityPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->can(Permission::ACTIVITIES_VIEWANY->value);
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Activity $activity): bool
{
return true;
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, Activity $activity): bool
{
return true;
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Activity $activity): bool
{
return true;
}

/**
* Determine whether the user can delete models.
*/
public function deleteAny(User $user): bool
{
return true;
}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Activity $activity): bool
{
return true;
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Activity $activity): bool
{
return true;
}
}

0 comments on commit 4d08590

Please sign in to comment.