Skip to content

Commit e757472

Browse files
committed
refactor: refactor isOwn to accept ExecutionContext
BREAKING CHANGE: isOwn now accepts ExecutionContext as the only arg
1 parent 3f2badd commit e757472

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { ReflectMetadata } from '@nestjs/common';
1+
import { SetMetadata } from '@nestjs/common';
22
import { Permission } from '../interfaces/permission.interface';
33
import { PERMISSIONS_METADATA } from '../authz.constants';
4+
import { ExecutionContext } from '@nestjs/common';
45

5-
const defaultIsOwn = (request: any): boolean => false;
6+
const defaultIsOwn = (ctx: ExecutionContext): boolean => false;
67

78
/**
8-
* 定义具有什么权限的用户才可以访问此路由。 可以定义多个权限,
9-
* 但是只有在所有权限都满足的情况下,权限判定才会通过。
9+
* You can define multiple permissions, but only
10+
* when all of them satisfied, could you access the route.
1011
*/
1112
export const UsePermissions = (...permissions: Permission[]) => {
1213
const perms = permissions.map(item => {
@@ -16,5 +17,5 @@ export const UsePermissions = (...permissions: Permission[]) => {
1617
return item;
1718
});
1819

19-
return ReflectMetadata(PERMISSIONS_METADATA, perms);
20+
return SetMetadata(PERMISSIONS_METADATA, perms);
2021
};
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { AuthAction, AuthPossession } from '../types';
1+
import { AuthActionVerb, AuthPossession } from '../types';
2+
import { ExecutionContext } from '@nestjs/common';
23

34
export interface Permission {
45
resource: string;
5-
action: AuthAction;
6+
action: AuthActionVerb;
67
possession: AuthPossession;
7-
isOwn?: (request: any) => boolean;
8+
isOwn?: (ctx: ExecutionContext) => boolean;
89
}

0 commit comments

Comments
 (0)