Skip to content

Commit

Permalink
Merge pull request #229 from UW-GAC/deploy/stage
Browse files Browse the repository at this point in the history
Deploy to prod
  • Loading branch information
jmcarson authored Apr 28, 2023
2 parents 4856bbe + 6f5ccac commit 4c8a595
Show file tree
Hide file tree
Showing 21 changed files with 648 additions and 71 deletions.
8 changes: 8 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,24 @@
"API_URL": DRUPAL_SITE_URL,
"OVERRIDE_NAME": "Gregor Consortium Site Login",
"SCOPES": [
# This role will be used to grant ACM view permission.
{
"drupal_machine_name": "dcc_staff",
"request_scope": True,
"django_group_name": "DCC Staff",
},
# This role will be use dto grant ACM edit permission.
{
"drupal_machine_name": "dcc_acm_admin",
"request_scope": True,
"django_group_name": "DCC ACM Admin",
},
# For now we can use the "DSA completed" group to determine who can link their accounts.
{
"drupal_machine_name": "dsa_completed",
"request_scope": True,
"django_group_name": "DSA completed",
},
],
}
}
Expand Down
16 changes: 13 additions & 3 deletions gregor_django/gregor_anvil/adapters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from anvil_consortium_manager.adapters.account import BaseAccountAdapter
from anvil_consortium_manager.adapters.workspace import BaseWorkspaceAdapter
from anvil_consortium_manager.tables import WorkspaceTable
from django.db.models import Q

from . import forms, models, tables
Expand Down Expand Up @@ -36,6 +35,17 @@ class UploadWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_form_class = forms.UploadWorkspaceForm
workspace_detail_template_name = "gregor_anvil/uploadworkspace_detail.html"

def get_autocomplete_queryset(self, queryset, q, forwarded={}):
"""Filter to Accounts where the email or the associated user name matches the query `q`."""
consent_group = forwarded.get("consent_group", None)
if consent_group:
queryset = queryset.filter(consent_group=consent_group)

if q:
queryset = queryset.filter(workspace__name__icontains=q)

return queryset


class ExampleWorkspaceAdapter(BaseWorkspaceAdapter):
"""Adapter for ExampleWorkspaces."""
Expand All @@ -45,7 +55,7 @@ class ExampleWorkspaceAdapter(BaseWorkspaceAdapter):
description = (
"Workspaces that contain examples of using AnVIL, working with data, etc."
)
list_table_class = WorkspaceTable
list_table_class = tables.DefaultWorkspaceTable
workspace_data_model = models.ExampleWorkspace
workspace_data_form_class = forms.ExampleWorkspaceForm
workspace_detail_template_name = "anvil_consortium_manager/workspace_detail.html"
Expand All @@ -69,7 +79,7 @@ class CombinedConsortiumDataWorkspaceAdapter(BaseWorkspaceAdapter):
type = "combined_consortium"
name = "Combined consortium data workspace"
description = "Workspaces for internal consortium use that contain data tables combined across upload workspaces"
list_table_class = WorkspaceTable
list_table_class = tables.DefaultWorkspaceTable
workspace_data_model = models.CombinedConsortiumDataWorkspace
workspace_data_form_class = forms.CombinedConsortiumDataWorkspaceForm
workspace_detail_template_name = (
Expand Down
18 changes: 18 additions & 0 deletions gregor_django/gregor_anvil/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ class ResearchCenterAdmin(SimpleHistoryAdmin):
)


@admin.register(models.PartnerGroup)
class PartnerGroupAdmin(SimpleHistoryAdmin):
"""Admin class for the PartnerGroup model."""

list_display = (
"short_name",
"full_name",
)
search_fields = (
"short_name",
"full_name",
)
sortable_by = (
"short_name",
"full_name",
)


@admin.register(models.UploadWorkspace)
class UploadWorkspaceAdmin(SimpleHistoryAdmin):
"""Admin class for the UploadWorkspace model."""
Expand Down
6 changes: 5 additions & 1 deletion gregor_django/gregor_anvil/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dal import autocomplete
from django import forms
from django.core.exceptions import ValidationError
from django.urls import reverse

from . import models

Expand Down Expand Up @@ -51,7 +52,10 @@ class Meta:
}
widgets = {
"upload_workspaces": autocomplete.ModelSelect2Multiple(
url="gregor_anvil:upload_workspaces:autocomplete",
url=reverse(
"anvil_consortium_manager:workspaces:autocomplete_by_type",
args=["upload"],
),
attrs={"data-theme": "bootstrap-5"},
),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 3.2.16 on 2023-04-27 17:10

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django_extensions.db.fields
import simple_history.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('gregor_anvil', '0007_releaseworkspace'),
]

