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

fix: Reading role permissions generates 500 error backend #3079

Merged

Conversation

novakzaballa
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

  • Add field roles to get organisation users

How did you test this code?

  • Make a request /api/v1/organisations/{organisation_pk}/users/

Copy link

vercel bot commented Nov 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2023 7:33pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2023 7:33pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2023 7:33pm

@github-actions github-actions bot added the api Issue related to the REST API label Nov 30, 2023
Copy link
Contributor

github-actions bot commented Nov 30, 2023

Uffizzi Preview deployment-41878 was deleted.

Comment on lines 249 to 251
def get_user_roles(self):
user_roles = UserRole.objects.filter(user=self)
return user_roles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If settings.IS_RBAC_INSTALLED is not present then this method will throw an error. Maybe catch the exception and fire a custom error to stop it from looking like a random 500 error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +63 to +64
if settings.IS_RBAC_INSTALLED:
roles = UserRoleSerializer(many=True, read_only=True, source="get_user_roles")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the if-statement that leads to roles not being set on the serializer. Is this how we do it throughout the codebase? I feel like defaulting roles to None would look better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is possible since UserRoleSerializer lives in RBAC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense.

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (3e662e2) 95.89% compared to head (abeb1d1) 95.87%.
Report is 2 commits behind head on main.

Files Patch % Lines
api/users/serializers.py 66.66% 2 Missing ⚠️
api/users/models.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3079      +/-   ##
==========================================
- Coverage   95.89%   95.87%   -0.02%     
==========================================
  Files        1039     1039              
  Lines       30721    30776      +55     
==========================================
+ Hits        29459    29508      +49     
- Misses       1262     1268       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +63 to +64
if settings.IS_RBAC_INSTALLED:
roles = UserRoleSerializer(many=True, read_only=True, source="get_user_roles")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense.

@novakzaballa novakzaballa added this pull request to the merge queue Nov 30, 2023
Merged via the queue into main with commit cee607a Nov 30, 2023
20 checks passed
@novakzaballa novakzaballa deleted the fix/reading-role-permissions-generates-500-error-be branch November 30, 2023 20:51
matthewelwell added a commit that referenced this pull request Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants