Compare commits

2 Commits

Author SHA1 Message Date
BOHA
68e6d80903 1.3.7 2026-03-27 17:32:22 +01:00
BOHA
af1b41994c fix: attendance shows only users with attendance.record permission
- Filter attendance admin/balances/workfund to users with attendance.record
  permission or admin role
- New attendance_users API action for user dropdown
- Fix missing prisma import in attendance route
- Fix user edit: empty password no longer blocks save (preprocess to undefined)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:32:22 +01:00
6 changed files with 69 additions and 20 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "app-ts", "name": "app-ts",
"version": "1.3.6", "version": "1.3.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "app-ts", "name": "app-ts",
"version": "1.3.6", "version": "1.3.7",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@dnd-kit/core": "^6.3.1", "@dnd-kit/core": "^6.3.1",

View File

@@ -1,6 +1,6 @@
{ {
"name": "app-ts", "name": "app-ts",
"version": "1.3.6", "version": "1.3.7",
"description": "", "description": "",
"main": "dist/server.js", "main": "dist/server.js",
"scripts": { "scripts": {

View File

@@ -561,7 +561,9 @@ export default function useAttendanceAdmin({ alert }: AlertContext) {
useEffect(() => { useEffect(() => {
const loadUsers = async () => { const loadUsers = async () => {
try { try {
const response = await apiFetch(`${API_BASE}/users?limit=1000`); const response = await apiFetch(
`${API_BASE}/attendance?action=attendance_users`,
);
const result = await response.json(); const result = await response.json();
if (result.success) { if (result.success) {
const apiUsers: ApiUser[] = result.data; const apiUsers: ApiUser[] = result.data;

View File

@@ -1,4 +1,5 @@
import { FastifyInstance } from "fastify"; import { FastifyInstance } from "fastify";
import prisma from "../../config/database";
import { requireAuth, requirePermission } from "../../middleware/auth"; import { requireAuth, requirePermission } from "../../middleware/auth";
import { logAudit } from "../../services/audit"; import { logAudit } from "../../services/audit";
import { success, error, parseId } from "../../utils/response"; import { success, error, parseId } from "../../utils/response";
@@ -132,6 +133,38 @@ export default async function attendanceRoutes(
return reply.send({ success: true, data }); return reply.send({ success: true, data });
} }
// --- action=attendance_users: users with attendance.record permission ---
if (action === "attendance_users") {
const users = await prisma.users.findMany({
where: {
is_active: true,
roles: {
is: {
OR: [
{ name: "admin" },
{
role_permissions: {
some: { permissions: { name: "attendance.record" } },
},
},
],
},
},
},
select: { id: true, first_name: true, last_name: true, username: true },
orderBy: { last_name: "asc" },
});
return reply.send({
success: true,
data: users.map((u) => ({
id: u.id,
first_name: u.first_name,
last_name: u.last_name,
username: u.username,
})),
});
}
// --- action=projects: active projects for attendance project switching --- // --- action=projects: active projects for attendance project switching ---
if (action === "projects") { if (action === "projects") {
const data = await attendanceService.getActiveProjects(); const data = await attendanceService.getActiveProjects();

View File

@@ -16,7 +16,10 @@ export const CreateUserSchema = z.object({
export const UpdateUserSchema = z.object({ export const UpdateUserSchema = z.object({
username: z.string().optional(), username: z.string().optional(),
email: z.string().email("Neplatný formát e-mailu").optional(), email: z.string().email("Neplatný formát e-mailu").optional(),
password: z.string().min(8, "Heslo musí mít alespoň 8 znaků").optional(), password: z.preprocess(
(v) => (v === "" ? undefined : v),
z.string().min(8, "Heslo musí mít alespoň 8 znaků").optional(),
),
first_name: z.string().optional(), first_name: z.string().optional(),
last_name: z.string().optional(), last_name: z.string().optional(),
role_id: z.union([z.number(), z.string(), z.null()]).optional(), role_id: z.union([z.number(), z.string(), z.null()]).optional(),

View File

@@ -4,6 +4,29 @@ import { getBusinessDaysInMonth } from "../utils/czech-holidays";
import { localDateStr } from "../utils/date"; import { localDateStr } from "../utils/date";
import { getSystemSettings } from "./system-settings"; import { getSystemSettings } from "./system-settings";
/** Get active users whose role has attendance.record permission (or admin role) */
async function getAttendanceUsers() {
return prisma.users.findMany({
where: {
is_active: true,
roles: {
is: {
OR: [
{ name: "admin" },
{
role_permissions: {
some: { permissions: { name: "attendance.record" } },
},
},
],
},
},
},
select: { id: true, first_name: true, last_name: true },
orderBy: { last_name: "asc" },
});
}
type AttendanceWithRelations = Prisma.attendanceGetPayload<{ type AttendanceWithRelations = Prisma.attendanceGetPayload<{
include: { include: {
users: { select: { id: true; first_name: true; last_name: true } }; users: { select: { id: true; first_name: true; last_name: true } };
@@ -421,11 +444,7 @@ export async function switchProject(userId: number, projectId: number | null) {
} }
export async function getBalances(year: number) { export async function getBalances(year: number) {
const users = await prisma.users.findMany({ const users = await getAttendanceUsers();
where: { is_active: true },
select: { id: true, first_name: true, last_name: true },
orderBy: { last_name: "asc" },
});
const balances: Record< const balances: Record<
string, string,
@@ -463,11 +482,7 @@ export async function getBalances(year: number) {
} }
export async function getWorkfund(year: number) { export async function getWorkfund(year: number) {
const users = await prisma.users.findMany({ const users = await getAttendanceUsers();
where: { is_active: true },
select: { id: true, first_name: true, last_name: true },
orderBy: { last_name: "asc" },
});
const now = new Date(); const now = new Date();
const currentYear = now.getFullYear(); const currentYear = now.getFullYear();
@@ -734,11 +749,7 @@ export async function getPrintData(
const monthStart = new Date(yr, mo - 1, 1); const monthStart = new Date(yr, mo - 1, 1);
const monthEnd = new Date(yr, mo, 0, 23, 59, 59); const monthEnd = new Date(yr, mo, 0, 23, 59, 59);
const users = await prisma.users.findMany({ const users = await getAttendanceUsers();
where: { is_active: true },
select: { id: true, first_name: true, last_name: true },
orderBy: { last_name: "asc" },
});
const where: Record<string, unknown> = { const where: Record<string, unknown> = {
shift_date: { gte: monthStart, lte: monthEnd }, shift_date: { gte: monthStart, lte: monthEnd },