Add usesMultifactor condition for user search in acp
authorjoshuaruesweg <ruesweg@woltlab.com>
Sun, 22 Nov 2020 11:03:34 +0000 (12:03 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sun, 22 Nov 2020 11:03:34 +0000 (12:03 +0100)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/condition/UserMultifactorCondition.class.php

index 0a015a876eb649a4d5748f2181ebf16ee2e9857f..2b70815363f986547b007df06fa61e5a67c4108a 100644 (file)
                        <classname>wcf\system\condition\UserOptionsCondition</classname>
                        <conditiongroup>userOptions</conditiongroup>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.user.multifactor</name>
+                       <definitionname>com.woltlab.wcf.condition.userSearch</definitionname>
+                       <classname>wcf\system\condition\UserMultifactorCondition</classname>
+                       <conditiongroup>general</conditiongroup>
+               </type>
                <!-- /user search conditions -->
                <!-- box controllers -->
                <type>
index cfec88c676035bb6b88307393c5f4bcd16703206..6276c2465ca0d5bd11563ee06a8625149adffd87 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 namespace wcf\system\condition;
 use wcf\data\condition\Condition;
+use wcf\data\DatabaseObjectList;
+use wcf\data\user\User;
+use wcf\data\user\UserList;
+use wcf\system\exception\InvalidObjectArgument;
 use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 
@@ -13,7 +17,9 @@ use wcf\system\WCF;
  * @package    WoltLabSuite\Core\System\Condition
  * @since       5.4
  */
-class UserMultifactorCondition extends AbstractSingleFieldCondition implements IContentCondition {
+class UserMultifactorCondition extends AbstractSingleFieldCondition implements IContentCondition, IObjectListCondition, IUserCondition {
+       use TObjectListUserCondition;
+       
        /**
         * @inheritDoc
         */
@@ -108,4 +114,28 @@ HTML;
        public function showContent(Condition $condition) {
                return (($condition->usesMultifactor && WCF::getUser()->multifactorActive) || (!$condition->usesMultifactor && !WCF::getUser()->multifactorActive));
        }
+       
+       /**
+        * @inheritDoc
+        */
+       public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
+               if (!($objectList instanceof UserList)) {
+                       throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
+               }
+               
+               if (isset($conditionData['usesMultifactor'])) {
+                       $objectList->getConditionBuilder()->add('user_table.multifactorActive = ?', [$conditionData['usesMultifactor']]);
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function checkUser(Condition $condition, User $user) {
+               if ($condition->usesMultifactor !== null && $user->multifactorActive != $condition->usesMultifactor) {
+                       return false;
+               }
+               
+               return true;
+       }
 }