From 998b9abcd58beca8867ff0dcd2e5ac43ed504807 Mon Sep 17 00:00:00 2001
From: Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>
Date: Tue, 23 Nov 2021 09:45:49 +0100
Subject: [PATCH] Repair missing relationship in JSONAPI schema of `messages'.

Additionally remove all unneccessary `$isPrimary` and `$includeList` variables that were added in #80.

Closes #434.
---
 lib/classes/JsonApi/Schemas/BlubberStatusgruppeThread.php | 3 ---
 lib/classes/JsonApi/Schemas/CalendarEvent.php             | 3 ---
 lib/classes/JsonApi/Schemas/Course.php                    | 2 --
 lib/classes/JsonApi/Schemas/CourseEvent.php               | 3 ---
 lib/classes/JsonApi/Schemas/CourseMember.php              | 1 -
 lib/classes/JsonApi/Schemas/Courseware/Block.php          | 3 ---
 lib/classes/JsonApi/Schemas/Courseware/BlockComment.php   | 3 ---
 lib/classes/JsonApi/Schemas/Courseware/BlockFeedback.php  | 3 ---
 lib/classes/JsonApi/Schemas/Courseware/Instance.php       | 3 ---
 lib/classes/JsonApi/Schemas/Courseware/UserDataField.php  | 3 ---
 lib/classes/JsonApi/Schemas/Courseware/UserProgress.php   | 3 ---
 lib/classes/JsonApi/Schemas/File.php                      | 1 -
 lib/classes/JsonApi/Schemas/FileRef.php                   | 3 ---
 lib/classes/JsonApi/Schemas/Folder.php                    | 1 -
 lib/classes/JsonApi/Schemas/InstituteMember.php           | 3 ---
 lib/classes/JsonApi/Schemas/LibraryFile.php               | 3 ---
 lib/classes/JsonApi/Schemas/Message.php                   | 1 +
 lib/classes/JsonApi/Schemas/ScheduleEntry.php             | 3 ---
 lib/classes/JsonApi/Schemas/SemType.php                   | 3 ---
 lib/classes/JsonApi/Schemas/SeminarCycleDate.php          | 3 ---
 lib/classes/JsonApi/Schemas/StudipComment.php             | 1 -
 lib/classes/JsonApi/Schemas/StudipNews.php                | 1 -
 22 files changed, 1 insertion(+), 52 deletions(-)

diff --git a/lib/classes/JsonApi/Schemas/BlubberStatusgruppeThread.php b/lib/classes/JsonApi/Schemas/BlubberStatusgruppeThread.php
index 484cb6929c9..76651e4af7e 100644
--- a/lib/classes/JsonApi/Schemas/BlubberStatusgruppeThread.php
+++ b/lib/classes/JsonApi/Schemas/BlubberStatusgruppeThread.php
@@ -17,9 +17,6 @@ class BlubberStatusgruppeThread extends BlubberThread
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = parent::getRelationships($resource, $context);
 
         $relationships[self::REL_STATUSGRUPPE] = [
diff --git a/lib/classes/JsonApi/Schemas/CalendarEvent.php b/lib/classes/JsonApi/Schemas/CalendarEvent.php
index 3ee6ab5f34b..7b348d5478d 100644
--- a/lib/classes/JsonApi/Schemas/CalendarEvent.php
+++ b/lib/classes/JsonApi/Schemas/CalendarEvent.php
@@ -37,9 +37,6 @@ class CalendarEvent extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         if ($owner = $resource->getOwner()) {
diff --git a/lib/classes/JsonApi/Schemas/Course.php b/lib/classes/JsonApi/Schemas/Course.php
index 98c890916f4..42fcfd2fd00 100644
--- a/lib/classes/JsonApi/Schemas/Course.php
+++ b/lib/classes/JsonApi/Schemas/Course.php
@@ -55,10 +55,8 @@ class Course extends SchemaProvider
 
     public function getRelationships($course, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
         $includeList = $context->getIncludePaths();
 
-
         $relationships = [];
 
         $relationships[self::REL_INSTITUTE] = $this->getInstitute($course, in_array(self::REL_INSTITUTE, $includeList));
diff --git a/lib/classes/JsonApi/Schemas/CourseEvent.php b/lib/classes/JsonApi/Schemas/CourseEvent.php
index d2ec52dd6b6..77f1d3157f4 100644
--- a/lib/classes/JsonApi/Schemas/CourseEvent.php
+++ b/lib/classes/JsonApi/Schemas/CourseEvent.php
@@ -36,9 +36,6 @@ class CourseEvent extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         if ($owner = $resource->course) {
diff --git a/lib/classes/JsonApi/Schemas/CourseMember.php b/lib/classes/JsonApi/Schemas/CourseMember.php
index 1997e8b7d02..e68264072c8 100644
--- a/lib/classes/JsonApi/Schemas/CourseMember.php
+++ b/lib/classes/JsonApi/Schemas/CourseMember.php
@@ -45,7 +45,6 @@ class CourseMember extends SchemaProvider
     public function getRelationships($membership, ContextInterface $context): iterable
     {
         $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
 
         $relationships = [];
 
diff --git a/lib/classes/JsonApi/Schemas/Courseware/Block.php b/lib/classes/JsonApi/Schemas/Courseware/Block.php
index ba3e21fea69..63fd96e47c6 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/Block.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/Block.php
@@ -51,9 +51,6 @@ class Block extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships[self::REL_COMMENTS] = [
diff --git a/lib/classes/JsonApi/Schemas/Courseware/BlockComment.php b/lib/classes/JsonApi/Schemas/Courseware/BlockComment.php
index c2abd5bf1b7..aac1bd042fd 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/BlockComment.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/BlockComment.php
@@ -38,9 +38,6 @@ class BlockComment extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships[self::REL_BLOCK] = [
diff --git a/lib/classes/JsonApi/Schemas/Courseware/BlockFeedback.php b/lib/classes/JsonApi/Schemas/Courseware/BlockFeedback.php
index b5992b7c2e0..7152c8a13e7 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/BlockFeedback.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/BlockFeedback.php
@@ -38,9 +38,6 @@ class BlockFeedback extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships[self::REL_BLOCK] = [
diff --git a/lib/classes/JsonApi/Schemas/Courseware/Instance.php b/lib/classes/JsonApi/Schemas/Courseware/Instance.php
index 2fba0e3995b..055c387defd 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/Instance.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/Instance.php
@@ -71,9 +71,6 @@ class Instance extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $user = $this->currentUser;
diff --git a/lib/classes/JsonApi/Schemas/Courseware/UserDataField.php b/lib/classes/JsonApi/Schemas/Courseware/UserDataField.php
index 810e870ce2c..d00f64d8833 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/UserDataField.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/UserDataField.php
@@ -38,9 +38,6 @@ class UserDataField extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships[self::REL_BLOCK] = [
diff --git a/lib/classes/JsonApi/Schemas/Courseware/UserProgress.php b/lib/classes/JsonApi/Schemas/Courseware/UserProgress.php
index 5d6e68a5bfe..f5493a869ed 100755
--- a/lib/classes/JsonApi/Schemas/Courseware/UserProgress.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/UserProgress.php
@@ -38,9 +38,6 @@ class UserProgress extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships[self::REL_BLOCK] = [
diff --git a/lib/classes/JsonApi/Schemas/File.php b/lib/classes/JsonApi/Schemas/File.php
index 8293b5fc1cd..8eb80469da2 100644
--- a/lib/classes/JsonApi/Schemas/File.php
+++ b/lib/classes/JsonApi/Schemas/File.php
@@ -44,7 +44,6 @@ class File extends SchemaProvider
     public function getRelationships($resource, ContextInterface $context): iterable
     {
         $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
 
         $relationships = [];
 
diff --git a/lib/classes/JsonApi/Schemas/FileRef.php b/lib/classes/JsonApi/Schemas/FileRef.php
index 5da46f6d475..d979537ed88 100644
--- a/lib/classes/JsonApi/Schemas/FileRef.php
+++ b/lib/classes/JsonApi/Schemas/FileRef.php
@@ -75,9 +75,6 @@ class FileRef extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships = $this->getFeedbackRelationship($relationships, $resource);
diff --git a/lib/classes/JsonApi/Schemas/Folder.php b/lib/classes/JsonApi/Schemas/Folder.php
index f2c5608ec4c..1cd5ba55a5f 100644
--- a/lib/classes/JsonApi/Schemas/Folder.php
+++ b/lib/classes/JsonApi/Schemas/Folder.php
@@ -53,7 +53,6 @@ class Folder extends SchemaProvider
     public function getRelationships($resource, ContextInterface $context): iterable
     {
         $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
 
         $relationships = [];
 
diff --git a/lib/classes/JsonApi/Schemas/InstituteMember.php b/lib/classes/JsonApi/Schemas/InstituteMember.php
index dbfe9170c6c..6777a2344c4 100644
--- a/lib/classes/JsonApi/Schemas/InstituteMember.php
+++ b/lib/classes/JsonApi/Schemas/InstituteMember.php
@@ -43,9 +43,6 @@ class InstituteMember extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [
             self::REL_USER => [
                 self::RELATIONSHIP_LINKS => [
diff --git a/lib/classes/JsonApi/Schemas/LibraryFile.php b/lib/classes/JsonApi/Schemas/LibraryFile.php
index 9073acb91ef..febcc100f62 100644
--- a/lib/classes/JsonApi/Schemas/LibraryFile.php
+++ b/lib/classes/JsonApi/Schemas/LibraryFile.php
@@ -76,9 +76,6 @@ class LibraryFile extends SchemaProvider
      */
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         $relationships = $this->getFeedbackRelationship($relationships, $resource);
diff --git a/lib/classes/JsonApi/Schemas/Message.php b/lib/classes/JsonApi/Schemas/Message.php
index 801c59ed18f..eeefe25094d 100644
--- a/lib/classes/JsonApi/Schemas/Message.php
+++ b/lib/classes/JsonApi/Schemas/Message.php
@@ -34,6 +34,7 @@ class Message extends SchemaProvider
     {
         $relationships = [];
 
+        $isPrimary = $context->getPosition()->getLevel() === 0;
         if ($isPrimary) {
             $relationships = $this->getSenderRelationship($relationships, $message, $this->shouldInclude($context, self::REL_SENDER));
             $relationships = $this->getRecipientsRelationship($relationships, $message, $this->shouldInclude($context, self::REL_RECIPIENTS));
diff --git a/lib/classes/JsonApi/Schemas/ScheduleEntry.php b/lib/classes/JsonApi/Schemas/ScheduleEntry.php
index e737e614770..3318f358b64 100644
--- a/lib/classes/JsonApi/Schemas/ScheduleEntry.php
+++ b/lib/classes/JsonApi/Schemas/ScheduleEntry.php
@@ -36,9 +36,6 @@ class ScheduleEntry extends SchemaProvider
      */
     public function getRelationships($entry, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $link = $this->createLinkToResource($entry->user);
 
         $relationships = [
diff --git a/lib/classes/JsonApi/Schemas/SemType.php b/lib/classes/JsonApi/Schemas/SemType.php
index eb44e93f29a..46b2e3ca84a 100644
--- a/lib/classes/JsonApi/Schemas/SemType.php
+++ b/lib/classes/JsonApi/Schemas/SemType.php
@@ -28,9 +28,6 @@ class SemType extends SchemaProvider
 
     public function getRelationships($resource, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         // SemClass
diff --git a/lib/classes/JsonApi/Schemas/SeminarCycleDate.php b/lib/classes/JsonApi/Schemas/SeminarCycleDate.php
index 531b58bfcb4..355e85682b9 100644
--- a/lib/classes/JsonApi/Schemas/SeminarCycleDate.php
+++ b/lib/classes/JsonApi/Schemas/SeminarCycleDate.php
@@ -40,9 +40,6 @@ class SeminarCycleDate extends SchemaProvider
      */
     public function getRelationships($entry, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
-
         $relationships = [];
 
         if ($course = \Course::find($entry->seminar_id)) {
diff --git a/lib/classes/JsonApi/Schemas/StudipComment.php b/lib/classes/JsonApi/Schemas/StudipComment.php
index 7ba2a2d0ba7..0232c15024a 100644
--- a/lib/classes/JsonApi/Schemas/StudipComment.php
+++ b/lib/classes/JsonApi/Schemas/StudipComment.php
@@ -28,7 +28,6 @@ class StudipComment extends SchemaProvider
     public function getRelationships($comment, ContextInterface $context): iterable
     {
         $isPrimary = $context->getPosition()->getLevel() === 0;
-        $includeList = $context->getIncludePaths();
 
         $relationships = [];
 
diff --git a/lib/classes/JsonApi/Schemas/StudipNews.php b/lib/classes/JsonApi/Schemas/StudipNews.php
index 98b2dc50f7d..1bf766aee4e 100644
--- a/lib/classes/JsonApi/Schemas/StudipNews.php
+++ b/lib/classes/JsonApi/Schemas/StudipNews.php
@@ -56,7 +56,6 @@ class StudipNews extends SchemaProvider
      */
     public function getRelationships($news, ContextInterface $context): iterable
     {
-        $isPrimary = $context->getPosition()->getLevel() === 0;
         $includeList = $context->getIncludePaths();
 
         $relationships = [];
-- 
GitLab