Skip to content

Commit

Permalink
Merge branch 'develop' into 470-notif-user-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
HesamKorki authored Nov 13, 2023
2 parents d663092 + 52fd8b0 commit 2bde86d
Show file tree
Hide file tree
Showing 82 changed files with 14,100 additions and 5,490 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ fabric.properties
elixir_daisy/settings_local.py
static/css/*
web/static/vendor/node_modules/*

web/static/js/*.bundle.js
web/static/js/*.bundle.js.LICENSE.txt


/log/*.log
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ repos:
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.15.0
hooks:
- id: eslint
files: web/static/vendor/(components|tests)/.*\.[jt]sx?$
types: [file]
additional_dependencies:
- eslint@8.15.0
- eslint-plugin-react@7.29.4
- eslint-plugin-react-hooks@4.6.0
7 changes: 5 additions & 2 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ sudo /usr/local/bin/pip3.9 install gunicorn
## NPM and Node.js

```bash
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install nodejs
apt-get update && apt-get install -y ca-certificates curl gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get update && apt-get install -y nodejs
```

Then you need to compile the static files.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ You are encouraged to try Daisy for yourself using our [DEMO deployment](https:/
1. Compile and deploy static files

```bash
cd web/static/vendor
npm run build
cd ../../../
docker-compose exec web python manage.py collectstatic
```
1. Create initial data in the database
Expand Down Expand Up @@ -224,7 +227,7 @@ cd web/static/vendor/
npm ci
```

### Compile daisy.scss
### Compile daisy.scss and React
```bash
cd web/static/vendor
npm run-script build
Expand Down
20 changes: 20 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ def user_data_steward(django_user_model):
return u


@pytest.fixture
def user_legal(django_user_model):
u = django_user_model.objects.create_user(
username="user.legal", password="password", email="legal@email.com"
)
g, _ = Group.objects.get_or_create(name=GroupConstants.LEGAL.value)
u.groups.add(g)
return u


@pytest.fixture
def user_auditor(django_user_model):
u = django_user_model.objects.create_user(
username="user.auditor", password="password", email="auditor@email.com"
)
g, _ = Group.objects.get_or_create(name=GroupConstants.AUDITOR.value)
u.groups.add(g)
return u


@pytest.fixture
def user_admin(django_user_model):
u = django_user_model.objects.create_superuser(
Expand Down
2 changes: 2 additions & 0 deletions core/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DataDeclarationSubFormFromExisting,
)
from .document import DocumentForm
from .project import ProjectForm
from .partner import PartnerForm
from .permission import UserPermFormSet
from .legal_basis import LegalBasisForm
Expand All @@ -35,6 +36,7 @@
"PartnerForm",
"LegalBasisForm",
"PartnerRoleForm",
"ProjectForm",
"UserPermFormSet",
"PublicationForm",
"ShareForm",
Expand Down
9 changes: 6 additions & 3 deletions core/forms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ class Meta:
heading_help = "Provide basic information for the new dataset."

def __init__(self, *args, **kwargs):
dataset = None
if "dataset" in kwargs:
dataset = kwargs.pop("dataset")
kwargs.pop("dataset", None)
keep_metadata = kwargs.pop("keep_metadata_field", False)

super().__init__(*args, **kwargs)
if not keep_metadata:
del self.fields["scientific_metadata"]

self.fields["local_custodians"].queryset = User.objects.exclude(
username="AnonymousUser"
)
Expand Down
5 changes: 5 additions & 0 deletions core/forms/importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django import forms


class ImportForm(forms.Form):
file = forms.FileField(required=True, label="Choose File")
3 changes: 3 additions & 0 deletions core/forms/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class Meta:

def __init__(self, *args, **kwargs):
kwargs["label_suffix"] = ""
keep_metadata_field = kwargs.pop("keep_metadata_field", False)
super().__init__(*args, **kwargs)
if not keep_metadata_field:
del self.fields["scientific_metadata"]
instance = kwargs.get("instance", None)

if "data" not in kwargs:
Expand Down
3 changes: 3 additions & 0 deletions core/models/contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.urls import reverse

from core import constants
from core.permissions.mapping import PERMISSION_MAPPING
Expand Down Expand Up @@ -118,6 +119,8 @@ class AppMeta:
)

# metadata = JSONField(null=True, blank=True, default=dict)
def get_absolute_url(self):
return reverse("contract", args=[str(self.pk)])

def add_partner_with_role(self, partner, role, contact=None):
partner_role = self.partners_roles.create(partner=partner)
Expand Down
4 changes: 4 additions & 0 deletions core/models/data_declaration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

from django.db import models
from django.urls import reverse
from enumchoicefield import EnumChoiceField, ChoiceEnum

from core import constants
Expand Down Expand Up @@ -217,6 +218,9 @@ class Meta:
help_text="This is the unique identifier used by DAISY for this dataset. This field annot be edited.",
)

def get_absolute_url(self):
return reverse("data_declaration", args=[str(self.pk)])

def copy(
self, source_data_declaration, excluded_fields=None, ignore_many_to_many=False
):
Expand Down
4 changes: 4 additions & 0 deletions core/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.module_loading import import_string
from guardian.models import GroupObjectPermissionBase, UserObjectPermissionBase
Expand Down Expand Up @@ -219,6 +220,9 @@ class AppMeta:
def __str__(self):
return self.acronym or self.title or "undefined"

def get_absolute_url(self):
return reverse("project", args=[str(self.pk)])

@property
def is_published(self):
return any(dataset.is_published for dataset in self.datasets.all())
Expand Down
3 changes: 3 additions & 0 deletions core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def is_part_of(self, *args):
def can_publish(self):
return self.is_superuser or self.is_part_of(constants.Groups.DATA_STEWARD.value)

def can_edit_metadata(self):
return self.is_part_of(constants.Groups.DATA_STEWARD.value)

# Permission management
# ======================================================================

Expand Down
84 changes: 84 additions & 0 deletions data/demo/elu-core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"$id": "https://raw.githubusercontent.com/elixir-luxembourg/json-schemas/v0.0.5/schemas/elu-core.json",
"title": "ELIXIR Luxembourg Core json schema",
"description": "Schema containing core attributes for any json serialisable ELIXIR Luxembourg record.",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"source",
"name"
],
"properties": {
"source": {
"type": "string",
"format": "uri"
},
"acronym": {
"type": ["string", "null"]
},
"name": {
"type": "string"
},
"description": {
"type": ["string", "null"]
},
"external_id": {
"type": ["string", "null"]
},
"elu_uuid": {
"type": ["string", "null"]
},
"other_external_id": {
"type": ["string", "null"]
},
"url": {
"type": ["string", "null"]
},
"contacts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"role": {
"type": "string",
"enum": [
"Principal_Investigator",
"Researcher",
"Data_Manager",
"Data_Protection_Officer",
"Legal_Representative",
"Other"
]
},
"email": {
"type": "string",
"format": "email"
},
"affiliations": {
"description": "Names of the affiliated institutions.",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": ["string", "null"]
}
}
},
"required": [
"first_name",
"last_name",
"role",
"email",
"affiliations"
]
}
}
}
}

26 changes: 26 additions & 0 deletions data/demo/partners.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"items": [
{
"name": "Centre Hospitalier de Togo",
"external_id": "ELU_I_19309",
"acronym": "CHT",
"is_clinical": true,
"geo_category": "National",
"sector_category": "PUBLIC",
"address": "Ave De La 6, Espoir Vie Togo, Lome",
"country_code": "TO",
"source": "example.com"
},
{
"name": "Hospitalier de Madagascar",
"external_id": "ELU_I_1939",
"acronym": "HMDGSK",
"is_clinical": true,
"geo_category": "National",
"sector_category": "PUBLIC",
"address": "Ave De La 6, Espoir Vie Togo, Antananarivo",
"country_code": "MG",
"source": "example.com"
}
]
}
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
# database
db:
image: postgres:10.1
restart: always
restart: on-failure
environment:
POSTGRES_PASSWORD: daisy
POSTGRES_USER: daisy
Expand All @@ -32,7 +32,7 @@ services:
# web werver frontend
nginx:
build: ./docker/nginx
restart: always
restart: on-failure
volumes:
- statics:/public/static:ro
ports:
Expand All @@ -50,7 +50,7 @@ services:
# rabbit mq
mq:
image: rabbitmq:3.9-management-alpine
restart: "always"
restart: on-failure
ports:
- "15672:15672"
- "5672:5672"
Expand Down
1 change: 1 addition & 0 deletions elixir_daisy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"django.contrib.messages.context_processors.messages",
"web.views.context_processors.daisy_version",
"web.views.context_processors.instance_branding",
"notification.views.context_processors.daisy_notifications_enabled",
],
},
},
Expand Down
12 changes: 11 additions & 1 deletion elixir_daisy/settings_local.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
COMPANY = "LCSB" # Used for generating some models' verbose names

HELPDESK_EMAIL = "lcsb-sysadmins@uni.lu"
ADMIN_NOTIFICATIONS_EMAIL = "" # used when there are notifications errors

# Placeholders on login page
# LOGIN_USERNAME_PLACEHOLDER = ''
Expand Down Expand Up @@ -79,6 +80,11 @@
# KEYCLOAK_USER = 'your service user for daisy'
# KEYCLOAK_PASS = 'the password for the service user'

# Email related setting
EMAIL_HOST = ""
EMAIL_PORT = 25
EMAIL_SENDER = ""

# Celery beat setting to schedule tasks on docker creation
CELERY_BEAT_SCHEDULE = {
"clean-accesses-every-day": {
Expand All @@ -87,6 +93,10 @@
},
"create-notifications-every-day": {
"task": "notification.tasks.create_notifications_for_entities",
"schedule": crontab(minute=15, hour=0),
"schedule": crontab(minute=15, hour=0)
},
"notifications-email-every-day": {
"task": "notification.tasks.send_notifications_for_user_upcoming_events",
"schedule": crontab(minute=0, hour=7), # Execute task in the morning
},
}
2 changes: 2 additions & 0 deletions elixir_daisy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from core.forms.user import UserAuthForm
from web.urls import web_urls
from notification.urls import notif_urls

urlpatterns = [
url(
Expand All @@ -31,6 +32,7 @@
),
url(r"^logout/$", auth_views.LogoutView.as_view(), name="logout"),
url(r"^admin/", admin.site.urls),
url(r"^notifications/", include(notif_urls)),
url(r"", include(web_urls)),
]

Expand Down
Loading

0 comments on commit 2bde86d

Please sign in to comment.