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

Grants: Add action to mark grants as rejected and send email #3758

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions backend/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ def create_grant_vouchers_on_pretix(modeladmin, request, queryset):
messages.success(request, f"{count} Vouchers created on Pretix!")


@admin.action(description="Mark grants as Rejected and send email")
@validate_single_conference_selection
def mark_rejected_and_send_email(modeladmin, request, queryset):
queryset = queryset.filter(
status__in=(
Grant.Status.waiting_list,
Grant.Status.waiting_list_maybe,
),
)

for grant in queryset:
grant.status = Grant.Status.rejected
grant.save()

send_grant_reply_rejected_email.delay(grant_id=grant.id)
messages.info(request, f"Sent Rejected reply email to {grant.name}")


class GrantAdminForm(forms.ModelForm):
class Meta:
model = Grant
Expand Down Expand Up @@ -468,6 +486,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
send_reply_email_waiting_list_update,
create_grant_vouchers_on_pretix,
send_voucher_via_email,
mark_rejected_and_send_email,
"delete_selected",
]
autocomplete_fields = ("user",)
Expand Down Expand Up @@ -533,9 +552,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
),
)

@admin.display(
description="User",
)
@admin.display(description="User", ordering="user__full_name")
def user_display_name(self, obj):
if obj.user_id:
return obj.user.display_name
Expand Down
30 changes: 30 additions & 0 deletions backend/grants/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
create_grant_vouchers_on_pretix,
send_reply_emails,
send_voucher_via_email,
mark_rejected_and_send_email,
)
from grants.models import Grant

Expand Down Expand Up @@ -503,3 +504,32 @@ def test_create_grant_vouchers_only_for_confirmed_grants(
assert grant_1.voucher_code is None
assert grant_2.pretix_voucher_id == 1
assert grant_2.voucher_code == "GRANT-123ZYZ"


def test_mark_rejected_and_send_email(rf, conference, grant_factory, mocker):
mock_messages = mocker.patch("grants.admin.messages")
grant1 = grant_factory(status=Grant.Status.waiting_list, conference=conference)
grant2 = grant_factory(
status=Grant.Status.waiting_list_maybe, conference=conference
)
request = rf.get("/")
mock_send_rejected_email = mocker.patch(
"grants.admin.send_grant_reply_rejected_email.delay"
)

mark_rejected_and_send_email(None, request=request, queryset=Grant.objects.all())

grant1.refresh_from_db()
grant2.refresh_from_db()
assert grant1.status == Grant.Status.rejected
assert grant2.status == Grant.Status.rejected
mock_messages.info.assert_has_calls(
[
call(request, f"Sent Rejected reply email to {grant1.name}"),
call(request, f"Sent Rejected reply email to {grant2.name}"),
],
any_order=True,
)
mock_send_rejected_email.assert_has_calls(
[call(grant_id=grant1.id), call(grant_id=grant2.id)], any_order=True
)
Loading