Skip to content
Snippets Groups Projects
Commit 7f1bdc86 authored by David Siegfried's avatar David Siegfried
Browse files

Delete clipboard items when room is deleted, closes #361

parent 87ef660b
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,7 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -60,7 +60,7 @@ class Clipboard extends \RESTAPI\RouteMap
if ($clipboard->user_id != $GLOBALS['user']->id) { if ($clipboard->user_id != $GLOBALS['user']->id) {
//Thou shalt not delete clipboards //Thou shalt not delete clipboards
//which don't belong to you! //which don't belong to you!
throw new AccessDeniedException(); throw new \AccessDeniedException();
} }
$name = $this->data['name']; $name = $this->data['name'];
...@@ -70,8 +70,6 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -70,8 +70,6 @@ class Clipboard extends \RESTAPI\RouteMap
$clipboard->name = $name; $clipboard->name = $name;
$success = false;
if ($clipboard->isDirty()) { if ($clipboard->isDirty()) {
$success = $clipboard->store(); $success = $clipboard->store();
} else { } else {
...@@ -107,10 +105,10 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -107,10 +105,10 @@ class Clipboard extends \RESTAPI\RouteMap
$this->notFound(_('Ungültige Merkzettel-ID!')); $this->notFound(_('Ungültige Merkzettel-ID!'));
} }
if ($clipboard->user_id != $GLOBALS['user']->id) { if ($clipboard->user_id !== $GLOBALS['user']->id) {
//Thou shalt not delete items of clipboards //Thou shalt not delete items of clipboards
//which don't belong to you! //which don't belong to you!
throw new AccessDeniedException(); throw new \AccessDeniedException();
} }
if (!$clipboard->delete()) { if (!$clipboard->delete()) {
...@@ -136,7 +134,7 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -136,7 +134,7 @@ class Clipboard extends \RESTAPI\RouteMap
if ($clipboard->user_id != $GLOBALS['user']->id) { if ($clipboard->user_id != $GLOBALS['user']->id) {
//Thou shalt not add items to clipboards //Thou shalt not add items to clipboards
//which don't belong to you! //which don't belong to you!
throw new AccessDeniedException(); throw new \AccessDeniedException();
} }
$range_id = \Request::get('range_id'); $range_id = \Request::get('range_id');
...@@ -162,7 +160,7 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -162,7 +160,7 @@ class Clipboard extends \RESTAPI\RouteMap
$result['widget_id'] = $widget_id; $result['widget_id'] = $widget_id;
} }
return $result; return $result;
} catch (Exception $e) { } catch (\Exception $e) {
$this->halt(500, $e->getMessage()); $this->halt(500, $e->getMessage());
} }
} }
...@@ -183,7 +181,7 @@ class Clipboard extends \RESTAPI\RouteMap ...@@ -183,7 +181,7 @@ class Clipboard extends \RESTAPI\RouteMap
if ($clipboard->user_id != $GLOBALS['user']->id) { if ($clipboard->user_id != $GLOBALS['user']->id) {
//Thou shalt not delete items of clipboards //Thou shalt not delete items of clipboards
//which don't belong to you! //which don't belong to you!
throw new AccessDeniedException(); throw new \AccessDeniedException();
} }
if ($clipboard->removeItem($range_id)) { if ($clipboard->removeItem($range_id)) {
......
...@@ -52,6 +52,7 @@ class Room extends Resource ...@@ -52,6 +52,7 @@ class Room extends Resource
$config['additional_fields']['building']['get'] = 'findBuilding'; $config['additional_fields']['building']['get'] = 'findBuilding';
$config['registered_callbacks']['before_store'][] = 'cbValidate'; $config['registered_callbacks']['before_store'][] = 'cbValidate';
$config['registered_callbacks']['after_delete'][] = 'cbDeleteClipboardItems';
parent::configure($config); parent::configure($config);
} }
...@@ -155,7 +156,7 @@ class Room extends Resource ...@@ -155,7 +156,7 @@ class Room extends Resource
* @param int $limit A limit for the result set. * @param int $limit A limit for the result set.
* @param Room[] $searchable_rooms An (optional) array of rooms * @param Room[] $searchable_rooms An (optional) array of rooms
* which will limit the search to the rooms in the array. * which will limit the search to the rooms in the array.
* @param Array $properties An array providing request properties * @param array $properties An array providing request properties
* and their values in case the request doesn't have (the desired) * and their values in case the request doesn't have (the desired)
* properties set. * properties set.
* *
...@@ -324,7 +325,7 @@ class Room extends Resource ...@@ -324,7 +325,7 @@ class Room extends Resource
/** /**
* Checks wheter rooms with public booking plans exist. * Checks whether rooms with public booking plans exist.
* *
* @return bool True, if at least one room has a public booking plan, * @return bool True, if at least one room has a public booking plan,
* false otherwise. * false otherwise.
...@@ -506,6 +507,11 @@ class Room extends Resource ...@@ -506,6 +507,11 @@ class Room extends Resource
return true; return true;
} }
public function cbDeleteClipboardItems()
{
ClipboardItem::deleteBySQL('range_id = ?', [$this->id]);
}
public function getRequiredPropertyNames() public function getRequiredPropertyNames()
{ {
...@@ -554,7 +560,7 @@ class Room extends Resource ...@@ -554,7 +560,7 @@ class Room extends Resource
* *
* @param Resource $resource The resource which shall be added as child. * @param Resource $resource The resource which shall be added as child.
* *
* @return True, if the resource could be added as child, false otherwise. * @return bool True, if the resource could be added as child, false otherwise.
* @throws InvalidResourceException If the specified resource belongs to * @throws InvalidResourceException If the specified resource belongs to
* the resource classes Room, Building or Location. * the resource classes Room, Building or Location.
* *
......
import {$gettext} from './gettext';
const Clipboard = { const Clipboard = {
current_delete_icon: null, current_delete_icon: null,
...@@ -19,7 +21,7 @@ const Clipboard = { ...@@ -19,7 +21,7 @@ const Clipboard = {
var current_clipboard_id = jQuery(clipboard).attr('data-id'); var current_clipboard_id = jQuery(clipboard).attr('data-id');
if (current_clipboard_id) { if (current_clipboard_id) {
if (current_clipboard_id == selected_clipboard_id) { if (current_clipboard_id === selected_clipboard_id) {
jQuery(clipboard).removeClass('invisible'); jQuery(clipboard).removeClass('invisible');
if (jQuery(clipboard).find(".empty-clipboard-message").hasClass("invisible")) { if (jQuery(clipboard).find(".empty-clipboard-message").hasClass("invisible")) {
jQuery("#clipboard-group-container").find('.widget-links').removeClass('invisible'); jQuery("#clipboard-group-container").find('.widget-links').removeClass('invisible');
...@@ -213,7 +215,7 @@ const Clipboard = { ...@@ -213,7 +215,7 @@ const Clipboard = {
//don't belong on the displayed page. That's all. //don't belong on the displayed page. That's all.
allowed_classes = allowed_classes.replace(' ', '').split(','); allowed_classes = allowed_classes.replace(' ', '').split(',');
if (allowed_classes.indexOf(range_type) == -1) { if (allowed_classes.indexOf(range_type) === -1) {
//The dropped item does not belong to the right class. //The dropped item does not belong to the right class.
//Set the "not allowed" CSS class //Set the "not allowed" CSS class
//for the "not allowed" animation. //for the "not allowed" animation.
...@@ -432,7 +434,7 @@ const Clipboard = { ...@@ -432,7 +434,7 @@ const Clipboard = {
confirmRemoveClick: function(event) { confirmRemoveClick: function(event) {
STUDIP.Clipboard.current_delete_icon = event.target; STUDIP.Clipboard.current_delete_icon = event.target;
STUDIP.Dialog.confirm( STUDIP.Dialog.confirm(
'Sind Sie sicher?', $gettext('Sind Sie sicher?'),
STUDIP.Clipboard.handleRemoveClick STUDIP.Clipboard.handleRemoveClick
); );
}, },
...@@ -475,7 +477,7 @@ const Clipboard = { ...@@ -475,7 +477,7 @@ const Clipboard = {
confirmRemoveItemClick: function(event) { confirmRemoveItemClick: function(event) {
STUDIP.Clipboard.current_delete_icon = event.target; STUDIP.Clipboard.current_delete_icon = event.target;
STUDIP.Dialog.confirm( STUDIP.Dialog.confirm(
'Sind Sie sicher?', $gettext('Sind Sie sicher?'),
STUDIP.Clipboard.removeItem STUDIP.Clipboard.removeItem
); );
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment