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

Fixed #1756 -- hide unpublished events from side menus for staff #1820

Conversation

ontowhee
Copy link
Contributor

Fixed #1756. Only return published events, even for staff users.

Screenshot 2024-12-10 at 10 43 10 PM Screenshot 2024-12-10 at 11 14 13 PM

@ontowhee ontowhee force-pushed the fix-1756-hide-side-menu-unpublished-events-for-staff branch from dc500c9 to ac1080d Compare December 11, 2024 08:51
Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, nice work! 🎸

The code change looks good, I just had a note about the test (I like the use of assertQuerySetEqual on response.context["events"] by the way, that seems like a robust and effective way to test what we want here 👍🏻 ).

blog/tests.py Outdated
Comment on lines 212 to 214
response = self.client.get(reverse("weblog:index"))
self.assertEqual(response.status_code, 200)
self.assertQuerySetEqual(response.context["events"], [])
Copy link
Member

Choose a reason for hiding this comment

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

This new test already passes with the old version of the code, because it's not useing a logged-in staff user.
I suggest to test things with three types of users: anonymous (not logged in), logged in (not staff), and logged in (staff). Something like this should work (not tested):

Suggested change
response = self.client.get(reverse("weblog:index"))
self.assertEqual(response.status_code, 200)
self.assertQuerySetEqual(response.context["events"], [])
for user in [
None,
User.objects.create(is_staff=False),
User.objects.create(is_staff=True),
]:
if user:
self.client.force_login(user)
response = self.client.get(reverse("weblog:index"))
with self.subTest(user=user):
self.assertEqual(response.status_code, 200)
self.assertQuerySetEqual(response.context["events"], [])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for these tests! I didn't think to check the anonymous, staff, and non-staff users. I've added these cases along with a superuser for good measure!

@ontowhee ontowhee force-pushed the fix-1756-hide-side-menu-unpublished-events-for-staff branch from ac1080d to 0909a14 Compare December 13, 2024 05:38
Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

Excellent, nice work 👍🏻

@bmispelon bmispelon merged commit 8e5a19f into django:main Dec 13, 2024
4 checks passed
@jefftriplett
Copy link
Member

@ontowhee awesome work. Thank you!

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.

Unpublished Events show up for staff in side menus
3 participants