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

Next/Prev entities should point to only entities in the queryset that the user is allowed to see #1415

Closed
gythaogg opened this issue Nov 20, 2024 · 4 comments · Fixed by #1399

Comments

@gythaogg
Copy link
Contributor

Continuing #1412

Consider the following ID sequence
1000, 1001*, 1002, 1003*, 1004 where entities marked with * are not accessible to the user.

Expected behaviour from page 1002:

  • Prev takes the user to 1000
  • Next takes the user to 1004

Current behaviour:

  • Prev takes the user to login page with a redirect to 1001
  • Next takes the user to login page with a redirect to 1003

I believe for a smooth experience, just like the listview that hides entities that the user doesn't have permissions to see, the next/prev links in the detail page should only link to the next/prev entities in the listview queryset that the user is allowed to see.

@gythaogg gythaogg added needs-attention This issue or pull request is in need of discussion, information, assessment by team members needs-design-decision Requires a decision to be made regarding design/implementation labels Nov 20, 2024
@b1rger
Copy link
Contributor

b1rger commented Nov 20, 2024

do you know if that works if you use your custom manager solution?

@gythaogg
Copy link
Contributor Author

I haven't quite managed to select different custom managers for different user access tiers (fiddling around middleware to get the user data).
But if I set a cusom queryset using a manager then the next/prev links will only show the next/prev available objects in this queryset. If the user tries to access an object outside this queryset directly using a URL then it will throw Page not found to that user

@b1rger
Copy link
Contributor

b1rger commented Nov 20, 2024

I haven't quite managed to select different custom managers for different user access tiers (fiddling around middleware to get the user data).

We are already using the crum middleware, so you could get the request using the get_current_request method - which then gives you the user

@gythaogg
Copy link
Contributor Author

gythaogg commented Nov 20, 2024

from crum import get_current_user - Thanks a lot!

Yes, I can confirm that if I setup the list access like so in the model then Prev/Next links will only take the user to the entities that are accessible to the user

This is the PR in Tibschol that implements it - https://github.com/acdh-oeaw/apis-instance-tibschol/pull/196/commits

The approach works well also with the other (nastier) custom managers I have for Instance and Work models.

@sennierer sennierer removed needs-attention This issue or pull request is in need of discussion, information, assessment by team members needs-design-decision Requires a decision to be made regarding design/implementation labels Dec 3, 2024
@gythaogg gythaogg linked a pull request Dec 17, 2024 that will close this issue
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 a pull request may close this issue.

3 participants