From 1383328e5dd8225d5acda2da4190357805e841b4 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <hackl@data-quest.de>
Date: Fri, 19 Jan 2024 08:30:20 +0000
Subject: [PATCH] =?UTF-8?q?Resolve=20"Courseware:=20Abruf=20des=20Zertifik?=
 =?UTF-8?q?ats,=20obwohl=20das=20f=C3=BCr=20die=20Unit=20gar=20nicht=20akt?=
 =?UTF-8?q?iviert=20ist"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3548

Merge request studip/studip!2524
---
 lib/classes/JsonApi/Schemas/Courseware/Unit.php   |  1 +
 .../courseware/unit/CoursewareUnitItem.vue        | 15 ++++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/classes/JsonApi/Schemas/Courseware/Unit.php b/lib/classes/JsonApi/Schemas/Courseware/Unit.php
index 901f2f0d882..6152e940e61 100644
--- a/lib/classes/JsonApi/Schemas/Courseware/Unit.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/Unit.php
@@ -34,6 +34,7 @@ class Unit extends SchemaProvider
             'public' => (int) $resource['public'],
             'release-date' => $resource['release_date'] ? date('c', $resource['release_date']) : null,
             'withdraw-date' => $resource['withdraw_date'] ? date('c', $resource['withdraw_date']) : null,
+            'config' => json_decode($resource['config']),
             'mkdate'    => date('c', $resource['mkdate']),
             'chdate'    => date('c', $resource['chdate']),
         ];
diff --git a/resources/vue/components/courseware/unit/CoursewareUnitItem.vue b/resources/vue/components/courseware/unit/CoursewareUnitItem.vue
index b1e82bfecc0..f09601e94d7 100644
--- a/resources/vue/components/courseware/unit/CoursewareUnitItem.vue
+++ b/resources/vue/components/courseware/unit/CoursewareUnitItem.vue
@@ -286,13 +286,14 @@ export default {
             createFeedback: 'feedback-elements/create',
             loadFeedbackElement: 'feedback-elements/loadById',
         }),
-        async checkCertificate() {
-            if (this.getStudipConfig('COURSEWARE_CERTIFICATES_ENABLE')) {
-                const response = await axios.get(STUDIP.URLHelper.getURL('jsonapi.php/v1/courseware-units/' +
-                    this.unit.id + '/certificate/' + STUDIP.USER_ID));
-                if (response.status === 200) {
-                    this.certificate = response.data;
-                }
+        checkCertificate() {
+            if (this.getStudipConfig('COURSEWARE_CERTIFICATES_ENABLE') && this.unit.attributes.config.certificate) {
+                axios.get(STUDIP.URLHelper.getURL('jsonapi.php/v1/courseware-units/' +
+                    this.unit.id + '/certificate/' + STUDIP.USER_ID))
+                    .then(response => {
+                        this.certificate = response.data;
+                    })
+                    .catch(error => {});
             }
         },
         executeDelete() {
-- 
GitLab