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

TBD: access mixins: support for custom exceptions #145

Closed
wants to merge 6 commits into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Aug 9, 2014

I wanted to use a custom exception with SuperuserRequiredMixin (Http404) and added support for it.

raise_exception can now be True, False, a custom exception or a callable (that should return a response).

I have then factored the no-permission handling into a separate function, and moved redirect_unauthenticated_users to the base mixin.

This does not include any documentation changes yet, because I wanted to gather feedback on it first.

E.g., I am not sure if handle_no_permission should fall back to raising an exception for any non-HTTP-response (not isinstance(ret, (HttpResponse, StreamingHttpResponse))).

@blueyed
Copy link
Contributor Author

blueyed commented Sep 30, 2014

I would appreciate some feedback on this.

E.g. is redirect_unauthenticated_users still useful / correctly named? Because now it's used to fallback to / call no_permissions_fail.

@kennethlove
Copy link
Member

This definitely needs docs. I'm not sure why you deleted the AnonymousUser test, though? That should still pass based on the changes to AccessMixin, shouldn't it?

We also definitely want to make sure the response is a valid HTTPResponse or StreamingHTTPResponse since Django requires a valid responses from views.

As for the naming of redirect_unauthenticated_users, that has been around for awhile, so if we did decide to rename/remove it, we'd need to go through a deprecation process. I'd say it should probably be renamed to redirect_invalid_users if anything.

@chrisjones-brack3t
Copy link
Member

Yep, that removed test does pass. All tests pass for me after merging in master. I'd like to get a new release out tomorrow or at the latest early next week. If you can get this together with docs it'll make it into the 1.5 release. Otherwise I'll push it back to 1.6.

@blueyed
Copy link
Contributor Author

blueyed commented Dec 5, 2014

@chrisjones-brack3t
Great. I'll probably not get to it until tomorrow, but will do so in the next days.

@blueyed
Copy link
Contributor Author

blueyed commented Dec 9, 2014

I'm not sure why you deleted the AnonymousUser test, though?

If you mean test_anonymous_redirects, this has been moved (e294f01).

I'll leave redirect_unauthenticated_users as-is for now.

 - Add `handle_no_permission`.
 - Move `no_permissions_fail` and `redirect_unauthenticated_users` to
   base AccessMixin.
The `redirect_unauthenticated_users` attribute has moved to the base
class.

Also add explicit tests for `redirect_unauthenticated_users=False`.
@blueyed
Copy link
Contributor Author

blueyed commented Dec 9, 2014

I've rebased the branch and updated the documentation: only the .rst for now, I am not sure about the class documentation - should this get added to the base class, or to all mixins, like it's currently done, or just both?

I've also changed it to pass the request argument to the raise_exception callback. Good?

@blueyed
Copy link
Contributor Author

blueyed commented Apr 17, 2015

@kennethlove
Can you please provide some feedback to my last comment?
I can (try to) rebase it again, of course.

@kennethlove kennethlove mentioned this pull request Apr 17, 2015
@blueyed blueyed deleted the custom-exceptions branch April 19, 2015 01:55
@blueyed
Copy link
Contributor Author

blueyed commented Apr 19, 2015

Thanks for merging!

However, it is missing docs probably and some questions are unanswered.
Should be followed up in #173 though anyway.

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