Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIDAPP-374]: Refactor all product administration permissions to a single permission #346

Merged
merged 24 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e0c737d
Start to setup People Administration
Orrison Dec 6, 2024
2b88f4d
Move items in UserManagement to their own top level navigation
Orrison Dec 9, 2024
f2ebc6a
Fix permissions of Contact Status
Orrison Dec 9, 2024
7b36765
Fix permissions of Contact Source
Orrison Dec 9, 2024
418c185
Update permissions for OrganizationType
Orrison Dec 9, 2024
6c80ccf
Fix permissions of OrganizationIndustry
Orrison Dec 9, 2024
9d56352
Fix permissions in OrganizationIndustryPolicy to use getKey() for abi…
Orrison Dec 9, 2024
7e750b7
Fix permissions in OrganizationTypePolicy to use getKey() for ability…
Orrison Dec 9, 2024
7ee00b7
Fix permissions in ContactSourcePolicy to use getKey() for ability ch…
Orrison Dec 9, 2024
ed3ccd4
Fix permissions in ContactStatusPolicy to use getKey() for ability ch…
Orrison Dec 9, 2024
f99ad9d
Refactor permissions in ServiceRequestTypePolicy to use product_admin…
Orrison Dec 9, 2024
9dcfa29
Refactor permissions in ServiceRequestStatusPolicy to use product_adm…
Orrison Dec 9, 2024
e24e5d8
Refactor permissions in ServiceRequestFormPolicy to use product_admin…
Orrison Dec 9, 2024
210ad43
Refactor permissions in SlaPolicy to use product_admin abilities
Orrison Dec 9, 2024
926125b
Refactor permissions in KnowledgeBaseCategoryPolicy to use product_ad…
Orrison Dec 9, 2024
90ed3c8
Refactor permissions in KnowledgeBaseQualityPolicy to use product_adm…
Orrison Dec 9, 2024
238cc5b
Refactor permissions in KnowledgeBaseStatusPolicy to use product_admi…
Orrison Dec 9, 2024
3c5af29
Refactor permissions in TagPolicy to use product_admin abilities
Orrison Dec 9, 2024
0425879
Refactor permissions in PronounsPolicy to use product_admin abilities
Orrison Dec 9, 2024
593f434
Refactor permissions in NotificationSettingPolicy to use product_admi…
Orrison Dec 9, 2024
cb8b1d4
Refactor permissions in EmailTemplatePolicy to use product_admin abil…
Orrison Dec 9, 2024
478db0a
Refactor permissions in SmsTemplatePolicy to use product_admin abilities
Orrison Dec 9, 2024
2729a6a
Add migration to delete unused product administration permissions
Orrison Dec 9, 2024
6c89e77
chore: fix enforcement of copyright on all files
Orrison Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\TextInput;
use App\Filament\Clusters\UserManagement;
use App\Filament\Tables\Columns\IdColumn;
use AidingApp\Authorization\Models\Permission;
use AidingApp\Authorization\Filament\Resources\PermissionResource\Pages\ViewPermission;
Expand All @@ -53,9 +52,7 @@ class PermissionResource extends Resource
{
protected static ?string $model = Permission::class;

protected static ?string $navigationIcon = 'heroicon-o-key';

protected static ?string $cluster = UserManagement::class;
protected static ?string $navigationGroup = 'People Administration';

protected static ?int $navigationSort = 40;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

use Filament\Resources\Resource;
use AidingApp\Authorization\Models\Role;
use App\Filament\Clusters\UserManagement;
use Illuminate\Database\Eloquent\Builder;
use AidingApp\Authorization\Filament\Resources\RoleResource\Pages\EditRole;
use AidingApp\Authorization\Filament\Resources\RoleResource\Pages\ViewRole;
Expand All @@ -50,9 +49,7 @@ class RoleResource extends Resource
{
protected static ?string $model = Role::class;

protected static ?string $navigationIcon = 'heroicon-o-shield-check';

protected static ?string $cluster = UserManagement::class;
protected static ?string $navigationGroup = 'People Administration';

protected static ?int $navigationSort = 30;

Expand Down
14 changes: 7 additions & 7 deletions app-modules/contact/src/Policies/ContactSourcePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,55 @@ public function before(Authenticatable $authenticatable): ?Response
public function viewAny(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'contact_source.view-any',
abilities: 'product_admin.view-any',
denyResponse: 'You do not have permission to view contact sources.'
);
}

public function view(Authenticatable $authenticatable, ContactSource $contactSource): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_source.*.view', "contact_source.{$contactSource->id}.view"],
abilities: ["product_admin.{$contactSource->getKey()}.view"],
denyResponse: 'You do not have permission to view this contact source.'
);
}

