-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Remove redundant has_access definition in superset #4689
Remove redundant has_access definition in superset #4689
Conversation
5dc0031
to
ca3b0d0
Compare
Codecov Report
@@ Coverage Diff @@
## master #4689 +/- ##
==========================================
- Coverage 71.87% 71.85% -0.03%
==========================================
Files 204 204
Lines 15323 15308 -15
Branches 1177 1177
==========================================
- Hits 11014 11000 -14
+ Misses 4306 4305 -1
Partials 3 3
Continue to review full report at Codecov.
|
ca3b0d0
to
48a95c4
Compare
superset/security.py
Outdated
@@ -92,6 +99,42 @@ def can_access(self, permission_name, view_name, user=None): | |||
return self.is_item_public(permission_name, view_name) | |||
return self._has_view_access(user, permission_name, view_name) | |||
|
|||
def has_method_access(self, f): |
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.
It might just be me but I don't like the idea of a decorator as a class method. It's probably ok though. I guess decorators are already complex in terms of what's inside them, external context make it more of a stretch.
superset/security.py
Outdated
return redirect( | ||
url_for( | ||
security_manager.auth_view.__class__.__name__ + '.login', | ||
next=request.full_path)) |
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.
Looked it up and the only difference from the orignal is this one line
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 checked here (http://flask-appbuilder.readthedocs.io/en/latest/_modules/flask_appbuilder/security/manager.html) and all the has_access methods are pretty different from what is in this method.
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.
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 will test things out using the default one and if that's fine, I will change this PR to removing the method
superset/security.py
Outdated
permission_str = f.__name__ | ||
|
||
def wraps(self, *args, **kwargs): | ||
from superset import security_manager |
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 I'm making an argument against my previous comment, but isn't self == security_manager
here?
superset/security.py
Outdated
from superset import security_manager | ||
permission_str = PERMISSION_PREFIX + f._permission_name | ||
if security_manager.has_access(permission_str, | ||
self.__class__.__name__): |
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.
Actually this is fairly confusing as there are two layers of self
here. self
here points to the SupersetView
class, and the one in the frame above it points to superset.security_manager
59fd375
to
5c8b498
Compare
5c8b498
to
4cd17c1
Compare
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 changed this PR to remove the has_access function defined in superset.
I'm now concerned if the next=?? line could potentially cause an error in edge cases I'm not thinking about. But all tests pass and I have accessed some of the endpoints wrapped by has_access successfully.
superset/security.py
Outdated
return redirect( | ||
url_for( | ||
security_manager.auth_view.__class__.__name__ + '.login', | ||
next=request.full_path)) |
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 checked here (http://flask-appbuilder.readthedocs.io/en/latest/_modules/flask_appbuilder/security/manager.html) and all the has_access methods are pretty different from what is in this method.
superset/security.py
Outdated
return redirect( | ||
url_for( | ||
security_manager.auth_view.__class__.__name__ + '.login', | ||
next=request.full_path)) |
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.
superset/security.py
Outdated
return redirect( | ||
url_for( | ||
security_manager.auth_view.__class__.__name__ + '.login', | ||
next=request.full_path)) |
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 will test things out using the default one and if that's fine, I will change this PR to removing the method
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.
Nice, some cleanup. This should work for us.
I'm all for code cleanup/refactoring. |
* update has_access to has_method_access * move has_access to sm and rename to has_method_access
* update has_access to has_method_access * move has_access to sm and rename to has_method_access
This is a follow-up PR to #4565. It removes the has_access from superset since it is defined in FAB here.
The only difference is the next parameter in the url_for function. I have tested it and I doubt it will cause any issues.
@john-bodley @mistercrunch