-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: respect user roles in dashboard APIs #36
Conversation
43e29ae
to
528d9cc
Compare
eeab1ce
to
7a1c893
Compare
7a1c893
to
809c621
Compare
febf1a2
to
287c599
Compare
287c599
to
773b02d
Compare
from simple_history.models import HistoricalRecords | ||
|
||
|
||
class ViewAllowedRoles(models.Model): |
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.
@shadinaif Isn't that a little bit too dynamic to our needs?
Would you mind sharing the details why do you think we cannot hard-code the allowed roles in every 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.
Maybe it's too dynamic right now. But I believe it'll make a lot more sense when FutureX customers start to use it. I actually guess they might ask for roles per tenant in the future!
e6e065b
to
71b59cd
Compare
71b59cd
to
aa1df58
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.
LGTM. Couldn't give it a deep review due to its size.
@cache_dict(timeout='FX_CACHE_TIMEOUT_COURSE_ACCESS_ROLES', key_generator_or_name=cs.CACHE_NAME_ALL_COURSE_ACCESS_ROLES) | ||
def get_all_course_access_roles() -> dict: |
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.
Note for Omar on performance: This is is probably an anti-pattern that slows down the request.
#perf
class FXViewRoleInfoMetaClass(type): | ||
"""Metaclass to provide role information to the 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.
Why a Metaclass is needed?
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.
Two reasons:
- To have schema check on the class definition for any new view in the future.
- To collect the needed information to apply data-migration (not DB-migration) automatically. If we add a view, it'll have its allowed roles saved in
ViewAllowedRoles
table automatically
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.
@shadinaif the code is fine and working and I couldn't fine huge issues in the code.
However, I think the course access roles cache is actually slowing down the site. I don't have data to show that, the code just doesn't look right and it has all sort of problems:
- Cache the results, which results in delayed permission granting and frustrating the users.
- The cache will store all users in a single object, while we need to check the permission of a single user (dashboard user) on every request.
I think it can be merged, but the cache needs to be tested to ensure it's not slowing requests down.
Thank you @OmarIthawi , can you please approve it? I have a plan for performance issues, I'll consider your note about the cache too for sure |
I thought I did approve it. Sorry. |
Respect user roles in dashboard APIs