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";
6
6
export const hostRestrictionPolicy = createPolicy (
7
7
"EventsHostRestrictionPolicy" ,
8
8
z . object ( { host : z . array ( z . enum ( OrganizationList ) ) } ) ,
9
- ( request : FastifyRequest , params ) => {
9
+ ( request : FastifyRequest & { username ?: string } , params ) => {
10
10
if ( ! request . url . startsWith ( "/api/v1/events" ) ) {
11
11
return {
12
12
allowed : true ,
13
13
message : "Skipped as route not in scope." ,
14
14
cacheKey : null ,
15
15
} ;
16
16
}
17
- const typedBody = request . body as { host : string } ;
17
+ const typedBody = request . body as { host : string , featured : boolean } ;
18
18
if ( ! typedBody || ! typedBody [ "host" ] ) {
19
19
return {
20
20
allowed : true ,
21
21
message : "Skipped as no host found." ,
22
22
cacheKey : null ,
23
23
} ;
24
24
}
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
+ }
25
32
if ( ! params . host . includes ( typedBody [ "host" ] ) ) {
26
33
return {
27
34
allowed : false ,
28
- message : `Denied by policy "EventsHostRestrictionPolicy".` ,
35
+ message : `Denied by policy "EventsHostRestrictionPolicy". Host must be one of: ${ params . host . toString ( ) } . ` ,
29
36
cacheKey : request . username || null ,
30
37
} ;
31
38
}
You can’t perform that action at this time.
0 commit comments