public function create(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'contact_source.create',
abilities: 'product_admin.create',
denyResponse: 'You do not have permission to create contact sources.'
);
}

public function update(Authenticatable $authenticatable, ContactSource $contactSource): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_source.*.update', "contact_source.{$contactSource->id}.update"],
abilities: ["product_admin.{$contactSource->getKey()}.update"],
denyResponse: 'You do not have permission to update this contact source.'
);
}

public function delete(Authenticatable $authenticatable, ContactSource $contactSource): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_source.*.delete', "contact_source.{$contactSource->id}.delete"],
abilities: ["product_admin.{$contactSource->getKey()}.delete"],
denyResponse: 'You do not have permission to delete this contact source.'
);
}

public function restore(Authenticatable $authenticatable, ContactSource $contactSource): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_source.*.restore', "contact_source.{$contactSource->id}.restore"],
abilities: ["product_admin.{$contactSource->getKey()}.restore"],
denyResponse: 'You do not have permission to restore this contact source.'
);
}

public function forceDelete(Authenticatable $authenticatable, ContactSource $contactSource): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_source.*.force-delete', "contact_source.{$contactSource->id}.force-delete"],
abilities: ["product_admin.{$contactSource->getKey()}.force-delete"],
denyResponse: 'You do not have permission to force delete this contact source.'
);
}
Expand Down
14 changes: 7 additions & 7 deletions app-modules/contact/src/Policies/ContactStatusPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,55 @@ public function before(Authenticatable $authenticatable): ?Response
public function viewAny(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'contact_status.view-any',
abilities: 'product_admin.view-any',
denyResponse: 'You do not have permission to view contact statuses.'
);
}

public function view(Authenticatable $authenticatable, ContactStatus $contactStatus): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_status.*.view', "contact_status.{$contactStatus->id}.view"],
abilities: ["product_admin.{$contactStatus->getKey()}.view"],
denyResponse: 'You do not have permission to view contact statuses.'
);
}

public function create(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'contact_status.create',
abilities: 'product_admin.create',
denyResponse: 'You do not have permission to create contact statuses.'
);
}

public function update(Authenticatable $authenticatable, ContactStatus $contactStatus): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_status.*.update', "contact_status.{$contactStatus->id}.update"],
abilities: ["product_admin.{$contactStatus->getKey()}.update"],
denyResponse: 'You do not have permission to update contact statuses.'
);
}

public function delete(Authenticatable $authenticatable, ContactStatus $contactStatus): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_status.*.delete', "contact_status.{$contactStatus->id}.delete"],
abilities: ["product_admin.{$contactStatus->getKey()}.delete"],
denyResponse: 'You do not have permission to delete contact statuses.'
);
}

public function restore(Authenticatable $authenticatable, ContactStatus $contactStatus): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_status.*.restore', "contact_status.{$contactStatus->id}.restore"],
abilities: ["product_admin.{$contactStatus->getKey()}.restore"],
denyResponse: 'You do not have permission to restore contact statuses.'
);
}

public function forceDelete(Authenticatable $authenticatable, ContactStatus $contactStatus): Response
{
return $authenticatable->canOrElse(
abilities: ['contact_status.*.force-delete', "contact_status.{$contactStatus->id}.force-delete"],
abilities: ["product_admin.{$contactStatus->getKey()}.force-delete"],
denyResponse: 'You do not have permission to force delete contact statuses.'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,55 @@ public function before(Authenticatable $authenticatable): ?Response
public function viewAny(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'organization_industry.view-any',
abilities: 'product_admin.view-any',
denyResponse: 'You do not have permission to view organization industries.'
);
}

public function view(Authenticatable $authenticatable, OrganizationIndustry $organizationIndustry): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_industry.*.view', "organization_industry.{ {$organizationIndustry->id}}.view"],
denyResponse: 'You do not have permission to view this organization industries.'
abilities: ["product_admin.{$organizationIndustry->getKey()}.view"],
denyResponse: 'You do not have permission to view this organization industry.'
);
}

public function create(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'organization_industry.create',
abilities: 'product_admin.create',
denyResponse: 'You do not have permission to create organization industries.'
);
}

public function update(Authenticatable $authenticatable, OrganizationIndustry $organizationIndustry): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_industry.*.update', "organization_industry.{ {$organizationIndustry->id}}.update"],
abilities: ["product_admin.{$organizationIndustry->getKey()}.update"],
denyResponse: 'You do not have permission to update this organization industry.'
);
}

public function delete(Authenticatable $authenticatable, OrganizationIndustry $organizationIndustry): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_industry.*.delete', "organization_industry.{ {$organizationIndustry->id}}.delete"],
abilities: ["product_admin.{$organizationIndustry->getKey()}.delete"],
denyResponse: 'You do not have permission to delete this organization industry.'
);
}

