Skip to content

Commit

Permalink
#457 - inactive user cleanup (#461)
Browse files Browse the repository at this point in the history
* #457 - feat: added checkbox for trashed users on vacations index

* #457 - feat: added some colors for blocked users to make them recognizable and stuff for filtering them on indexes

* #457 - fix: cleaning

* #457 - fix: cleaning 2

* #457 - fix: added permission to displaying inactive users on index views

* #457 - fix: ended adjustment connected with new permission for inactive users

* #457 - fix: code review fixes applied

* #457 - fix: code review fixes

* Update app/Http/Controllers/ResumeController.php

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>

* #457 - fix: code review fixes

* #457 - fix: fix

---------

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>
  • Loading branch information
kamilpiech97 and krzysztofrewak authored Jul 12, 2024
1 parent cb6b910 commit d01a022
Show file tree
Hide file tree
Showing 33 changed files with 113 additions and 57 deletions.
9 changes: 8 additions & 1 deletion app/Domain/EmployeesMilestonesRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->canSeeInactiveUsers();

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")
Expand All @@ -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();

Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/AssignedBenefitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()->canSeeInactiveUsers())
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/BenefitsReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function store(BenefitsReportRequest $request): RedirectResponse
$nameReport = $request->get("name");

$users = User::query()
->withTrashed($request->user()->canSeeInactiveUsers())
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/EmployeesMilestonesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 9 additions & 4 deletions app/Http/Controllers/EquipmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Carbon\Carbon;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
Expand All @@ -26,29 +28,32 @@ class EquipmentController extends Controller
*/
public function index(Request $request): RedirectResponse|Response
{
if ($request->user()->cannot("manageEquipment")) {
$authUser = $request->user();

if ($authUser->cannot("manageEquipment")) {
return redirect()->route("equipment-items.indexForEmployee");
}

$searchQuery = $request->query("search");

$equipmentItems = EquipmentItem::query()
->with("assignee")
->with(["assignee" => fn(BelongsTo $query): BelongsTo => $query->withTrashed()])
->search($searchQuery)
->when(
$request->query("assignee") && $request->query("assignee") !== "unassigned",
fn($query) => $query->where("assignee_id", $request->query("assignee")),
fn(Builder $query): Builder => $query->where("assignee_id", $request->query("assignee")),
)
->when(
$request->query("assignee") === "unassigned",
fn($query) => $query->where("assignee_id", null),
fn(Builder $query): Builder => $query->where("assignee_id", null),
)
->labels($request->query("labels"))
->orderBy("id_number")
->paginate()
->withQueryString();

$users = User::query()
->withTrashed($authUser->canSeeInactiveUsers())
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/KeysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Toby\Http\Controllers;

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Inertia\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand All @@ -22,12 +23,15 @@ class KeysController extends Controller
{
public function index(Request $request): Response
{
$authUser = $request->user();
$keys = Key::query()
->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($authUser->canSeeInactiveUsers()))
->with("user")
->get()
->sortBy("id");

$users = User::query()
->withTrashed($authUser->canSeeInactiveUsers())
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MonthlyUsageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __invoke(
$currentUser = $request->user();

$users = User::query()
->withTrashed()
->withTrashed($currentUser->canSeeInactiveUsers())
->withVacationLimitIn($currentYearPeriod)
->where("id", "!=", $currentUser->id)
->orderByProfileField("last_name")
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/OvertimeRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,20 @@ public function indexForApprovers(
$yearPeriod = $yearPeriodRetriever->selected();
$status = $request->get("status", "all");
$user = $request->get("user");
$authUser = $request->user();
$withTrashedUsers = $authUser->canSeeInactiveUsers();

$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();

$users = User::query()
->withTrashed($withTrashedUsers)
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/ResumeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Symfony\Component\HttpFoundation\BinaryFileResponse;
use Toby\Domain\ResumeGenerator;
Expand All @@ -18,12 +20,14 @@

class ResumeController extends Controller
{
public function index(): Response
public function index(Request $request): Response
{
$this->authorize("manageResumes");

$resumes = Resume::query()
->with("user")
->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($request->user()->canSeeInactiveUsers()))
->orWhere("user_id", null)
->latest("updated_at")
->paginate();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function destroy(User $user): RedirectResponse
$user->delete();

return back()
->with("success", __("User deleted."));
->with("success", __("User blocked."));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/VacationCalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public function index(
): Response {
$month = Month::fromNameOrCurrent((string)$month);
$currentUser = $request->user();
$withTrashedUsers = $currentUser->canSeeInactiveUsers();

$yearPeriod = $yearPeriodRetriever->selected();
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());

$users = User::query()
->withTrashed($withTrashedUsers)
->where("id", "!=", $currentUser->id)
->orderByProfileField("last_name")
->orderByProfileField("first_name")
Expand All @@ -42,6 +44,7 @@ public function index(
"current" => Month::current(),
"selected" => $month->value,
"users" => SimpleUserResource::collection($users),
"withBlockedUsers" => $withTrashedUsers,
]);
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/VacationLimitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand All @@ -25,6 +27,7 @@ public function edit(YearPeriodRetriever $yearPeriodRetriever, UserVacationStats

$limits = $yearPeriod
->vacationLimits()
->whereRelation("user", fn(Builder $query): Builder => $query->withTrashed($request->user()->canSeeInactiveUsers()))
->with("user.profile")
->has("user")
->get()
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/VacationRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,21 @@ public function indexForApprovers(
$status = $request->get("status", "all");
$user = $request->get("user");
$type = $request->get("type");
$authUser = $request->user();
$withTrashedUsers = $authUser->canSeeInactiveUsers();

$vacationRequests = VacationRequest::query()
->with(["vacations.user.profile", "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))
->when($type !== null, fn(Builder $query): Builder => $query->where("type", $type))
->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user()))
->states(VacationRequestStatesRetriever::filterByStatusGroup($status, $authUser))
->latest()
->paginate();

$users = User::query()
->withTrashed($withTrashedUsers)
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/SimpleUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function toArray($request): array
"last_name" => $this->profile->last_name,
"email" => $this->email,
"avatar" => $this->profile->getAvatar(),
"isActive" => $this->deleted_at === null,
];
}
}
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public function endOfEmploymentInCurrentCompany(): ?UserHistory
->first();
}

public function canSeeInactiveUsers(): bool
{
return $this->can("showInactiveUsers");
}

public function keys(): HasMany
{
return $this->hasMany(Key::class);
Expand Down
1 change: 1 addition & 0 deletions config/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"managePermissions",
"manageHolidays",
"manageUsers",
"showInactiveUsers",
"manageKeys",
"manageTechnologies",
"manageResumes",
Expand Down
2 changes: 1 addition & 1 deletion lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"The request must be for at least one day.": "Wniosek musi być co najmniej na jeden dzień.",
"The request cannot be created at the turn of the year.": "Wniosek nie może zostać złożony na przełomie roku.",
"User created.": "Użytkownik utworzony.",
"User blocked.": "Użytkownik zablokowany.",
"User updated.": "Użytkownik zaktualizowany.",
"User deleted.": "Użytkownik usunięty.",
"User restored.": "Użytkownik przywrócony.",
"Permissions updated.": "Uprawnienia zaktualizowane.",
"Holiday created.": "Dzień wolny utworzony.",
Expand Down
5 changes: 5 additions & 0 deletions resources/js/Composables/permissionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 6 additions & 5 deletions resources/js/Pages/AssignedBenefits/AssignedBenefits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ function isBenefitHasCompanion(benefitId) {
<tr
v-for="(item, index) in form.items"
:key="item.user.id"
class="group hover:bg-blumilk-25 divide-x divide-gray-300"
:class="[item.user.isActive ? '' : 'bg-gray-100', 'group hover:bg-blumilk-25 divide-x divide-gray-300']"
>
<th class="group p-2 sticky left-0 outline outline-1 outline-offset-0 outline-gray-300 bg-white hover:bg-blumilk-25 group-hover:bg-blumilk-25">
<th :class="[item.user.isActive ? 'bg-white' : 'bg-gray-100', 'group p-2 sticky left-0 outline outline-1 outline-offset-0 outline-gray-300 hover:bg-blumilk-25 group-hover:bg-blumilk-25']">
<div class="flex justify-start items-center">
<span class="inline-flex justify-center items-center w-8 h-8 rounded-full">
<img :src="item.user.avatar">
Expand All @@ -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"
>
Expand All @@ -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"
>
Expand All @@ -226,7 +227,7 @@ function isBenefitHasCompanion(benefitId) {
<TextArea
v-model="item.comment"
:resize="true"
class="w-full sm:text-sm border-none appearance-none mt-1 focus:ring-0 focus:bg-blumilk-25 group-hover:bg-blumilk-25 resize-y h-full"
:class="[item.user.isActive ? '' : 'bg-gray-100', 'w-full sm:text-sm border-none appearance-none mt-1 focus:ring-0 focus:bg-blumilk-25 group-hover:bg-blumilk-25 resize-y h-full']"
style="min-height: 40px"
/>
</td>
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/BenefitsReport/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ function generateUrl(){
<tr
v-for="item in benefitsReportData"
:key="item.user.id"
:class="[ selectedUsers.find((selectedUser) => selectedUser === item.user.id) && 'bg-blumilk-25']"
class="group bg-white hover:bg-blumilk-25 group-hover:bg-blumilk-25 divide-x divide-gray-300"
:class="[ selectedUsers.find((selectedUser) => selectedUser === item.user.id) && 'bg-blumilk-25', [!item.user.isActive ? 'bg-gray-100' : 'bg-white']]"
class="group hover:bg-blumilk-25 group-hover:bg-blumilk-25 divide-x divide-gray-300"
>
<td
:class="[ selectedUsers.find((selectedUser) => selectedUser === item.user.id) && 'bg-blumilk-25']"
class="relative w-12 px-6 sm:w-16 sm:px-8 space-x-4 sticky left-0 outline outline-1 outline-offset-0 outline-gray-300 group bg-white hover:bg-blumilk-25 group-hover:bg-blumilk-25"
:class="[ selectedUsers.find((selectedUser) => selectedUser === item.user.id) && 'bg-blumilk-25', [!item.user.isActive ? 'bg-gray-100' : 'bg-white']]"
class="relative w-12 px-6 sm:w-16 sm:px-8 space-x-4 sticky left-0 outline outline-1 outline-offset-0 outline-gray-300 group hover:bg-blumilk-25 group-hover:bg-blumilk-25"
>
<div>
<div
Expand Down
Loading

0 comments on commit d01a022

Please sign in to comment.