File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -6,26 +6,33 @@ import { FastifyRequest } from "fastify";
66export 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 }
You can’t perform that action at this time.
0 commit comments