feat: implement permissions and actions management
- Add permissions logic for status options in corrective actions. - Create tests for permissions functionality. - Implement queries for user authentication and actions management. - Develop Actions page to display and manage corrective actions. - Create authentication pages for login, setup, and password reset. - Add IncidentDetail page to view incident details and associated actions. - Implement Settings page for user management and password changes.
This commit is contained in:
1 parent
708da6b9f7
commit
3f6dff5f24
94 files changed
+7213
-643
No files matched your search
+61
-7
@@ -1,6 +1,6 @@
|
||||
// Request validation schemas, shared so the web app can validate forms with the same rules as the API.
|
||||
import { z } from 'zod'
|
||||
import { areaKinds, incidentStatuses, incidentTypes, roles, severities } from './enums.ts'
|
||||
import { actionKinds, actionStatuses, areaKinds, incidentStatuses, incidentTypes, rcaMethods, roles, rootCauseCategories, severities } from './enums.ts'
|
||||
|
||||
const email = z.string().trim().toLowerCase().max(254).pipe(z.email())
|
||||
const password = z.string().min(10, 'Use at least 10 characters').max(256)
|
||||
@@ -14,9 +14,11 @@ export const loginSchema = z.object({ email, password: z.string().min(1).max(256
|
||||
|
||||
export const changePasswordSchema = z.object({ currentPassword: z.string().min(1).max(256), newPassword: password })
|
||||
|
||||
export const createUserSchema = z.object({ name, email, role: z.enum(roles), password })
|
||||
/** Without a password, the user is emailed an invitation to set one. */
|
||||
export const createUserSchema = z.object({ name, email, role: z.enum(roles), password: password.optional() })
|
||||
|
||||
export const updateUserSchema = z.object({ name: name.optional(), role: z.enum(roles).optional(), active: z.boolean().optional() })
|
||||
/** `password` lets an admin set a new password when email isn't available. */
|
||||
export const updateUserSchema = z.object({ name: name.optional(), role: z.enum(roles).optional(), active: z.boolean().optional(), password: password.optional() })
|
||||
|
||||
export const createSiteSchema = z.object({ name, address: optionalText(500), timezone: z.string().trim().max(64).optional() })
|
||||
|
||||
@@ -39,10 +41,57 @@ export const createIncidentSchema = z.object({
|
||||
anonymous: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export const updateIncidentSchema = createIncidentSchema
|
||||
.omit({ anonymous: true })
|
||||
.partial()
|
||||
.extend({ status: z.enum(incidentStatuses).optional() })
|
||||
/** Status changes go through transitions, not updates. */
|
||||
export const updateIncidentSchema = createIncidentSchema.omit({ anonymous: true }).partial()
|
||||
|
||||
export const transitionSchema = z.object({ to: z.enum(incidentStatuses), note: optionalText(5_000) })
|
||||
|
||||
export const commentSchema = z.object({ body: z.string().trim().min(1).max(5_000) })
|
||||
|
||||
export const investigationSchema = z.object({
|
||||
leadId: z.uuid().nullish(),
|
||||
method: z.enum(rcaMethods).optional(),
|
||||
summary: optionalText(20_000),
|
||||
completed: z.boolean().optional(),
|
||||
})
|
||||
|
||||
const rootCauseFields = {
|
||||
category: z.enum(rootCauseCategories),
|
||||
description: z.string().trim().min(1).max(2_000),
|
||||
whys: z.array(z.string().trim().min(1).max(1_000)).max(10),
|
||||
}
|
||||
|
||||
export const rootCauseSchema = z.object({ ...rootCauseFields, whys: rootCauseFields.whys.default([]) })
|
||||
|
||||
// Update schemas are written out rather than derived with .partial(): in Zod 4, .partial() keeps
|
||||
// defaults, so a partial update would silently reset omitted fields.
|
||||
export const updateRootCauseSchema = z.object(rootCauseFields).partial()
|
||||
|
||||
const isoDate = z.iso.date()
|
||||
|
||||
const actionFields = {
|
||||
title: name,
|
||||
description: optionalText(5_000),
|
||||
kind: z.enum(actionKinds),
|
||||
assigneeId: z.uuid().nullish(),
|
||||
dueDate: isoDate.nullish(),
|
||||
rootCauseId: z.uuid().nullish(),
|
||||
}
|
||||
|
||||
export const createActionSchema = z.object({ ...actionFields, kind: actionFields.kind.default('corrective') })
|
||||
|
||||
export const updateActionSchema = z.object({ ...actionFields, status: z.enum(actionStatuses) }).partial()
|
||||
|
||||
export const actionListQuery = z.object({
|
||||
scope: z.enum(['mine', 'all']).default('mine'),
|
||||
filter: z.enum(['open', 'overdue', 'done', 'all']).default('open'),
|
||||
})
|
||||
|
||||
export const emailOnlySchema = z.object({ email })
|
||||
|
||||
export const tokenSchema = z.object({ token: z.string().min(20).max(200) })
|
||||
|
||||
export const resetPasswordSchema = z.object({ token: z.string().min(20).max(200), newPassword: password })
|
||||
|
||||
export const incidentListQuery = z.object({
|
||||
page: z.coerce.number().int().min(1).default(1),
|
||||
@@ -57,4 +106,9 @@ export const incidentListQuery = z.object({
|
||||
export type SetupInput = z.infer<typeof setupSchema>
|
||||
export type CreateIncidentInput = z.input<typeof createIncidentSchema>
|
||||
export type UpdateIncidentInput = z.infer<typeof updateIncidentSchema>
|
||||
export type CreateActionInput = z.input<typeof createActionSchema>
|
||||
export type UpdateActionInput = z.input<typeof updateActionSchema>
|
||||
export type RootCauseInput = z.input<typeof rootCauseSchema>
|
||||
export type UpdateRootCauseInput = z.input<typeof updateRootCauseSchema>
|
||||
export type InvestigationInput = z.input<typeof investigationSchema>
|
||||
export type IncidentListQuery = z.infer<typeof incidentListQuery>
|
||||
Reference in new issue
Block a user