From fbc5b0542b69a59da01f4c57583a48f51eb16ab0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn=20K=C3=BCnsem=C3=B6ller?=
 <jkuensem@physik.uni-bielefeld.de>
Date: Wed, 26 May 2021 16:58:32 +0200
Subject: [PATCH] TMSS-776: add extra action permissions for operator to make
 test pass

---
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py | 20 +++++++++++++++++++
 .../test/t_permissions_system_roles.py        |  3 +++
 2 files changed, 23 insertions(+)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index 600ad8986c9..9952156c0c1 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -775,6 +775,26 @@ def assign_system_permissions():
 
         # Note: we only grant view permissions, since alteration is only permitted to users who are superuser anyway.
 
+    # extra actions
+
+    # TODO: Verify that these permissions are correctly assigned!
+    #  we could in principle generically assign permissions for GET/POST actions equivalent to view/change on the model
+    #  itself, but the PO said it's probably not that simple.
+    for subtask_perm in ['get_progress_subtask',
+                         'input_dataproducts_subtask',
+                         'output_dataproducts_subtask',
+                         'parset_subtask',
+                         'predecessors_subtask',
+                         'process_feedback_and_set_to_finished_if_complete_subtask',
+                         'reprocess_raw_feedback_for_subtask_and_set_to_finished_if_complete_subtask',
+                         'state_log_subtask',
+                         'successors_subtask',
+                         'task_log_subtask',
+                         'transformed_output_dataproduct_subtask',
+                         'schedule_subtask',
+                         'unschedule_subtask']:
+        operator_group.permissions.add(Permission.objects.get(codename=subtask_perm))
+
 
 def populate_system_test_users():
     # TODO: Set proper credentials (passwords at least) or remove before we hit production
diff --git a/SAS/TMSS/backend/test/t_permissions_system_roles.py b/SAS/TMSS/backend/test/t_permissions_system_roles.py
index d45efaa21a9..a6daa04805c 100755
--- a/SAS/TMSS/backend/test/t_permissions_system_roles.py
+++ b/SAS/TMSS/backend/test/t_permissions_system_roles.py
@@ -121,6 +121,9 @@ class SystemPermissionTestCase(unittest.TestCase):
         # Retrieve operator system role
         cls.operator_group = Group.objects.get(name='operator')
 
+    def setUp(self):
+        super().setUp()
+        logger.info("Now running '%s'. If this times out, the permission polling is probably not stopping because the permission in question is not correctly assigned to the assigned group." % self._testMethodName)
 
     def test_SubtaskViewSet_has_TMSSPermissions_in_permission_classes(self):
         # Assert SubtaskViewSet has the TMSSPermissions permission class.
-- 
GitLab