From e88665b1b341b13d4ea3d880bda93f44026fe510 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Fri, 27 Jan 2023 18:29:18 +0100
Subject: move inheritance of permissions to JSON-API controller, fixes #2094

---
 lib/classes/JsonApi/Routes/Courseware/StructuralElementsCreate.php  | 4 ++--
 resources/vue/components/courseware/CoursewareStructuralElement.vue | 6 ------
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/lib/classes/JsonApi/Routes/Courseware/StructuralElementsCreate.php b/lib/classes/JsonApi/Routes/Courseware/StructuralElementsCreate.php
index 47ada63..4c9525b 100644
--- a/lib/classes/JsonApi/Routes/Courseware/StructuralElementsCreate.php
+++ b/lib/classes/JsonApi/Routes/Courseware/StructuralElementsCreate.php
@@ -81,8 +81,8 @@ class StructuralElementsCreate extends JsonApiController
             'title' => self::arrayGet($json, 'data.attributes.title', ''),
             'purpose' => self::arrayGet($json, 'data.attributes.purpose', $parent->purpose),
             'payload' => self::arrayGet($json, 'data.attributes.payload', ''),
-            'read_approval' => self::arrayGet($json, 'data.attributes.read-approval', []),
-            'write_approval' => self::arrayGet($json, 'data.attributes.write-approval', []),
+            'read_approval' => self::arrayGet($json, 'data.attributes.read-approval', $parent->read_approval),
+            'write_approval' => self::arrayGet($json, 'data.attributes.write-approval', $parent->write_approval),
             'position' => $parent->countChildren()
         ]);
 
diff --git a/resources/vue/components/courseware/CoursewareStructuralElement.vue b/resources/vue/components/courseware/CoursewareStructuralElement.vue
index af5331b..5332226 100644
--- a/resources/vue/components/courseware/CoursewareStructuralElement.vue
+++ b/resources/vue/components/courseware/CoursewareStructuralElement.vue
@@ -1518,8 +1518,6 @@ export default {
             const title = this.newChapterName; // this is the title of the new element
             const purpose = this.newChapterPurpose;
             let parent_id = this.currentId; // new page is descandant as default
-            let writeApproval = this.currentElement.attributes['write-approval'];
-            let readApproval = this.currentElement.attributes['read-approval'];
 
             this.errorEmptyChapterName = title.trim();
             if (this.errorEmptyChapterName === '') {
@@ -1527,16 +1525,12 @@ export default {
             }
             if (this.newChapterParent === 'sibling') {
                 parent_id = this.structuralElement.relationships.parent.data.id;
-                writeApproval = [];
-                readApproval = [];
             }
             this.showElementAddDialog(false);
             this.createStructuralElement({
                 attributes: {
                     title: title,
                     purpose: purpose,
-                    'write-approval':  writeApproval,
-                    'read-approval': readApproval
                 },
                 templateId: this.newChapterTemplate ? this.newChapterTemplate.id : null,
                 parentId: parent_id,
-- 
cgit v1.0

