-
Notifications
You must be signed in to change notification settings - Fork 9
Add AffectedScope-decorator #4931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fraxachun
wants to merge
9
commits into
main
Choose a base branch
from
affected-scope
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
35091e6
Add AffectedScope-decorator
fraxachun 77179db
Fix code in documentation
fraxachun 8cc442e
Export AffectedScope from cms-api
fraxachun 4574970
Merge remote-tracking branch 'origin/main' into affected-scope
fraxachun f17e083
Improve typing of AffectedScope
fraxachun 352cca4
Skip undefined values in content scope check
fraxachun 966b089
Update docs
fraxachun a63a649
Merge remote-tracking branch 'origin/main' into affected-scope
fraxachun ec266ce
Adapt tests
fraxachun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@comet/cms-api": minor | ||
| --- | ||
|
|
||
| Add `@AffectedScope` decorator | ||
|
|
||
| See https://docs.comet-dxp.com/docs/core-concepts/content-scope/evaluate-content-scopes#operations-that-require-a-content-scope-independently-of-a-specific-entity |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@comet/cms-api": minor | ||
| --- | ||
|
|
||
| Skip undefined values in content scope check | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
packages/api/cms-api/src/user-permissions/decorators/affected-scope.decorator.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { SetMetadata } from "@nestjs/common"; | ||
|
|
||
| import { type ContentScope } from "../../user-permissions/interfaces/content-scope.interface"; | ||
|
|
||
| export type AffectedScopeMeta = { | ||
| argsToScope: (args: Record<string, unknown>) => ContentScope; | ||
johnnyomair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export const AFFECTED_SCOPE_METADATA_KEY = "affectedScope"; | ||
|
|
||
| export const AffectedScope = <T>(argsToScope: (args: T) => ContentScope): MethodDecorator => { | ||
johnnyomair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return SetMetadata<string, AffectedScopeMeta>(AFFECTED_SCOPE_METADATA_KEY, { argsToScope: argsToScope as AffectedScopeMeta["argsToScope"] }); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 352cca4
Why this change?
nullandundefinedscope dimensions the same inAccessControlService#isAllowed#2643There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't changing this a breaking change? Now
nullisn't treated as "not existing" any longer, but rather "no specific value set". I can imagine that this would break access control in some of our applications.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main difference is that it's a bit more loose.
Before:
{foo: undefined}forced the user having{foo: null}or{foo: undefined}{foo: null}forced the user having{foo: null}or{foo: undefined}Now:
{foo: undefined}doesn't require to have a content scope{foo: null}forces the user having{foo: null}It's breaking indeed if the user's content-scope consists of
undefinedvalues:Breaking:
{foo: null}isn't allowed anymore if the user has{foo: undefined}Can we neglect this? If not, re-adding these lines should be make it compatible again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also could revert this breaking change. It's not really necessary, but it makes handling optional values easier in
argsToScopeeasier.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ben-Ho @kaufmo what do you think about this? To my best knowledge you're the only ones that have projects with optional scope dimensions.