Skip to content

Commit

Permalink
projects: validation workflow
Browse files Browse the repository at this point in the history
* Adds a validation workflow to projects for HEP Valais.
* Adds a blueprint for validation email templates.
* Adds fixtures for HEP Valais organisation.
* Adds a JSON schema for storing validation data.
* Creates an extension to process validation when a record is saved.
* Adds a Marshmallow schema for validation data.
* Adds emails for all actions and languages.
* Adds a cached property in resource record to get the index name.
* Adds a method to get the string representation of a project object.
* Adjusts projects permissions depending on the status.
* Enables facet and filter for project validation status.
* Adds a mapping for validation data in Elasticsearch.
* Removes specific fields for projects in deposit process, to have a generic approach.
* Closes #457.

Co-Authored-by: Sébastien Délèze <sebastien.deleze@rero.ch>
  • Loading branch information
Sébastien Délèze committed Jun 8, 2021
1 parent ad20ccc commit 428f148
Show file tree
Hide file tree
Showing 45 changed files with 1,120 additions and 200 deletions.
Binary file added data/organisations/hepvs/hepvs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions data/users/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,35 @@
"organisation": {
"$ref": "https://sonar.ch/api/organisations/rero"
}
},
{
"first_name": "Michèle",
"last_name": "Guernon",
"email": "rero.sonar+hepvssubmitter@gmail.com",
"password": "$pbkdf2-sha512$25000$29ubk1KqFUJorTXmHAPAmA$ooj0RJyHyinmZw/.pNMXne8p70X/BDoX5Ypww24OIguSWEo3y.KT6hiwxwHS5OynZNkgnLvfR3m1mNVfsHgfgA",
"role": "submitter",
"birth_date": "1968-04-06",
"street": "Glennerstrasse 96",
"postal_code": "1202",
"city": "Genève",
"phone": "+41225022590",
"organisation": {
"$ref": "https://sonar.ch/api/organisations/hepvs"
}
},
{
"first_name": "Gabriel",
"last_name": "Fortin",
"email": "rero.sonar+hepvsmoderator@gmail.com",
"password": "$pbkdf2-sha512$25000$29ubk1KqFUJorTXmHAPAmA$ooj0RJyHyinmZw/.pNMXne8p70X/BDoX5Ypww24OIguSWEo3y.KT6hiwxwHS5OynZNkgnLvfR3m1mNVfsHgfgA",
"role": "moderator",
"birth_date": "1972-10-28",
"street": "Glennerstrasse 96",
"postal_code": "3004",
"city": "Bern",
"phone": "+41914105597",
"organisation": {
"$ref": "https://sonar.ch/api/organisations/hepvs"
}
}
]
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
'shibboleth_authenticator = \
sonar.modules.shibboleth_authenticator.views.client:blueprint',
'pdf_extractor = \
sonar.modules.pdf_extractor.views.client:blueprint'
sonar.modules.pdf_extractor.views.client:blueprint',
'validation = sonar.modules.validation.views:blueprint'
],
'invenio_base.api_blueprints': [
'pdf_extractor = sonar.modules.pdf_extractor.views.api:blueprint',
Expand All @@ -86,6 +87,7 @@
'monitoring = sonar.monitoring.views:blueprint',
'translations = sonar.translations.rest:blueprint',
'suggestions = sonar.suggestions.rest:blueprint',
'validation = sonar.modules.validation.views:blueprint'
],
'invenio_assets.webpack': [
'sonar_theme = sonar.theme.webpack:theme'
Expand Down
112 changes: 112 additions & 0 deletions sonar/common/jsonschemas/validation-v1.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"title": "Validation",
"description": "Schema representing a validation workflow.",
"type": "object",
"additionalProperties": false,
"properties": {
"status": {
"$ref": "#/definitions/status"
},
"action": {
"$ref": "#/definitions/action"
},
"user": {
"$ref": "#/definitions/user"
},
"comment": {
"$ref": "#/definitions/comment"
},
"logs": {
"title": "Logs",
"description": "List of logs.",
"type": "array",
"minItems": 1,
"items": {
"title": "Log",
"type": "object",
"additionalProperties": false,
"properties": {
"status": {
"$ref": "#/definitions/status"
},
"action": {
"$ref": "#/definitions/action"
},
"user": {
"$ref": "#/definitions/user"
},
"comment": {
"$ref": "#/definitions/comment"
},
"date": {
"title": "Date",
"description": "Date when the log is created.",
"type": "string",
"minLength": 1
}
},
"required": [
"status",
"action",
"user",
"date"
]
}
}
},
"required": [
"status",
"action",
"user"
],
"definitions": {
"status": {
"title": "Status",
"description": "Current status of the record in the validation process.",
"type": "string",
"default": "in_progress",
"enum": [
"in_progress",
"to_validate",
"validated",
"rejected",
"ask_for_changes"
]
},
"action": {
"title": "Action",
"description": "Current action done in the validation process.",
"type": "string",
"default": "save",
"enum": [
"save",
"publish",
"approve",
"reject",
"ask_for_changes"
]
},
"user": {
"title": "User",
"description": "User which created the record.",
"type": "object",
"additionalProperties": false,
"properties": {
"$ref": {
"title": "User",
"type": "string",
"pattern": "^https://sonar.ch/api/users/.*?$"
}
},
"required": [
"$ref"
]
},
"comment": {
"title": "Comment",
"description": "Comment associated with the current action.",
"type": "string",
"minLength": 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,9 @@
"rows": 5
}
}
},
"validation": {
"$ref": "validation-v1.0.0.json"
}
},
"propertiesOrder": [
Expand Down
19 changes: 16 additions & 3 deletions sonar/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ def language_value(values,
return get_language_value(values, locale, value_field,
language_field)

@app.template_filter()
def get_admin_record_detail_url(record):
r"""Return the frontend application URL for a record detail.
:param record: Record object.
:returns: Absolute URL to recrod detail.
:rtype: str
"""
url = [
app.config.get('SONAR_APP_ANGULAR_URL')[:-1], 'records',
record.index_name, 'detail', record.pid.pid_value
]
return '/'.join(url)

def create_resources(self):
"""Create resources."""
# Initialize the project resource with the corresponding service.
Expand Down Expand Up @@ -188,6 +202,5 @@ def set_accept_mimetype():
in flask_resources: https://github.com/inveniosoftware/flask-resources/blob/master/flask_resources/content_negotiation.py#L105
"""
if request.args.get('format'):
request.accept_mimetypes = MIMEAccept([
(request.args['format'], 1)
])
request.accept_mimetypes = MIMEAccept([(request.args['format'],
1)])
54 changes: 0 additions & 54 deletions sonar/modules/deposits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,60 +325,6 @@ def create_document(self):
# Store organisation
data['organisation'] = current_user_record['organisation']

# Project identifier
if project.get('identifier'):
data['identifiedBy'] = {
'type': 'bf:Identifier',
'value': project['identifier']
}
data.pop('identifier')

# Investigators
if project.get('investigators'):
data['investigators'] = []
for investigator in project['investigators']:
investigator_data = {
'agent': {
'preferred_name': investigator['name']
},
'role': [investigator['role']],
}

if investigator.get('affiliation'):
investigator_data[
'affiliation'] = investigator.get(
'affiliation')

if investigator.get('orcid'):
investigator_data['identifiedBy'] = {
'type': 'bf:Local',
'source': 'ORCID',
'value': investigator.get('orcid')
}

data['investigators'].append(investigator_data)

# Funding organisations
if project.get('funding_organisations'):
data['funding_organisations'] = []
for funding_organisation in project[
'funding_organisations']:
funding_organisation_data = {
'agent': {
'preferred_name':
funding_organisation['name']
}
}

if funding_organisation.get('identifier'):
funding_organisation_data['identifiedBy'] = {
'type': 'bf:Identifier',
'value': funding_organisation['identifier']
}

data['funding_organisations'].append(
funding_organisation_data)

project_record = sonar.service('projects').create(
g.identity, {'metadata': data})
project = {
Expand Down
119 changes: 1 addition & 118 deletions sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json
Original file line number Diff line number Diff line change
Expand Up @@ -961,130 +961,13 @@
"type": "string",
"format": "date",
"pattern": "^[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$"
},
"identifier": {
"title": "Identifier",
"type": "string",
"minLength": 1
},
"investigators": {
"title": "Investigators",
"type": "array",
"items": {
"title": "Investigator",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"title": "Name",
"type": "string",
"minLength": 1
},
"role": {
"title": "Role",
"type": "string",
"enum": [
"investigator",
"coinvestigator"
],
"form": {
"templateOptions": {
"wrappers": [
"card"
]
},
"options": [
{
"label": "investigator",
"value": "investigator"
},
{
"label": "coinvestigator",
"value": "coinvestigator"
}
]
}
},
"affiliation": {
"title": "Affiliation",
"type": "string",
"minLength": 1
},
"orcid": {
"title": "ORCID",
"type": "string",
"minLength": 1,
"pattern": "^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$",
"form": {
"templateOptions": {
"placeholder": "Example: 1111-2222-3333-4444"
}
}
}
},
"propertiesOrder": [
"name",
"role",
"affiliation",
"orcid"
],
"required": [
"name",
"role"
]
},
"form": {
"templateOptions": {
"wrappers": [
"card"
]
}
}
},
"funding_organisations": {
"title": "Funding organisations",
"type": "array",
"items": {
"title": "Funding organisation",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"title": "Name",
"type": "string",
"minLength": 1
},
"identifier": {
"title": "Identifier",
"type": "string",
"minLength": 1
}
},
"propertiesOrder": [
"name",
"identifier"
],
"required": [
"name"
]
},
"form": {
"templateOptions": {
"wrappers": [
"card"
]
}
}
}
},
"propertiesOrder": [
"name",
"description",
"startDate",
"endDate",
"identifier",
"investigators",
"funding_organisations"
"endDate"
],
"required": [
"name",
Expand Down
Loading

0 comments on commit 428f148

Please sign in to comment.