Skip to content
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

Add docs for user permissions #2128

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Add docs for user permissions #2128

wants to merge 24 commits into from

Conversation

fraxachun
Copy link
Contributor

@fraxachun fraxachun commented Jun 2, 2024

@nsams
Copy link
Member

nsams commented Jun 3, 2024

User-permissions have basically the same topic as the content-scope docs. If you want to move parts into user-permissions you should at least add a link.

Or - maybe the whole content-scope topic should be integrated into user-permissions

@fraxachun
Copy link
Contributor Author

User-permissions have basically the same topic as the content-scope docs. If you want to move parts into user-permissions you should at least add a link.

Actually, there is one: https://github.com/vivid-planet/comet/pull/2128/files#diff-6de07fe72c2ca99e1f939c8c7fb83a75b8cc2d3461488b02eddfaacc471de65cR22

Or - maybe the whole content-scope topic should be integrated into user-permissions

I thought about this but decided to leave the general explanation as is and move the permission specific parts.

@nsams
Copy link
Member

nsams commented Jun 4, 2024

not the other way where you removed @ScopedEntity and @AffectedEntity (https://github.com/vivid-planet/comet/pull/2128/files#diff-05e86dd9dbc3fa6137f21d6a53defee69158651691820542b313fd9f925a2a3fL59)

@fraxachun
Copy link
Contributor Author

@nsams nsams removed their request for review June 5, 2024 05:53
docs/docs/content-scope/content-website.md Outdated Show resolved Hide resolved
docs/docs/content-scope/data-driven-application.md Outdated Show resolved Hide resolved
docs/docs/logging/index.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/index.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/index.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
Use this option only when you are sure that checking the scope is not necessary (e.g. the current entity does not have a scope). Do not add it just because it seems cumbersome at the moment to add the correct `AffectedEntity`/`ScopedEntity` decorators.
:::

:::note
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note doesn't seem right here. Was this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because in many cases skipScopeCheck is disabled only for this reason. But we could think about a more prominent location for this advice since it covers a fairly extensive design guideline.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, maybe add a sentence that skipScopeCheck shouldn't be used in combination with @GetCurrentUser()?

But we could think about a more prominent location for this advice since it covers a fairly extensive design guideline.

This could be something for a follow-up PR regarding general API design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/docs/user-permissions/admin.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/admin.md Show resolved Hide resolved
fraxachun and others added 9 commits June 13, 2024 12:08
Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
@johnnyomair
Copy link
Collaborator

@fraxachun this PR still has some open concerns (to be fair, they are hidden by GitHub's UI)

image

docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/index.md Outdated Show resolved Hide resolved
docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
## Scope check

:::caution
COMET DXP validates the data relevant for the operation, but cannot check if the validated data is finally used. You are responsible for applying the validated data in your operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds confusing to me. I guess what it should tell me is "Be careful which data you use and how you use it in your operation to not accidentally bypass the scope check".

What do you think about:

Suggested change
COMET DXP validates the data relevant for the operation, but cannot check if the validated data is finally used. You are responsible for applying the validated data in your operations.
COMET DXP validates the scope of the data relevant for the operation, but it cannot check how you use the data / what you do with the data within the operation. It's your job to use the data in a responsible way and without bypassing the scope check in your code. This means, for example:
- configuring the scope check for all data used in your operation (not just for one entity)
- not loading additional data from the DB without considering the scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand these examples.

docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
// Note: you can trust "dealerId" being in a valid scope, but you need to make sure that your business code restricts this query to the given dealer
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also mention that you can have multiple AffectedEntity decorators:

Suggested change
It's possible to add multiple `@AffectedEntity` decorators to one operation if multiple entities are affected:
\```ts
@Query(Product)
@AffectedEntity(Product)
@AffectedEntity(Dealer, { idArg: "dealerId" })
async product(@Args("id", { type: () => ID }) id: string, @Args("dealerId", { type: () => ID }) dealerId: string): Promise<Product> {
//...
}
\```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:::info
You might have to load multiple relations for nested data.
:::

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For documents that get their scope from a `PageTreeNode`, you can pass the helper service `PageTreeNodeDocumentEntityScopeService` provided by the library:
\```ts
@ScopedEntity(PageTreeNodeDocumentEntityScopeService)
export class PredefinedPage extends BaseEntity<PredefinedPage, "id"> implements DocumentInterface {
\```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 116 to 118
+ @AffectedEntity(User)
- async myProducts(@GetCurrentUser() currentUser: CurrentUser): Promise<Product[]> {
+ async productsForUser(@Args("userId", { type: () => ID }) userId: string): Promise<Product[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, I suppose. We either need

Suggested change
+ @AffectedEntity(User)
- async myProducts(@GetCurrentUser() currentUser: CurrentUser): Promise<Product[]> {
+ async productsForUser(@Args("userId", { type: () => ID }) userId: string): Promise<Product[]> {
+ @AffectedEntity(User)
- async myProducts(@GetCurrentUser() currentUser: CurrentUser): Promise<Product[]> {
+ async productsForUser(@Args("id", { type: () => ID }) id: string): Promise<Product[]> {

or

Suggested change
+ @AffectedEntity(User)
- async myProducts(@GetCurrentUser() currentUser: CurrentUser): Promise<Product[]> {
+ async productsForUser(@Args("userId", { type: () => ID }) userId: string): Promise<Product[]> {
+ @AffectedEntity(User, { idArg: "userId" })
- async myProducts(@GetCurrentUser() currentUser: CurrentUser): Promise<Product[]> {
+ async productsForUser(@Args("userId", { type: () => ID }) userId: string): Promise<Product[]> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/docs/user-permissions/access-control.md Outdated Show resolved Hide resolved
@johnnyomair
Copy link
Collaborator

@fraxachun what's the status here? IMO it would be good to have docs for user permissions asap.

@fraxachun
Copy link
Contributor Author

@johnnyomair @thomasdax98 I updated this PR to merge in v7 main and tried to resolve all concerns (except #2128 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants