diff --git a/TandemPlugin.class.php b/TandemPlugin.class.php index 54a1e6f3e18f5db01499259e13ed34bfb2a20d08..81aabaf1ac5c183c6973b44f411ff394bd4c1171 100644 --- a/TandemPlugin.class.php +++ b/TandemPlugin.class.php @@ -16,7 +16,7 @@ require_once(__DIR__ . '/models/TandemProfile.class.php'); require_once(__DIR__ . '/models/TandemPair.class.php'); - +require_once(__DIR__ . '/models/BlocklistEntry.class.php'); require_once(__DIR__ . '/classes/TandemMatching.class.php'); @@ -48,6 +48,12 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin } + public function userHasAccess($user_id) + { + return !\TandemPlugin\BlocklistEntry::userIsBlocked($user_id); + } + + public function __construct() { parent::__construct(); @@ -67,10 +73,10 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin if (!Request::get('username')) { //No username parameter set: //We must be on the current user's profile page. - $show_navigation = true; + $show_navigation = $this->userHasAccess($user->id); } else { if (Request::get('username') == $user->username) { - $show_navigation = true; + $show_navigation = $this->userHasAccess($user->id); } } @@ -157,6 +163,12 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin ); $navigation->addSubNavigation('languages', $sub_navigation); + $sub_navigation = new Navigation( + dgettext('TandemPlugin', 'Blockliste'), + PluginEngine::getURL('tandemplugin/admin/blocklist') + ); + $navigation->addSubNavigation('blocklist', $sub_navigation); + if ($top_navigation) { $top_navigation->addSubNavigation( $navigation_name, diff --git a/assets/css/TandemPlugin.css b/assets/css/TandemPlugin.css index 27cd657a37cc54f9d26d1520b87df0b64177995d..905488acf390d7bdb350ad3e194c0d2e62be67e6 100644 --- a/assets/css/TandemPlugin.css +++ b/assets/css/TandemPlugin.css @@ -21,3 +21,12 @@ display: none; } } + + +@media all +{ + table.TandemPlugin button.action-menu-icon { + border: none; + background: none; + } +} diff --git a/controllers/admin.php b/controllers/admin.php index 363b5b56386dd8eb337c280f1d17cc5e6d1d1830..f227aa5aa6e0a8e3c6a6271f4fe1d61207dce138 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -15,6 +15,7 @@ require_once(__DIR__ . '/../models/TandemProfile.class.php'); require_once(__DIR__ . '/../models/TandemPair.class.php'); +require_once(__DIR__ . '/../models/BlocklistEntry.class.php'); class AdminController extends PluginController @@ -758,4 +759,93 @@ class AdminController extends PluginController } } } + + + public function blocklist_action() + { + $sidebar = Sidebar::get(); + $actions = new ActionsWidget(); + $actions->addLink( + dgettext('TandemPlugin', 'Eintrag hinzufügen'), + $this->url_for('admin/add_to_blocklist'), + Icon::create('add'), + ['data-dialog' => ''] + ); + $sidebar->addWidget($actions); + + $this->blocklist_entries = \TandemPlugin\BlocklistEntry::findBySQL( + "INNER JOIN `auth_user_md5` USING (`user_id`) + ORDER BY `auth_user_md5`.`Nachname` ASC, `auth_user_md5`.`Vorname` ASC" + ); + } + + + public function add_to_blocklist_action() + { + $this->user_search = new QuickSearch('user_id', new StandardSearch('user_id')); + $this->user_id = ''; + $this->reason = ''; + if (Request::isPost()) { + CSRFProtection::verifyUnsafeRequest(); + $this->user_id = Request::get('user_id'); + $this->reason = Request::get('reason'); + $user = null; + if ($this->user_id) { + $user = User::find($this->user_id); + } + if (!$user) { + PageLayout::postError(dgettext('TandemPlugin', 'Es wurde keine Person angegeben!')); + return; + } + $this->user_search->defaultValue($user->id, $user->getFullName('full_rev')); + + $exists = \TandemPlugin\BlocklistEntry::countByUser_id($user->id) > 0; + if ($exists) { + PageLayout::postInfo( + sprintf( + dgettext('TandemPlugin', '%s ist bereits auf der Blockliste.'), + $user->getFullName() + ) + ); + return; + } + $entry = new \TandemPlugin\BlocklistEntry(); + $entry->user_id = $user->id; + $entry->reason = $this->reason ?? ''; + if ($entry->store()) { + PageLayout::postSuccess( + sprintf( + dgettext('TandemPlugin', '%s wurde zur Blockliste hinzugefügt.'), + $user->getFullName() + ) + ); + $this->response->add_header('X-Dialog-Close', '1'); + } else { + PageLayout::postFailure( + sprintf( + dgettext('TandemPlugin', 'Beim Hinzufügen von %s zur Blockliste trat ein Fehler auf.'), + $user->getFullName() + ) + ); + } + } + } + + + public function delete_from_blocklist_action($user_id) + { + CSRFProtection::verifyUnsafeRequest(); + + $deleted_c = \TandemPlugin\BlocklistEntry::deleteByUser_id($user_id); + if ($deleted_c > 0) { + PageLayout::postSuccess( + dgettext('TandemPlugin', 'Die Person wurde von der Blockliste entfernt.') + ); + } elseif ($deleted_c === 0) { + PageLayout::postWarning( + dgettext('TandemPlugin', 'Es gab keinen Eintrag auf der Blockliste für die gewählte Person.') + ); + } + $this->redirect('admin/blocklist'); + } } diff --git a/controllers/my_tandems.php b/controllers/my_tandems.php index 9cfef4842f2a4d12179b8dcf14e464edb1850ad4..498c8d5d2edefd48fb63a1a30b47c3791433eeb7 100644 --- a/controllers/my_tandems.php +++ b/controllers/my_tandems.php @@ -66,6 +66,12 @@ class MyTandemsController extends PluginController $this->user = User::findCurrent(); + if (!$this->plugin->userHasAccess($this->user->id)) { + throw new AccessDeniedException( + dgettext('TandemPlugin', 'Sie befinden sich auf der Blockliste und dürfen daher das TandemPlugin nicht nutzen!') + ); + } + $this->buildSidebar(); } diff --git a/controllers/pair.php b/controllers/pair.php index 7471b2c46dd4ce2458c241ddc38115e439dbc168..3599005985a0bc7caa05c93f413779004578aa1b 100644 --- a/controllers/pair.php +++ b/controllers/pair.php @@ -26,6 +26,12 @@ class PairController extends PluginController parent::before_filter($action, $args); $this->user = User::findCurrent(); + + if (!$this->plugin->userHasAccess($this->user->id)) { + throw new AccessDeniedException( + dgettext('TandemPlugin', 'Sie befinden sich auf der Blockliste und dürfen daher das TandemPlugin nicht nutzen!') + ); + } } diff --git a/controllers/profile.php b/controllers/profile.php index ad734b23cccc779984305db0c0d4c66fa182220e..bba2d033ce61b8553d7ace455f6f3f5267c61b66 100644 --- a/controllers/profile.php +++ b/controllers/profile.php @@ -25,6 +25,19 @@ class ProfileController extends PluginController { protected $utf8decode_xhr = true; + + public function before_filter(&$action, &$args) + { + parent::before_filter($action, $args); + + if (!$this->plugin->userHasAccess($GLOBALS['user']->id)) { + throw new AccessDeniedException( + dgettext('TandemPlugin', 'Sie befinden sich auf der Blockliste und dürfen daher das TandemPlugin nicht nutzen!') + ); + } + } + + private function addEditHandler($edit_mode = false) { //load the list of languages: diff --git a/migrations/12_add_blocklist.php b/migrations/12_add_blocklist.php new file mode 100644 index 0000000000000000000000000000000000000000..93438a4c48a50d6f27ea23c653f7d8dd1ea42e30 --- /dev/null +++ b/migrations/12_add_blocklist.php @@ -0,0 +1,26 @@ +<?php + + +class AddBlocklist extends Migration +{ + protected function up() + { + $db = DBManager::get(); + $db->exec( + "CREATE TABLE IF NOT EXISTS `tandemplugin_blocklist_entries` ( + user_id CHAR(32) NOT NULL, + reason VARCHAR(256) NULL, + mkdate BIGINT(10) NOT NULL DEFAULT '0', + chdate BIGINT(10) NOT NULL DEFAULT '0', + PRIMARY KEY (user_id) + )" + ); + } + + + protected function down() + { + $db = DBManager::get(); + $db->exec("DROP TABLE IF EXISTS `tandemplugin_blocklist_entries`"); + } +} diff --git a/models/BlocklistEntry.class.php b/models/BlocklistEntry.class.php new file mode 100644 index 0000000000000000000000000000000000000000..b32c66325c097629c21786c6295189c65c26fe70 --- /dev/null +++ b/models/BlocklistEntry.class.php @@ -0,0 +1,60 @@ +<?php + + +/** + * This file is part of the TandemPlugin for Stud.IP + * + * 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 Moritz Strohm <strohm@data-quest.de> + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Plugin + **/ + + +namespace TandemPlugin; + + +require_once(__DIR__ . '/TandemPair.class.php'); +require_once(__DIR__ . '/../classes/TandemManager.class.php'); + + +class BlocklistEntry extends \SimpleORMap +{ + protected static function configure($config = []) + { + $config['db_table'] = 'tandemplugin_blocklist_entries'; + + $config['belongs_to']['user'] = [ + 'class_name' => \User::class, + 'foreign_key' => 'user_id' + ]; + $config['registered_callbacks']['after_store'][] = 'cbDeleteTandemData'; + parent::configure($config); + } + + + public function cbDeleteTandemData($entry) + { + if (empty($entry->user)) { + return; + } + + $pairs = \TandemPair::findByUserId($entry->user->id); + if (!$pairs) { + return; + } + foreach ($pairs as $pair) { + \TandemManager::terminatePair($pair, $entry->user); + } + } + + + public static function userIsBlocked($user_id) + { + return self::countByUser_id($user_id) > 0; + } +} diff --git a/plugin.manifest b/plugin.manifest index 745fc7af477054f4bf7ede3aed1805e55a56fb05..275fbb39382e5302dbfa159df978b2cf2dd66f56 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginname=TandemPlugin pluginclassname=TandemPlugin origin=data-quest -version=1.4.0 +version=1.5.0 description=Dieses Plugin ermöglicht es, Sprachtandems innerhalb der Stud.IP Platform zu bilden. -studipMinVersion=4.0 +studipMinVersion=5.0 studipMaxVersion=5.9.99 diff --git a/views/admin/add_to_blocklist.php b/views/admin/add_to_blocklist.php new file mode 100644 index 0000000000000000000000000000000000000000..e2477152ee1e6d48d5f7748d16e0b725c8789329 --- /dev/null +++ b/views/admin/add_to_blocklist.php @@ -0,0 +1,15 @@ +<form class="default" method="post" action="<?= $controller->link_for('admin/add_to_blocklist') ?>" + data-dialog="reload-on-close"> + <?= CSRFProtection::tokenTag() ?> + <label> + <?= dgettext('TandemPlugin', 'Person suchen') ?> + <?= $user_search->render() ?> + </label> + <label> + <?= dgettext('TandemPlugin', 'Grund für die Sperrung') ?> + <input name="reason" type="text" maxlength="255" value="<?= htmlReady($reason) ?>"> + </label> + <div data-dialog-button> + <?= \Studip\Button::create(dgettext('TandemPlugin', 'Hinzufügen'), 'save') ?> + </div> +</form> diff --git a/views/admin/blocklist.php b/views/admin/blocklist.php new file mode 100644 index 0000000000000000000000000000000000000000..2cf3f0c921b35c80be9b8ac2f489f5c75ded04b8 --- /dev/null +++ b/views/admin/blocklist.php @@ -0,0 +1,30 @@ +<table class="default TandemPlugin"> + <caption><?= dgettext('TandemPlugin', 'Einträge auf der Blockliste') ?></caption> + <thead> + <tr> + <th><?= dgettext('TandemPlugin', 'Nachname, Vorname') ?></th> + <th><?= dgettext('TandemPlugin', 'Grund für die Sperrung') ?></th> + <th class="actions"><?= dgettext('TandemPlugin', 'Entfernen') ?></th> + </tr> + </thead> + <tbody> + <? foreach ($blocklist_entries as $entry) : ?> + <? + $user_name = !empty($entry->user) ? $entry->user->getFullName('full_rev') : ''; + ?> + <tr> + <td><?= htmlReady($user_name) ?></td> + <td><?= htmlReady($entry->reason) ?></td> + <td class="actions"> + <form class="default" method="post" action="<?= $controller->link_for('admin/delete_from_blocklist/' . $entry->user->id) ?>"> + <?= CSRFProtection::tokenTag() ?> + <button class="action-menu-icon" title="<?= sprintf(dgettext('TandemPlugin', '%s von der Blockliste entfernen'), $user_name) ?>" + data-confirm="<?= sprintf(dgettext('TandemPlugin', 'Soll %s wirklich von der Blockliste entfernt werden?'), $user_name) ?>"> + <?= Icon::create('trash')->asImg(['aria-hidden' => 'true']) ?> + </button> + </form> + </td> + </tr> + <? endforeach ?> + </tbody> +</table>