From 715e3c293877c8e9da8cc3292c94b16f9b029d26 Mon Sep 17 00:00:00 2001
From: Ron Lucke <lucke@elan-ev.de>
Date: Wed, 9 Oct 2024 08:30:58 +0000
Subject: [PATCH] AvatarController hat verwaisten Code

Closes #4666

Merge request studip/studip!3484
---
 app/controllers/avatar.php                   | 200 -------------------
 app/controllers/blubber.php                  |   4 +-
 app/controllers/course/messenger.php         |   4 +-
 db/migrations/6.0.21_update_help_content.php |  30 +++
 4 files changed, 34 insertions(+), 204 deletions(-)
 delete mode 100644 app/controllers/avatar.php
 create mode 100644 db/migrations/6.0.21_update_help_content.php

diff --git a/app/controllers/avatar.php b/app/controllers/avatar.php
deleted file mode 100644
index 5111078df44..00000000000
--- a/app/controllers/avatar.php
+++ /dev/null
@@ -1,200 +0,0 @@
-<?php
-/**
- * AvatarController - Administration of all avatar related settings
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * @author      Jan-Hendrik Willms <tleilax+studip@gmail.com>
- * @author      Thomas Hackl <thomas.hackl@uni-passau.de>
- * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
- * @category    Stud.IP
- * @since       4.2
- */
-
-class AvatarController extends AuthenticatedController
-{
-    /**
-     * Display the avatar information of a user, course or institute
-     * @param string $type object type: 'user', 'course' or 'institute'
-     * @param string $id ID of the object this avatar belongs to
-     */
-    public function update_action($type, $id)
-    {
-        // Check for permission to save a new avatar.
-        if ($type == 'user') {
-            PageLayout::setHelpKeyword('Basis.HomepageBild');
-            PageLayout::setTitle(_('Profilbild ändern'));
-
-            $has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
-            $class = Avatar::class;
-            $this->cancel_link = $this->url_for('profile', ['username' => User::find($id)->username]);
-        } else if ($type == 'institute') {
-            PageLayout::setTitle(Context::getHeaderLine() . ' - ' . _('Einrichtungsbild ändern'));
-
-            $has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
-            $class = InstituteAvatar::class;
-            $this->cancel_link = $this->url_for('institute/basicdata/index', ['cid' => $id]);
-        } else {
-            PageLayout::setTitle(Context::getHeaderLine() . ' - ' . _('Veranstaltungsbild ändern'));
-
-            $has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
-            $course = Course::find($id);
-            if ($course->isStudygroup()) {
-                $class = 'StudygroupAvatar';
-                $this->cancel_link = $this->url_for('course/studygroup/edit?cid=' . $id);
-            } else {
-                $class = CourseAvatar::class;
-                $this->cancel_link = $this->url_for('course/management?cid=' . $id);
-            }
-        }
-
-        if (!$has_perm) {
-            throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
-        }
-
-        if ($type === 'user') {
-            Navigation::activateItem('/profile/index');
-        } else if ($type === 'institute') {
-            Navigation::activateItem('/admin/institute/details');
-        } else {
-            Navigation::activateItem('/course/admin/avatar');
-
-            if ($GLOBALS['perm']->have_studip_perm('admin', $id)) {
-                $widget = new CourseManagementSelectWidget();
-                Sidebar::get()->addWidget($widget);
-            }
-        }
-
-
-        $avatar = $class::getAvatar($id);
-        $this->avatar = $avatar->getURL($class::NORMAL);
-        $this->customized = $avatar->is_customized();
-
-        $this->type = $type;
-        $this->id = $id;
-    }
-
-    /**
-     * Upload a new avatar or removes the current avatar.
-     * Sends an information email to the user if the action was not invoked by himself.
-     * @param string $type object type: 'user', 'course' or 'institute'
-     * @param string $id ID of the object this avatar belongs to
-     */
-    public function upload_action($type, $id)
-    {
-        CSRFProtection::verifyUnsafeRequest();
-
-        // Check for permission to save a new avatar.
-        if ($type == 'user') {
-            $has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
-            $class = Avatar::class;
-            $redirect = 'profile?username=' . User::find($id)->username;
-        } else if ($type == 'institute') {
-            $has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
-            $class = InstituteAvatar::class;
-            $redirect = 'institute/basicdata/index';
-        } else {
-            $has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
-            $course = Course::find($id);
-            if ($course->isStudygroup()) {
-                $class = 'StudygroupAvatar';
-                $redirect = 'course/studygroup/edit/?cid=' . $id;
-            } else {
-                $class = CourseAvatar::class;
-                $redirect = 'course/management';
-            }
-        }
-
-        if (!$has_perm) {
-            throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
-        }
-
-        if (Request::submitted('reset')) {
-
-            $class::getAvatar($id)->reset();
-            if ($type == 'user') {
-                Visibility::removePrivacySetting('picture', $id);
-            }
-            PageLayout::postSuccess(_('Bild gelöscht.'));
-
-        } elseif (Request::submitted('upload')) {
-            try {
-
-                // Get the Base64-encoded data from cropper.
-                $imgdata = Request::get('cropped-image');
-
-                // Extract actual image data (prepended by mime type and meta data)
-                list($type, $imgdata) = explode(';', $imgdata);
-                list(, $imgdata) = explode(',', $imgdata);
-                $imgdata = base64_decode($imgdata);
-                // Write data to file.
-                $filename = $GLOBALS['TMP_PATH'] . '/avatar-' . $id . '.png';
-                file_put_contents($filename, $imgdata);
-
-                // Use new image file for avatar creation.
-                $class::getAvatar($id)->createFrom($filename);
-
-                NotificationCenter::postNotification('AvatarDidUpload', $id);
-
-                $message = _('Die Bilddatei wurde erfolgreich hochgeladen. '
-                            .'Eventuell sehen Sie das neue Bild erst, nachdem Sie diese Seite '
-                            .'neu geladen haben (in den meisten Browsern F5 drücken).');
-                PageLayout::postSuccess($message);
-
-                // Send message to user if necessary.
-                if ($type == 'user') {
-                    setTempLanguage($id);
-                    $this->postPrivateMessage(_("Ein neues Bild wurde hochgeladen.\n"));
-                    restoreLanguage();
-                    Visibility::addPrivacySetting(_('Eigenes Bild'), 'picture', 'commondata', 1, $id);
-                }
-
-                unlink($filename);
-            } catch (Exception $e) {
-                PageLayout::postError($e->getMessage());
-            }
-        }
-        $this->relocate($redirect);
-    }
-
-    /**
-     * Deletes a custom avatar.
-     * @param string $type object type: 'user', 'course' or 'institute'
-     * @param string $id ID of the object this avatar belongs to
-     */
-    public function delete_action($type, $id)
-    {
-        // Check for permission to delete avatar.
-        if ($type == 'user') {
-            $has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
-            $class = 'Avatar';
-            $redirect = 'profile';
-        } else if ($type == 'institute') {
-            $has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
-            $class = 'InstituteAvatar';
-            $redirect = 'institute/basicdata/index';
-        } else {
-            $has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
-            $course = Course::find($id);
-            if ($course->isStudygroup()) {
-                $class = 'StudygroupAvatar';
-                $redirect = 'course/studygroup/edit/?cid=' . $id;
-            } else {
-                $class = 'CourseAvatar';
-                $redirect = 'course/management';
-            }
-        }
-
-        if (!$has_perm) {
-            throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
-        }
-
-        $class::getAvatar($id)->reset();
-
-        PageLayout::postMessage(MessageBox::success(_('Das Bild wurde gelöscht.')));
-        $this->relocate($redirect);
-    }
-}
diff --git a/app/controllers/blubber.php b/app/controllers/blubber.php
index 15d16061407..d206a4ad075 100644
--- a/app/controllers/blubber.php
+++ b/app/controllers/blubber.php
@@ -56,8 +56,8 @@ class BlubberController extends AuthenticatedController
                 sprintf(
                     _('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'),
                     '<a href="' .
-                        URLHelper::getLink('dispatch.php/avatar/update/user/' . $GLOBALS['user']->id) .
-                        '" data-dialog>',
+                        URLHelper::getLink('dispatch.php/settings/avatar/') .
+                        '" >',
                     '</a>'
                 )
             );
diff --git a/app/controllers/course/messenger.php b/app/controllers/course/messenger.php
index 710ac871de8..8d00f52fbe9 100644
--- a/app/controllers/course/messenger.php
+++ b/app/controllers/course/messenger.php
@@ -55,8 +55,8 @@ class Course_MessengerController extends AuthenticatedController
                 sprintf(
                     _('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'),
                     '<a href="' .
-                        URLHelper::getURL('dispatch.php/avatar/update/user/' . $GLOBALS['user']->id) .
-                        '" data-dialog>',
+                        URLHelper::getURL('dispatch.php/settings/avatar/') .
+                        '" >',
                     '</a>'
                 )
             );
diff --git a/db/migrations/6.0.21_update_help_content.php b/db/migrations/6.0.21_update_help_content.php
new file mode 100644
index 00000000000..480bfc7414f
--- /dev/null
+++ b/db/migrations/6.0.21_update_help_content.php
@@ -0,0 +1,30 @@
+<?php
+
+final class UpdateHelpContent extends Migration
+{
+    public function description()
+    {
+        return 'Update route for avatar help content';
+    }
+    protected function up()
+    {
+        DBManager::get()->exec(
+            "UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar' WHERE `help_content`.`content_id` = 'abfb5d03de288d02df436f9a8bb96d9d'"
+        );
+        DBManager::get()->exec(
+            "UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar' WHERE `help_content`.`content_id` = '5fab81bbd1e19949f304df08ea21ca1b'"
+        );
+
+        
+    }
+
+    protected function down()
+    {
+        DBManager::get()->exec(
+            "UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar/update' WHERE `help_content`.`content_id` = 'abfb5d03de288d02df436f9a8bb96d9d'"
+        );
+        DBManager::get()->exec(
+            "UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar/update' WHERE `help_content`.`content_id` = '5fab81bbd1e19949f304df08ea21ca1b'"
+        );
+    }
+}
-- 
GitLab