Disallow user trophy edit for automatically awarded trophies
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:48:45 +0000 (21:48 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:48:45 +0000 (21:48 +0200)
See #2315

wcfsetup/install/files/acp/templates/userTrophyList.tpl
wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php

index e1bf0d4e4081a9d31cd18f45ba342cfab4925c65..b278e32f370f0502caa71ea798d15cdf344ee3e6 100644 (file)
                        {foreach from=$objects item=userTrophy}
                                <tr class="userTrophyRow">
                                        <td class="columnIcon">
-                                               <a href="{link controller='UserTrophyEdit' id=$userTrophy->userTrophyID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon16 fa-pencil"></span></a>
-                                               <span class="icon icon16 fa-times pointer jsDeleteButton jsTooltip" data-confirm-message-html="{lang __encode="true"}wcf.acp.trophy.userTrophy.delete.confirmMessage{/lang}" data-object-id="{@$userTrophy->getObjectID()}" title="{lang}wcf.global.button.delete{/lang}"></span>
+                                               {if $userTrophy->getTrophy()->awardAutomatically}
+                                                       <span class="icon icon16 fa-pencil disabled" title="{lang}wcf.global.button.edit{/lang}"></span>
+                                                       <span class="icon icon16 fa-times disabled" title="{lang}wcf.global.button.delete{/lang}"></span>
+                                               {else}
+                                                       <a href="{link controller='UserTrophyEdit' id=$userTrophy->userTrophyID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon16 fa-pencil{if $userTrophy->getTrophy()->awardAutomatically} disabled{/if}"></span></a>
+                                                       <span class="icon icon16 fa-times pointer jsDeleteButton jsTooltip{if $userTrophy->getTrophy()->awardAutomatically} disabled{/if}" data-confirm-message-html="{lang __encode="true"}wcf.acp.trophy.userTrophy.delete.confirmMessage{/lang}" data-object-id="{@$userTrophy->getObjectID()}" title="{lang}wcf.global.button.delete{/lang}"></span>
+                                               {/if}
                                        </td>
                                        <td class="columnID columnUserTrophyID">{@$userTrophy->userTrophyID}</td>
                                        <td class="columnText columnUsername"><a href="{link controller='UserEdit' id=$userTrophy->userID}{/link}" title="{lang}wcf.acp.user.edit{/lang}">{$userTrophy->getUserProfile()->username}</a></td>
index 1a42571dce728a3ec13852e000145fc7e56a3db7..418b59314f3b205ff21b9b003dd78aa77dec9790 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\user\trophy;
 use wcf\data\user\UserAction;
 use wcf\data\AbstractDatabaseObjectAction;
+use wcf\system\exception\PermissionDeniedException;
 
 /**
  * Provides user trophy actions. 
@@ -33,6 +34,20 @@ class UserTrophyAction extends AbstractDatabaseObjectAction {
                return $returnValues; 
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function validateDelete() {
+               parent::validateDelete();
+               
+               /** @var UserTrophy $object */
+               foreach ($this->objects as $object) {
+                       if ($object->getTrophy()->awardAutomatically) {
+                               throw new PermissionDeniedException(); 
+                       }
+               }
+       }
+       
        /**
         * @inheritDoc
         */