feat(tickets): allow staff to archive tickets, hiding them from the front-end
Archived tickets disappear from every front-end surface for all users (staff included): helpdesk list, detail page 404s, dashboard widget, and project board/sprints/releases/search views. They remain fully visible in the Payload admin panel, where un-archiving restores them. The collection hook stamps archivedAt and appends an activity entry on each toggle; the archiveTicket server action is tickets:staff gated and emits a ticket:archive event. Edits and votes on archived tickets are rejected.
This commit is contained in:
parent
38e6b3d89f
commit
e0f305b026
19 changed files with 38516 additions and 19 deletions
|
|
@ -39,7 +39,8 @@ export default async function TicketPage({ params }: TicketPageProps) {
|
||||||
})
|
})
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
|
|
||||||
if (!ticket) {
|
// Archived tickets are hidden from the front-end for everyone, staff included.
|
||||||
|
if (!ticket || (ticket as unknown as Ticket).archived) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
import config from "@payload-config";
|
import config from "@payload-config";
|
||||||
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
|
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
|
|
@ -69,7 +70,9 @@ async function getTicketOrThrow(
|
||||||
const ticket = (await payload
|
const ticket = (await payload
|
||||||
.findByID({ collection: "tickets", id: ticketId, depth: 0, overrideAccess: true })
|
.findByID({ collection: "tickets", id: ticketId, depth: 0, overrideAccess: true })
|
||||||
.catch(() => null)) as unknown as Ticket | null;
|
.catch(() => null)) as unknown as Ticket | null;
|
||||||
if (!ticket) throw new Error("Ticket not found.");
|
// Archived tickets are invisible to the front-end; stale links behave as
|
||||||
|
// if the ticket never existed.
|
||||||
|
if (!ticket || ticket.archived) throw new Error("Ticket not found.");
|
||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,3 +404,48 @@ export async function assignTicket(
|
||||||
: { success: false, error: message };
|
: { success: false, error: message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function archiveTicket(ticketId: number): Promise<ActionResult> {
|
||||||
|
try {
|
||||||
|
const { payload, user } = await authenticate();
|
||||||
|
const userId = user.id as number;
|
||||||
|
|
||||||
|
if (!(await hasPermission(payload, user, "tickets:staff"))) {
|
||||||
|
throw new Error("Only staff can archive tickets.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// getTicketOrThrow rejects archived tickets, so this only ever archives
|
||||||
|
// a visible ticket.
|
||||||
|
const ticket = await getTicketOrThrow(payload, ticketId);
|
||||||
|
|
||||||
|
await payload.update({
|
||||||
|
collection: "tickets",
|
||||||
|
id: ticketId,
|
||||||
|
data: { archived: true },
|
||||||
|
overrideAccess: true,
|
||||||
|
depth: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
// No notifications: the ticket is hidden from every front-end surface,
|
||||||
|
// so there is no link target to point anyone at. Un-archiving happens in
|
||||||
|
// the admin panel only.
|
||||||
|
await emitGameEvent(payload, {
|
||||||
|
type: EventTypes.TicketArchive,
|
||||||
|
message: `Ticket #${ticketId} archived: ${ticket.title}`,
|
||||||
|
actor: userId,
|
||||||
|
targetCollection: "tickets",
|
||||||
|
targetId: ticketId,
|
||||||
|
});
|
||||||
|
|
||||||
|
// The client navigates to the list after archiving; make sure the
|
||||||
|
// server-rendered queue is refetched without the archived ticket.
|
||||||
|
revalidatePath("/helpdesk");
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
return message === "Unauthorized"
|
||||||
|
? { success: false, error: "You must be logged in." }
|
||||||
|
: { success: false, error: message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { TicketsView } from "@/components/frontend/helpdesk/TicketsView";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
import { LifeBuoyIcon } from "lucide-react";
|
import { LifeBuoyIcon } from "lucide-react";
|
||||||
import { getTicketVoteSummaries } from "@/lib/tickets/voteState";
|
import { getTicketVoteSummaries } from "@/lib/tickets/voteState";
|
||||||
|
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Helpdesk: Polaris Task Force",
|
title: "Helpdesk: Polaris Task Force",
|
||||||
|
|
@ -48,6 +49,7 @@ export default async function HelpdeskPage() {
|
||||||
|
|
||||||
const ticketsRes = await payload.find({
|
const ticketsRes = await payload.find({
|
||||||
collection: "tickets",
|
collection: "tickets",
|
||||||
|
where: NON_ARCHIVED_WHERE,
|
||||||
sort: "-updatedAt",
|
sort: "-updatedAt",
|
||||||
limit: 200,
|
limit: 200,
|
||||||
depth: 2,
|
depth: 2,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { resolveLevel } from "@/utils/xp/resolveLevel";
|
||||||
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
|
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
|
||||||
import { canViewIntelligence } from "@/utils/access-control/canViewIntelligence";
|
import { canViewIntelligence } from "@/utils/access-control/canViewIntelligence";
|
||||||
import { getCurrencyConfig } from "@/lib/banking";
|
import { getCurrencyConfig } from "@/lib/banking";
|
||||||
import { CLOSING_STATUSES } from "@/lib/tickets/ticketMeta";
|
import { CLOSING_STATUSES, NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
import { ProfileSummary } from "@/components/frontend/dashboard/ProfileSummary";
|
import { ProfileSummary } from "@/components/frontend/dashboard/ProfileSummary";
|
||||||
import { MissionBriefing } from "@/components/frontend/dashboard/MissionBriefing";
|
import { MissionBriefing } from "@/components/frontend/dashboard/MissionBriefing";
|
||||||
import { RecentEvents } from "@/components/frontend/dashboard/RecentEvents";
|
import { RecentEvents } from "@/components/frontend/dashboard/RecentEvents";
|
||||||
|
|
@ -258,7 +258,7 @@ export default async function HomePage() {
|
||||||
payload
|
payload
|
||||||
.find({
|
.find({
|
||||||
collection: "tickets",
|
collection: "tickets",
|
||||||
where: { reporter: { equals: userId } },
|
where: { and: [{ reporter: { equals: userId } }, NON_ARCHIVED_WHERE] },
|
||||||
sort: "-updatedAt",
|
sort: "-updatedAt",
|
||||||
limit: 10,
|
limit: 10,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { notFound, redirect } from "next/navigation";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
import { ProjectBoardView } from "@/components/frontend/projects/ProjectBoardView";
|
import { ProjectBoardView } from "@/components/frontend/projects/ProjectBoardView";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
|
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Board | Polaris Task Force",
|
title: "Board | Polaris Task Force",
|
||||||
|
|
@ -53,7 +54,7 @@ export default async function BoardPage({
|
||||||
const [ticketResult, sprintResult, labelResult] = await Promise.all([
|
const [ticketResult, sprintResult, labelResult] = await Promise.all([
|
||||||
payload.find({
|
payload.find({
|
||||||
collection: "tickets" as any,
|
collection: "tickets" as any,
|
||||||
where: { project: { equals: project.id } },
|
where: { and: [{ project: { equals: project.id } }, NON_ARCHIVED_WHERE] },
|
||||||
depth: 2,
|
depth: 2,
|
||||||
limit: 500,
|
limit: 500,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { getPayload } from "payload";
|
||||||
import { ReleasesView } from "@/components/frontend/projects/ReleasesView";
|
import { ReleasesView } from "@/components/frontend/projects/ReleasesView";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
import { richTextToPlaintext } from "@/lib/projects/projectMeta";
|
import { richTextToPlaintext } from "@/lib/projects/projectMeta";
|
||||||
|
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Releases: Polaris Task Force",
|
title: "Releases: Polaris Task Force",
|
||||||
|
|
@ -47,7 +48,7 @@ export default async function ReleasesPage({ params }: { params: Promise<{ key:
|
||||||
}),
|
}),
|
||||||
payload.find({
|
payload.find({
|
||||||
collection: "tickets" as any,
|
collection: "tickets" as any,
|
||||||
where: { project: { equals: project.id } },
|
where: { and: [{ project: { equals: project.id } }, NON_ARCHIVED_WHERE] },
|
||||||
depth: 0,
|
depth: 0,
|
||||||
limit: 500,
|
limit: 500,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { notFound, redirect } from "next/navigation";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
import { SprintsView } from "@/components/frontend/projects/SprintsView";
|
import { SprintsView } from "@/components/frontend/projects/SprintsView";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { hasPermission } from "@/utils/access-control/hasPermission";
|
||||||
|
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Sprints: Polaris Task Force",
|
title: "Sprints: Polaris Task Force",
|
||||||
|
|
@ -50,7 +51,7 @@ export default async function SprintsPage({
|
||||||
}),
|
}),
|
||||||
payload.find({
|
payload.find({
|
||||||
collection: "tickets" as any,
|
collection: "tickets" as any,
|
||||||
where: { project: { equals: project.id } },
|
where: { and: [{ project: { equals: project.id } }, NON_ARCHIVED_WHERE] },
|
||||||
depth: 0,
|
depth: 0,
|
||||||
limit: 500,
|
limit: 500,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { headers as nextHeaders } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
import { ProjectSearchView } from "@/components/frontend/projects/ProjectSearchView";
|
import { ProjectSearchView } from "@/components/frontend/projects/ProjectSearchView";
|
||||||
|
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "Search: Polaris Task Force",
|
title: "Search: Polaris Task Force",
|
||||||
|
|
@ -20,7 +21,7 @@ export default async function SearchPage() {
|
||||||
const [ticketResult, labelResult] = await Promise.all([
|
const [ticketResult, labelResult] = await Promise.all([
|
||||||
payload.find({
|
payload.find({
|
||||||
collection: "tickets" as any,
|
collection: "tickets" as any,
|
||||||
where: { project: { exists: true } },
|
where: { and: [{ project: { exists: true } }, NON_ARCHIVED_WHERE] },
|
||||||
depth: 2,
|
depth: 2,
|
||||||
pagination: false,
|
pagination: false,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ collections/
|
||||||
server/ 5 files # MissionFiles, ModLists, GameServers, ArmaCommands, ArmaSyncEvents
|
server/ 5 files # MissionFiles, ModLists, GameServers, ArmaCommands, ArmaSyncEvents
|
||||||
world/ 5 files # Maps (basemap config), MapRoads/MapZones/ResourceNodes (map features), NarrativeEvents
|
world/ 5 files # Maps (basemap config), MapRoads/MapZones/ResourceNodes (map features), NarrativeEvents
|
||||||
projects/ 4 files # Projects, Labels, Releases, Sprints (Jira-like)
|
projects/ 4 files # Projects, Labels, Releases, Sprints (Jira-like)
|
||||||
tickets/ 2 files # Tickets (Lexical rich text), TicketVotes
|
tickets/ 2 files # Tickets (Lexical rich text; `archived` hides from all front-ends, admin panel only), TicketVotes
|
||||||
wiki/ 3 files # WikiPages, WikiRevisions, WikiTemplates
|
wiki/ 3 files # WikiPages, WikiRevisions, WikiTemplates
|
||||||
story/ 3 files # StoryBeats (Chronicle chapters), StoryBeatStates (read markers/reactions),
|
story/ 3 files # StoryBeats (Chronicle chapters), StoryBeatStates (read markers/reactions),
|
||||||
# Voiceovers (audio narration uploads for the Chronicle, attached to beats)
|
# Voiceovers (audio narration uploads for the Chronicle, attached to beats)
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ export const Tickets: CollectionConfig = {
|
||||||
"category",
|
"category",
|
||||||
"reporter",
|
"reporter",
|
||||||
"assignee",
|
"assignee",
|
||||||
|
"archived",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
],
|
],
|
||||||
listSearchableFields: ["title", "id"],
|
listSearchableFields: ["title", "id"],
|
||||||
|
|
@ -141,6 +142,19 @@ export const Tickets: CollectionConfig = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Archive toggles → system entry + archivedAt management. Archived
|
||||||
|
// tickets are hidden from every front-end surface; un-archiving only
|
||||||
|
// happens in the admin panel.
|
||||||
|
if (next.archived !== undefined && Boolean(prev.archived) !== Boolean(next.archived)) {
|
||||||
|
if (next.archived) {
|
||||||
|
next.archivedAt = now;
|
||||||
|
changes.push("Ticket archived");
|
||||||
|
} else {
|
||||||
|
next.archivedAt = null;
|
||||||
|
changes.push("Ticket restored from archive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const message of changes) {
|
for (const message of changes) {
|
||||||
entries.push(systemEntry(message, now));
|
entries.push(systemEntry(message, now));
|
||||||
}
|
}
|
||||||
|
|
@ -299,6 +313,24 @@ export const Tickets: CollectionConfig = {
|
||||||
date: { pickerAppearance: "dayAndTime" },
|
date: { pickerAppearance: "dayAndTime" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "archived",
|
||||||
|
type: "checkbox",
|
||||||
|
defaultValue: false,
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"Archived tickets are hidden from the front-end for everyone (staff included) and remain accessible only here in the admin panel. Uncheck to restore the ticket.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "archivedAt",
|
||||||
|
type: "date",
|
||||||
|
admin: {
|
||||||
|
readOnly: true,
|
||||||
|
description: "Set automatically when the ticket is archived.",
|
||||||
|
date: { pickerAppearance: "dayAndTime" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// --- Project tracking fields (Phase 1) ---
|
// --- Project tracking fields (Phase 1) ---
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,20 @@ import {
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { TicketBadges, TicketCategoryBadge } from "@/components/frontend/helpdesk/TicketBadges";
|
import { TicketBadges, TicketCategoryBadge } from "@/components/frontend/helpdesk/TicketBadges";
|
||||||
import { TicketTimeline } from "@/components/frontend/helpdesk/TicketTimeline";
|
import { TicketTimeline } from "@/components/frontend/helpdesk/TicketTimeline";
|
||||||
import { assignTicket, replyToTicket, updateTicketStatus } from "@/app/(frontend)/helpdesk/actions";
|
import {
|
||||||
|
archiveTicket,
|
||||||
|
assignTicket,
|
||||||
|
replyToTicket,
|
||||||
|
updateTicketStatus,
|
||||||
|
} from "@/app/(frontend)/helpdesk/actions";
|
||||||
import { CLOSING_STATUSES, TICKET_STATUSES, type TicketStatus } from "@/lib/tickets/ticketMeta";
|
import { CLOSING_STATUSES, TICKET_STATUSES, type TicketStatus } from "@/lib/tickets/ticketMeta";
|
||||||
import { CalendarClockIcon, HistoryIcon, SendIcon, Settings2Icon } from "lucide-react";
|
import {
|
||||||
|
ArchiveIcon,
|
||||||
|
CalendarClockIcon,
|
||||||
|
HistoryIcon,
|
||||||
|
SendIcon,
|
||||||
|
Settings2Icon,
|
||||||
|
} from "lucide-react";
|
||||||
import { EditTicketDialog } from "@/components/frontend/helpdesk/EditTicketDialog";
|
import { EditTicketDialog } from "@/components/frontend/helpdesk/EditTicketDialog";
|
||||||
import { TicketVoteButton } from "@/components/frontend/helpdesk/TicketVoteButton";
|
import { TicketVoteButton } from "@/components/frontend/helpdesk/TicketVoteButton";
|
||||||
import type { TicketVoteSummary } from "@/lib/tickets/voteState";
|
import type { TicketVoteSummary } from "@/lib/tickets/voteState";
|
||||||
|
|
@ -98,10 +109,14 @@ export function TicketDetail({
|
||||||
const [confirmCancel, setConfirmCancel] = useState(false);
|
const [confirmCancel, setConfirmCancel] = useState(false);
|
||||||
const [cancelBusy, setCancelBusy] = useState(false);
|
const [cancelBusy, setCancelBusy] = useState(false);
|
||||||
const cancelTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const cancelTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const [confirmArchive, setConfirmArchive] = useState(false);
|
||||||
|
const [archiveBusy, setArchiveBusy] = useState(false);
|
||||||
|
const archiveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
if (cancelTimerRef.current) clearTimeout(cancelTimerRef.current);
|
if (cancelTimerRef.current) clearTimeout(cancelTimerRef.current);
|
||||||
|
if (archiveTimerRef.current) clearTimeout(archiveTimerRef.current);
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
@ -180,6 +195,37 @@ export function TicketDetail({
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleArchive() {
|
||||||
|
setArchiveBusy(true);
|
||||||
|
setControlError(null);
|
||||||
|
const result = await archiveTicket(ticket.id);
|
||||||
|
setArchiveBusy(false);
|
||||||
|
if (result.success) {
|
||||||
|
setConfirmArchive(false);
|
||||||
|
toast.success("Ticket archived");
|
||||||
|
// The ticket is hidden from the front-end now, so leave the detail page.
|
||||||
|
// The archiveTicket action revalidates /helpdesk; refresh() after push()
|
||||||
|
// makes the client refetch instead of serving a prefetched RSC payload.
|
||||||
|
router.push("/helpdesk");
|
||||||
|
router.refresh();
|
||||||
|
} else {
|
||||||
|
setControlError(result.error ?? "Could not archive the ticket.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestArchive() {
|
||||||
|
if (confirmArchive) {
|
||||||
|
void handleArchive();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setConfirmArchive(true);
|
||||||
|
if (archiveTimerRef.current) clearTimeout(archiveTimerRef.current);
|
||||||
|
archiveTimerRef.current = setTimeout(() => {
|
||||||
|
setConfirmArchive(false);
|
||||||
|
archiveTimerRef.current = null;
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full max-w-5xl flex-col gap-6">
|
<div className="flex w-full max-w-5xl flex-col gap-6">
|
||||||
<section className="flex flex-col gap-4">
|
<section className="flex flex-col gap-4">
|
||||||
|
|
@ -289,6 +335,21 @@ export function TicketDetail({
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-2 border-t pt-3 sm:col-span-2">
|
||||||
|
<p className="text-xs text-muted-foreground sm:max-w-[60%]">
|
||||||
|
Archiving hides this ticket from the Helpdesk for everyone, including staff. It can
|
||||||
|
only be restored from the admin panel.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={requestArchive}
|
||||||
|
disabled={archiveBusy || controlBusy !== null}
|
||||||
|
>
|
||||||
|
<ArchiveIcon className="mr-1.5 size-3.5" />
|
||||||
|
{archiveBusy ? "Archiving..." : confirmArchive ? "Confirm archive?" : "Archive ticket"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
{controlError && (
|
{controlError && (
|
||||||
<p role="alert" className="text-sm text-red-400 sm:col-span-2">
|
<p role="alert" className="text-sm text-red-400 sm:col-span-2">
|
||||||
{controlError}
|
{controlError}
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,20 @@ async function ticketById(payload: Payload, ticketId: number): Promise<Ticket> {
|
||||||
if (!Number.isInteger(ticketId) || ticketId <= 0) {
|
if (!Number.isInteger(ticketId) || ticketId <= 0) {
|
||||||
throw new Error("Ticket not found.");
|
throw new Error("Ticket not found.");
|
||||||
}
|
}
|
||||||
return payload.findByID({
|
const ticket = (await payload
|
||||||
collection: "tickets",
|
.findByID({
|
||||||
id: ticketId,
|
collection: "tickets",
|
||||||
depth: 0,
|
id: ticketId,
|
||||||
overrideAccess: true,
|
depth: 0,
|
||||||
});
|
overrideAccess: true,
|
||||||
|
})
|
||||||
|
.catch(() => null)) as Ticket | null;
|
||||||
|
// Archived tickets are invisible to the front-end; treat them as missing so
|
||||||
|
// stale links cannot be edited or voted on.
|
||||||
|
if (!ticket || ticket.archived) {
|
||||||
|
throw new Error("Ticket not found.");
|
||||||
|
}
|
||||||
|
return ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
function snapshotOf(ticket: Ticket): TicketEditSnapshot {
|
function snapshotOf(ticket: Ticket): TicketEditSnapshot {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
* UI style maps. Single source of truth used by the collection, server actions,
|
* UI style maps. Single source of truth used by the collection, server actions,
|
||||||
* and the frontend.
|
* and the frontend.
|
||||||
*/
|
*/
|
||||||
|
import type { Where } from "payload";
|
||||||
|
|
||||||
export const TICKET_STATUSES = [
|
export const TICKET_STATUSES = [
|
||||||
{ label: "Open", value: "open" },
|
{ label: "Open", value: "open" },
|
||||||
|
|
@ -84,6 +85,16 @@ export const CLOSING_STATUSES: readonly TicketStatus[] = [
|
||||||
"closed",
|
"closed",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where-clause fragment excluding archived tickets. Archived tickets are
|
||||||
|
* hidden from every front-end surface for all users (staff included) and stay
|
||||||
|
* accessible only through the Payload admin panel. Combine with other
|
||||||
|
* conditions via `and: [...]`.
|
||||||
|
*/
|
||||||
|
export const NON_ARCHIVED_WHERE: Where = {
|
||||||
|
archived: { not_equals: true },
|
||||||
|
};
|
||||||
|
|
||||||
/** Badge color classes per status, keyed for use with the shadcn `Badge` component. */
|
/** Badge color classes per status, keyed for use with the shadcn `Badge` component. */
|
||||||
export const STATUS_STYLES: Record<TicketStatus, string> = {
|
export const STATUS_STYLES: Record<TicketStatus, string> = {
|
||||||
open: "bg-sky-500/15 text-sky-400 border-sky-500/30",
|
open: "bg-sky-500/15 text-sky-400 border-sky-500/30",
|
||||||
|
|
|
||||||
38198
src/migrations/20261007_044017_add_ticket_archival.json
Normal file
38198
src/migrations/20261007_044017_add_ticket_archival.json
Normal file
File diff suppressed because it is too large
Load diff
13
src/migrations/20261007_044017_add_ticket_archival.ts
Normal file
13
src/migrations/20261007_044017_add_ticket_archival.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||||
|
|
||||||
|
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
ALTER TABLE "tickets" ADD COLUMN "archived" boolean DEFAULT false;
|
||||||
|
ALTER TABLE "tickets" ADD COLUMN "archived_at" timestamp(3) with time zone;`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
ALTER TABLE "tickets" DROP COLUMN "archived";
|
||||||
|
ALTER TABLE "tickets" DROP COLUMN "archived_at";`)
|
||||||
|
}
|
||||||
|
|
@ -114,6 +114,7 @@ import * as migration_20261006_203217_add_dialogue_entry_gate from './20261006_2
|
||||||
import * as migration_20261006_205845_add_flag_time_windows from './20261006_205845_add_flag_time_windows';
|
import * as migration_20261006_205845_add_flag_time_windows from './20261006_205845_add_flag_time_windows';
|
||||||
import * as migration_20261007_025942_add_event_log_visibility from './20261007_025942_add_event_log_visibility';
|
import * as migration_20261007_025942_add_event_log_visibility from './20261007_025942_add_event_log_visibility';
|
||||||
import * as migration_20261007_040914_add_reinforcement_pools from './20261007_040914_add_reinforcement_pools';
|
import * as migration_20261007_040914_add_reinforcement_pools from './20261007_040914_add_reinforcement_pools';
|
||||||
|
import * as migration_20261007_044017_add_ticket_archival from './20261007_044017_add_ticket_archival';
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
{
|
{
|
||||||
|
|
@ -694,6 +695,11 @@ export const migrations = [
|
||||||
{
|
{
|
||||||
up: migration_20261007_040914_add_reinforcement_pools.up,
|
up: migration_20261007_040914_add_reinforcement_pools.up,
|
||||||
down: migration_20261007_040914_add_reinforcement_pools.down,
|
down: migration_20261007_040914_add_reinforcement_pools.down,
|
||||||
name: '20261007_040914_add_reinforcement_pools'
|
name: '20261007_040914_add_reinforcement_pools',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
up: migration_20261007_044017_add_ticket_archival.up,
|
||||||
|
down: migration_20261007_044017_add_ticket_archival.down,
|
||||||
|
name: '20261007_044017_add_ticket_archival'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4760,6 +4760,14 @@ export interface Ticket {
|
||||||
* Set automatically when the ticket reaches a closing status.
|
* Set automatically when the ticket reaches a closing status.
|
||||||
*/
|
*/
|
||||||
closedAt?: string | null;
|
closedAt?: string | null;
|
||||||
|
/**
|
||||||
|
* Archived tickets are hidden from the front-end for everyone (staff included) and remain accessible only here in the admin panel. Uncheck to restore the ticket.
|
||||||
|
*/
|
||||||
|
archived?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Set automatically when the ticket is archived.
|
||||||
|
*/
|
||||||
|
archivedAt?: string | null;
|
||||||
/**
|
/**
|
||||||
* Project this ticket belongs to. Null = standalone/backlog.
|
* Project this ticket belongs to. Null = standalone/backlog.
|
||||||
*/
|
*/
|
||||||
|
|
@ -9693,6 +9701,8 @@ export interface TicketsSelect<T extends boolean = true> {
|
||||||
id?: T;
|
id?: T;
|
||||||
};
|
};
|
||||||
closedAt?: T;
|
closedAt?: T;
|
||||||
|
archived?: T;
|
||||||
|
archivedAt?: T;
|
||||||
project?: T;
|
project?: T;
|
||||||
sprint?: T;
|
sprint?: T;
|
||||||
release?: T;
|
release?: T;
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ export const EventTypes = {
|
||||||
TicketEdit: "ticket:edit",
|
TicketEdit: "ticket:edit",
|
||||||
TicketVote: "ticket:vote",
|
TicketVote: "ticket:vote",
|
||||||
TicketUnvote: "ticket:unvote",
|
TicketUnvote: "ticket:unvote",
|
||||||
|
TicketArchive: "ticket:archive",
|
||||||
|
|
||||||
// Wiki
|
// Wiki
|
||||||
WikiPageCreate: "wiki:page-create",
|
WikiPageCreate: "wiki:page-create",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { beforeAll, afterAll, describe, expect, it } from "vitest";
|
||||||
import type { Ticket, User } from "@/payload-types";
|
import type { Ticket, User } from "@/payload-types";
|
||||||
import { plaintextToLexical } from "@/lib/tickets/lexical";
|
import { plaintextToLexical } from "@/lib/tickets/lexical";
|
||||||
import { getStaffUserIds } from "@/lib/tickets/staff";
|
import { getStaffUserIds } from "@/lib/tickets/staff";
|
||||||
import { STATUS_LABEL, TICKET_STATUSES } from "@/lib/tickets/ticketMeta";
|
import { NON_ARCHIVED_WHERE, STATUS_LABEL, TICKET_STATUSES } from "@/lib/tickets/ticketMeta";
|
||||||
import { setTicketVoteForUser, updateTicketByAuthor } from "@/lib/tickets/mutations";
|
import { setTicketVoteForUser, updateTicketByAuthor } from "@/lib/tickets/mutations";
|
||||||
|
|
||||||
let payload: Payload;
|
let payload: Payload;
|
||||||
|
|
@ -479,4 +479,106 @@ describe("Tickets", () => {
|
||||||
"Canceled tickets cannot receive votes",
|
"Canceled tickets cannot receive votes",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stamps archivedAt and appends system entries on archive and restore", async () => {
|
||||||
|
const ticket = await createTicket(reporter.id, `${RUN} Archivable`);
|
||||||
|
expect(ticket.archived).toBeFalsy();
|
||||||
|
|
||||||
|
await payload.update({
|
||||||
|
collection: "tickets",
|
||||||
|
id: ticket.id,
|
||||||
|
data: { archived: true },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const archived = await fetchTicket(ticket.id);
|
||||||
|
expect(archived.archived).toBe(true);
|
||||||
|
expect(archived.archivedAt).toBeTruthy();
|
||||||
|
expect(activityTexts(archived)).toContain("Ticket archived");
|
||||||
|
|
||||||
|
// Restoring (admin panel only) clears the stamp and logs the restore.
|
||||||
|
await payload.update({
|
||||||
|
collection: "tickets",
|
||||||
|
id: ticket.id,
|
||||||
|
data: { archived: false },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const restored = await fetchTicket(ticket.id);
|
||||||
|
expect(restored.archived).toBe(false);
|
||||||
|
expect(restored.archivedAt).toBeNull();
|
||||||
|
expect(activityTexts(restored)).toContain("Ticket restored from archive");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("excludes archived tickets from front-end queries but keeps them in the admin panel", async () => {
|
||||||
|
const visible = await createTicket(reporter.id, `${RUN} Archive visible`);
|
||||||
|
const hidden = await createTicket(reporter.id, `${RUN} Archive hidden`);
|
||||||
|
await payload.update({
|
||||||
|
collection: "tickets",
|
||||||
|
id: hidden.id,
|
||||||
|
data: { archived: true },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Front-end list pattern (helpdesk page): NON_ARCHIVED_WHERE hides it.
|
||||||
|
const frontendRes = await payload.find({
|
||||||
|
collection: "tickets",
|
||||||
|
where: { and: [{ title: { contains: RUN } }, NON_ARCHIVED_WHERE] },
|
||||||
|
limit: 100,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
const frontendIds = frontendRes.docs.map((ticket) => ticket.id);
|
||||||
|
expect(frontendIds).toContain(visible.id);
|
||||||
|
expect(frontendIds).not.toContain(hidden.id);
|
||||||
|
|
||||||
|
// Admin panel pattern: unfiltered reads still see archived tickets.
|
||||||
|
const adminRes = await payload.find({
|
||||||
|
collection: "tickets",
|
||||||
|
where: { title: { contains: RUN } },
|
||||||
|
limit: 100,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
expect(adminRes.docs.map((ticket) => ticket.id)).toContain(hidden.id);
|
||||||
|
|
||||||
|
// Even the reporter's own scoped read with the front-end filter hides it.
|
||||||
|
const scopedRes = await payload.find({
|
||||||
|
collection: "tickets",
|
||||||
|
where: { and: [{ reporter: { equals: reporter.id } }, NON_ARCHIVED_WHERE] },
|
||||||
|
limit: 100,
|
||||||
|
depth: 0,
|
||||||
|
user: reporter,
|
||||||
|
overrideAccess: false,
|
||||||
|
});
|
||||||
|
const scopedIds = scopedRes.docs.map((ticket) => ticket.id);
|
||||||
|
expect(scopedIds).toContain(visible.id);
|
||||||
|
expect(scopedIds).not.toContain(hidden.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats archived tickets as missing for edits and votes", async () => {
|
||||||
|
const ticket = await createTicket(reporter.id, `${RUN} Archived mutations`);
|
||||||
|
await payload.update({
|
||||||
|
collection: "tickets",
|
||||||
|
id: ticket.id,
|
||||||
|
data: { archived: true },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
updateTicketByAuthor(payload, reporter, {
|
||||||
|
ticketId: ticket.id,
|
||||||
|
title: `${RUN} Should not stick`,
|
||||||
|
description: `${RUN} should not stick`,
|
||||||
|
category: "bug_report",
|
||||||
|
priority: "high",
|
||||||
|
}),
|
||||||
|
).rejects.toThrow("Ticket not found");
|
||||||
|
|
||||||
|
await expect(setTicketVoteForUser(payload, reporter, ticket.id, true)).rejects.toThrow(
|
||||||
|
"Ticket not found",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect((await fetchTicket(ticket.id)).title).toBe(`${RUN} Archived mutations`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue