Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Conversation

@bjrne
Copy link
Member

@bjrne bjrne commented Jul 11, 2020

Closes #121
Closes #137

template_name = "approve_hospitals.html"

def get(self, request, p_type):
# If you are not a staff user, the method decorator takes care of showing a 404 page,
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 get a 404 as fake user A1:
image

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch - the django decorator staff_member_required redirects to the login page under the assumption that you need to log in again with the higher ranked user.

You can override this behaviour like I did in cc5057d and 892abf0, but one might forget this. Under the assumption that we want to show as little information as possible about our internal url structures (debatable as an open source plattform), I added a customized version of the staff_member_required decorator, which has this behavior built-in, but also customizable. Let me know what you think!

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a possibility to override staff_member_required with our version project-wide?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could give it the same name and import it from our repo, but I thought that might be too easy to miss in a future PR (to check whether the import is right when the decorator is used later in the file). I don't think we can override an import from a django package.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could in theory add a test for it though - but that might be overkill.

@bjrne bjrne self-assigned this Jul 11, 2020
@bjrne bjrne requested a review from Baschdl July 11, 2020 21:19
Copy link
Contributor

@Baschdl Baschdl left a comment

Choose a reason for hiding this comment

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

@bjrne
Copy link
Member Author

bjrne commented Jul 13, 2020

The 404 is not intended by behaviour added in this PR, it is a result of the problem described in #157. The login redirect is a result of the login decorator sitting before the other one. We need to discuss what behaviour we want, e.g. what page do you see for a URL that you have access to, but are not logged in yet. This is a decision between obfuscation and good UX.

p_type = self.kwargs["p_type"]
if "delete" in post_params:
p = get_object_or_404(Participant[self.kwargs["p_type"]], uuid=post_params["uuid"])
if not request.user.has_perm("matching.delete_participant%s" % p_type.lower()):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also test for matching.delete_participant%s and matching.can_approve_type_%s with a class-based decorator. A person who can't change the values, should probably also not see these pages.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand what you mean - those get tested in lines 27-30. These here are for the actual action.

I think using a class decorator would be less expressive as it would probably have a long name. If you use them separately as decorators, both would be required. But I think not every approver would have the rights to delete participants and vice versa?

Copy link
Contributor

@Baschdl Baschdl Jul 14, 2020

Choose a reason for hiding this comment

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

You're right, I missed that. I still think it would be more consistent to have a method decorator and not have decorators on classes, decorators on methods and checks in a method (which makes it hard to check with a quick glance if the right permissions are set). But I see that this decorator would also not be totally self-explanatory.

@bjrne bjrne requested a review from feeds July 14, 2020 11:46
@josauder josauder self-requested a review July 14, 2020 12:32
return self.post_approve(request, p_type, args, kwargs)
return self.get(request, p_type)

def post_delete(self, request, p_type, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we want to add the decorators here?

@bjrne
Copy link
Member Author

bjrne commented Jul 19, 2020

This will also wait for a decision on permission names (refer to #183).

@bjrne bjrne requested a review from Baschdl August 16, 2020 12:04
@bjrne
Copy link
Member Author

bjrne commented Aug 16, 2020

Will test thoroughly again and also revise checks for buttons on staff-profile.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add permission check on user deletion Only approver should be able to approve

3 participants