Skip to content

Commit

Permalink
add 'Schedule Viewer' as volunteer import role (#754)
Browse files Browse the repository at this point in the history
[#188743929]
  • Loading branch information
uraniumanchor authored Jan 4, 2025
1 parent d70d107 commit d2d8ab2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
13 changes: 8 additions & 5 deletions listperms.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ def _get_builtin_permissions(opts):

tracker = apps.get_app_config('tracker')

perms = set()

for model in tracker.get_models():
perms |= {f'tracker.{p[0]}' for p in _get_all_permissions(model._meta)}
perms = sorted(
{
f'tracker.{p[0]}'
for model in tracker.get_models()
for p in _get_all_permissions(model._meta)
}
)

logger.debug('--PERMISSIONS LIST--')
logger.debug(perms)

perm_list = '\n | '.join(f"'{p}'" for p in sorted(perms))
perm_list = '\n | '.join(f"'{p}'" for p in perms)

result = f"""// autogenerated
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "donation_tracker",
"version": "0.1.0",
"version": "3.3.0",
"description": "GDQ Donation Tracker",
"scripts": {
"build": "NODE_ENV=${NODE_ENV:-production} webpack",
"start": "NODE_ENV=${NODE_ENV:-development} SOURCE_MAPS=${SOURCE_MAPS:-1} webpack-dev-server",
"test": "NO_MANIFEST=1 karma start --single-run",
"test:watch": "NO_MANIFEST=1 karma start",
"test": "karma start --single-run",
"test:watch": "karma start",
"fix:prettier": "prettier --write \"bundles/**\" \"spec/**\"",
"fix:lint": "yarn lint --fix",
"fix:all": "yarn fix:prettier && yarn fix:lint",
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import json
import os
import subprocess

Expand Down Expand Up @@ -32,7 +33,7 @@ def get_package_name(name):

setup(
name=get_package_name('django-donation-tracker'),
version='3.3',
version=json.load(open('package.json'))['version'],
author='Games Done Quick',
author_email='[email protected]',
packages=find_packages(include=['tracker', 'tracker.*']),
Expand Down
19 changes: 16 additions & 3 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def test_send_volunteer_emails(self):
{{ user }} is a head donation screener.
{% elif is_host %}
{{ user }} is a host.
{% elif is_schedule %}
{{ user }} is a schedule viewer.
{% else %}
{{ user }} is a donation screener.
{% endif %}""",
Expand All @@ -387,6 +389,7 @@ def test_send_volunteer_emails(self):
"""position,name,username,email
Host,Jesse Doe,Garden,[email protected]
Head Donations,John Doe,Ribs,[email protected]
Schedule,Jack Doe,Snakes,[email protected]
Donations,Jane Doe,Apples,[email protected]
Donations,Add Min,SHOULD_NOT_CHANGE,[email protected]
Donations,,invalid,invalid.email.com
Expand All @@ -405,11 +408,11 @@ def test_send_volunteer_emails(self):
)
self.assertRedirects(response, reverse('admin:tracker_event_changelist'))
self.assertEqual(
emails + 5,
emails + 6,
post_office.models.Email.objects.count(),
'Did not send five emails',
'Did not send six emails',
)
self.assertEqual(users + 4, User.objects.count(), 'Did not add four users')
self.assertEqual(users + 5, User.objects.count(), 'Did not add five users')
self.super_user.refresh_from_db()
self.assertTrue(
Group.objects.get(name='Bid Admin')
Expand Down Expand Up @@ -441,6 +444,16 @@ def test_send_volunteer_emails(self):
post_office.models.Email.objects.get(to='[email protected]').message,
"jesse's email was not tagged as host",
)
self.assertIn(
'Snakes is a schedule viewer.',
post_office.models.Email.objects.get(to='[email protected]').message,
"jack's email was not tagged as a schedule viewer",
)
self.assertTrue(
Group.objects.get(name='Schedule Viewer')
in User.objects.get(email='[email protected]').groups.all(),
'jack should belong to Schedule Viewer',
)
self.assertTrue(
Group.objects.get(name='Bid Tracker')
in User.objects.get(email='[email protected]').groups.all(),
Expand Down
26 changes: 26 additions & 0 deletions tracker/admin/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ def send_volunteer_emails_view(request, pk):
admin_codenames
), 'some permissions were missing, check admin_codenames or that all migrations have run'
admin_group.permissions.set(admin_permissions)

schedule_group = auth.Group.objects.get_or_create(
name='Schedule Viewer'
)[0]
schedule_codenames = [
'view_interstitial',
]
schedule_permissions = auth.Permission.objects.filter(
content_type__app_label='tracker',
codename__in=schedule_codenames,
)
assert schedule_permissions.count() == len(
schedule_codenames
), 'some permissions were missing, check schedule_codenames or that all migrations have run'
schedule_group.permissions.set(schedule_permissions)

successful = 0
email_validator = EmailValidator()
for row, volunteer in enumerate(volunteers, start=2):
Expand All @@ -266,6 +282,9 @@ def send_volunteer_emails_view(request, pk):
)
is_head = 'head' in volunteer['position'].strip().lower()
is_host = 'host' in volunteer['position'].strip().lower()
is_schedule = (
'schedule' in volunteer['position'].strip().lower()
)
email = volunteer['email'].strip()
email_validator(email)
username = volunteer['username'].strip()
Expand All @@ -285,9 +304,15 @@ def send_volunteer_emails_view(request, pk):
if is_head:
user.groups.add(admin_group)
user.groups.remove(tracker_group)
user.groups.remove(schedule_group)
elif is_schedule:
user.groups.remove(admin_group)
user.groups.remove(tracker_group)
user.groups.add(schedule_group)
else:
user.groups.remove(admin_group)
user.groups.add(tracker_group)
user.groups.remove(schedule_group)
user.save()

if created:
Expand All @@ -307,6 +332,7 @@ def send_volunteer_emails_view(request, pk):
event=event,
is_head=is_head,
is_host=is_host,
is_schedule=is_schedule,
password_reset_url=request.build_absolute_uri(
reverse('tracker:password_reset')
),
Expand Down
7 changes: 6 additions & 1 deletion tracker/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def default_volunteer_registration_template():
event -- the Event that this email is being send for
is_host -- True if the user was imported as a host
is_head -- True if the user was imported as a head donation screener
is_schedule -- True if the user was imported as a schedule viewer
confirmation_url -- the full URL (including token) the user should visit to confirm their registration and set their password
password_reset_url -- the full URL the user should visit if the above link expires (happens after 3 days if using default Django settings)
admin_url -- the full URL of the admin site (which will redirect them to login if need be)
Expand All @@ -70,8 +71,10 @@ def default_volunteer_registration_template():
You are receiving this e-mail because you have been listed as a head donation processor during {{ event.name }}.
{% elif is_host %}
You are receiving this e-mail because you have been listed as a host during {{ event.name }}.
{% elif is_schedule %}
You are receiving this e-mail because you have been listed as a schedule viewer during {{ event.name }}.
{% else %}
You are receiving this e-mail because you have been listed as a donation processer during {{ event.name }}.
You are receiving this e-mail because you have been listed as a donation processor during {{ event.name }}.
{% endif %}
{% if user.is_active %}
Expand Down Expand Up @@ -100,6 +103,8 @@ def default_volunteer_registration_template():
You are receiving this e-mail because you have been listed as a head donation processor during {{ event.name }}.
{% elif is_host %}
You are receiving this e-mail because you have been listed as a host during {{ event.name }}.
{% elif is_schedule %}
You are receiving this e-mail because you have been listed as a schedule viewer during {{ event.name }}.
{% else %}
You are receiving this e-mail because you have been listed as a donation processor during {{ event.name }}.
{% endif %}
Expand Down

0 comments on commit d2d8ab2

Please sign in to comment.