From 64eea6377fdf7a9e89a3acabaafc58c6e1e14877 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Fri, 14 Apr 2023 14:43:13 +0000 Subject: [PATCH] Resolve "Materialien von anderen Servern nicht zugreifbar" Closes #2542 Merge request studip/studip!1718 --- app/controllers/oer/endpoints.php | 13 ++++++++++--- app/controllers/oer/market.php | 6 +++--- app/views/oer/market/profile.php | 6 +++--- app/views/oer/mymaterial/_material_list.php | 6 +++--- lib/models/ExternalUser.php | 5 +++++ lib/models/OERHost.php | 6 +++--- lib/models/OERMaterial.php | 6 ++++-- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/controllers/oer/endpoints.php b/app/controllers/oer/endpoints.php index 448565dac2e..30c97160f57 100644 --- a/app/controllers/oer/endpoints.php +++ b/app/controllers/oer/endpoints.php @@ -223,11 +223,14 @@ class Oer_EndpointsController extends StudipController 'avatar' => $userdata['external_contact'] ? $user->avatar_url : Avatar::getAvatar($userdata['user_id'])->getURL(Avatar::NORMAL), + 'description' => $userdata['external_contact'] + ? $user['data']['description'] + : $user->datafields, 'host_url' => $material->host ? $material->host['url'] : $me['url'] ]; } $this->render_json([ - 'data' => [ + 'data' => [ 'name' => $material['name'], 'short_description' => $material['short_description'], 'description' => $material['description'], @@ -407,7 +410,9 @@ class Oer_EndpointsController extends StudipController $user['contact_type'] = 'oercampus'; $user['name'] = $data['user']['name']; $user['avatar_url'] = $data['user']['avatar']; - $user['data']['description'] = $data['user']['description'] ?: ""; + $user['data'] = [ + 'description' => $data['user']['description'] ?: '' + ]; $user->store(); $review = OERReview::findOneBySQL("display_class = 'OERReview' @@ -488,7 +493,9 @@ class Oer_EndpointsController extends StudipController $user['contact_type'] = 'oercampus'; $user['name'] = $data['user']['name']; $user['avatar_url'] = $data['user']['avatar']; - $user['data']['description'] = $data['user']['description'] ?: ""; + $user['data'] = [ + 'description' => $data['user']['description'] ?: '' + ]; $user->store(); $comment = new BlubberComment(); diff --git a/app/controllers/oer/market.php b/app/controllers/oer/market.php index fadc7b60aa5..9e15406bd57 100644 --- a/app/controllers/oer/market.php +++ b/app/controllers/oer/market.php @@ -453,9 +453,9 @@ class Oer_MarketController extends StudipController if ($this->user->isNew()) { throw new Exception(_("Nutzer ist nicht erfasst.")); } - $this->materials = OERMaterial::findBySQL("user_id = ? - AND host_id IS NOT NULL - ORDER BY mkdate DESC", [ + $this->materials = OERMaterial::findBySQL("LEFT JOIN oer_material_users ON (oer_material_users.material_id = oer_material.material_id AND external_contact = 1) + WHERE oer_material_users.user_id = ? + ORDER BY oer_material.mkdate DESC", [ $external_user_id ]); } diff --git a/app/views/oer/market/profile.php b/app/views/oer/market/profile.php index cce1342d0d5..5c904128fea 100644 --- a/app/views/oer/market/profile.php +++ b/app/views/oer/market/profile.php @@ -1,11 +1,11 @@ <div style="display: flex; width: 100%; margin-bottom: 20px;"> <div> - <img class="avatar-normal" src="<?= htmlReady($user['avatar']) ?>"> + <img class="avatar-normal" src="<?= htmlReady($user['avatar_url']) ?>"> </div> <div style="width: 100%; padding-left: 10px;"> <h1><?= htmlReady($user['name']) ?></h1> <div> - <?= formatReady($user['description']) ?> + <?= formatReady($user['data']['description']) ?> </div> </div> </div> @@ -19,7 +19,7 @@ </h1> </header> <section> - <?= $this->render_partial("mymaterial/_material_list.php", ['materialien' => $materials]) ?> + <?= $this->render_partial("oer/mymaterial/_material_list.php", ['materialien' => $materials]) ?> </section> </section> <? endif ?> diff --git a/app/views/oer/mymaterial/_material_list.php b/app/views/oer/mymaterial/_material_list.php index 371c3920d44..237ae0758fb 100644 --- a/app/views/oer/mymaterial/_material_list.php +++ b/app/views/oer/mymaterial/_material_list.php @@ -44,17 +44,17 @@ <? endif ?> </td> <td> - <a href="<?= $controller->statistics($material) ?>" data-dialog="size=auto"> + <a href="<?= $controller->link_for('oer/mymaterial/statistics/' . $material->id) ?>" data-dialog="size=auto"> <?= OERDownloadcounter::countBySQL('material_id = ?', [$material->id]) ?> </a> </td> <td class="actions"> <? if ($material->isMine()) : ?> - <a href="<?= $controller->edit($material) ?>" data-dialog + <a href="<?= $controller->link_for('oer/mymaterial/edit/' . $material->id) ?>" data-dialog title="<?= _('Lernmaterial bearbeiten') ?>"> <?= Icon::create('edit', Icon::ROLE_CLICKABLE)->asImg(20) ?> </a> - <form action="<?= $controller->delete($material) ?>" + <form action="<?= $controller->link_for('oer/mymaterial/delete/' . $material->id) ?>" class="inlineform" method="post" data-confirm="<?= _('Dieses Material wirklich löschen?') ?>"> diff --git a/lib/models/ExternalUser.php b/lib/models/ExternalUser.php index d4bfd722626..53a079ac583 100644 --- a/lib/models/ExternalUser.php +++ b/lib/models/ExternalUser.php @@ -24,6 +24,11 @@ class ExternalUser extends SimpleORMap protected static function configure($config = []) { $config['db_table'] = 'external_users'; + $config['belongs_to']['host'] = [ + 'class_name' => OERHost::class, + 'foreign_key' => 'host_id' + ]; + $config['serialized_fields']['data'] = 'JSONArrayObject'; parent::configure($config); } } diff --git a/lib/models/OERHost.php b/lib/models/OERHost.php index bf8f483087e..19f2bb23338 100644 --- a/lib/models/OERHost.php +++ b/lib/models/OERHost.php @@ -267,10 +267,10 @@ class OERHost extends OERIdentity if ($materialdata['external_contact']) { $user = $materialdata['oeruser']; $users[] = [ - 'user_id' => $user['foreign_user_id'], + 'user_id' => $user['foreign_id'], 'name' => $user['name'], - 'avatar' => $user['avatar'], - 'description' => $user['description'], + 'avatar' => $user['avatar_url'], + 'description' => $user['data']['description'], 'host_url' => $user->host['url'], 'link' => URLHelper::getURL('dispatch.php/oer/market/profile/' . $user->getId()), 'hostname' => $this['name'] diff --git a/lib/models/OERMaterial.php b/lib/models/OERMaterial.php index c84d7b5ff79..911aaa2de1a 100644 --- a/lib/models/OERMaterial.php +++ b/lib/models/OERMaterial.php @@ -566,7 +566,9 @@ class OERMaterial extends SimpleORMap $user['contact_type'] = "oercampus"; $user['name'] = $review_data['user']['name']; $user['avatar_url'] = $review_data['user']['avatar'] ?: null; - $user['data']['description'] = $review_data['user']['description'] ?: null; + $user['data'] = [ + 'description' => $review_data['user']['description'] ?: '' + ]; $user->store(); $review['user_id'] = $user->getId(); @@ -609,7 +611,7 @@ class OERMaterial extends SimpleORMap } $user['name'] = $userdata['name']; $user['avatar_url'] = $userdata['avatar'] ?: null; - $userdata = $user['data'] ? $user['data']->toArrayCopy() : []; + $userdata = $user['data'] ? $user['data']->getArrayCopy() : []; $userdata['description'] = $userdata['description'] ?: null; $user['data'] = $userdata; $user->store(); -- GitLab