Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
drupal
Commits
b7d593bb
Commit
b7d593bb
authored
Jun 02, 2017
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2878483
by dawehner, Berdir, kalpaitch: loadEntityByUuid() should skip access checks
parent
ea67660b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
0 deletions
+71
-0
core/lib/Drupal/Core/Entity/EntityStorageBase.php
core/lib/Drupal/Core/Entity/EntityStorageBase.php
+1
-0
core/modules/system/tests/modules/entity_test/entity_test.module
...dules/system/tests/modules/entity_test/entity_test.module
+15
-0
core/modules/system/tests/modules/entity_test/entity_test.permissions.yml
...tem/tests/modules/entity_test/entity_test.permissions.yml
+2
-0
core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php
...s/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php
+53
-0
No files found.
core/lib/Drupal/Core/Entity/EntityStorageBase.php
View file @
b7d593bb
...
...
@@ -499,6 +499,7 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value
public
function
loadByProperties
(
array
$values
=
[])
{
// Build a query to fetch the entity IDs.
$entity_query
=
$this
->
getQuery
();
$entity_query
->
accessCheck
(
FALSE
);
$this
->
buildPropertyQuery
(
$entity_query
,
$values
);
$result
=
$entity_query
->
execute
();
return
$result
?
$this
->
loadMultiple
(
$result
)
:
[];
...
...
core/modules/system/tests/modules/entity_test/entity_test.module
View file @
b7d593bb
...
...
@@ -6,6 +6,7 @@
*/
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Database\Query\AlterableInterface
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\FieldableEntityInterface
;
...
...
@@ -792,3 +793,17 @@ function entity_test_entity_test_create_access(AccountInterface $account, $conte
// No opinion.
return
AccessResult
::
neutral
();
}
/**
* Implements hook_query_entity_test_access_alter().
*/
function
entity_test_query_entity_test_access_alter
(
AlterableInterface
$query
)
{
if
(
!
\Drupal
::
state
()
->
get
(
'entity_test_query_access'
))
{
return
;
}
/** @var \Drupal\Core\Database\Query\Select|\Drupal\Core\Database\Query\AlterableInterface $query */
if
(
!
\Drupal
::
currentUser
()
->
hasPermission
(
'view all entity_test_query_access entities'
))
{
$query
->
condition
(
'entity_test_query_access.name'
,
'published entity'
);
}
}
core/modules/system/tests/modules/entity_test/entity_test.permissions.yml
View file @
b7d593bb
...
...
@@ -12,6 +12,8 @@ administer entity_test_with_bundle content:
description
:
'
administer
entity_test_with_bundle
content'
administer entity_test_bundle content
:
title
:
'
administer
entity_test_bundle
content'
view all entity_test_query_access entities
:
title
:
'
view
all
entity_test_query_access
entities'
permission_callbacks
:
-
\Drupal\entity_test\EntityTestPermissions::entityTestBundlePermissions
core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php
0 → 100644
View file @
b7d593bb
<?php
namespace
Drupal\KernelTests\Core\Entity
;
use
Drupal\entity_test\Entity\EntityTest
;
use
Drupal\KernelTests\KernelTestBase
;
/**
* Tests loading entities by UUID.
*
* @group entity
*/
class
EntityLoadByUuidTest
extends
KernelTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'entity_test'
,
'user'
];
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
installEntitySchema
(
'user'
);
$this
->
installEntitySchema
(
'entity_test'
);
}
/**
* Ensures that ::loadEntityByUuid() doesn't apply access checking.
*/
public
function
testLoadEntityByUuidAccessChecking
()
{
\Drupal
::
state
()
->
set
(
'entity_test_query_access'
,
TRUE
);
// Create two test entities.
$entity_0
=
EntityTest
::
create
([
'type'
=>
'entity_test'
,
'name'
=>
'published entity'
]);
$entity_0
->
save
();
$entity_1
=
EntityTest
::
create
([
'type'
=>
'entity_test'
,
'name'
=>
'unpublished entity'
]);
$entity_1
->
save
();
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
$repository
=
\Drupal
::
service
(
'entity.repository'
);
$this
->
assertEquals
(
$entity_0
->
id
(),
$repository
->
loadEntityByUuid
(
'entity_test'
,
$entity_0
->
uuid
())
->
id
());
$this
->
assertEquals
(
$entity_1
->
id
(),
$repository
->
loadEntityByUuid
(
'entity_test'
,
$entity_1
->
uuid
())
->
id
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment