diff --git a/app/Domain/EmployeesMilestonesRetriever.php b/app/Domain/EmployeesMilestonesRetriever.php index 8bd6c04d..8aa71af8 100644 --- a/app/Domain/EmployeesMilestonesRetriever.php +++ b/app/Domain/EmployeesMilestonesRetriever.php @@ -12,18 +12,23 @@ class EmployeesMilestonesRetriever { + protected bool $hasPermissionToViewInactiveUsers; + public function __construct( protected VacationTypeConfigRetriever $configRetriever, ) {} - public function getResults(?string $searchText, ?string $sort): Collection + public function getResults(User $user, ?string $searchText, ?string $sort): Collection { + $this->hasPermissionToViewInactiveUsers = $user->hasPermissionTo("showInactiveUsers"); + return match ($sort) { "birthday-asc" => $this->getUpcomingBirthdays($searchText), "birthday-desc" => $this->getUpcomingBirthdays($searchText, "desc"), "seniority-asc" => $this->getSeniority($searchText), "seniority-desc" => $this->getSeniority($searchText, "desc"), default => User::query() + ->withTrashed($this->hasPermissionToViewInactiveUsers) ->search($searchText) ->orderByProfileField("last_name") ->orderByProfileField("first_name") @@ -34,6 +39,7 @@ public function getResults(?string $searchText, ?string $sort): Collection public function getUpcomingBirthdays(?string $searchText, string $direction = "asc"): Collection { $users = User::query() + ->withTrashed($this->hasPermissionToViewInactiveUsers) ->search($searchText) ->get(); @@ -43,6 +49,7 @@ public function getUpcomingBirthdays(?string $searchText, string $direction = "a public function getSeniority(?string $searchText, string $direction = "asc"): Collection { return User::query() + ->withTrashed($this->hasPermissionToViewInactiveUsers) ->search($searchText) ->orderBy( UserHistory::query() diff --git a/app/Http/Controllers/AssignedBenefitController.php b/app/Http/Controllers/AssignedBenefitController.php index 2fd21d27..706cd373 100644 --- a/app/Http/Controllers/AssignedBenefitController.php +++ b/app/Http/Controllers/AssignedBenefitController.php @@ -6,6 +6,7 @@ use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Support\Arr; use Inertia\Response; use Toby\Enums\Month; @@ -22,11 +23,12 @@ class AssignedBenefitController extends Controller /** * @throws AuthorizationException */ - public function index(): Response + public function index(Request $request): Response { $this->authorize("manageBenefits"); $users = User::query() + ->withTrashed($request->user()->hasPermissionTo("showInactiveUsers")) ->orderByProfileField("last_name") ->orderByProfileField("first_name") ->get(); diff --git a/app/Http/Controllers/EmployeesMilestonesController.php b/app/Http/Controllers/EmployeesMilestonesController.php index 080d533a..1618b05d 100644 --- a/app/Http/Controllers/EmployeesMilestonesController.php +++ b/app/Http/Controllers/EmployeesMilestonesController.php @@ -16,7 +16,7 @@ public function index(Request $request, EmployeesMilestonesRetriever $employeesM $searchText = $request->query("search"); $sort = $request->query("sort"); - $users = $employeesMilestoneRetriever->getResults($searchText, $sort); + $users = $employeesMilestoneRetriever->getResults($request->user(), $searchText, $sort); return inertia("EmployeesMilestones", [ "users" => EmployeeMilestoneResource::collection($users), diff --git a/app/Http/Controllers/EquipmentController.php b/app/Http/Controllers/EquipmentController.php index f05d7af1..489d812d 100644 --- a/app/Http/Controllers/EquipmentController.php +++ b/app/Http/Controllers/EquipmentController.php @@ -33,7 +33,7 @@ public function index(Request $request): RedirectResponse|Response $searchQuery = $request->query("search"); $equipmentItems = EquipmentItem::query() - ->with("assignee") + ->with(["assignee" => fn($query) => $query->withTrashed()]) ->search($searchQuery) ->when( $request->query("assignee") && $request->query("assignee") !== "unassigned", @@ -49,6 +49,7 @@ public function index(Request $request): RedirectResponse|Response ->withQueryString(); $users = User::query() + ->withTrashed() ->orderByProfileField("last_name") ->orderByProfileField("first_name") ->get(); diff --git a/app/Http/Controllers/KeysController.php b/app/Http/Controllers/KeysController.php index bb7a1a3b..42e221ba 100644 --- a/app/Http/Controllers/KeysController.php +++ b/app/Http/Controllers/KeysController.php @@ -28,6 +28,7 @@ public function index(Request $request): Response ->sortBy("id"); $users = User::query() + ->withTrashed($request->user()->hasPermissionTo("showInactiveUsers")) ->orderByProfileField("last_name") ->orderByProfileField("first_name") ->get(); diff --git a/app/Http/Controllers/MonthlyUsageController.php b/app/Http/Controllers/MonthlyUsageController.php index 311fd346..43b2705c 100644 --- a/app/Http/Controllers/MonthlyUsageController.php +++ b/app/Http/Controllers/MonthlyUsageController.php @@ -25,7 +25,7 @@ public function __invoke( $currentUser = $request->user(); $users = User::query() - ->withTrashed() + ->withTrashed($currentUser->hasPermissionTo("showInactiveUsers")) ->withVacationLimitIn($currentYearPeriod) ->where("id", "!=", $currentUser->id) ->orderByProfileField("last_name") diff --git a/app/Http/Controllers/OvertimeRequestController.php b/app/Http/Controllers/OvertimeRequestController.php index ba234858..1f5dcd28 100644 --- a/app/Http/Controllers/OvertimeRequestController.php +++ b/app/Http/Controllers/OvertimeRequestController.php @@ -98,14 +98,15 @@ public function indexForApprovers( $yearPeriod = $yearPeriodRetriever->selected(); $status = $request->get("status", "all"); $user = $request->get("user"); - $withTrashedUsers = $request->boolean("withTrashedUsers") ?? false; + $authUser = $request->user(); + $withTrashedUsers = $authUser->can("showInactiveUsers"); $overtimeRequests = OvertimeRequest::query() ->with(["user.permissions", "user.profile"]) ->whereBelongsTo($yearPeriod) ->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($withTrashedUsers)) ->when($user !== null, fn(Builder $query): Builder => $query->where("user_id", $user)) - ->states(OvertimeRequestStatesRetriever::filterByStatusGroup($status, $request->user())) + ->states(OvertimeRequestStatesRetriever::filterByStatusGroup($status, $authUser)) ->latest() ->paginate(); diff --git a/app/Http/Controllers/ResumeController.php b/app/Http/Controllers/ResumeController.php index ddedaecf..2863de7e 100644 --- a/app/Http/Controllers/ResumeController.php +++ b/app/Http/Controllers/ResumeController.php @@ -4,6 +4,7 @@ namespace Toby\Http\Controllers; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; use Inertia\Response; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -24,6 +25,7 @@ public function index(): Response $resumes = Resume::query() ->with("user") + ->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed(false)) ->latest("updated_at") ->paginate(); diff --git a/app/Http/Controllers/VacationCalendarController.php b/app/Http/Controllers/VacationCalendarController.php index 51ff6857..9b3f22d0 100644 --- a/app/Http/Controllers/VacationCalendarController.php +++ b/app/Http/Controllers/VacationCalendarController.php @@ -23,7 +23,7 @@ public function index( ): Response { $month = Month::fromNameOrCurrent((string)$month); $currentUser = $request->user(); - $withTrashedUsers = $request->boolean("withBlockedUsers"); + $withTrashedUsers = $currentUser->hasPermissionTo("showInactiveUsers"); $yearPeriod = $yearPeriodRetriever->selected(); $carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber()); diff --git a/app/Http/Controllers/VacationLimitController.php b/app/Http/Controllers/VacationLimitController.php index 80422025..8e6b18e5 100644 --- a/app/Http/Controllers/VacationLimitController.php +++ b/app/Http/Controllers/VacationLimitController.php @@ -4,7 +4,9 @@ namespace Toby\Http\Controllers; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Inertia\Response; use Toby\Domain\UserVacationStatsRetriever; use Toby\Helpers\YearPeriodRetriever; @@ -16,7 +18,7 @@ class VacationLimitController extends Controller { - public function edit(YearPeriodRetriever $yearPeriodRetriever, UserVacationStatsRetriever $statsRetriever): Response + public function edit(Request $request, YearPeriodRetriever $yearPeriodRetriever, UserVacationStatsRetriever $statsRetriever): Response { $this->authorize("manageVacationLimits"); @@ -25,6 +27,7 @@ public function edit(YearPeriodRetriever $yearPeriodRetriever, UserVacationStats $limits = $yearPeriod ->vacationLimits() + ->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($request->user()->hasPermissionTo("showInactiveUsers"))) ->with("user.profile") ->has("user") ->get() diff --git a/app/Http/Controllers/VacationRequestController.php b/app/Http/Controllers/VacationRequestController.php index f557f61f..025d6685 100644 --- a/app/Http/Controllers/VacationRequestController.php +++ b/app/Http/Controllers/VacationRequestController.php @@ -105,7 +105,8 @@ public function indexForApprovers( $status = $request->get("status", "all"); $user = $request->get("user"); $type = $request->get("type"); - $withTrashedUsers = $request->boolean("withTrashedUsers") ?? false; + $authUser = $request->user(); + $withTrashedUsers = $authUser->can("showInactiveUsers"); $vacationRequests = VacationRequest::query() ->with(["vacations.user.profile", "user.permissions", "user.profile"]) @@ -113,7 +114,7 @@ public function indexForApprovers( ->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($withTrashedUsers)) ->when($user !== null, fn(Builder $query): Builder => $query->where("user_id", $user)) ->when($type !== null, fn(Builder $query): Builder => $query->where("type", $type)) - ->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user())) + ->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $authUser)) ->latest() ->paginate(); @@ -131,7 +132,6 @@ public function indexForApprovers( "status" => $status, "user" => (int)$user, "type" => $type, - "withTrashedUsers" => $withTrashedUsers, ], ]); } diff --git a/config/permission.php b/config/permission.php index bcfaba39..480bfa1d 100644 --- a/config/permission.php +++ b/config/permission.php @@ -40,6 +40,7 @@ "managePermissions", "manageHolidays", "manageUsers", + "showInactiveUsers", "manageKeys", "manageTechnologies", "manageResumes", diff --git a/resources/js/Composables/permissionInfo.js b/resources/js/Composables/permissionInfo.js index bb62fb84..802e4166 100644 --- a/resources/js/Composables/permissionInfo.js +++ b/resources/js/Composables/permissionInfo.js @@ -14,6 +14,11 @@ const permissionsInfo = [ 'value': 'manageUsers', 'section': 'Użytkownicy', }, + { + 'name': 'Widoczność zablokowanych użytkowników', + 'value': 'showInactiveUsers', + 'section': 'Użytkownicy', + }, { 'name': 'Zarządzanie kluczami', 'value': 'manageKeys', diff --git a/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue b/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue index 78d1d480..adfb7bab 100644 --- a/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue +++ b/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue @@ -171,9 +171,9 @@ function isBenefitHasCompanion(benefitId) { - +
@@ -198,7 +198,8 @@ function isBenefitHasCompanion(benefitId) { :name="`${benefit.id}-employer-${index}`" type="number" step="0.01" - class="w-full h-full sm:text-sm appearance-none border-none text-right p-0 px-3 m-0 ring-inset hover:bg-blumilk-25 group-hover:bg-blumilk-25 focus:bg-blumilk-25 focus:ring-2 focus:ring-blumilk-300" + class="" + :class="[item.user.isActive ? '' : 'bg-gray-100', 'w-full h-full sm:text-sm appearance-none border-none text-right p-0 px-3 m-0 ring-inset hover:bg-blumilk-25 group-hover:bg-blumilk-25 focus:bg-blumilk-25 focus:ring-2 focus:ring-blumilk-300']" title="Wprowadź kwotę." min="0" > @@ -209,7 +210,7 @@ function isBenefitHasCompanion(benefitId) { :name="`${benefit.id}-employee-${index}`" type="number" step="0.01" - class="w-full h-full sm:text-sm appearance-none border-none text-right p-0 px-3 m-0 ring-inset hover:bg-blumilk-25 group-hover:bg-blumilk-25 focus:bg-blumilk-25 focus:ring-2 focus:ring-blumilk-300" + :class="[item.user.isActive ? '' : 'bg-gray-100', 'w-full h-full sm:text-sm appearance-none border-none text-right p-0 px-3 m-0 ring-inset hover:bg-blumilk-25 group-hover:bg-blumilk-25 focus:bg-blumilk-25 focus:ring-2 focus:ring-blumilk-300']" title="Wprowadź kwotę." min="0" > @@ -226,7 +227,7 @@ function isBenefitHasCompanion(benefitId) {