From 1df74c2e2b0934ef21d426a71557b3dfde680a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taavi=20V=C3=A4=C3=A4n=C3=A4nen?= Date: Thu, 23 Nov 2023 20:55:01 +0200 Subject: [PATCH] Replace more users of getModule() for enabled checks Bug: T242031 Change-Id: I602b5c0cf36096a7fc41116874e776277bf6f833 --- src/Hook/HookHandler.php | 4 ++-- src/Special/VerifyOATHForUser.php | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Hook/HookHandler.php b/src/Hook/HookHandler.php index b374716f..d904d523 100644 --- a/src/Hook/HookHandler.php +++ b/src/Hook/HookHandler.php @@ -101,7 +101,7 @@ class HookHandler implements // If there is no existing module for the user, and the user is not allowed to enable it, // we have nothing to show. if ( - $oathUser->getModule() === null && + !$oathUser->isTwoFactorAuthEnabled() && !$this->permissionManager->userHasRight( $user, 'oathauth-enable' ) ) { return true; @@ -182,7 +182,7 @@ class HookHandler implements } $oathUser = $this->userRepo->findByUser( $user ); - if ( $oathUser->getModule() === null ) { + if ( !$oathUser->isTwoFactorAuthEnabled() ) { // Not enabled, strip the groups return $intersect; } diff --git a/src/Special/VerifyOATHForUser.php b/src/Special/VerifyOATHForUser.php index 1761513d..0dafbab3 100644 --- a/src/Special/VerifyOATHForUser.php +++ b/src/Special/VerifyOATHForUser.php @@ -6,7 +6,6 @@ use ConfigException; use FormSpecialPage; use HTMLForm; use ManualLogEntry; -use MediaWiki\Extension\OATHAuth\IModule; use MediaWiki\Extension\OATHAuth\OATHUserRepository; use MediaWiki\Logger\LoggerFactory; use MediaWiki\User\UserFactory; @@ -119,14 +118,9 @@ class VerifyOATHForUser extends FormSpecialPage { } $oathUser = $this->userRepo->findByUser( $user ); - if ( !( $oathUser->getModule() instanceof IModule ) || - !$oathUser->getModule()->isEnabled( $oathUser ) ) { - $result = self::OATHAUTH_NOT_ENABLED; - } else { - $result = self::OATHAUTH_IS_ENABLED; - } - - $this->enabledStatus = $result; + $this->enabledStatus = $oathUser->isTwoFactorAuthEnabled() + ? self::OATHAUTH_IS_ENABLED + : self::OATHAUTH_NOT_ENABLED; // message used: logentry-oath-verify $logEntry = new ManualLogEntry( 'oath', 'verify' );