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

#457 - inactive user cleanup #461

Merged
merged 12 commits into from
Jul 12, 2024
Merged
3 changes: 3 additions & 0 deletions app/Http/Controllers/OvertimeRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,19 @@ public function indexForApprovers(
$yearPeriod = $yearPeriodRetriever->selected();
$status = $request->get("status", "all");
$user = $request->get("user");
$withTrashedUsers = $request->boolean("withTrashedUsers") ?? false;

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

$users = User::query()
->withTrashed($withTrashedUsers)
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
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 = $request->boolean("withBlockedUsers");

$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,
]);
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/VacationRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ public function indexForApprovers(
$status = $request->get("status", "all");
$user = $request->get("user");
$type = $request->get("type");
$withTrashedUsers = $request->boolean("withTrashedUsers") ?? false;

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

$users = User::query()
->withTrashed($withTrashedUsers)
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();
Expand All @@ -128,6 +131,7 @@ public function indexForApprovers(
"status" => $status,
"user" => (int)$user,
"type" => $type,
"withTrashedUsers" => $withTrashedUsers,
],
]);
}
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,
];
}
}
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
48 changes: 41 additions & 7 deletions resources/js/Pages/Calendar.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup>
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/vue/24/solid'
import { computed, ref } from 'vue'
import { computed, reactive, ref, watch } from 'vue'
import { useMonthInfo } from '@/Composables/monthInfo.js'
import VacationTypeCalendarIcon from '@/Shared/VacationTypeCalendarIcon.vue'
import CalendarDay from '@/Shared/CalendarDay.vue'
import { debounce } from 'lodash'
import { Inertia } from '@inertiajs/inertia'

