-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(authz): let permission interceptor handle nesting (#48)
* fix(authz): remove duplicate provide exports * fix(authz): remove alias of condition service * fix(authz): let interceptor handle nesting * Adapt `PermissionInterceptor` such that it also considers nested properties (objects as well as array). * Remove request scope from interceptor * Use proper constants for metadata
- Loading branch information
1 parent
961c268
commit 8f2d5c9
Showing
8 changed files
with
240 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const AUTHORIZATION_MODULE_OPTIONS = 'AUTHORIZATION_MODULE_OPTIONS'; | ||
export const AUTHORIZATION_EXPOSED_WITH_PERMISSION_PROPS = | ||
'AUTHORIZATION_EXPOSED_WITH_PERMISSION_PROPS '; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 13 additions & 4 deletions
17
packages/nestjs-authorization/src/permissions/expose-with-permission.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { Action } from '../actions/action'; | ||
import { AUTHORIZATION_EXPOSED_WITH_PERMISSION_PROPS } from '../authorization.constants'; | ||
|
||
export function ExposeWithPermission(action: Action): PropertyDecorator { | ||
return (target, key) => { | ||
const fields = Reflect.getMetadata('actions', target) || []; | ||
if (!fields.includes(key)) { | ||
fields.push([key, action]); | ||
const props = | ||
Reflect.getMetadata( | ||
AUTHORIZATION_EXPOSED_WITH_PERMISSION_PROPS, | ||
target | ||
) || []; | ||
if (!props.includes(key)) { | ||
props.push([key, action]); | ||
} | ||
Reflect.defineMetadata('actions', fields, target); | ||
Reflect.defineMetadata( | ||
AUTHORIZATION_EXPOSED_WITH_PERMISSION_PROPS, | ||
props, | ||
target | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.