-
-
Notifications
You must be signed in to change notification settings - Fork 900
[RFC] Add a system for getting parent resource and play security #7107
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
Comments
I don't think there's a way to "play" the security defined on another resource, but if $crawl is a member of your CrawlUrl you should be able to populate it with the Link, then reuse the existing voter with something like |
It means I should get the crawl url first, then get the crawl (it's another db storage, so it needs another query anyway) and then play security. There is an extra step here. but but, may be I'm overthinking here... But I have another example, maybe more explicit. |
You can pass the id to your Voter, which means you could have something like this on your operation : ...different from what you had in mind, no doubt...but i can see lots of difficulties trying to make this automatic 🤔 |
Hello, Maybe you can use https://api-platform.com/docs/core/extensions/ ? It's just another guard to properly query if your data associated with user id as it works quite good for me. Also I've slightly modified your code: #[ApiResource(
operations: [
new Get(
uriTemplate: '/crawls/{crawlId}/crawl-urls/{id}',
requirements: [
'id' => Requirement::UUID,
'crawlUrlId' => Requirement::UUID,
],
// ⚠⚠⚠⚠ this is probably bullshit, I don't understand the from/to thing ⚠⚠⚠⚠
uriVariables: [
'crawlId' => new Link(
fromClass: Crawl::class,
// parameterName: 'id', you don't need this?
toProperty: 'crawl', // this should be relation https://api-platform.com/docs/admin/handling-relations/#using-an-autocomplete-input-for-relations
identifiers: ['id'], // this is Crawl::class id
),
'id' => new Link(
fromClass: CrawlUrl::class, // this should be from class?
),
],
),
],
)]
class CrawlUrl Basically this is works great with relation but if you need more custom logic, then you should probably take a look at this #5732 ? Thanks! |
Thanks for the discussion. I'm closing it in favor of #7112, which is much much better ! |
There's security on links:
You need to specify: new Link(securityObjectName: 'object', security: 'is_granted()', fromClass: Crawl::class) This will call: |
Hello,
It's still a bit vague in my mind, But I always face the same issue,
and I did not found a way to code it.
I have a resource name
Crawl
(stored and Doctrine, but exposed via a custom DTO + security) and some subresource namedCrawlUrl
(stored in ClickHouse, but exposed via a custom DTO + security)I have the following endpoint
/crawls/{id}
/crawls/{crawlId}/crawl-urls/{id}
In my CrawlUrlItemProvider (for examples) I would like to be able to write such code
Did I miss something, or is it something out of scope? If no, could this be implemented in APIP?
I imagine something like:
may be linked to #7105
The text was updated successfully, but these errors were encountered: