Skip to content

Commit 6b7aab2

Browse files
committed
EventsHostRestrictionPolicy: no featured events
1 parent 697d310 commit 6b7aab2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/common/policies/events.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ import { FastifyRequest } from "fastify";
66
export const hostRestrictionPolicy = createPolicy(
77
"EventsHostRestrictionPolicy",
88
z.object({ host: z.array(z.enum(OrganizationList)) }),
9-
(request: FastifyRequest, params) => {
9+
(request: FastifyRequest & { username?: string }, params) => {
1010
if (!request.url.startsWith("/api/v1/events")) {
1111
return {
1212
allowed: true,
1313
message: "Skipped as route not in scope.",
1414
cacheKey: null,
1515
};
1616
}
17-
const typedBody = request.body as { host: string };
17+
const typedBody = request.body as { host: string, featured: boolean };
1818
if (!typedBody || !typedBody["host"]) {
1919
return {
2020
allowed: true,
2121
message: "Skipped as no host found.",
2222
cacheKey: null,
2323
};
2424
}
25+
if (typedBody["featured"]) {
26+
return {
27+
allowed: false,
28+
message: `Denied by policy "EventsHostRestrictionPolicy". Event must not be featured.`,
29+
cacheKey: request.username || null,
30+
};
31+
}
2532
if (!params.host.includes(typedBody["host"])) {
2633
return {
2734
allowed: false,
28-
message: `Denied by policy "EventsHostRestrictionPolicy".`,
35+
message: `Denied by policy "EventsHostRestrictionPolicy". Host must be one of: ${params.host.toString()}.`,
2936
cacheKey: request.username || null,
3037
};
3138
}

0 commit comments

Comments
 (0)