Skip to content

Commit

Permalink
Merge branch 'dependabot/pip/django-allauth-0.61.1' of github.com:UW-…
Browse files Browse the repository at this point in the history
…GAC/primed-django into dependabot/pip/django-allauth-0.61.1
  • Loading branch information
jmcarson committed Apr 12, 2024
2 parents 16b1c2f + 0e6f2f6 commit 6c03f03
Show file tree
Hide file tree
Showing 75 changed files with 3,863 additions and 828 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ DJANGO_EMAIL_PORT=
DJANGO_EMAIL_HOST_USER=
DJANGO_EMAIL_HOST_PASSWORD=
DJANGO_EMAIL_USE_TLS=

# drupal api
DRUPAL_API_CLIENT_ID=
DRUPAL_API_CLIENT_SECRET=
DRUPAL_API_REL_PATH=
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
# ahead of planned upgrades we can add versions as
# needed
python-version: [3.8]
mariadb-version: ["10.4"]
mariadb-version: ["10.4", "10.5"]

services:
mysql:
Expand Down
44 changes: 32 additions & 12 deletions add_cdsa_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
ManagedGroupFactory,
)
from django.conf import settings
from django.core.management import call_command

from primed.cdsa.tests import factories
from primed.duo.tests.factories import DataUseModifierFactory, DataUsePermissionFactory
from primed.duo.models import DataUseModifier, DataUsePermission
from primed.primed_anvil.models import Study, StudySite
from primed.primed_anvil.tests.factories import StudyFactory, StudySiteFactory
from primed.users.models import User
from primed.users.tests.factories import UserFactory

# Load duos
call_command("load_duo")

# create the CDSA auth group
cdsa_group = ManagedGroupFactory.create(name=settings.ANVIL_CDSA_GROUP_NAME)
# Add PRIMED ADMINS group
cc_admins_group = ManagedGroupFactory.create(name=settings.ANVIL_CC_ADMINS_GROUP_NAME)

# Create major versions
major_version = factories.AgreementMajorVersionFactory.create(version=1)

Expand All @@ -28,11 +37,8 @@
)

# Create a couple signed CDSAs.
dup = DataUsePermissionFactory.create(abbreviation="GRU")
dum = DataUseModifierFactory.create(abbreviation="NPU")

# create the CDSA auth group
cdsa_group = ManagedGroupFactory.create(name=settings.ANVIL_CDSA_GROUP_NAME)
dup = DataUsePermission.objects.get(abbreviation="GRU")
dum = DataUseModifier.objects.get(abbreviation="NPU")

# Create some study sites.
StudySiteFactory.create(short_name="CC", full_name="Coordinating Center")
Expand All @@ -47,7 +53,7 @@
signed_agreement__representative=UserFactory.create(name="Ken Rice"),
signed_agreement__signing_institution="UW",
signed_agreement__representative_role="Contact PI",
signed_agreement__is_primary=True,
is_primary=True,
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CC"),
)
Expand All @@ -60,7 +66,7 @@
signed_agreement__representative=UserFactory.create(name="Sally Adebamowo"),
signed_agreement__signing_institution="UM",
signed_agreement__representative_role="Contact PI",
signed_agreement__is_primary=True,
is_primary=True,
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
Expand All @@ -73,7 +79,7 @@
signed_agreement__representative=UserFactory.create(name="Bamidele Tayo"),
signed_agreement__signing_institution="Loyola",
signed_agreement__representative_role="Co-PI",
signed_agreement__is_primary=False,
is_primary=False,
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
Expand All @@ -86,7 +92,7 @@
signed_agreement__representative=UserFactory.create(name="Brackie Mitchell"),
signed_agreement__signing_institution="UM",
signed_agreement__representative_role="Co-I",
signed_agreement__is_primary=False,
is_primary=False,
signed_agreement__version=v11,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
Expand All @@ -113,6 +119,8 @@
signed_agreement__signing_institution="UW",
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
additional_limitations="This data can only be used for testing the app.",
requires_study_review=True,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1006.signed_agreement.anvil_access_group
Expand All @@ -123,7 +131,7 @@
signed_agreement__representative=UserFactory.create(name="Wendy"),
signed_agreement__signing_institution="JHU",
signed_agreement__representative_role="Field Center PI",
signed_agreement__is_primary=False,
is_primary=False,
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
)
Expand All @@ -136,7 +144,7 @@
signed_agreement__representative=UserFactory.create(name="Jerry"),
signed_agreement__signing_institution="Lundquist",
signed_agreement__representative_role="Analysis Center PI",
signed_agreement__is_primary=False,
is_primary=False,
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
)
Expand Down Expand Up @@ -219,5 +227,17 @@
workspace__name="DEMO_PRIMED_CDSA_MESA_2",
study=Study.objects.get(short_name="MESA"),
data_use_permission=dup,
additional_limitations="Additional limitations for workspace.",
)
cdsa_workspace_2.data_use_modifiers.add(dum)


