Maybe fix inactivity notices?
This commit is contained in:
parent
d6a99b56cf
commit
2fc73a62cc
@ -3,7 +3,7 @@ import validateInactivityNotice from "./validate.js";
|
|||||||
|
|
||||||
export async function onRequestDelete(context: RequestContext) {
|
export async function onRequestDelete(context: RequestContext) {
|
||||||
const kvResult = await context.env.DATA.get(
|
const kvResult = await context.env.DATA.get(
|
||||||
`inactivity_${context.params.id}`,
|
`inactivity_${context.params.id}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!kvResult) return jsonError("No inactivity notice with that ID", 404);
|
if (!kvResult) return jsonError("No inactivity notice with that ID", 404);
|
||||||
@ -14,7 +14,7 @@ export async function onRequestDelete(context: RequestContext) {
|
|||||||
)
|
)
|
||||||
return jsonError(
|
return jsonError(
|
||||||
"You do not have permission to delete this inactivity notice",
|
"You do not have permission to delete this inactivity notice",
|
||||||
403,
|
403
|
||||||
);
|
);
|
||||||
|
|
||||||
await context.env.DATA.delete(`inactivity_${context.params.id}`);
|
await context.env.DATA.delete(`inactivity_${context.params.id}`);
|
||||||
@ -23,7 +23,7 @@ export async function onRequestDelete(context: RequestContext) {
|
|||||||
.run();
|
.run();
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 204,
|
status: 204
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
DM: 1 << 11,
|
DM: 1 << 11,
|
||||||
ET: 1 << 4,
|
ET: 1 << 4,
|
||||||
FM: 1 << 7,
|
FM: 1 << 7,
|
||||||
WM: 1 << 6,
|
WM: 1 << 6
|
||||||
};
|
};
|
||||||
|
|
||||||
const userAdminDepartments = Object.keys(adminDepartments).filter(
|
const userAdminDepartments = Object.keys(adminDepartments).filter(
|
||||||
(dept) => context.data.current_user.permissions & adminDepartments[dept],
|
(dept) => context.data.current_user.permissions & adminDepartments[dept]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!userAdminDepartments.length)
|
if (!userAdminDepartments.length)
|
||||||
@ -49,7 +49,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
|
|
||||||
const requestedNotice: { [k: string]: any } | null =
|
const requestedNotice: { [k: string]: any } | null =
|
||||||
await context.env.DATA.get(`inactivity_${context.params.id as string}`, {
|
await context.env.DATA.get(`inactivity_${context.params.id as string}`, {
|
||||||
type: "json",
|
type: "json"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!requestedNotice)
|
if (!requestedNotice)
|
||||||
@ -57,31 +57,26 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
|
|
||||||
const decisions: { [dept: string]: boolean } = {};
|
const decisions: { [dept: string]: boolean } = {};
|
||||||
|
|
||||||
userAdminDepartments.forEach((dept) =>
|
for (const department of userAdminDepartments)
|
||||||
Object.defineProperty(decisions, dept, {
|
decisions[department] = accepted;
|
||||||
value: accepted,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Object.defineProperty(requestedNotice, "decisions", {
|
requestedNotice.decisions = decisions;
|
||||||
value: decisions,
|
|
||||||
});
|
|
||||||
|
|
||||||
await context.env.DATA.put(
|
await context.env.DATA.put(
|
||||||
`inactivity_${context.params.id as string}`,
|
`inactivity_${context.params.id as string}`,
|
||||||
JSON.stringify(requestedNotice),
|
JSON.stringify(requestedNotice),
|
||||||
{ expirationTtl: 63072000 },
|
{ expirationTtl: 63072000 }
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 204,
|
status: 204
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function onRequestPut(context: RequestContext) {
|
export async function onRequestPut(context: RequestContext) {
|
||||||
const kvResult: InactivityNoticeProps | null = await context.env.DATA.get(
|
const kvResult: InactivityNoticeProps | null = await context.env.DATA.get(
|
||||||
`inactivity_${context.params.id}`,
|
`inactivity_${context.params.id}`,
|
||||||
{ type: "json" },
|
{ type: "json" }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!kvResult) return jsonError("No inactivity notice with that ID", 404);
|
if (!kvResult) return jsonError("No inactivity notice with that ID", 404);
|
||||||
@ -89,11 +84,11 @@ export async function onRequestPut(context: RequestContext) {
|
|||||||
if (kvResult.user.id !== context.data.current_user.id)
|
if (kvResult.user.id !== context.data.current_user.id)
|
||||||
return jsonError(
|
return jsonError(
|
||||||
"You do not have permission to modify this inactivity notice",
|
"You do not have permission to modify this inactivity notice",
|
||||||
403,
|
403
|
||||||
);
|
);
|
||||||
|
|
||||||
const d1entry = await context.env.D1.prepare(
|
const d1entry = await context.env.D1.prepare(
|
||||||
"SELECT open FROM inactivity_notices WHERE id = ?;",
|
"SELECT open FROM inactivity_notices WHERE id = ?;"
|
||||||
)
|
)
|
||||||
.bind(context.params.id)
|
.bind(context.params.id)
|
||||||
.run();
|
.run();
|
||||||
@ -108,7 +103,7 @@ export async function onRequestPut(context: RequestContext) {
|
|||||||
end,
|
end,
|
||||||
reason,
|
reason,
|
||||||
start,
|
start,
|
||||||
context.data.departments,
|
context.data.departments
|
||||||
);
|
);
|
||||||
|
|
||||||
if (validationFailureResponse) return validationFailureResponse;
|
if (validationFailureResponse) return validationFailureResponse;
|
||||||
@ -122,11 +117,11 @@ export async function onRequestPut(context: RequestContext) {
|
|||||||
`inactivity_${context.params.id}`,
|
`inactivity_${context.params.id}`,
|
||||||
JSON.stringify(kvResult),
|
JSON.stringify(kvResult),
|
||||||
{
|
{
|
||||||
expirationTtl: 63072000,
|
expirationTtl: 63072000
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 204,
|
status: 204
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user