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
Add has permission class decorator #150
Add has permission class decorator #150
Conversation
This decorator adds permission for each method of `aiohttp.web.View` class
Codecov Report
@@ Coverage Diff @@
## master #150 +/- ##
==========================================
+ Coverage 94.97% 95.44% +0.47%
==========================================
Files 10 11 +1
Lines 517 702 +185
Branches 18 25 +7
==========================================
+ Hits 491 670 +179
- Misses 20 23 +3
- Partials 6 9 +3
Continue to review full report at Codecov.
|
@@ -147,6 +156,41 @@ def wrapper(fn): | |||
return wrapper | |||
|
|||
|
|||
def class_has_permission(permission_prefix, context=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.
Just curious, may be name this function view_has_permission
to indicate that decorator works for web.View
?
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.
Yes we can change the name, but if the has_permission
decorator is deprecated (#169) I think that we cannot use this API to have set global permission.
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 was thought that not just has_permission
was deprecated, but the decorator-way to check permissions is deprecated. Wouldn't this one face the same fate?
'delete': 'delete'} | ||
|
||
for method_name, permission in methods.items(): | ||
method = getattr(cls, method_name, 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.
should we also check type of cls
object and throw TypeError
if cls
is not web.Veiw
?
If we'll decide to deprecate decorators the PR should be revisited. |
Thank you for PR. |
Decorator that set permission for each
aiohttp.web.View
method.Note: This pull request is based on #148