# Add a workspace with no primary cdsa.
cdsa_workspace_3 = factories.CDSAWorkspaceFactory.create(
workspace__billing_project__name="demo-primed-cdsa",
workspace__name="DEMO_PRIMED_CDSA_ARIC_1",
study=Study.objects.create(
short_name="ARIC", full_name="Atherosclerosis Risk in Communities"
),
data_use_permission=dup,
)
44 changes: 44 additions & 0 deletions add_data_prep_example_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Temporary script to create some test data.
# Run with: python manage.py shell < add_data_prep_example_data.py


from primed.cdsa.tests.factories import CDSAWorkspaceFactory
from primed.dbgap.tests.factories import dbGaPWorkspaceFactory
from primed.miscellaneous_workspaces.tests import factories
from primed.primed_anvil.tests.factories import StudyFactory

# Create a dbGaP workspace.
fhs = StudyFactory.create(short_name="FHS", full_name="Framingham Heart Study")
workspace_dbgap = dbGaPWorkspaceFactory.create(
dbgap_study_accession__dbgap_phs=7,
dbgap_study_accession__studies=[fhs],
dbgap_version=33,
dbgap_participant_set=12,
dbgap_consent_code=1,
dbgap_consent_abbreviation="HMB",
workspace__name="DBGAP_FHS_v33_p12_HMB",
)

# Create a data prep workspace.
workspace_dbgap_prep = factories.DataPrepWorkspaceFactory.create(
target_workspace=workspace_dbgap.workspace,
workspace__name="DBGAP_FHS_v33_p12_HMB_PREP",
)


# Create a CDSA workspace.
workspace_cdsa = CDSAWorkspaceFactory.create(
study__short_name="MESA",
workspace__name="CDSA_MESA_HMB",
)

# Create a data prep workspace.
factories.DataPrepWorkspaceFactory.create(
target_workspace=workspace_cdsa.workspace,
workspace__name="CDSA_MESA_HMB_PREP_1",
is_active=False,
)
workspace_cdsa_prep = factories.DataPrepWorkspaceFactory.create(
target_workspace=workspace_cdsa.workspace,
workspace__name="CDSA_MESA_HMB_PREP_2",
)
23 changes: 23 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"simple_history",
"dbbackup",
"django_htmx",
"constance",
]

LOCAL_APPS = [
Expand Down Expand Up @@ -205,6 +206,7 @@
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"constance.context_processors.config",
"primed.utils.context_processors.settings_context",
],
},
Expand Down Expand Up @@ -368,6 +370,17 @@
# https://django-tables2.readthedocs.io/en/latest/pages/custom-rendering.html?highlight=django_tables2_template#available-templates
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html"

# django-constance
# ------------------------------------------------------------------------------
CONSTANCE_CONFIG = {
"ANNOUNCEMENT_TEXT": ("", "Site-wide announcement message", str),
}

CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_IGNORE_ADMIN_VERSION_CHECK = True
# CONSTANCE_DATABASE_CACHE_BACKEND = "default"
CONSTANCE_DATABASE_CACHE_AUTOFILL_TIMEOUT = None

# django-anvil-consortium-manager
# ------------------------------------------------------------------------------
ANVIL_API_SERVICE_ACCOUNT_FILE = env("ANVIL_API_SERVICE_ACCOUNT_FILE")
Expand All @@ -390,3 +403,13 @@
# Specify the subject for AnVIL account verification emails.
ANVIL_ACCOUNT_LINK_EMAIL_SUBJECT = "Verify your AnVIL account email"
ANVIL_ACCOUNT_VERIFY_NOTIFICATION_EMAIL = "[email protected]"

DRUPAL_API_CLIENT_ID = env("DRUPAL_API_CLIENT_ID", default="")
DRUPAL_API_CLIENT_SECRET = env("DRUPAL_API_CLIENT_SECRET", default="")
DRUPAL_API_REL_PATH = env("DRUPAL_API_REL_PATH", default="mockapi")
DRUPAL_DATA_AUDIT_DEACTIVATE_USERS = env(
"DRUPAL_DATA_AUDIT_DEACTIVATE_USERS", default=False
)
DRUPAL_DATA_AUDIT_REMOVE_USER_SITES = env(
"DRUPAL_DATA_AUDIT_REMOVE_USER_SITES", default=False
)
22 changes: 22 additions & 0 deletions primed/cdsa/adapters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from anvil_consortium_manager.adapters.workspace import BaseWorkspaceAdapter
from anvil_consortium_manager.forms import WorkspaceForm
from anvil_consortium_manager.models import Workspace

