Skip to content

Commit

Permalink
Merge pull request #467 from code4romania/266-update-edit-permissions…
Browse files Browse the repository at this point in the history
…-on-the-ngo-admin-user-in-the-staff-section

Edit ngo admin
  • Loading branch information
gheorghelupu17 authored Dec 31, 2024
2 parents c9d19ba + ec7698c commit 15f7edf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 6 additions & 1 deletion app/Concerns/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Enums\AdminPermission;
use App\Enums\CasePermission;
use App\Models\Beneficiary;
use App\Models\User;
use Filament\Facades\Filament;

trait HasPermissions
Expand Down Expand Up @@ -53,7 +54,7 @@ public function hasAccessToBeneficiary(Beneficiary $beneficiary): bool
return false;
}

public function hasAccessToStaff(): bool
public function hasAccessToStaff(?User $model = null): bool
{
if ($this->isAdmin()) {
return true;
Expand All @@ -63,6 +64,10 @@ public function hasAccessToStaff(): bool
return true;
}

if ($model && $model->isNgoAdmin()) {
return false;
}

return (bool) $this->permissions?->admin_permissions->contains(AdminPermission::CAN_CHANGE_STAFF);
}

Expand Down
9 changes: 4 additions & 5 deletions app/Filament/Organizations/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
use App\Enums\CasePermission;
use App\Filament\Organizations\Resources\UserResource\Pages;
use App\Forms\Components\Select;
use App\Infolists\Components\DateTimeEntry;
use App\Models\OrganizationUserPermissions;
use App\Models\Role;
use App\Models\User;
use App\Tables\Columns\DateTimeColumn;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Group;
Expand Down Expand Up @@ -73,6 +71,7 @@ public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(fn (Builder $query) => $query->with(['rolesInOrganization', 'userStatus']))
->heading(__('user.heading.table'))
->columns([
TextColumn::make('first_name')
->sortable()
Expand All @@ -89,7 +88,8 @@ public static function table(Table $table): Table

TextColumn::make('userStatus.status')
->sortable()
->label(__('user.labels.account_status')),
->label(__('user.labels.account_status'))
->suffix(fn (User $record) => $record->isNgoAdmin() ? '**' : ''),

DateTimeColumn::make('last_login_at')
->sortable()
Expand All @@ -101,8 +101,7 @@ public static function table(Table $table): Table
->actions([
Tables\Actions\ViewAction::make()
->label(__('general.action.view_details')),
])
->heading(__('user.heading.table'));
]);
}

public static function getPages(): array
Expand Down
4 changes: 2 additions & 2 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function viewAny(User $user): bool
*/
public function view(User $user, User $model): bool
{
return $user->hasAccessToStaff();
return $user->hasAccessToStaff($model);
}

/**
Expand All @@ -37,7 +37,7 @@ public function create(User $user): bool
*/
public function update(User $user, User $model): bool
{
return $user->hasAccessToStaff();
return $user->hasAccessToStaff($model);
}

/**
Expand Down

0 comments on commit 15f7edf

Please sign in to comment.