12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
66
app/Policies/ContactPolicy.php
Normal file
66
app/Policies/ContactPolicy.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Models\User;
|
||||
|
||||
class ContactPolicy
|
||||
{
|
||||
public function before(User $user): ?bool
|
||||
{
|
||||
return $user->is_super_admin ? true : null;
|
||||
}
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->canAccessCustomer();
|
||||
}
|
||||
|
||||
public function view(User $user, Contact $contact): bool
|
||||
{
|
||||
if ($user->canAccessAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->sharesCompanyWith($user, $contact);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->canAccessCustomer();
|
||||
}
|
||||
|
||||
public function update(User $user, Contact $contact): bool
|
||||
{
|
||||
if ($user->canAccessAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->sharesCompanyWith($user, $contact);
|
||||
}
|
||||
|
||||
public function delete(User $user, Contact $contact): bool
|
||||
{
|
||||
return $user->canAccessAdmin();
|
||||
}
|
||||
|
||||
public function restore(User $user, Contact $contact): bool
|
||||
{
|
||||
return $user->canAccessAdmin();
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Contact $contact): bool
|
||||
{
|
||||
return $user->is_super_admin === true;
|
||||
}
|
||||
|
||||
private function sharesCompanyWith(User $user, Contact $contact): bool
|
||||
{
|
||||
if (blank($contact->company_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->companies()->whereKey($contact->company_id)->exists();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue