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

Exit staff mode after permission revocation #2355

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ybrnr
Copy link
Collaborator

@ybrnr ybrnr commented Dec 16, 2024

fix #2205

Copy link
Member

@janno42 janno42 left a comment

Choose a reason for hiding this comment

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

Nice 👍

Please check the formatting

Copy link
Collaborator

@Kakadus Kakadus left a comment

Choose a reason for hiding this comment

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

naturally, a test would be nice : )

Thanks!

@@ -52,6 +52,9 @@ def is_in_staff_mode(request):


def update_staff_mode(request):
if not request.user.has_staff_permission:
exit_staff_mode(request)
return
assert request.user.has_staff_permission
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this assertion is no longer needed

Copy link
Member

Choose a reason for hiding this comment

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

I'd move it up to line 33, where I think it would still add value.

The call graphs we can get now are a bit wonky. We can have
enter_staff_mode -> update_staff_mode -> finds out that not request.user.has_staff_permission -> exit_staff_mode and returns without exception, which is probably never what the initial caller intended?

It seems to me that update_staff_mode was about "update the timestamp in the session to now()" in the past, now it has changed semantics. Could use a little clean up in general, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved the assertion to line 33

Copy link
Member

Choose a reason for hiding this comment

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

I agree that, while it's not super urgent, the names could be improved. In general, enter_staff_mode seems unneeded since #1587. The current update_staff_mode is more of a try_entering_or_refreshing_staff_mode. I don't have a strong opinion, but having a "try to enter, but we will check whether you are allowed" as the only way to enter staff mode seems fair to me. Maybe the enter_staff_mode view should check that entering worked?

Copy link
Member

@richardebeling richardebeling left a comment

Choose a reason for hiding this comment

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

Blocking for missing test, since this is authorization logic and we discovered a code path in the issue that we considered not to happen naturally before. Feel free to assign the PR to me if you want me to write the test.

Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Very cool, thanks! Could you change the title to something more descriptive? The issue number doesn't need to appear, we will always be able to find it through the PR number, which will be automatically included once we merge :)

Comment on lines +56 to +58
if not request.user.has_staff_permission:
exit_staff_mode(request)
return
Copy link
Member

Choose a reason for hiding this comment

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

@richardebeling @Kakadus Should we log something here?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with both adding and not adding logging.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can only manage one of the two

Copy link
Member

@niklasmohrin niklasmohrin Jan 27, 2025

Choose a reason for hiding this comment

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

If you both don't care, I would prefer if we added a small info-level log like "user {} tried to update staff mode session without permission" @ybrnr

Edit: nevermind, @richardebeling convinced me against this afterall

@ybrnr ybrnr changed the title Iss2205 Staff mode user gets redirected to non staff mode on permission change Jan 21, 2025
@niklasmohrin
Copy link
Member

@ybrnr How about "Exit staff mode after permission revocation"?

@Kakadus Kakadus changed the title Staff mode user gets redirected to non staff mode on permission change Exit staff mode after permission revocation Jan 27, 2025
Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Blocking for #2355 (comment)

Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Nothing to see here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Clear session of user on permission change
5 participants