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

[Low Priority] View documentation #374

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

john-westcott-iv
Copy link
Member

@john-westcott-iv john-westcott-iv commented May 8, 2024

Fixes #371
Requires #133 (needs rebase after this has merged)

@john-westcott-iv john-westcott-iv changed the title View documentation [WIP] View documentation May 9, 2024
@john-westcott-iv john-westcott-iv changed the title [WIP] View documentation View documentation May 9, 2024
@john-westcott-iv john-westcott-iv added the Ready for review This PR is ready for review either initially or comments have been address label May 9, 2024
Copy link

sonarcloud bot commented May 9, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Where string is the name of the field under the related section in the API and URL is the URL to that object. For example, a return like:
```
{
'authenticators': reverse('user-authenticators-list', kwargs={'pk': obj.pk}),
Copy link
Member

Choose a reason for hiding this comment

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

Where does obj come from?

Copy link
Member

Choose a reason for hiding this comment

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

...a return like:

...from UserViewSet.extra_related_fields...

```
Would cause `authenticators` to be listed under the related field and the related URL will be generated from the user-authenticators-list url and should end up as something like `/api/users/:id/authenticators/`.

This can be particularly useful if a feature in DAB wants to extend a view that is created by a service. In this case you can create a MixIn like `ansible_base.oauth2_provider.views/user_mixin.DABOAuth2UserViewsetMixin` which can set `extra_related_fields` and then have the view in the service extend the MixIn.
Copy link
Member

Choose a reason for hiding this comment

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

This can be particularly useful if a feature in DAB wants to extend a view that is created by a service.

As I said in #363, I don't think that's actually a good idea.

ansible_base.oauth2_provider.views/user_mixin.DABOAuth2UserViewsetMixin

/ -> .?

and then have the view in the service extend the MixIn.

I'd prefer capitalization "Mixin"

And I also don't get it. Wouldn't the app just import a AuthenticatorViewSet from DAB and declare that in related views when registering UserViewSet? This thing here is really complicated and I don't see what it does that's useful.

Copy link
Member

Choose a reason for hiding this comment

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

There's too much ground to cover here. Start with the basics. You have a model in the end-user app, and a related model in DAB. You want to define related endpoints of the end-user's model (User) in the DAB app. You make it sound like you're doing this in DAB, but that's not 100% true even in what you're describing here. You define a mixin and use that in the end-user's app. That needs to be spelled out in greater detail. It is defined in the end-user app, what you're describing is just a method for vendoring helper code that the end-user app can use, from DAB, when there is references between those models.

'authenticators': reverse('user-authenticators-list', kwargs={'pk': obj.pk}),
}
```
Would cause `authenticators` to be listed under the related field and the related URL will be generated from the user-authenticators-list url and should end up as something like `/api/users/:id/authenticators/`.
Copy link
Member

Choose a reason for hiding this comment

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

cause authenticators to be listed under the related field and the related URL

The language isn't super clear. I would suggest "under the related field" --> "inside of the "related" dictionary in the User model's serializer"

@john-westcott-iv john-westcott-iv changed the title View documentation [Low Priority] View documentation May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review This PR is ready for review either initially or comments have been address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document view-level extra_related_fields()
3 participants