-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add-associated-data-prep-workspace-t…
…ables-on-workspace-detail
- Loading branch information
Showing
40 changed files
with
1,810 additions
and
176 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from django.contrib.sites.models import Site | ||
from django.core.mail import send_mail | ||
from django.core.management.base import BaseCommand | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
|
||
from ...audit import signed_agreement_audit, workspace_audit | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Run dbGaP access audit." | ||
|
||
def add_arguments(self, parser): | ||
email_group = parser.add_argument_group(title="Email reports") | ||
email_group.add_argument( | ||
"--email", | ||
help="""Email to which to send access reports that need action or have errors.""", | ||
) | ||
|
||
def _audit_signed_agreements(self): | ||
self.stdout.write("Running SignedAgreement access audit... ", ending="") | ||
data_access_audit = signed_agreement_audit.SignedAgreementAccessAudit() | ||
data_access_audit.run_audit() | ||
|
||
# Construct the url for handling errors. | ||
url = ( | ||
"https://" | ||
+ Site.objects.get_current().domain | ||
+ reverse("cdsa:audit:signed_agreements:all") | ||
) | ||
self._report_results(data_access_audit, url) | ||
self._send_email(data_access_audit, url) | ||
|
||
def _audit_workspaces(self): | ||
self.stdout.write("Running CDSAWorkspace access audit... ", ending="") | ||
data_access_audit = workspace_audit.WorkspaceAccessAudit() | ||
data_access_audit.run_audit() | ||
|
||
# Construct the url for handling errors. | ||
url = ( | ||
"https://" | ||
+ Site.objects.get_current().domain | ||
+ reverse("cdsa:audit:workspaces:all") | ||
) | ||
self._report_results(data_access_audit, url) | ||
self._send_email(data_access_audit, url) | ||
|
||
def _report_results(self, data_access_audit, resolve_url): | ||
# Report errors and needs access. | ||
audit_ok = data_access_audit.ok() | ||
if audit_ok: | ||
self.stdout.write(self.style.SUCCESS("ok!")) | ||
else: | ||
self.stdout.write(self.style.ERROR("problems found.")) | ||
|
||
# Print results | ||
self.stdout.write("* Verified: {}".format(len(data_access_audit.verified))) | ||
self.stdout.write( | ||
"* Needs action: {}".format(len(data_access_audit.needs_action)) | ||
) | ||
self.stdout.write("* Errors: {}".format(len(data_access_audit.errors))) | ||
|
||
if not audit_ok: | ||
self.stdout.write( | ||
self.style.ERROR(f"Please visit {resolve_url} to resolve these issues.") | ||
) | ||
|
||
def _send_email(self, data_access_audit, url): | ||
# Send email if requested and there are problems. | ||
if not data_access_audit.ok(): | ||
subject = "CDSA {} errors".format(data_access_audit.__class__.__name__) | ||
html_body = render_to_string( | ||
"primed_anvil/email_audit_report.html", | ||
context={ | ||
"title": subject, | ||
"data_access_audit": data_access_audit, | ||
"url": url, | ||
}, | ||
) | ||
send_mail( | ||
subject, | ||
"Audit problems found. Please see attached report.", | ||
None, | ||
[self.email], | ||
fail_silently=False, | ||
html_message=html_body, | ||
) | ||
|
||
def handle(self, *args, **options): | ||
self.email = options["email"] | ||
self._audit_signed_agreements() | ||
self._audit_workspaces() |
29 changes: 29 additions & 0 deletions
29
primed/cdsa/migrations/0015_dataaffiliateagreement_additional_limitations_and_more.py
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,29 @@ | ||
# Generated by Django 4.2.10 on 2024-03-12 21:38 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cdsa", "0014_gsr_restricted_help_and_verbose"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="dataaffiliateagreement", | ||
name="additional_limitations", | ||
field=models.TextField( | ||
blank=True, | ||
help_text="Additional limitations on data use as specified in the signed CDSA.", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="historicaldataaffiliateagreement", | ||
name="additional_limitations", | ||
field=models.TextField( | ||
blank=True, | ||
help_text="Additional limitations on data use as specified in the signed CDSA.", | ||
), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
...rations/0016_rename_data_use_limitations_cdsaworkspace_additional_limitations_and_more.py
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,23 @@ | ||
# Generated by Django 4.2.10 on 2024-03-14 18:35 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cdsa", "0015_dataaffiliateagreement_additional_limitations_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="cdsaworkspace", | ||
old_name="data_use_limitations", | ||
new_name="additional_limitations", | ||
), | ||
migrations.RenameField( | ||
model_name="historicalcdsaworkspace", | ||
old_name="data_use_limitations", | ||
new_name="additional_limitations", | ||
), | ||
] |
Oops, something went wrong.