Fix permission check on protection log
*I2341e6f inverted the permission check, such that now the link is only shown to unprivileged users Bug: T234017 Change-Id: I0977f1ab1a72840303aeca2367a30546d83117d4
This commit is contained in:
parent
825d66bfa4
commit
1d59041fc8
2 changed files with 43 additions and 1 deletions
|
|
@ -101,7 +101,7 @@ class ProtectLogFormatter extends LogFormatter {
|
|||
];
|
||||
|
||||
// Show change protection link
|
||||
if ( !MediaWikiServices::getInstance()
|
||||
if ( MediaWikiServices::getInstance()
|
||||
->getPermissionManager()
|
||||
->userHasRight( $this->context->getUser(), 'protect' )
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -428,4 +428,46 @@ class ProtectLogFormatterTest extends LogFormatterTestCase {
|
|||
public function testMoveProtLogDatabaseRows( $row, $extra ) {
|
||||
$this->doTestLogFormatter( $row, $extra );
|
||||
}
|
||||
|
||||
public function provideGetActionLinks() {
|
||||
yield [
|
||||
[ 'protect' ],
|
||||
true
|
||||
];
|
||||
yield [
|
||||
[],
|
||||
false
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $permissions
|
||||
* @param bool $shouldMatch
|
||||
* @dataProvider provideGetActionLinks
|
||||
* @covers ProtectLogFormatter::getActionLinks
|
||||
*/
|
||||
public function testGetActionLinks( array $permissions, $shouldMatch ) {
|
||||
RequestContext::resetMain();
|
||||
$user = $this->getTestUser()->getUser();
|
||||
$this->overrideUserPermissions( $user, $permissions );
|
||||
$row = $this->expandDatabaseRow( [
|
||||
'type' => 'protect',
|
||||
'action' => 'unprotect',
|
||||
'comment' => 'unprotect comment',
|
||||
'namespace' => NS_MAIN,
|
||||
'title' => 'ProtectPage',
|
||||
'params' => [],
|
||||
], false );
|
||||
$context = new RequestContext();
|
||||
$context->setUser( $user );
|
||||
$formatter = LogFormatter::newFromRow( $row );
|
||||
$formatter->setContext( $context );
|
||||
if ( $shouldMatch ) {
|
||||
$this->assertStringMatchesFormat(
|
||||
'%Aaction=protect%A', $formatter->getActionLinks() );
|
||||
} else {
|
||||
$this->assertStringNotMatchesFormat(
|
||||
'%Aaction=protect%A', $formatter->getActionLinks() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue