Allow disabling the admin contact in ContactForm
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 11:23:23 +0000 (12:23 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 11:23:23 +0000 (12:23 +0100)
Resolves #3967

com.woltlab.wcf/page.xml
wcfsetup/install/files/acp/templates/contactRecipientAdd.tpl
wcfsetup/install/files/acp/templates/contactSettings.tpl
wcfsetup/install/files/lib/acp/form/ContactRecipientEditForm.class.php
wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php
wcfsetup/install/files/lib/form/ContactForm.class.php
wcfsetup/install/files/lib/system/page/handler/ContactFormPageHandler.class.php [new file with mode: 0644]

index 015bfccbfdfe66d487d4591d8949aa5db6a644ff..4e2fbb15a2c7924b2dd288bfdc860c93154e4126 100644 (file)
                        <controller>wcf\form\ContactForm</controller>
                        <name language="de">Kontaktformular</name>
                        <name language="en">Contact Form</name>
+                       <handler>wcf\system\page\handler\ContactFormPageHandler</handler>
                        <options>module_contact_form</options>
                        <content language="en">
                                <title>Contact</title>
index ca2ef2a0e87bfaba27e951518c3551c671b30b5a..b0489d26811143f81a529b88f32976112297c882 100644 (file)
                        </dd>
                </dl>
                
-               {if $action != 'edit' || !$recipient->isAdministrator}
-                       <dl>
-                               <dt></dt>
-                               <dd>
-                                       <label><input type="checkbox" name="isDisabled" value="1"{if $isDisabled} checked{/if}> {lang}wcf.acp.contact.recipient.isDisabled{/lang}</label>
-                               </dd>
-                       </dl>
-               {/if}
+               <dl>
+                       <dt></dt>
+                       <dd>
+                               <label><input type="checkbox" name="isDisabled" value="1"{if $isDisabled} checked{/if}> {lang}wcf.acp.contact.recipient.isDisabled{/lang}</label>
+                       </dd>
+               </dl>
                
                {event name='dataFields'}
        </div>
index 3f1c0ccf88f37776d7352db2a877bfd64ee089e8..0bf0a32613deeb7adb2a49ba2e80a0b1d2de344b 100644 (file)
                                                
                                                <span class="statusDisplay sortableButtonContainer">
                                                        <span class="icon icon16 fa-arrows sortableNodeHandle"></span>
-                                                       {if $recipient->isAdministrator}
-                                                               <span class="icon icon16 fa-check-square-o disabled"></span>
-                                                       {else}
-                                                               <span class="icon icon16 fa-{if !$recipient->isDisabled}check-square-o{else}square-o{/if} jsToggleButton jsTooltip pointer" title="{lang}wcf.global.button.{if $recipient->isDisabled}enable{else}disable{/if}{/lang}" data-object-id="{@$recipient->recipientID}"></span>
-                                                       {/if}
+                                                       <span class="icon icon16 fa-{if !$recipient->isDisabled}check-square-o{else}square-o{/if} jsToggleButton jsTooltip pointer" title="{lang}wcf.global.button.{if $recipient->isDisabled}enable{else}disable{/if}{/lang}" data-object-id="{@$recipient->recipientID}"></span>
                                                        <a href="{link controller='ContactRecipientEdit' id=$recipient->recipientID}{/link}"><span title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip icon icon16 fa-pencil"></a>
                                                        {if $recipient->originIsSystem}
                                                                <span class="icon icon16 fa-times disabled"></span>
index 82e4e37a5ac1d3e4afcfad951dcd727a74f3d07c..102cb839caf8d8ee436b0c27933248ffb3ad01ea 100644 (file)
@@ -60,18 +60,6 @@ class ContactRecipientEditForm extends ContactRecipientAddForm
         }
     }
 
-    /**
-     * @inheritDoc
-     */
-    public function validate()
-    {
-        parent::validate();
-
-        if ($this->recipient->isAdministrator) {
-            $this->isDisabled = 0;
-        }
-    }
-
     /**
      * @inheritDoc
      */
index 1fd016483e343c1bafe198c00838612620f917a4..55399896211199656c31dcecbff05404dcebef7e 100644 (file)
@@ -71,12 +71,6 @@ class ContactRecipientAction extends AbstractDatabaseObjectAction implements ISo
     public function validateToggle()
     {
         parent::validateUpdate();
-
-        foreach ($this->getObjects() as $object) {
-            if ($object->isAdministrator) {
-                throw new PermissionDeniedException();
-            }
-        }
     }
 
     /**
index ef2b97fb40d34cf42b7232a6bf9747ef6d655a60..343be8b52dc7e7fad27b40fdd7157921c5f8efb4 100644 (file)
@@ -92,7 +92,7 @@ class ContactForm extends AbstractCaptchaForm
         $this->recipientList->getConditionBuilder()->add("contact_recipient.isDisabled = ?", [0]);
         $this->recipientList->readObjects();
 
-        if (\count($this->recipientList) < 0) {
+        if (!\count($this->recipientList)) {
             throw new IllegalLinkException();
         }
 
diff --git a/wcfsetup/install/files/lib/system/page/handler/ContactFormPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/ContactFormPageHandler.class.php
new file mode 100644 (file)
index 0000000..0f8c629
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace wcf\system\page\handler;
+
+use wcf\system\WCF;
+
+/**
+ * Hides the contact form if no recipients are enabled.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Page\Handler
+ * @since   5.4
+ */
+class ContactFormPageHandler extends AbstractMenuPageHandler
+{
+    /**
+     * @inheritDoc
+     */
+    public function isVisible($objectID = null)
+    {
+        $sql = "SELECT EXISTS(
+                    SELECT  *
+                    FROM    wcf" . WCF_N . "_contact_recipient
+                    WHERE   isDisabled = ?
+                )";
+        $statement = WCF::getDB()->prepareStatement($sql);
+        $statement->execute([0]);
+
+        return $statement->fetchSingleColumn();
+    }
+}