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 AffectedArg-decorator #1707

Closed
wants to merge 1 commit into from
Closed

Conversation

fraxachun
Copy link
Contributor

@fraxachun fraxachun commented Feb 15, 2024

Current situation is that when a scope-argument is present in a graphql-request this is used to check the content scope. However, in certain situations (e.g. the ContentScope only has one field) we just want to submit the value instead of a scope-Object:

    @Query(() => Customers)
    @AffectedArg((tenantId: string) => ({tenantId}))
    async customersForTenant(@Args("tenantId") tenantId: string): Promise<PaginatedNews> {

@fraxachun fraxachun force-pushed the user-permissions-affected-arg branch from b7429fe to 5e18b6a Compare February 15, 2024 13:52
@nsams
Copy link
Member

nsams commented Feb 15, 2024

please add usage examples to the description of this PR

@nsams
Copy link
Member

nsams commented Feb 15, 2024

Why not use @AffectedEntity(Teanent, { idArg: "teanentId"}); together with @ScopedEntity in Teanent entity?

@fraxachun
Copy link
Contributor Author

Why not use @AffectedEntity(Teanent, { idArg: "teanentId"}); together with @ScopedEntity in Teanent entity?

You're right, this accomplishes the same and in the end is more logical.

@fraxachun fraxachun closed this Feb 19, 2024
@johnnyomair
Copy link
Collaborator

Wasn't our intention to remove the scope arg magic and make it explicit? Something like @AffectedArg("scope")?

@fraxachun
Copy link
Contributor Author

Wasn't our intention to remove the scope arg magic and make it explicit? Something like @AffectedArg("scope")?

Initially yes. But I can't think of a case where you want to change the name of the scope-argument without having an affected entity. Do you?

Because if not I think it's sufficient to just let the dev know when it's missing: https://github.com/vivid-planet/comet/blob/main/packages/api/cms-api/src/user-permissions/auth/user-permissions.guard.ts#L46

@johnnyomair
Copy link
Collaborator

Do you?

No.

The "problem" that still remains that if developers send a scope arg, they may assume that everything is validated correctly, where it may not be. For example:

updateTenant(
  scope: { tenantId: "123" }, // ID of the parent tenant
  id: "456" // Actual ID of the tenant
)

This operation will be allowed if a user has access to the parent tenant, but will not verify if a user can access the child tenant. I thought this is what we we're talking about last week.

@johnnyomair johnnyomair deleted the user-permissions-affected-arg branch July 24, 2024 07:50
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.

3 participants