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

Ability to customize what happens when a view permission fails #812

Closed
simonw opened this issue Jun 8, 2020 · 3 comments
Closed

Ability to customize what happens when a view permission fails #812

simonw opened this issue Jun 8, 2020 · 3 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 8, 2020

Currently view permission failures raise a Forbidden error which is transformed into a 403.

It would be good if this page could offer a way forward - maybe just by linking to (or redirecting to) a login screen. This behaviour will vary based on authentication plugins, so a new plugin hook is probably the best way to do this.

@simonw
Copy link
Owner Author

simonw commented Jun 9, 2020

I'm going to figure this out by working with simonw/datasette-auth-github#62

@simonw
Copy link
Owner Author

simonw commented Jul 1, 2020

This can be a plugin hook:

@hookspec
def forbidden(datasette, request, message, send):
    "Custom response for a 403 forbidden error"

If the hook returns a Response object, it will be returned to the user. Plugins are likely to want to return a redirect response.

Maybe the hook can instead use the send argument to respond to the request and return True which means "I've responded to this"?

I'm going to leave send off for the moment - I can add that in the future if it turns out it would have been a good idea.

@simonw
Copy link
Owner Author

simonw commented Jul 1, 2020

This case may not be covered without extra work:

if not self.ds.config("allow_download") or db.is_mutable:
raise DatasetteError("Database download is forbidden", status=403)

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

No branches or pull requests

1 participant