from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceUserTable

from . import forms, models, tables

Expand All @@ -18,3 +21,22 @@ class CDSAWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_model = models.CDSAWorkspace
workspace_data_form_class = forms.CDSAWorkspaceForm
workspace_detail_template_name = "cdsa/cdsaworkspace_detail.html"

def get_extra_detail_context_data(self, workspace, request):
extra_context = {}
associated_data_prep = Workspace.objects.filter(
dataprepworkspace__target_workspace=workspace
)
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceUserTable(
associated_data_prep
)
extra_context["data_prep_active"] = associated_data_prep.filter(
dataprepworkspace__is_active=True
).exists()
# Get the primary CDSA for this study, assuming it exists.
try:
extra_context["primary_cdsa"] = workspace.cdsaworkspace.get_primary_cdsa()
except models.DataAffiliateAgreement.DoesNotExist:
extra_context["primary_cdsa"] = None

return extra_context
10 changes: 5 additions & 5 deletions primed/cdsa/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class SignedAgreement(SimpleHistoryAdmin):
"cc_id",
"representative",
"type",
"is_primary",
# "is_primary",
"date_signed",
"version",
)
list_filter = (
"type",
"is_primary",
# "is_primary",
"version",
"status",
)
Expand All @@ -79,7 +79,7 @@ class MemberAgreementAdmin(SimpleHistoryAdmin):
)
list_filter = (
"study_site",
"signed_agreement__is_primary",
# "signed_agreement__is_primary",
"signed_agreement__status",
)

Expand All @@ -94,7 +94,7 @@ class DataAffiliateAgreementAdmin(SimpleHistoryAdmin):
)
list_filter = (
"study",
"signed_agreement__is_primary",
# "signed_agreement__is_primary",
"signed_agreement__status",
)

Expand All @@ -108,7 +108,7 @@ class NonDataAffiliateAgreementAdmin(SimpleHistoryAdmin):
"affiliation",
)
list_filter = (
"signed_agreement__is_primary",
# "signed_agreement__is_primary",
"signed_agreement__status",
)

Expand Down
18 changes: 4 additions & 14 deletions primed/cdsa/audit/signed_agreement_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ class SignedAgreementAccessAudit(PRIMEDAudit):
PRIMARY_NOT_ACTIVE = "Primary agreement for this CDSA is not active."

# Other errors
ERROR_NON_DATA_AFFILIATE_COMPONENT = (
"Non-data affiliate agreements must be primary."
)
ERROR_OTHER_CASE = "Signed Agreement did not match any expected situations."

results_table_class = SignedAgreementAccessAuditTable
Expand Down Expand Up @@ -218,23 +215,15 @@ def _audit_component_agreement(self, signed_agreement):
if hasattr(signed_agreement, "memberagreement"):
# Member
primary_qs = models.SignedAgreement.objects.filter(
is_primary=True,
memberagreement__is_primary=True,
memberagreement__study_site=signed_agreement.memberagreement.study_site,
)
elif hasattr(signed_agreement, "dataaffiliateagreement"):
# Data affiliate
primary_qs = models.SignedAgreement.objects.filter(
is_primary=True,
dataaffiliateagreement__is_primary=True,
dataaffiliateagreement__study=signed_agreement.dataaffiliateagreement.study,
)
elif hasattr(signed_agreement, "nondataaffiliateagreement"):
self.errors.append(
OtherError(
signed_agreement=signed_agreement,
note=self.ERROR_NON_DATA_AFFILIATE_COMPONENT,
)
)
return
primary_exists = primary_qs.exists()
primary_active = primary_qs.filter(
status=models.SignedAgreement.StatusChoices.ACTIVE,
Expand Down Expand Up @@ -320,7 +309,8 @@ def _audit_component_agreement(self, signed_agreement):
) # pragma: no cover

def _audit_signed_agreement(self, signed_agreement):
if signed_agreement.is_primary:
agreement_type = signed_agreement.get_agreement_type()
if not hasattr(agreement_type, "is_primary") or agreement_type.is_primary:
self._audit_primary_agreement(signed_agreement)
else:
self._audit_component_agreement(signed_agreement)
Expand Down
2 changes: 1 addition & 1 deletion primed/cdsa/audit/workspace_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _audit_workspace(self, workspace):
child_group=self.anvil_cdsa_group,
).exists()
primary_qs = models.DataAffiliateAgreement.objects.filter(
study=workspace.study, signed_agreement__is_primary=True
study=workspace.study, is_primary=True
)
primary_exists = primary_qs.exists()

Expand Down
Loading

0 comments on commit 6c03f03

Please sign in to comment.