Improve ManageForm

Make sure that particular form is only loaded when it actually makes sense
for it to load, not when its just requested.

Bug: T218211
Change-Id: Ibae0279451b4a6a4a1d1ce212bbbbf919900a46d
This commit is contained in:
Dejan Savuljesku 2019-09-03 14:09:31 +02:00
parent 4b06d3a66a
commit 36485440ee

View file

@ -4,6 +4,7 @@ namespace MediaWiki\Extension\OATHAuth\Module;
use MediaWiki\Auth\SecondaryAuthenticationProvider; use MediaWiki\Auth\SecondaryAuthenticationProvider;
use MediaWiki\Extension\OATHAuth\HTMLForm\IManageForm; use MediaWiki\Extension\OATHAuth\HTMLForm\IManageForm;
use MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm;
use MediaWiki\Extension\OATHAuth\IAuthKey; use MediaWiki\Extension\OATHAuth\IAuthKey;
use MediaWiki\Extension\OATHAuth\IModule; use MediaWiki\Extension\OATHAuth\IModule;
use MediaWiki\Extension\OATHAuth\Key\TOTPKey; use MediaWiki\Extension\OATHAuth\Key\TOTPKey;
@ -12,7 +13,6 @@ use MediaWiki\Extension\OATHAuth\OATHUserRepository;
use MediaWiki\Extension\OATHAuth\Special\OATHManage; use MediaWiki\Extension\OATHAuth\Special\OATHManage;
use MWException; use MWException;
use MediaWiki\Extension\OATHAuth\HTMLForm\TOTPEnableForm; use MediaWiki\Extension\OATHAuth\HTMLForm\TOTPEnableForm;
use MediaWiki\Extension\OATHAuth\HTMLForm\TOTPDisableForm;
use MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider; use MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider;
class TOTP implements IModule { class TOTP implements IModule {
@ -107,14 +107,14 @@ class TOTP implements IModule {
* @return IManageForm|null * @return IManageForm|null
*/ */
public function getManageForm( $action, OATHUser $user, OATHUserRepository $repo ) { public function getManageForm( $action, OATHUser $user, OATHUserRepository $repo ) {
switch ( $action ) { $isEnabledForUser = $user->getModule() instanceof self;
case OATHManage::ACTION_ENABLE: if ( $action === OATHManage::ACTION_ENABLE && !$isEnabledForUser ) {
return new TOTPEnableForm( $user, $repo, $this ); return new TOTPEnableForm( $user, $repo, $this );
case OATHManage::ACTION_DISABLE:
return new TOTPDisableForm( $user, $repo, $this );
default:
return null;
} }
if ( $action === OATHManage::ACTION_DISABLE && $isEnabledForUser ) {
return new TOTPDisableForm( $user, $repo, $this );
}
return null;
} }
/** /**