Add a decorator that makes a view require a feature
Review Request #9007 — Created June 9, 2017 and submitted
The
@feature_required(f)
decorator makes the decorated view require
thef
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.
- Change Summary:
-
whitespace
- Diff:
-
Revision 2 (+29)
Checks run (2 succeeded)
-
-
-
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 anot_enabled_view
argument that defaults tolambda *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.
- Change Summary:
-
Address Christian's issues; add unit tests.
- Description:
-
The
@feature_required(f)
decorator makes the decorated view require~ the f
feature to be enabled to be executed. Otherwise a 404 will be~ returned. ~ 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. - Testing Done:
-
~ Tested this with an upcoming patch for RB. [TODO: r/?]
~ Tested this with an upcoming patch for RB.
+ + Added unit tests.