mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Degroup: Return early if user is a temporary user
Treat temporary users the same as IP users. Neither has user groups, so return early for both. Bug: T335062 Change-Id: I20b48608cf6ba5f8e8e36a378d66c603d84b032f
This commit is contained in:
parent
aa5b57f8a5
commit
573838efc5
|
@ -11,6 +11,7 @@ use MediaWiki\Extension\AbuseFilter\Variables\UnsetVariableException;
|
|||
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
||||
use MediaWiki\User\UserGroupManager;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserNameUtils;
|
||||
use MessageLocalizer;
|
||||
use TitleValue;
|
||||
|
||||
|
@ -27,6 +28,9 @@ class Degroup extends Consequence implements HookAborterConsequence, ReversibleC
|
|||
/** @var UserGroupManager */
|
||||
private $userGroupManager;
|
||||
|
||||
/** @var UserNameUtils */
|
||||
private $userNameUtils;
|
||||
|
||||
/** @var FilterUser */
|
||||
private $filterUser;
|
||||
|
||||
|
@ -37,6 +41,7 @@ class Degroup extends Consequence implements HookAborterConsequence, ReversibleC
|
|||
* @param Parameters $params
|
||||
* @param VariableHolder $vars
|
||||
* @param UserGroupManager $userGroupManager
|
||||
* @param UserNameUtils $userNameUtils
|
||||
* @param FilterUser $filterUser
|
||||
* @param MessageLocalizer $messageLocalizer
|
||||
*/
|
||||
|
@ -44,12 +49,14 @@ class Degroup extends Consequence implements HookAborterConsequence, ReversibleC
|
|||
Parameters $params,
|
||||
VariableHolder $vars,
|
||||
UserGroupManager $userGroupManager,
|
||||
UserNameUtils $userNameUtils,
|
||||
FilterUser $filterUser,
|
||||
MessageLocalizer $messageLocalizer
|
||||
) {
|
||||
parent::__construct( $params );
|
||||
$this->vars = $vars;
|
||||
$this->userGroupManager = $userGroupManager;
|
||||
$this->userNameUtils = $userNameUtils;
|
||||
$this->filterUser = $filterUser;
|
||||
$this->messageLocalizer = $messageLocalizer;
|
||||
}
|
||||
|
@ -60,7 +67,10 @@ class Degroup extends Consequence implements HookAborterConsequence, ReversibleC
|
|||
public function execute(): bool {
|
||||
$user = $this->parameters->getUser();
|
||||
|
||||
if ( !$user->isRegistered() ) {
|
||||
if (
|
||||
!$user->isRegistered() ||
|
||||
$this->userNameUtils->isTemp( $user->getName() )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,14 @@ class ConsequencesFactory {
|
|||
* @return Degroup
|
||||
*/
|
||||
public function newDegroup( Parameters $params, VariableHolder $vars ): Degroup {
|
||||
return new Degroup( $params, $vars, $this->userGroupManager, $this->filterUser, $this->messageLocalizer );
|
||||
return new Degroup(
|
||||
$params,
|
||||
$vars,
|
||||
$this->userGroupManager,
|
||||
$this->userNameUtils,
|
||||
$this->filterUser,
|
||||
$this->messageLocalizer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ use MediaWiki\Extension\AbuseFilter\FilterUser;
|
|||
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
||||
use MediaWiki\User\UserGroupManager;
|
||||
use MediaWiki\User\UserIdentityValue;
|
||||
use MediaWiki\User\UserNameUtils;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Degroup
|
||||
|
@ -47,6 +48,7 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
VariableHolder::newFromArray( [ 'user_groups' => [ '*', 'user', 'sysop' ] ] ),
|
||||
$userGroupManager,
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$filterUser,
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
@ -68,6 +70,7 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
VariableHolder::newFromArray( [ 'user_groups' => [ '*', 'user' ] ] ),
|
||||
$userGroupManager,
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$this->createMock( FilterUser::class ),
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
@ -95,6 +98,7 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
new VariableHolder(),
|
||||
$userGroupManager,
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$filterUser,
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
@ -116,6 +120,32 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
$this->createMock( VariableHolder::class ),
|
||||
$userGroupManager,
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$filterUser,
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
$this->assertFalse( $degroup->execute() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function testExecute_temp() {
|
||||
$user = new UserIdentityValue( 10, '*12345' );
|
||||
$params = $this->provideGetMessageParameters( $user )->current()[0];
|
||||
$userGroupManager = $this->createMock( UserGroupManager::class );
|
||||
$userGroupManager->expects( $this->never() )->method( $this->anything() );
|
||||
$userNameUtils = $this->createMock( UserNameUtils::class );
|
||||
$userNameUtils->method( 'isTemp' )
|
||||
->willReturn( true );
|
||||
$filterUser = $this->createMock( FilterUser::class );
|
||||
$filterUser->expects( $this->never() )->method( $this->anything() );
|
||||
|
||||
$degroup = new Degroup(
|
||||
$params,
|
||||
$this->createMock( VariableHolder::class ),
|
||||
$userGroupManager,
|
||||
$userNameUtils,
|
||||
$filterUser,
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
@ -152,6 +182,7 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
VariableHolder::newFromArray( [ 'user_groups' => $hadGroups ] ),
|
||||
$userGroupManager,
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$this->createMock( FilterUser::class ),
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
@ -172,6 +203,7 @@ class DegroupTest extends MediaWikiIntegrationTestCase {
|
|||
$params,
|
||||
new VariableHolder(),
|
||||
$this->createMock( UserGroupManager::class ),
|
||||
$this->createMock( UserNameUtils::class ),
|
||||
$this->createMock( FilterUser::class ),
|
||||
$this->getMsgLocalizer()
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue