Skip to content

Commit

Permalink
Assign groups for superusers also
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Dec 28, 2023
1 parent e05f14b commit a15b3d7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 70 deletions.
64 changes: 26 additions & 38 deletions booking/management/commands/cancel_unpaid_bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,47 +124,35 @@ def cancel_bookings(self, now):
for event in send_waiting_list:
waiting_list_users = WaitingListUser.objects.filter(event=event)
if waiting_list_users.exists():
try:
send_waiting_list_email(
event, [user.user for user in waiting_list_users]
)
ActivityLog.objects.create(
log='Waiting list email sent to user(s) {} for '
'event {}'.format(
', '.join(
[wluser.user.username for wluser in waiting_list_users]
),
event
)
)
except Exception as e:
# send mail to tech support with Exception
send_support_email(
e, __name__, "Automatic cancel job - waiting list email"
send_waiting_list_email(
event, [user.user for user in waiting_list_users]
)
ActivityLog.objects.create(
log='Waiting list email sent to user(s) {} for '
'event {}'.format(
', '.join(
[wluser.user.username for wluser in waiting_list_users]
),
event
)
)

if bookings_for_studio_email:
# send single mail to Studio
try:
send_mail('{} Booking{} been automatically cancelled'.format(
settings.ACCOUNT_EMAIL_SUBJECT_PREFIX,
' has' if len(bookings_for_studio_email) == 1 else 's have'),
get_template(
'booking/email/booking_auto_cancelled_studio_email.txt'
send_mail('{} Booking{} been automatically cancelled'.format(
settings.ACCOUNT_EMAIL_SUBJECT_PREFIX,
' has' if len(bookings_for_studio_email) == 1 else 's have'),
get_template(
'booking/email/booking_auto_cancelled_studio_email.txt'
).render({'bookings': bookings_for_studio_email}),
settings.DEFAULT_FROM_EMAIL,
[settings.DEFAULT_STUDIO_EMAIL],
html_message=get_template(
'booking/email/booking_auto_cancelled_studio_email.html'
).render({'bookings': bookings_for_studio_email}),
settings.DEFAULT_FROM_EMAIL,
[settings.DEFAULT_STUDIO_EMAIL],
html_message=get_template(
'booking/email/booking_auto_cancelled_studio_email.html'
).render({'bookings': bookings_for_studio_email}),
fail_silently=False)
self.stdout.write(
'Cancellation emails sent for booking ids {}'.format(
', '.join([str(booking.id) for booking in bookings_for_studio_email])
)
)
except Exception as e:
# send mail to tech support with Exception
send_support_email(
e, __name__, "Automatic cancel job - studio email"
fail_silently=False)
self.stdout.write(
'Cancellation emails sent for booking ids {}'.format(
', '.join([str(booking.id) for booking in bookings_for_studio_email])
)
)
6 changes: 1 addition & 5 deletions booking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ def __str__(self):
return self.group.name.title()

def has_permission(self, user):
if user.is_superuser or self.group == self.open_to_all_group():
if self.group == self.open_to_all_group():
return True
return self.group in user.groups.all()

def add_user(self, user):
if user.is_superuser:
return
if self.group not in user.groups.all():
user.groups.add(self.group)

def remove_user(self, user):
if user.is_superuser:
return
if self.group in user.groups.all():
user.groups.remove(self.group)

Expand Down
2 changes: 1 addition & 1 deletion studioadmin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def staff_user():
yield staff_user


@pytest.fixture(autouse=True)
@pytest.fixture()
def instructor_user(client):
user = User.objects.create_user(username="instructor", password="test")
group, _ = Group.objects.get_or_create(name="instructors")
Expand Down
12 changes: 0 additions & 12 deletions studioadmin/tests/test_views/test_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,6 @@ def test_filter_options(self):
else:
self.assertFalse(opt['available'])

def test_instructor_cannot_change_regular_student(self):
reg_student = baker.make_recipe('booking.user')
perm = Permission.objects.get(codename='is_regular_student')
reg_student.user_permissions.add(perm)
reg_student.save()

resp = self._get_response(
self.instructor_user, {'change_user': [reg_student.id]}
)
reg_student = User.objects.get(id=reg_student.id)
self.assertTrue(reg_student.has_perm('booking.is_regular_student'))

def test_display_disclaimers(self):
"""
Test that users with online disclaimers do not display print disclaimer
Expand Down
24 changes: 10 additions & 14 deletions templates/studioadmin/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,16 @@ <h2>Registered Users</h2>
<td class="text-center studioadmin-tbl">{{ user.first_name|abbr_name }} {{ user.last_name|abbr_name }}</td>
<td class="text-center studioadmin-tbl">{% if user.userprofile.pronouns %}{{ user.userprofile.pronouns }}{% endif %}</td>
{% if request.user.is_staff %}
{% if user.is_superuser %}
<td class="text-center studioadmin-tbl">N/A</td>
{% else %}
<td class="text-center studioadmin-tbl" id="toggle_permission_{{ user.id }}">
{% for allowed_group in allowed_groups %}
<div
id="toggle-et-{{ allowed_group.id }}-user-{{ user.id }}"
hx-get={% url 'studioadmin:toggle_permission' user.id allowed_group.id %}
>
{% include "studioadmin/includes/toggle_permission_button.html" %}
</div>
{% endfor %}
</td>
{% endif %}
<td class="text-center studioadmin-tbl" id="toggle_permission_{{ user.id }}">
{% for allowed_group in allowed_groups %}
<div
id="toggle-et-{{ allowed_group.id }}-user-{{ user.id }}"
hx-get={% url 'studioadmin:toggle_permission' user.id allowed_group.id %}
>
{% include "studioadmin/includes/toggle_permission_button.html" %}
</div>
{% endfor %}
</td>
{% endif %}
<td class="text-center studioadmin-tbl td-disclaimer">
{% if user|has_online_disclaimer %}
Expand Down

0 comments on commit a15b3d7

Please sign in to comment.