From 1ab7861f7c49cc2f08461be5fef1cbada260b364 Mon Sep 17 00:00:00 2001
From: Peter Weber <Peter.Weber@rero.ch>
Date: Wed, 22 Dec 2021 11:51:26 +0100
Subject: [PATCH] schema: distinguish supervisor co-supervisors

* Distinguish between thesis supervisor and co-supervisors
* Adds dgc "Degree committee member" for field contribution.role in document and deposit.
* Closes #733

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
---
 .../deposits/deposit-v1.0.0_src.json          | 11 +++++--
 .../documents/document-v1.0.0_src.json        | 32 +++++++++++--------
 sonar/modules/documents/views.py              |  2 +-
 tests/ui/documents/test_documents_views.py    |  4 ++-
 4 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json b/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json
index 0ce80e23..9c97382d 100644
--- a/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json
+++ b/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json
@@ -1113,11 +1113,12 @@
             "type": "string",
             "default": "cre",
             "enum": [
-              "dgs",
-              "prt",
               "cre",
+              "ctb",
               "edt",
-              "ctb"
+              "dgc",
+              "dgs",
+              "prt"
             ],
             "form": {
               "templateOptions": {
@@ -1138,6 +1139,10 @@
                   "label": "contribution_role_edt",
                   "value": "edt"
                 },
+                {
+                  "label": "contribution_role_dgc",
+                  "value": "dgc"
+                },
                 {
                   "label": "contribution_role_dgs",
                   "value": "dgs"
diff --git a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
index fde12631..c1d23cbd 100644
--- a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
+++ b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
@@ -1354,6 +1354,7 @@
                         "allowAdd": true
                       }
                     }
+
                   }
                 },
                 "propertiesOrder": [
@@ -1978,34 +1979,39 @@
         "title": "Role",
         "type": "string",
         "enum": [
-          "dgs",
-          "prt",
           "cre",
+          "ctb",
           "edt",
-          "ctb"
+          "dgc",
+          "dgs",
+          "prt"
         ],
         "default": "cre",
         "form": {
           "options": [
-            {
-              "label": "contribution_role_dgs",
-              "value": "dgs"
-            },
-            {
-              "label": "contribution_role_prt",
-              "value": "prt"
-            },
             {
               "label": "contribution_role_cre",
               "value": "cre"
             },
+            {
+              "label": "contribution_role_ctb",
+              "value": "ctb"
+            },
             {
               "label": "contribution_role_edt",
               "value": "edt"
             },
             {
-              "label": "contribution_role_ctb",
-              "value": "ctb"
+              "label": "contribution_role_dgc",
+              "value": "dgc"
+            },
+            {
+              "label": "contribution_role_dgs",
+              "value": "dgs"
+            },
+            {
+              "label": "contribution_role_prt",
+              "value": "prt"
             }
           ]
         }
diff --git a/sonar/modules/documents/views.py b/sonar/modules/documents/views.py
index a6b6e5bb..66cd5690 100644
--- a/sonar/modules/documents/views.py
+++ b/sonar/modules/documents/views.py
@@ -194,7 +194,7 @@ def contributors(record):
     if not record.get('contribution'):
         return []
 
-    priorities = ['cre', 'ctb', 'dgs', 'edt', 'prt']
+    priorities = ['cre', 'ctb', 'dgs', 'dgc', 'edt', 'prt']
 
     return sorted(record['contribution'],
                   key=lambda i: priorities.index(i['role'][0]))
diff --git a/tests/ui/documents/test_documents_views.py b/tests/ui/documents/test_documents_views.py
index 40f1c47e..be5d194b 100644
--- a/tests/ui/documents/test_documents_views.py
+++ b/tests/ui/documents/test_documents_views.py
@@ -236,6 +236,8 @@ def test_contributors():
     """Test ordering contributors."""
     contributors = [{
         'role': ['dgs']
+    }, {
+        'role': ['dgc']
     }, {
         'role': ['ctb']
     }, {
@@ -246,7 +248,7 @@ def test_contributors():
         'role': ['cre']
     }]
 
-    priorities = ['cre', 'ctb', 'dgs', 'edt', 'prt']
+    priorities = ['cre', 'ctb', 'dgs', 'dgc', 'edt', 'prt']
 
     for index, contributor in enumerate(
             views.contributors({'contribution': contributors})):