-
Notifications
You must be signed in to change notification settings - Fork 1
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 group members view with permission checks #30
base: main
Are you sure you want to change the base?
Conversation
… checks. - Implement `group_members_view` to display members of a research group based on the `GroupMember` model. - Added permission checks to allow access only for the group owner or an admin. - Included check for PI (Principal Investigator) status to ensure group ownership. - Render `group_members.html` for authorised users; display `no_group.html` with a message for non-PI users.
Ruff
required docstring and permissions…
Based on our session yesterday you're hopefully now able to try this out in the browser @HarmonicReflux? |
# Conflicts: # imperial_coldfront_plugin/urls.py
I am getting closer @cc-a , but encounter this error int eh CI/CD tests: I import |
I've taken the liberty of pushing a couple of commits. The first addresses the issue you reported by updating the settings used during tests to include the I then hit a subsequent issue with mypy that I was unable to resolve. I'm going to create a follow up issue to look into how to deal with these mypy issues properly but have disabled the mypy checks for now. Maybe I'm just missing something but I'm increasingly dubious of the merits of using mypy with Django. |
Thanks for this. Well, as per out discussions in person and online, maybe its best to deactivate It is certainly worth looking into it in more detail so we have a good assessment of the technical debt we incur switching |
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 can't work out how to test this. How do I access the view?
A question: Is a new file generated in the |
Yes, if there are changes to the models then we need to make migrations, which are then saved in |
@AdrianDAlessandro Unfortunately you'll have to type the url in manually. Until we get #21 there is nowhere obvious to put the link. |
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.
We'll need some tests for this but let's do that in follow up PR.
I went to |
@AdrianDAlessandro I think you need to go to |
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.
Ok, I managed to work out I need to navigate to http://127.0.0.1:8000/icl/group/1/members/ and it worked for when I wasn't a PI. But after setting is_pi
to True it failed with this error (I believe the same error mypy was showing):
...
File "/usr/src/imperial_coldfront_plugin/imperial_coldfront_plugin/views.py", line 51, in group_members_view
group_members = GroupMembership.objects.filter(owner=user)
...
FieldError at /icl/group/1/members/
Cannot resolve keyword 'owner' into field. Choices are: group, group_id, id, member, member_id
|
||
from .models import GroupMembership | ||
|
||
User = get_user_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.
This feels wrong... Shouldn't we be using get_user_model()
directly each time?
if request.user != user and not request.user.is_superuser: | ||
return HttpResponseForbidden("Permission denied") |
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 can only superusers can view this?
if request.user != user and not request.user.is_superuser: | ||
return HttpResponseForbidden("Permission denied") | ||
|
||
if not user.userprofile.is_pi: |
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.
Is this userprofile
a field provided by coldfront?
Description
group_members_view
to display members of a research group based on theGroupMember
model.group_members.html
for authorised users; displayno_group.html
with a message for non-PI users.Fixes #18, #34.
Type of change
Key checklist
python -m pytest
)python -m sphinx -b html docs docs/build
)pre-commit run --all-files
)Further checks