Skip to content
Snippets Groups Projects
Commit 3a1b320c authored by Moritz Strohm's avatar Moritz Strohm
Browse files

Added blocklist functionality

parent 878f8ffa
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -21,3 +21,12 @@
display: none;
}
}
@media all
{
table.TandemPlugin button.action-menu-icon {
border: none;
background: none;
}
}
......@@ -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');
}
}
......@@ -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();
}
......
......@@ -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!')
);
}
}
......
......@@ -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:
......
<?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`");
}
}
<?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;
}
}
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
<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>
<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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment