-
Notifications
You must be signed in to change notification settings - Fork 342
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
Closes #7: Implement OPTIONS method #29
Conversation
1 similar comment
def wrapper(*args, **kwargs): | ||
kwargs[object_arg_name] = resolver(kwargs) | ||
return func(*args, **kwargs) | ||
return wrapper | ||
if isinstance(func, type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, swap the if
block with the wrapper
function as if it is a class, there is no need in the function at all.
@@ -135,6 +139,18 @@ def dump_wrapper(*args, **kwargs): | |||
return model.dump(response).data | |||
return dump_wrapper | |||
|
|||
def dump_response_with_model_decorator(func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, it is a duplicate chunk of code.
@@ -153,6 +157,7 @@ def decorator(func): | |||
# Avoid circilar dependency | |||
from app.modules.users import permissions | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a redundant extra new line (1 blank line is enough).
@@ -170,6 +175,9 @@ def wrapper(*args, **kwargs): | |||
|
|||
protected_func = _permission_decorator(func) | |||
|
|||
if not hasattr(protected_func, '_decorators'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, create a separate function to avoid such XXX code duplication. I'm still in doubt if I advised a right way of doing this (I mean using _decorators
attribute on the function itself).
539ae85
to
47415a7
Compare
@@ -46,6 +46,12 @@ def resolve_object(self, object_arg_name, resolver): | |||
... # user is a User instance here | |||
""" | |||
def decorator(func): | |||
if isinstance(func, type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have just realized that we need to rename func
to func_or_class
here since we support both use-cases.
47415a7
to
011d393
Compare
@@ -83,6 +83,8 @@ def decorator(func): | |||
from app.extensions import oauth2 | |||
from app.modules.users import permissions | |||
|
|||
self.register_decorator_in_function(func, decorator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use oauth2.require_oauth(*oauth_scopes)
as a decorator here (and move it closer to the oauth_protected_func = ...
line) since otherwise this will call self.doc
and other unnecessary stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.register_decorator_in_function(func, oauth2.require_oauth(*oauth_scopes))
@@ -170,6 +172,7 @@ def wrapper(*args, **kwargs): | |||
|
|||
protected_func = _permission_decorator(func) | |||
|
|||
self.register_decorator_in_function(protected_func, decorator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, we only need to register _permission_decorator
.
1 similar comment
@@ -199,6 +202,15 @@ def wrapper(*args, **kwargs): | |||
|
|||
return decorator | |||
|
|||
def register_decorator_in_function(self, func, decorator_to_register): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's start the name with underscore since it is for internal use only.
- I think since we only register access-restriction-related decorators, we may indicate this in the function name, e.g.
_register_access_restriction_decorator
. - Also, rename
_decorators
to_access_restriction_decorators
.
011d393
to
bbb397a
Compare
def wrapper(cls): | ||
if 'OPTIONS' in cls.methods: | ||
cls.options = self.response(code=204)(cls.options) | ||
doc = kwargs.pop('doc', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to copy this, just nest the decorators:
def route(...):
base_wrapper = super().route(self, *args, **kwargs)
def wrapper(cls):
if 'OPTIONS'...
...
return base_wrapper(cls)
return wrapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks!
@@ -83,6 +83,7 @@ def decorator(func): | |||
from app.extensions import oauth2 | |||
from app.modules.users import permissions | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this empty line either.
Create Resource patched in flask_restplus_patched that inherits restplus Resource and define the `options` method there. Patch some of decorators to be possible to be impemented with classes. Patch some decorators to get access to permission decorators to perform permission checks in option.
bbb397a
to
fc2722b
Compare
Create Resource patched in flask_restplus_patched that inherits restplus Resource and define the
options
method there.Patch some of decorators to be possible to be impemented with classes. Patch some decorators to get access to permission decorators to perform permission checks in option.