File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 1
- import { ReflectMetadata } from '@nestjs/common' ;
1
+ import { SetMetadata } from '@nestjs/common' ;
2
2
import { Permission } from '../interfaces/permission.interface' ;
3
3
import { PERMISSIONS_METADATA } from '../authz.constants' ;
4
+ import { ExecutionContext } from '@nestjs/common' ;
4
5
5
- const defaultIsOwn = ( request : any ) : boolean => false ;
6
+ const defaultIsOwn = ( ctx : ExecutionContext ) : boolean => false ;
6
7
7
8
/**
8
- * 定义具有什么权限的用户才可以访问此路由。 可以定义多个权限,
9
- * 但是只有在所有权限都满足的情况下,权限判定才会通过。
9
+ * You can define multiple permissions, but only
10
+ * when all of them satisfied, could you access the route.
10
11
*/
11
12
export const UsePermissions = ( ...permissions : Permission [ ] ) => {
12
13
const perms = permissions . map ( item => {
@@ -16,5 +17,5 @@ export const UsePermissions = (...permissions: Permission[]) => {
16
17
return item ;
17
18
} ) ;
18
19
19
- return ReflectMetadata ( PERMISSIONS_METADATA , perms ) ;
20
+ return SetMetadata ( PERMISSIONS_METADATA , perms ) ;
20
21
} ;
Original file line number Diff line number Diff line change 1
- import { AuthAction , AuthPossession } from '../types' ;
1
+ import { AuthActionVerb , AuthPossession } from '../types' ;
2
+ import { ExecutionContext } from '@nestjs/common' ;
2
3
3
4
export interface Permission {
4
5
resource : string ;
5
- action : AuthAction ;
6
+ action : AuthActionVerb ;
6
7
possession : AuthPossession ;
7
- isOwn ?: ( request : any ) => boolean ;
8
+ isOwn ?: ( ctx : ExecutionContext ) => boolean ;
8
9
}
You can’t perform that action at this time.
0 commit comments