public function restore(Authenticatable $authenticatable, OrganizationIndustry $organizationIndustry): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_industry.*.restore', "organization_industry.{ {$organizationIndustry->id}}.restore"],
abilities: ["product_admin.{$organizationIndustry->getKey()}.restore"],
denyResponse: 'You do not have permission to restore this organization industry.'
);
}

public function forceDelete(Authenticatable $authenticatable, OrganizationIndustry $organizationIndustry): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_industry.*.force-delete', "organization_industry.{ {$organizationIndustry->id}}.force-delete"],
abilities: ["product_admin.{$organizationIndustry->getKey()}.force-delete"],
denyResponse: 'You do not have permission to force delete this organization industry.'
);
}
Expand Down
14 changes: 7 additions & 7 deletions app-modules/contact/src/Policies/OrganizationTypePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,55 @@ public function before(Authenticatable $authenticatable): ?Response
public function viewAny(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'organization_type.view-any',
abilities: 'product_admin.view-any',
denyResponse: 'You do not have permission to view organization types.'
);
}

public function view(Authenticatable $authenticatable, OrganizationType $organizationType): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_type.*.view', "organization_type.{$organizationType->id}.view"],
abilities: ["product_admin.{$organizationType->getKey()}.view"],
denyResponse: 'You do not have permission to view this organization types.'
);
}

public function create(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'organization_type.create',
abilities: 'product_admin.create',
denyResponse: 'You do not have permission to create organization types.'
);
}

public function update(Authenticatable $authenticatable, OrganizationType $organizationType): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_type.*.update', "organization_type.{$organizationType->id}.update"],
abilities: ["product_admin.{$organizationType->getKey()}.update"],
denyResponse: 'You do not have permission to update this organization type.'
);
}

public function delete(Authenticatable $authenticatable, OrganizationType $organizationType): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_type.*.delete', "organization_type.{$organizationType->id}.delete"],
abilities: ["product_admin.{$organizationType->getKey()}.delete"],
denyResponse: 'You do not have permission to delete this organization type.'
);
}

public function restore(Authenticatable $authenticatable, OrganizationType $organizationType): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_type.*.restore', "organization_type.{$organizationType->id}.restore"],
abilities: ["product_admin.{$organizationType->getKey()}.restore"],
denyResponse: 'You do not have permission to restore this organization type.'
);
}

public function forceDelete(Authenticatable $authenticatable, OrganizationType $organizationType): Response
{
return $authenticatable->canOrElse(
abilities: ['organization_type.*.force-delete', "organization_type.{$organizationType->id}.force-delete"],
abilities: ["product_admin.{$organizationType->getKey()}.force-delete"],
denyResponse: 'You do not have permission to force delete this organization type.'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
livewire(ContactSourceResource\Pages\CreateContactSource::class)
->assertForbidden();

$user->givePermissionTo('contact_source.view-any');
$user->givePermissionTo('contact_source.create');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.create');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
])
->assertForbidden();

$user->givePermissionTo('contact_source.view-any');
$user->givePermissionTo('contact_source.*.update');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.*.update');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
ContactSourceResource::getUrl('index')
)->assertForbidden();

$user->givePermissionTo('contact_source.view-any');
$user->givePermissionTo('product_admin.view-any');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
])
)->assertForbidden();

$user->givePermissionTo('contact_source.view-any');
$user->givePermissionTo('contact_source.*.view');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.*.view');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
livewire(ContactStatusResource\Pages\CreateContactStatus::class)
->assertForbidden();

$user->givePermissionTo('contact_status.view-any');
$user->givePermissionTo('contact_status.create');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.create');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
])
->assertForbidden();

$user->givePermissionTo('contact_status.view-any');
$user->givePermissionTo('contact_status.*.update');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.*.update');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
ContactStatusResource::getUrl('index')
)->assertForbidden();

$user->givePermissionTo('contact_status.view-any');
$user->givePermissionTo('product_admin.view-any');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
])
)->assertForbidden();

$user->givePermissionTo('contact_status.view-any');
$user->givePermissionTo('contact_status.*.view');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.*.view');

actingAs($user)
->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
livewire(CreateOrganizationIndustry::class)
->assertForbidden();

$user->givePermissionTo('organization_industry.view-any');
$user->givePermissionTo('organization_industry.create');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.create');

actingAs($user)
->get(
Expand All @@ -71,8 +71,8 @@
test('Create New Organization Industry', function () {
$user = User::factory()->licensed(Contact::getLicenseType())->create();

$user->givePermissionTo('organization_industry.view-any');
$user->givePermissionTo('organization_industry.create');
$user->givePermissionTo('product_admin.view-any');
$user->givePermissionTo('product_admin.create');

actingAs($user);

Expand Down
Loading