Skip to content
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

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

shadinaif
Copy link
Collaborator

Respect user roles in dashboard APIs

@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch 5 times, most recently from 43e29ae to 528d9cc Compare June 25, 2024 13:38
@shadinaif shadinaif changed the title Respect user roles in dashboard APIs feat: respect user roles in dashboard APIs Jun 25, 2024
@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch 7 times, most recently from eeab1ce to 7a1c893 Compare June 26, 2024 14:44
@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch from 7a1c893 to 809c621 Compare June 26, 2024 15:40
@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch from febf1a2 to 287c599 Compare June 29, 2024 16:44
@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch from 287c599 to 773b02d Compare June 29, 2024 16:58
from simple_history.models import HistoricalRecords


class ViewAllowedRoles(models.Model):
Copy link
Collaborator

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?

Copy link
Collaborator Author

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!

@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch 2 times, most recently from e6e065b to 71b59cd Compare July 2, 2024 16:00
@shadinaif shadinaif force-pushed the shadinaif/dashboard-user-roles branch from 71b59cd to aa1df58 Compare July 2, 2024 16:10
@shadinaif shadinaif marked this pull request as ready for review July 2, 2024 16:12
@shadinaif shadinaif requested review from OmarIthawi and iamjazzar July 6, 2024 10:56
Copy link

@iamjazzar iamjazzar left a 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.

Comment on lines +71 to +72
@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:
Copy link
Collaborator

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

Comment on lines +182 to +183
class FXViewRoleInfoMetaClass(type):
"""Metaclass to provide role information to the view."""
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

@OmarIthawi OmarIthawi left a 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.

@shadinaif
Copy link
Collaborator Author

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

@shadinaif shadinaif requested a review from OmarIthawi July 8, 2024 10:54
@OmarIthawi
Copy link
Collaborator

I thought I did approve it. Sorry.

@shadinaif shadinaif merged commit c1f3d8c into main Jul 8, 2024
3 checks passed
@shadinaif shadinaif deleted the shadinaif/dashboard-user-roles branch July 8, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants