-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send email to admins when un-embargo requested
- Loading branch information
Showing
5 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
dandiapi/api/templates/api/mail/dandisets_to_unembargo.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% autoescape off %} | ||
The following new dandisets are awaiting un-embargo: | ||
|
||
{% for ds in dandisets %} | ||
Dandiset ID: {{ ds.identifier }} | ||
Owners: {{ ds.owners }} | ||
Number of Assets: {{ ds.asset_count }} | ||
Total data size: {{ ds.size }} | ||
{% endfor %} | ||
{% endautoescape %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from guardian.shortcuts import assign_perm | ||
import pytest | ||
|
||
from dandiapi.api.models.dandiset import Dandiset | ||
from dandiapi.api.services.embargo import AssetBlobEmbargoedError, remove_asset_blob_embargoed_tag | ||
from dandiapi.api.tasks.scheduled import send_dandisets_to_unembargo_email | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_remove_asset_blob_embargoed_tag_fails_on_embargod(embargoed_asset_blob, asset_blob): | ||
with pytest.raises(AssetBlobEmbargoedError): | ||
remove_asset_blob_embargoed_tag(embargoed_asset_blob) | ||
|
||
# Test that error not raised on non-embargoed asset blob | ||
remove_asset_blob_embargoed_tag(asset_blob) | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_unembargo_dandiset_sends_emails( | ||
api_client, user, dandiset, draft_version_factory, mailoutbox | ||
): | ||
draft_version_factory(dandiset=dandiset) | ||
|
||
assign_perm('owner', user, dandiset) | ||
api_client.force_authenticate(user=user) | ||
|
||
dandiset.embargo_status = Dandiset.EmbargoStatus.EMBARGOED | ||
dandiset.save() | ||
|
||
resp = api_client.post(f'/api/dandisets/{dandiset.identifier}/unembargo/') | ||
assert resp.status_code == 200 | ||
|
||
# Simulate the scheduled task calling this function | ||
send_dandisets_to_unembargo_email() | ||
|
||
assert mailoutbox | ||
assert 'un-embargo' in mailoutbox[0].subject | ||
assert dandiset.identifier in mailoutbox[0].message().get_payload() | ||
assert user.username in mailoutbox[0].message().get_payload() |