Add a decorator that makes a view require a feature

Review Request #9007 — Created June 9, 2017 and submitted

Information

Djblets
release-0.10.x

Reviewers

The @feature_required(f) decorator makes the decorated view require
the f feature to be enabled to be executed. Otherwise a backup view
will be called, which by default returns a 404 Not Found error. This
view may be customized by the caller to return any sort of response.

  • Tested this with an upcoming patch for RB.
  • Ran unit tests.
Description From Last Updated

This needs unit tests.

chipx86chipx86

W293 blank line contains whitespace

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

Thinking we may want to allow for a little more flexibility in what's returned here. A 404 might be appropriate …

chipx86chipx86
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

brennie
chipx86
  1. 
      
  2. This needs unit tests.

  3. djblets/features/decorators.py (Diff revision 2)
     
     

    Thinking we may want to allow for a little more flexibility in what's returned here. A 404 might be appropriate for a lot of things, but a 403 might be for others. It might also be really nice to allow some other thing to be returned (redirect, custom page with instructions on requesting access to the thing, etc.).

    How about letting feature_required take a not_enabled_view argument that defaults to lambda *args, **kwargs: HttpResponseNotFound()? Then callers could leave it at the default to get a 404, or could override the behavior to return whatever they want.

  4. 
      
brennie
brennie
david
  1. Ship It!
  2. 
      
brennie
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.10.x (e6511ad)
Loading...