WMDE-leszek has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/362241 )
Change subject: EntityContentFactory does not implement EntityPermissionChecker ...................................................................... EntityContentFactory does not implement EntityPermissionChecker For wiki page based storage use WikiPageEntityStorePermissionChecker. Change-Id: Ie101617a89c3d4df549aa3e56fa04f8d71c93236 --- M repo/includes/Content/EntityContentFactory.php M repo/tests/phpunit/includes/Content/EntityContentFactoryTest.php 2 files changed, 1 insertion(+), 225 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/41/362241/1 diff --git a/repo/includes/Content/EntityContentFactory.php b/repo/includes/Content/EntityContentFactory.php index b5b61c4..f54d796 100644 --- a/repo/includes/Content/EntityContentFactory.php +++ b/repo/includes/Content/EntityContentFactory.php @@ -6,9 +6,7 @@ use MediaWiki\Interwiki\InterwikiLookup; use MWException; use OutOfBoundsException; -use Status; use Title; -use User; use Wikibase\Content\EntityInstanceHolder; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; @@ -17,7 +15,6 @@ use Wikibase\EntityContent; use Wikibase\Repo\Store\EntityTitleStoreLookup; use Wikibase\Lib\Store\StorageException; -use Wikibase\Repo\Store\EntityPermissionChecker; use Wikibase\Store\EntityIdLookup; use Wikimedia\Assert\Assert; @@ -29,7 +26,7 @@ * @author Daniel Kinzler * @author Bene* < benestar.wikime...@gmail.com > */ -class EntityContentFactory implements EntityTitleStoreLookup, EntityIdLookup, EntityPermissionChecker { +class EntityContentFactory implements EntityTitleStoreLookup, EntityIdLookup { /** * @var string[] Entity type ID to content model ID mapping. @@ -278,113 +275,6 @@ public function newFromRedirect( EntityRedirect $redirect ) { $handler = $this->getContentHandlerForType( $redirect->getEntityId()->getEntityType() ); return $handler->makeEntityRedirectContent( $redirect ); - } - - /** - * @param User $user - * @param string $permission - * @param Title $entityPage - * @param string $quick - * - * //XXX: would be nice to be able to pass the $short flag too, - * as used by getUserPermissionsErrorsInternal. But Title doesn't expose that. - * @todo Move to a separate service (merge into WikiPageEntityStore?) - * - * @return Status a status object representing the check's result. - */ - protected function getPermissionStatus( User $user, $permission, Title $entityPage, $quick = '' ) { - $errors = $entityPage->getUserPermissionsErrors( $permission, $user, $quick !== 'quick' ); - return $this->getStatusForPermissionErrors( $errors ); - } - - /** - * @param string[] $errors - * - * @return Status - */ - protected function getStatusForPermissionErrors( array $errors ) { - $status = Status::newGood(); - - foreach ( $errors as $error ) { - call_user_func_array( array( $status, 'fatal' ), $error ); - $status->setResult( false ); - } - - return $status; - } - - /** - * @see EntityPermissionChecker::getPermissionStatusForEntityId - * - * @param User $user - * @param string $permission - * @param EntityId $entityId - * @param string $quick - * - * @return Status a status object representing the check's result. - * - * @todo Move to a separate service (merge into WikiPageEntityStore?) - */ - public function getPermissionStatusForEntityId( User $user, $permission, EntityId $entityId, $quick = '' ) { - $title = $this->getTitleForId( $entityId ); - return $this->getPermissionStatus( $user, $permission, $title, $quick ); - } - - /** - * @see EntityPermissionChecker::getPermissionStatusForEntityType - * - * @param User $user - * @param string $permission - * @param string $entityType - * @param string $quick - * - * @return Status a status object representing the check's result. - * - * @todo Move to a separate service (merge into WikiPageEntityStore?) - */ - public function getPermissionStatusForEntityType( User $user, $permission, $entityType, $quick = '' ) { - $ns = $this->getNamespaceForType( $entityType ); - $dummyTitle = Title::makeTitle( $ns, '/' ); - - return $this->getPermissionStatus( $user, $permission, $dummyTitle, $quick ); - } - - /** - * @see EntityPermissionChecker::getPermissionStatusForEntity - * - * @note When checking for the 'edit' permission, this will check the 'createpage' - * permission first in case the entity does not yet exist (i.e. if $entity->getId() - * returns null). - * - * @param User $user - * @param string $permission - * @param EntityDocument $entity - * @param string $quick - * - * @return Status a status object representing the check's result. - * - * @todo Move to a separate service (merge into WikiPageEntityStore?) - */ - public function getPermissionStatusForEntity( User $user, $permission, EntityDocument $entity, $quick = '' ) { - $id = $entity->getId(); - $status = null; - - if ( !$id ) { - $entityType = $entity->getType(); - - if ( $permission === 'edit' ) { - // for editing a non-existing page, check the createpage permission - $status = $this->getPermissionStatusForEntityType( $user, 'createpage', $entityType, $quick ); - } - - if ( !$status || $status->isOK() ) { - $status = $this->getPermissionStatusForEntityType( $user, $permission, $entityType, $quick ); - } - } else { - $status = $this->getPermissionStatusForEntityId( $user, $permission, $id, $quick ); - } - - return $status; } } diff --git a/repo/tests/phpunit/includes/Content/EntityContentFactoryTest.php b/repo/tests/phpunit/includes/Content/EntityContentFactoryTest.php index 43a2ae8..2776d9a 100644 --- a/repo/tests/phpunit/includes/Content/EntityContentFactoryTest.php +++ b/repo/tests/phpunit/includes/Content/EntityContentFactoryTest.php @@ -15,7 +15,6 @@ use Wikibase\DataModel\Entity\PropertyId; use Wikibase\Repo\Content\EntityContentFactory; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Repo\Tests\PermissionsHelper; /** * @covers Wikibase\Repo\Content\EntityContentFactory @@ -204,119 +203,6 @@ $this->setExpectedException( OutOfBoundsException::class ); $factory->getEntityHandlerForContentModel( 'foo' ); - } - - public function provideGetPermissionStatusForEntity() { - return array( - 'read allowed for non-existing entity' => array( - 'read', - array( 'read' => true ), - null, - array( - 'getPermissionStatusForEntity' => true, - 'getPermissionStatusForEntityType' => true, - ), - ), - 'edit and createpage allowed for new entity' => array( - 'edit', - array( 'read' => true, 'edit' => true, 'createpage' => true ), - null, - array( - 'getPermissionStatusForEntity' => true, - 'getPermissionStatusForEntityType' => true, - ), - ), - 'implicit createpage not allowed for new entity' => array( - 'edit', - array( 'read' => true, 'edit' => true, 'createpage' => false ), - null, - array( - 'getPermissionStatusForEntity' => false, // "createpage" is implicitly needed - 'getPermissionStatusForEntityType' => true, // "edit" is allowed for type - ), - ), - 'createpage not allowed' => array( - 'createpage', - array( 'read' => true, 'edit' => true, 'createpage' => false ), - null, - array( - 'getPermissionStatusForEntity' => false, // "createpage" is implicitly needed - 'getPermissionStatusForEntityType' => false, // "createpage" is not allowed - ), - ), - 'edit allowed for existing item' => array( - 'edit', - array( 'read' => true, 'edit' => true, 'createpage' => false ), - 'Q23', - array( - 'getPermissionStatusForEntity' => true, - 'getPermissionStatusForEntityType' => true, - 'getPermissionStatusForEntityId' => true, - ), - ), - 'edit not allowed' => array( - 'edit', - array( 'read' => true, 'edit' => false ), - 'Q23', - array( - 'getPermissionStatusForEntity' => false, - 'getPermissionStatusForEntityType' => false, - 'getPermissionStatusForEntityId' => false, - ), - ), - 'delete not allowed' => array( - 'delete', - array( 'read' => true, 'delete' => false ), - null, - array( - 'getPermissionStatusForEntity' => false, - 'getPermissionStatusForEntityType' => false, - ), - ), - ); - } - - /** - * @dataProvider provideGetPermissionStatusForEntity - */ - public function testGetPermissionStatusForEntity( $action, array $permissions, $id, array $expectations ) { - global $wgUser; - - $entity = new Item(); - - if ( $id ) { - // "exists" - $entity->setId( new ItemId( $id ) ); - } - - $this->stashMwGlobals( 'wgUser' ); - $this->stashMwGlobals( 'wgGroupPermissions' ); - - PermissionsHelper::applyPermissions( - // set permissions for implicit groups - array( '*' => $permissions, - 'user' => $permissions, - 'autoconfirmed' => $permissions, - 'emailconfirmed' => $permissions ), - array() // remove all groups not implied - ); - - $factory = $this->newFactory(); - - if ( isset( $expectations['getPermissionStatusForEntity'] ) ) { - $status = $factory->getPermissionStatusForEntity( $wgUser, $action, $entity ); - $this->assertEquals( $expectations['getPermissionStatusForEntity'], $status->isOK() ); - } - - if ( isset( $expectations['getPermissionStatusForEntityType'] ) ) { - $status = $factory->getPermissionStatusForEntityType( $wgUser, $action, $entity->getType() ); - $this->assertEquals( $expectations['getPermissionStatusForEntityType'], $status->isOK() ); - } - - if ( isset( $expectations['getPermissionStatusForEntityId'] ) ) { - $status = $factory->getPermissionStatusForEntityId( $wgUser, $action, $entity->getId() ); - $this->assertEquals( $expectations['getPermissionStatusForEntityId'], $status->isOK() ); - } } public function newFromEntityProvider() { -- To view, visit https://gerrit.wikimedia.org/r/362241 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie101617a89c3d4df549aa3e56fa04f8d71c93236 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: WMDE-leszek <leszek.mani...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits