From 12ddc5878d34c7023ebd88d01493b3c7b4f417e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Wed, 4 Sep 2019 15:32:48 +0200 Subject: [PATCH] Add a function, to disable usage for reactions --- com.woltlab.wcf/templates/userProfileLikes.tpl | 2 +- .../js/WoltLabSuite/Core/Ui/Reaction/Handler.js | 15 ++++++++++++++- .../lib/acp/form/ReactionTypeAddForm.class.php | 6 +++++- .../lib/data/reaction/ReactionAction.class.php | 9 +++++++++ .../lib/data/reaction/type/ReactionType.class.php | 3 ++- .../lib/system/reaction/ReactionHandler.class.php | 5 +++-- wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ wcfsetup/setup/db/install.sql | 3 ++- 9 files changed, 40 insertions(+), 7 deletions(-) diff --git a/com.woltlab.wcf/templates/userProfileLikes.tpl b/com.woltlab.wcf/templates/userProfileLikes.tpl index 260c314460..5dd3b3c8f4 100644 --- a/com.woltlab.wcf/templates/userProfileLikes.tpl +++ b/com.woltlab.wcf/templates/userProfileLikes.tpl @@ -18,7 +18,7 @@ diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js index 5e6b18046e..782f8f95fc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js @@ -217,7 +217,12 @@ define( }); if (reactionTypeID) { - elBySel('.reactionTypeButton[data-reaction-type-id="' + reactionTypeID + '"]', this._getPopover()).classList.add('active'); + var reactionTypeButton = elBySel('.reactionTypeButton[data-reaction-type-id="' + reactionTypeID + '"]', this._getPopover()); + reactionTypeButton.classList.add('active'); + + if (~~elData(reactionTypeButton, 'is-assignable') === 0) { + elShow(reactionTypeButton); + } } }, @@ -306,6 +311,8 @@ define( reactionTypeItem.className = 'reactionTypeButton jsTooltip'; elData(reactionTypeItem, 'reaction-type-id', reactionType.reactionTypeID); elData(reactionTypeItem, 'title', reactionType.title); + elData(reactionTypeItem, 'is-assignable', ~~reactionType.isAssignable); + reactionTypeItem.title = reactionType.title; var reactionTypeItemSpan = elCreate('span'); @@ -319,6 +326,10 @@ define( reactionTypeItem.addEventListener(WCF_CLICK_EVENT, this._react.bind(this, reactionType.reactionTypeID)); + if (!reactionType.isAssignable) { + elHide(reactionTypeItem); + } + popoverContentHTML.appendChild(reactionTypeItem); } @@ -372,6 +383,8 @@ define( if (this._popoverCurrentObjectId !== 0) { this._getPopover().classList.remove('active'); + elBySelAll('.reactionTypeButton[data-is-assignable="0"]', this._getPopover(), elHide); + if (this._options.isButtonGroupNavigation) { this._objects.get(this._popoverCurrentObjectId).forEach(function (elementData) { elementData.reactButton.closest('nav').style.cssText = ""; diff --git a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php index 2cbade39ff..75f149597a 100644 --- a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php @@ -4,6 +4,7 @@ use wcf\data\reaction\type\ReactionTypeAction; use wcf\data\reaction\type\ReactionTypeList; use wcf\form\AbstractFormBuilderForm; use wcf\system\form\builder\container\FormContainer; +use wcf\system\form\builder\field\BooleanFormField; use wcf\system\form\builder\field\ShowOrderFormField; use wcf\system\form\builder\field\TitleFormField; use wcf\system\form\builder\field\UploadFormField; @@ -60,7 +61,10 @@ class ReactionTypeAddForm extends AbstractFormBuilderForm { ShowOrderFormField::create() ->description('wcf.acp.reactionType.showOrder.description') ->required() - ->options(new ReactionTypeList()) + ->options(new ReactionTypeList()), + BooleanFormField::create('isAssignable') + ->label('wcf.acp.reactionType.isAssignable') + ->description('wcf.acp.reactionType.isAssignable.description') ]); $iconContainer = FormContainer::create('imageSection') diff --git a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php index 650e9f91dd..523fe88ae1 100644 --- a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php @@ -201,6 +201,15 @@ class ReactionAction extends AbstractDatabaseObjectAction { throw new PermissionDeniedException(); } } + + if (!$this->reactionType->isAssignable) { + // check, if the reaction is reverted + $like = Like::getLike($this->likeableObject->getObjectType()->objectTypeID, $this->likeableObject->getObjectID(), WCF::getUser()->userID); + + if (!$like->likeID || $like->reactionTypeID !== $this->reactionType->reactionTypeID) { + throw new IllegalLinkException(); + } + } } /** diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php index fca986dc02..acbdffb2cd 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php @@ -11,12 +11,13 @@ use wcf\system\WCF; * @copyright 2001-2019 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\Data\Reaction\Type - * @since 5.2 + * @since 5.2 * * @property-read integer $reactionTypeID unique id of the reaction type * @property-read string $title * @property-read integer $showOrder position of the reaction type in relation to the other reaction types * @property-read string $iconFile the file location of the icon + * @property-read boolean $isAssignable `1`, if the reaction can be assigned */ class ReactionType extends DatabaseObject implements ITitledObject { /** diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index 926e6a2cb1..028ad7a2a6 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -35,7 +35,7 @@ use wcf\util\StringUtil; * @copyright 2001-2019 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Reaction - * @since 5.2 + * @since 5.2 */ class ReactionHandler extends SingletonFactory { /** @@ -79,7 +79,8 @@ class ReactionHandler extends SingletonFactory { 'renderedIcon' => $reaction->renderIcon(), 'iconPath' => $reaction->getIconPath(), 'showOrder' => $reaction->showOrder, - 'reactionTypeID' => $reaction->reactionTypeID + 'reactionTypeID' => $reaction->reactionTypeID, + 'isAssignable' => $reaction->isAssignable, ]; } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f7a0c2b9d0..07cda1e702 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2575,6 +2575,8 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index b3c4886b71..b0e09914d1 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2503,6 +2503,8 @@ If you have already bought the licenses for the listed apps, th + + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 082f4c6ad8..8e31d21f40 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1201,7 +1201,8 @@ CREATE TABLE wcf1_reaction_type ( reactionTypeID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), showOrder INT(10) NOT NULL DEFAULT 0, - iconFile MEDIUMTEXT + iconFile MEDIUMTEXT, + isAssignable TINYINT(1) NOT NULL DEFAULT 1 ); DROP TABLE IF EXISTS wcf1_registry; -- 2.20.1