Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443205
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443205
Commits
00ed1ed4
Unverified
Commit
00ed1ed4
authored
6 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2888853
by vaplas, Wim Leers: FileAccessControlHandler cacheability metadata inaccurate
parent
0d6d22af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/file/src/FileAccessControlHandler.php
+2
-2
2 additions, 2 deletions
core/modules/file/src/FileAccessControlHandler.php
core/modules/file/tests/src/Kernel/AccessTest.php
+24
-0
24 additions, 0 deletions
core/modules/file/tests/src/Kernel/AccessTest.php
with
26 additions
and
2 deletions
core/modules/file/src/FileAccessControlHandler.php
+
2
−
2
View file @
00ed1ed4
...
...
@@ -52,11 +52,11 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
// services can be more properly injected.
$allowed_fids
=
\Drupal
::
service
(
'session'
)
->
get
(
'anonymous_allowed_file_ids'
,
[]);
if
(
!
empty
(
$allowed_fids
[
$entity
->
id
()]))
{
return
AccessResult
::
allowed
();
return
AccessResult
::
allowed
()
->
addCacheContexts
([
'session'
,
'user'
])
;
}
}
else
{
return
AccessResult
::
allowed
();
return
AccessResult
::
allowed
()
->
addCacheContexts
([
'user'
])
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/file/tests/src/Kernel/AccessTest.php
+
24
−
0
View file @
00ed1ed4
...
...
@@ -123,4 +123,28 @@ public function testCreateAccess() {
$this
->
assertFalse
(
$this
->
file
->
access
(
'create'
));
}
/**
* Tests cacheability metadata.
*/
public
function
testFileCacheability
()
{
$file
=
File
::
create
([
'filename'
=>
'green-scarf'
,
'uri'
=>
'private://green-scarf'
,
'filemime'
=>
'text/plain'
,
'status'
=>
FILE_STATUS_PERMANENT
,
]);
$file
->
save
();
\Drupal
::
service
(
'session'
)
->
set
(
'anonymous_allowed_file_ids'
,
[
$file
->
id
()
=>
$file
->
id
()]);
$account
=
User
::
getAnonymousUser
();
$file
->
setOwnerId
(
$account
->
id
())
->
save
();
$this
->
assertSame
([
'session'
,
'user'
],
$file
->
access
(
'view'
,
$account
,
TRUE
)
->
getCacheContexts
());
$this
->
assertSame
([
'session'
,
'user'
],
$file
->
access
(
'download'
,
$account
,
TRUE
)
->
getCacheContexts
());
$account
=
$this
->
user1
;
$file
->
setOwnerId
(
$account
->
id
())
->
save
();
$this
->
assertSame
([
'user'
],
$file
->
access
(
'view'
,
$account
,
TRUE
)
->
getCacheContexts
());
$this
->
assertSame
([
'user'
],
$file
->
access
(
'download'
,
$account
,
TRUE
)
->
getCacheContexts
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment