Skip to content

Commit

Permalink
Merge branch 'main' into feature/audit-drupal-data
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarson committed Apr 12, 2024
2 parents a8bc6ea + cb62072 commit 6d122ed
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 175 deletions.
4 changes: 2 additions & 2 deletions primed/cdsa/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from anvil_consortium_manager.forms import WorkspaceForm
from anvil_consortium_manager.models import Workspace

from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceTable
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceUserTable

from . import forms, models, tables

Expand All @@ -27,7 +27,7 @@ def get_extra_detail_context_data(self, workspace, request):
associated_data_prep = Workspace.objects.filter(
dataprepworkspace__target_workspace=workspace
)
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable(
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceUserTable(
associated_data_prep
)
extra_context["data_prep_active"] = associated_data_prep.filter(
Expand Down
37 changes: 3 additions & 34 deletions primed/cdsa/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,10 @@ def render_date_shared(self, record):
return "—"


class CDSAWorkspaceStaffTable(tables.Table):
class CDSAWorkspaceUserTable(tables.Table):
"""A table for the CDSAWorkspace model."""

name = tables.Column(linkify=True)
billing_project = tables.Column(linkify=True)
cdsaworkspace__data_use_permission__abbreviation = tables.Column(
verbose_name="DUO permission",
linkify=lambda record: record.cdsaworkspace.data_use_permission.get_absolute_url(),
Expand All @@ -329,7 +328,6 @@ class Meta:
model = Workspace
fields = (
"name",
"billing_project",
"cdsaworkspace__study",
"cdsaworkspace__data_use_permission__abbreviation",
"cdsaworkspace__data_use_modifiers",
Expand All @@ -351,27 +349,10 @@ def render_cdsaworkspace__requires_study_review(self, record):
return mark_safe(f'<i class="bi bi-{icon}" style="color: {color}"></i>')


class CDSAWorkspaceUserTable(tables.Table):
class CDSAWorkspaceStaffTable(CDSAWorkspaceUserTable):
"""A table for the CDSAWorkspace model."""

name = tables.Column(linkify=True)
billing_project = tables.Column()
cdsaworkspace__data_use_permission__abbreviation = tables.Column(
verbose_name="DUO permission",
)
cdsaworkspace__study = tables.Column()
cdsaworkspace__data_use_modifiers = tables.ManyToManyColumn(
transform=lambda x: x.abbreviation,
verbose_name="DUO modifiers",
)
cdsaworkspace__requires_study_review = BooleanIconColumn(
verbose_name="Study review required?",
orderable=False,
true_icon="dash-circle-fill",
true_color="#ffc107",
)
cdsaworkspace__gsr_restricted = BooleanIconColumn(orderable=False)
is_shared = WorkspaceSharedWithConsortiumColumn()
billing_project = tables.Column(linkify=True)

class Meta:
model = Workspace
Expand All @@ -385,15 +366,3 @@ class Meta:
"cdsaworkspace__gsr_restricted",
)
order_by = ("name",)

def render_cdsaworkspace__requires_study_review(self, record):
try:
if record.cdsaworkspace.get_primary_cdsa().requires_study_review:
icon = "dash-circle-fill"
color = "#ffc107"
else:
return ""
except models.DataAffiliateAgreement.DoesNotExist:
icon = "question-circle-fill"
color = "red"
return mark_safe(f'<i class="bi bi-{icon}" style="color: {color}"></i>')
27 changes: 25 additions & 2 deletions primed/cdsa/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from freezegun import freeze_time

from primed.duo.tests.factories import DataUseModifierFactory, DataUsePermissionFactory
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceTable
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceUserTable
from primed.miscellaneous_workspaces.tests.factories import DataPrepWorkspaceFactory
from primed.primed_anvil.tests.factories import (
AvailableDataFactory,
Expand Down Expand Up @@ -7436,14 +7436,37 @@ def test_render_duo_modifiers(self):
self.assertContains(response, modifiers[0].abbreviation)
self.assertContains(response, modifiers[1].abbreviation)

def test_associated_data_prep_view_user(self):
"""View users do not see the associated data prep section"""
user = User.objects.create_user(username="test-view", password="test-view")
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)

obj = factories.CDSAWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(target_workspace=obj.workspace)
self.client.force_login(user)
response = self.client.get(obj.get_absolute_url())
self.assertNotContains(response, "Associated data prep workspaces")

def test_associated_data_prep_staff_view_user(self):
"""Staff view users do see the associated data prep section."""
obj = factories.CDSAWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(target_workspace=obj.workspace)
self.client.force_login(self.user)
response = self.client.get(obj.get_absolute_url())
self.assertContains(response, "Associated data prep workspaces")

def test_associated_data_prep_workspaces_context_exists(self):
obj = factories.CDSAWorkspaceFactory.create()
self.client.force_login(self.user)
response = self.client.get(obj.get_absolute_url())
self.assertIn("associated_data_prep_workspaces", response.context_data)
self.assertIsInstance(
response.context_data["associated_data_prep_workspaces"],
DataPrepWorkspaceTable,
DataPrepWorkspaceUserTable,
)

def test_only_show_one_associated_data_prep_workspace(self):
Expand Down
19 changes: 4 additions & 15 deletions primed/collaborative_analysis/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
from anvil_consortium_manager.models import Workspace


class CollaborativeAnalysisWorkspaceStaffTable(tables.Table):
class CollaborativeAnalysisWorkspaceUserTable(tables.Table):
"""Class to render a table of Workspace objects with CollaborativeAnalysisWorkspace data."""

name = tables.columns.Column(linkify=True)
billing_project = tables.Column(linkify=True)
collaborativeanalysisworkspace__custodian = tables.Column(linkify=True)
number_source_workspaces = tables.columns.Column(
accessor="pk",
verbose_name="Number of source workspaces",
Expand All @@ -18,7 +16,6 @@ class Meta:
model = Workspace
fields = (
"name",
"billing_project",
"collaborativeanalysisworkspace__custodian",
"number_source_workspaces",
)
Expand All @@ -29,16 +26,12 @@ def render_number_source_workspaces(self, record):
return record.collaborativeanalysisworkspace.source_workspaces.count()


class CollaborativeAnalysisWorkspaceUserTable(tables.Table):
class CollaborativeAnalysisWorkspaceStaffTable(CollaborativeAnalysisWorkspaceUserTable):
"""Class to render a table of Workspace objects with CollaborativeAnalysisWorkspace data."""

name = tables.columns.Column(linkify=True)
billing_project = tables.Column()
number_source_workspaces = tables.columns.Column(
accessor="pk",
verbose_name="Number of source workspaces",
orderable=False,
)
billing_project = tables.Column(linkify=True)
collaborativeanalysisworkspace__custodian = tables.Column(linkify=True)

class Meta:
model = Workspace
Expand All @@ -49,7 +42,3 @@ class Meta:
"number_source_workspaces",
)
order_by = ("name",)

def render_number_source_workspaces(self, record):
"""Render the number of source workspaces."""
return record.collaborativeanalysisworkspace.source_workspaces.count()
4 changes: 2 additions & 2 deletions primed/dbgap/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from anvil_consortium_manager.forms import WorkspaceForm
from anvil_consortium_manager.models import Workspace

from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceTable
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceUserTable

from . import forms, models, tables

Expand All @@ -25,7 +25,7 @@ def get_extra_detail_context_data(self, workspace, request):
associated_data_prep = Workspace.objects.filter(
dataprepworkspace__target_workspace=workspace
)
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable(
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceUserTable(
associated_data_prep
)
extra_context["data_prep_active"] = associated_data_prep.filter(
Expand Down
49 changes: 16 additions & 33 deletions primed/dbgap/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ def render_dbgap_phs(self, value):
return "phs{0:06d}".format(value)


class dbGaPWorkspaceStaffTable(tables.Table):
class dbGaPWorkspaceUserTable(tables.Table):
"""Class to render a table of Workspace objects with dbGaPWorkspace workspace data."""

name = tables.columns.Column(linkify=True)
billing_project = tables.Column(linkify=True)
dbgap_accession = dbGaPAccessionColumn(
accessor="dbgapworkspace__get_dbgap_accession",
dbgap_link_accessor="dbgapworkspace__get_dbgap_link",
Expand All @@ -91,11 +90,6 @@ class dbGaPWorkspaceStaffTable(tables.Table):
dbgapworkspace__dbgap_consent_abbreviation = tables.columns.Column(
verbose_name="Consent"
)
number_approved_dars = tables.columns.Column(
accessor="pk",
verbose_name="Approved DARs",
orderable=False,
)
dbgapworkspace__gsr_restricted = BooleanIconColumn(
orderable=False, true_icon="dash-circle-fill", true_color="#ffc107"
)
Expand All @@ -105,43 +99,23 @@ class Meta:
model = Workspace
fields = (
"name",
"billing_project",
"dbgap_accession",
"dbgapworkspace__dbgap_consent_abbreviation",
"number_approved_dars",
"dbgapworkspace__gsr_restricted",
"is_shared",
)
order_by = ("name",)

def render_number_approved_dars(self, record):
n = (
record.dbgapworkspace.get_data_access_requests(most_recent=True)
.filter(dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED)
.count()
)
return n


class dbGaPWorkspaceUserTable(tables.Table):
class dbGaPWorkspaceStaffTable(dbGaPWorkspaceUserTable):
"""Class to render a table of Workspace objects with dbGaPWorkspace workspace data."""

name = tables.columns.Column(linkify=True)
billing_project = tables.Column()
dbgap_accession = dbGaPAccessionColumn(
accessor="dbgapworkspace__get_dbgap_accession",
dbgap_link_accessor="dbgapworkspace__get_dbgap_link",
order_by=(
"dbgapworkspace__dbgap_study_accession__dbgap_phs",
"dbgapworkspace__dbgap_version",
"dbgapworkspace__dbgap_participant_set",
),
)
dbgapworkspace__dbgap_consent_abbreviation = tables.columns.Column(
verbose_name="Consent"
billing_project = tables.Column(linkify=True)
number_approved_dars = tables.columns.Column(
accessor="pk",
verbose_name="Approved DARs",
orderable=False,
)
dbgapworkspace__gsr_restricted = BooleanIconColumn(orderable=False)
is_shared = WorkspaceSharedWithConsortiumColumn()

class Meta:
model = Workspace
Expand All @@ -150,11 +124,20 @@ class Meta:
"billing_project",
"dbgap_accession",
"dbgapworkspace__dbgap_consent_abbreviation",
"number_approved_dars",
"dbgapworkspace__gsr_restricted",
"is_shared",
)
order_by = ("name",)

def render_number_approved_dars(self, record):
n = (
record.dbgapworkspace.get_data_access_requests(most_recent=True)
.filter(dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED)
.count()
)
return n


class dbGaPApplicationTable(tables.Table):
"""Class to render a table of dbGaPApplication objects."""
Expand Down
27 changes: 25 additions & 2 deletions primed/dbgap/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from freezegun import freeze_time

from primed.duo.tests.factories import DataUseModifierFactory, DataUsePermissionFactory
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceTable
from primed.miscellaneous_workspaces.tables import DataPrepWorkspaceUserTable
from primed.miscellaneous_workspaces.tests.factories import DataPrepWorkspaceFactory
from primed.primed_anvil.tests.factories import ( # DataUseModifierFactory,; DataUsePermissionFactory,
StudyFactory,
Expand Down Expand Up @@ -953,14 +953,37 @@ def test_links_audit_access_view_permission(self):
),
)

def test_associated_data_prep_view_user(self):
"""View users do not see the associated data prep section"""
user = User.objects.create_user(username="test-view", password="test-view")
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)

obj = factories.dbGaPWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(target_workspace=obj.workspace)
self.client.force_login(user)
response = self.client.get(obj.get_absolute_url())
self.assertNotContains(response, "Associated data prep workspaces")

def test_associated_data_prep_staff_view_user(self):
"""Staff view users do see the associated data prep section."""
obj = factories.dbGaPWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(target_workspace=obj.workspace)
self.client.force_login(self.user)
response = self.client.get(obj.get_absolute_url())
self.assertContains(response, "Associated data prep workspaces")

def test_associated_data_prep_workspaces_context_exists(self):
obj = factories.dbGaPWorkspaceFactory.create()
self.client.force_login(self.user)
response = self.client.get(obj.get_absolute_url())
self.assertIn("associated_data_prep_workspaces", response.context_data)
self.assertIsInstance(
response.context_data["associated_data_prep_workspaces"],
DataPrepWorkspaceTable,
DataPrepWorkspaceUserTable,
)

def test_only_show_one_associated_data_prep_workspace(self):
Expand Down
4 changes: 2 additions & 2 deletions primed/duo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
self.user = UserFactory.create(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)

Expand Down Expand Up @@ -180,7 +180,7 @@ def setUp(self):
self.user = UserFactory.create(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)

Expand Down
9 changes: 3 additions & 6 deletions primed/duo/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from anvil_consortium_manager.auth import (
AnVILConsortiumManagerStaffViewRequired,
AnVILConsortiumManagerViewRequired,
)
from anvil_consortium_manager.auth import AnVILConsortiumManagerViewRequired
from django.http import Http404
from django.views.generic import DetailView, ListView

from . import models


class DataUsePermissionList(AnVILConsortiumManagerStaffViewRequired, ListView):
class DataUsePermissionList(AnVILConsortiumManagerViewRequired, ListView):

model = models.DataUsePermission

Expand Down Expand Up @@ -41,7 +38,7 @@ def get_context_data(self, **kwargs):
return context


class DataUseModifierList(AnVILConsortiumManagerStaffViewRequired, ListView):
class DataUseModifierList(AnVILConsortiumManagerViewRequired, ListView):

model = models.DataUseModifier

Expand Down
4 changes: 2 additions & 2 deletions primed/miscellaneous_workspaces/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class DataPrepWorkspaceAdapter(BaseWorkspaceAdapter):
type = "data_prep"
name = "Data prep workspace"
description = "Workspaces used to prepare data for sharing or update data that is already shared"
list_table_class_staff_view = tables.DataPrepWorkspaceTable
list_table_class_view = tables.DataPrepWorkspaceTable
list_table_class_staff_view = tables.DataPrepWorkspaceStaffTable
list_table_class_view = tables.DataPrepWorkspaceUserTable
workspace_form_class = WorkspaceForm
workspace_data_model = models.DataPrepWorkspace
workspace_data_form_class = forms.DataPrepWorkspaceForm
Expand Down
Loading

0 comments on commit 6d122ed

Please sign in to comment.