const props = defineProps({
users: Object,
Expand All @@ -12,6 +14,11 @@ const props = defineProps({
current: String,
selected: String,
years: Object,
withBlockedUsers: Boolean,
})

const form = reactive({
withTrashedUsers: props.withBlockedUsers ?? false,
})

let activeElement = ref(undefined)
Expand Down Expand Up @@ -45,12 +52,21 @@ function linkParameters(user, day) {
function linkVacationRequest(user){
return props.auth.user.id === user.id || props.auth.can.manageRequestsAsTechnicalApprover || props.auth.can.manageRequestsAsAdministrativeApprover
}

watch(form, debounce(() => {
Inertia.get('', {
withBlockedUsers: form.withTrashedUsers,
}, {
preserveState: true,
replace: true,
})
}, 150))
</script>

<template>
<InertiaHead title="Kalendarz" />
<div class="bg-white shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div class="flex-row sm:flex justify-between items-center p-4 sm:px-6">
<div class="flex items-center">
<h2 class="text-lg font-medium leading-6 text-center text-gray-900">
Kalendarz
Expand All @@ -59,7 +75,7 @@ function linkVacationRequest(user){
<InertiaLink
v-if="previousMonth"
as="button"
:href="`/calendar/${previousMonth.value}`"
:href="`/calendar/${previousMonth.value}?withBlockedUsers=${form.withTrashedUsers}`"
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
>
<ChevronLeftIcon class="w-5 h-5" />
Expand All @@ -73,15 +89,15 @@ function linkVacationRequest(user){
<InertiaLink
v-if="years.current.year === years.selected.year"
as="button"
:href="`/calendar/${currentMonth.value}`"
:href="`/calendar/${currentMonth.value}?withBlockedUsers=${form.withTrashedUsers}`"
class="hidden focus:relative items-center p-2 text-sm font-medium text-gray-700 hover:text-gray-900 bg-white hover:bg-gray-50 border-y border-gray-300 focus:outline-blumilk-500 md:flex"
>
Dzisiaj
</InertiaLink>
<InertiaLink
v-if="nextMonth"
as="button"
:href="`/calendar/${nextMonth.value}`"
:href="`/calendar/${nextMonth.value}?withBlockedUsers=${form.withTrashedUsers}`"
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
>
<ChevronRightIcon class="w-5 h-5" />
Expand All @@ -95,12 +111,12 @@ function linkVacationRequest(user){
</div>
</div>
<div
class="flex"
class="flex mt-3 sm:mt-0"
>
<a
v-if="auth.can.manageRequestsAsAdministrativeApprover"
:href="`/vacation/timesheet/${selectedMonth.value}`"
class="block py-3 px-4 ml-3 text-sm font-medium leading-4 text-center text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
class="block py-3 px-4 sm:ml-3 text-sm font-medium leading-4 text-center text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
>
Pobierz plik Excel
</a>
Expand All @@ -113,6 +129,23 @@ function linkVacationRequest(user){
</a>
</div>
</div>
<div
v-if="auth.can.manageRequestsAsAdministrativeApprover"
class="flex items-center space-x-2 pb-2 px-4 sm:px-6"
>
<input
id="withTrashedUsers"
v-model="form.withTrashedUsers"
class="left-6 top-1/2 h-4 w-4 rounded border-gray-300 text-blumilk-600 focus:ring-blumilk-500"
type="checkbox"
>
<label
class="block text-sm font-medium text-gray-700"
for="withTrashedUsers"
>
Zablokowani użytkownicy
</label>
</div>
<div class="overflow-x-auto">
<table class="w-full text-sm text-center border border-gray-300">
<thead>
Expand Down Expand Up @@ -142,6 +175,7 @@ function linkVacationRequest(user){
<tr
v-for="user in users.data"
:key="user.id"
:class="[user.isActive ? '' : 'bg-gray-100']"
>
<th class="p-2 border border-gray-300">
<div class="flex justify-start items-center">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/MonthlyUsage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function isCurrentMonth(month) {
<tr
v-for="item in monthlyUsage"
:key="item.user.id"
class="hover:bg-blumilk-25"
:class="[item.user.isActive ? '' : 'bg-gray-100', 'hover:bg-blumilk-25']"
>
<th class="p-4 text-sm font-semibold text-gray-500 capitalize whitespace-nowrap">
<div class="flex justify-start items-center">
Expand Down
20 changes: 18 additions & 2 deletions resources/js/Pages/OvertimeRequest/IndexForApprovers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ const statuses = [
const form = reactive({
user: props.users.data.find(user => user.id === props.filters.user) ?? null,
status: statuses.find(status => status.value === props.filters.status) ?? statuses[0],
withTrashedUsers: props.filters.withTrashedUsers ?? false,
})

watch(form, debounce(() => {
Inertia.get('/overtime/requests', {
user: form.user?.id,
status: form.status.value,
withTrashedUsers: form.withTrashedUsers,
}, {
preserveState: true,
replace: true,
Expand Down Expand Up @@ -142,7 +144,7 @@ watch(form, debounce(() => {
as="template"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9', user.isActive ? '' : 'bg-gray-100']"
>
<div class="flex items-center">
<img
Expand All @@ -166,6 +168,20 @@ watch(form, debounce(() => {
</ListboxOptions>
</transition>
</div>
<div class="flex items-center space-x-2 mt-3">
<input
id="withTrashedUsers"
v-model="form.withTrashedUsers"
class="left-6 top-1/2 h-4 w-4 rounded border-gray-300 text-blumilk-600 focus:ring-blumilk-500"
type="checkbox"
>
<label
class="block text-sm font-medium text-gray-700"
for="withTrashedUsers"
>
Zablokowani użytkownicy
</label>
</div>
</Listbox>
<Listbox
v-model="form.status"
Expand Down Expand Up @@ -275,7 +291,7 @@ watch(form, debounce(() => {
:key="request.id"
:href="`/overtime/requests/${request.id}`"
as="tr"
class="relative hover:bg-blumilk-25 hover:cursor-pointer"
:class="[request.user.isActive ? '' : 'bg-gray-100', 'relative hover:bg-blumilk-25 hover:cursor-pointer']"
>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<InertiaLink
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/VacationLimits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ watch(() => form.items, () => {
<tr
v-for="(item, index) in form.items"
:key="item.id"
class="hover:bg-blumilk-25"
:class="[item.user.deleted ? 'bg-gray-100' : '', 'hover:bg-blumilk-25']"
>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<div class="flex">
Expand Down
Loading
Loading