operations = [
migrations.CreateModel(
name='PartnerGroup',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('short_name', models.CharField(max_length=15, unique=True)),
('full_name', models.CharField(max_length=255)),
],
options={
'get_latest_by': 'modified',
'abstract': False,
},
),
migrations.CreateModel(
name='HistoricalPartnerGroup',
fields=[
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('short_name', models.CharField(db_index=True, max_length=15)),
('full_name', models.CharField(max_length=255)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical partner group',
'verbose_name_plural': 'historical partner groups',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
33 changes: 33 additions & 0 deletions gregor_django/gregor_anvil/migrations/0009_unique_full_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.16 on 2023-04-27 19:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('gregor_anvil', '0008_historicalpartnergroup_partnergroup'),
]

operations = [
migrations.AlterField(
model_name='historicalpartnergroup',
name='full_name',
field=models.CharField(db_index=True, max_length=255),
),
migrations.AlterField(
model_name='historicalresearchcenter',
name='full_name',
field=models.CharField(db_index=True, max_length=255),
),
migrations.AlterField(
model_name='partnergroup',
name='full_name',
field=models.CharField(max_length=255, unique=True),
),
migrations.AlterField(
model_name='researchcenter',
name='full_name',
field=models.CharField(max_length=255, unique=True),
),
]
26 changes: 25 additions & 1 deletion gregor_django/gregor_anvil/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ResearchCenter(TimeStampedModel, models.Model):
short_name = models.CharField(max_length=15, unique=True)
"""The short name of the Research Center."""

full_name = models.CharField(max_length=255)
full_name = models.CharField(max_length=255, unique=True)
"""The full name of the Research Center."""

history = HistoricalRecords()
Expand All @@ -56,6 +56,30 @@ def get_absolute_url(self):
return reverse("gregor_anvil:research_centers:detail", args=[self.pk])


class PartnerGroup(TimeStampedModel, models.Model):
"""A model to track Partner Groups"""

short_name = models.CharField(max_length=15, unique=True)
"""The short name of the Partner Group"""

full_name = models.CharField(max_length=255, unique=True)
"""The full name of the Partner Group"""

history = HistoricalRecords()

def __str__(self):
"""String method.
Returns:
A string showing the short_name of the object.
"""
return self.short_name

def get_absolute_url(self):
"""Return the absolute url for this object."""
return reverse("gregor_anvil:partner_groups:detail", args=[self.pk])


class UploadWorkspace(TimeStampedModel, BaseWorkspaceData):
"""A model to track additional data about an upload workspace."""

Expand Down
64 changes: 62 additions & 2 deletions gregor_django/gregor_anvil/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import django_tables2 as tables
from anvil_consortium_manager.adapters.workspace import workspace_adapter_registry
from anvil_consortium_manager.models import Account, Workspace
from django.utils.html import format_html

from . import models

Expand Down Expand Up @@ -33,6 +34,16 @@ class Meta:
fields = ("full_name", "short_name")


class PartnerGroupTable(tables.Table):
"""A table for PartnerGroups."""

full_name = tables.Column(linkify=True)

class Meta:
model = models.PartnerGroup
fields = ("full_name", "short_name")


class ConsentGroupTable(tables.Table):
"""A table for `ConsentGroups`."""

Expand All @@ -46,7 +57,54 @@ class Meta:
)


class UploadWorkspaceTable(tables.Table):
class WorkspaceSharedWithConsortiumTable(tables.Table):
"""Table including a column to indicate if a workspace is shared with PRIMED_ALL."""

is_shared = tables.columns.Column(
accessor="pk",
verbose_name="Shared with GREGoR?",
orderable=False,
)

def render_is_shared(self, record):
is_shared = record.workspacegroupsharing_set.filter(
group__name="GREGOR_ALL"
).exists()
if is_shared:
icon = "check-circle-fill"
color = "green"
value = format_html(
"""<i class="bi bi-{}" style="color: {};"></i>""".format(icon, color)
)
else:
value = ""
return value


class DefaultWorkspaceTable(WorkspaceSharedWithConsortiumTable, tables.Table):
"""Class to use for default workspace tables in GREGoR."""

name = tables.Column(linkify=True, verbose_name="Workspace")
billing_project = tables.Column(linkify=True)
number_groups = tables.Column(
verbose_name="Number of groups shared with",
empty_values=(),
orderable=False,
accessor="workspacegroupsharing_set__count",
)

class Meta:
model = Workspace
fields = (
"name",
"billing_project",
"number_groups",
"is_shared",
)
order_by = ("name",)


class UploadWorkspaceTable(WorkspaceSharedWithConsortiumTable, tables.Table):
"""A table for Workspaces that includes fields from UploadWorkspace."""

name = tables.columns.Column(linkify=True)
Expand All @@ -58,10 +116,11 @@ class Meta:
"uploadworkspace__research_center",
"uploadworkspace__consent_group",
"uploadworkspace__version",
"is_shared",
)


class TemplateWorkspaceTable(tables.Table):
class TemplateWorkspaceTable(WorkspaceSharedWithConsortiumTable, tables.Table):
"""A table for Workspaces that includes fields from TemplateWorkspace."""

name = tables.columns.Column(linkify=True)
Expand All @@ -71,6 +130,7 @@ class Meta:
fields = (
"name",
"templateworkspace__intended_use",
"is_shared",
)


Expand Down
11 changes: 11 additions & 0 deletions gregor_django/gregor_anvil/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class Meta:
django_get_or_create = ["short_name"]


class PartnerGroupFactory(DjangoModelFactory):
"""A factory for the PartnerGroup model."""

short_name = Faker("word")
full_name = Faker("company")

class Meta:
model = models.PartnerGroup
django_get_or_create = ["short_name"]


class UploadWorkspaceFactory(DjangoModelFactory):
"""A factory for the UploadWorkspace model."""

Expand Down
Loading

0 comments on commit 4c8a595

Please sign in to comment.