Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
linkit
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
linkit
Merge requests
!4
Issue
#3049946
: Unpublished nodes not included even when option is selected
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3049946
: Unpublished nodes not included even when option is selected
issue/linkit-3049946:3049946-unpublished-nodes-not-included
into
8.x-5.x
Overview
0
Commits
4
Pipelines
0
Changes
1
Open
Stefanos Petrakis
requested to merge
issue/linkit-3049946:3049946-unpublished-nodes-not-included
into
8.x-5.x
4 years ago
Overview
0
Commits
4
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
8.x-5.x
version 2
2c65ee3d
4 years ago
version 1
d75a0cc0
4 years ago
8.x-5.x (HEAD)
and
latest version
latest version
5aad04a6
4 commits,
4 years ago
version 2
2c65ee3d
2 commits,
4 years ago
version 1
d75a0cc0
1 commit,
4 years ago
1 file
+
49
−
19
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/Linkit/Matcher/NodeMatcher.php
+
49
−
19
Options
@@ -85,30 +85,60 @@ class NodeMatcher extends EntityMatcher {
protected
function
buildEntityQuery
(
$search_string
)
{
$query
=
parent
::
buildEntityQuery
(
$search_string
);
if
(
$this
->
configuration
[
'include_unpublished'
]
==
FALSE
)
{
$query
->
condition
(
'status'
,
NodeInterface
::
PUBLISHED
);
// Default case: Users can only see published nodes.
$condition
=
$query
->
andConditionGroup
()
->
condition
(
'status'
,
NodeInterface
::
PUBLISHED
);
// We can skip filtering for these cases.
if
(
$this
->
currentUserCanViewAllContent
()
||
$this
->
currentUserHasNodeGrants
())
{
$condition
=
NULL
;
}
elseif
(
count
(
$this
->
moduleHandler
->
getImplementations
(
'node_grants'
))
===
0
)
{
if
((
$this
->
currentUser
->
hasPermission
(
'bypass node access'
)
||
$this
->
currentUser
->
hasPermission
(
'view any unpublished content'
)))
{
// User can see all content, no check necessary.
}
elseif
(
$this
->
currentUser
->
hasPermission
(
'view own unpublished content'
))
{
// Users with "view own unpublished content" can see only their own.
if
(
$this
->
configuration
[
'include_unpublished'
]
==
TRUE
)
{
$or_condition
=
$query
->
orConditionGroup
()
->
condition
(
'status'
,
NodeInterface
::
PUBLISHED
)
->
condition
(
'uid'
,
$this
->
currentUser
->
id
());
$query
->
condition
(
$or_condition
);
}
}
// OR-based filtering for holders of 'view own unpublished content'.
elseif
(
$this
->
currentUserCanViewOwnUnpublishedContent
())
{
$condition
=
$query
->
orConditionGroup
()
->
condition
(
'status'
,
NodeInterface
::
PUBLISHED
)
->
condition
(
'uid'
,
$this
->
currentUser
->
id
());
}
else
{
// All other users should only get published results.
$query
->
condition
(
'status'
,
NodeInterface
::
PUBLISHED
);
// Add the generated condition, if one is set.
if
(
$condition
)
{
$query
->
condition
(
$condition
);
}
return
$query
;
}
/**
* Checks whether the current user is allowed to view all content.
*
* This check takes 'include_unpublished' into account.
*/
protected
function
currentUserCanViewAllContent
()
{
// Some users can see all content.
return
$this
->
configuration
[
'include_unpublished'
]
&&
(
$this
->
currentUser
->
hasPermission
(
'bypass node access'
)
||
$this
->
currentUser
->
hasPermission
(
'view any unpublished content'
));
}
/**
* Checks whether any module grants global 'view' access to the current user.
*
* This check takes 'include_unpublished' into account.
*/
protected
function
currentUserHasNodeGrants
()
{
return
$this
->
configuration
[
'include_unpublished'
]
&&
$this
->
moduleHandler
->
getImplementations
(
'node_grants'
)
&&
$this
->
entityTypeManager
->
getAccessControlHandler
(
'node'
)
->
checkAllGrants
(
$this
->
currentUser
);
}
/**
* Checks whether the user is allowed to view own nodes.
*
* This check takes 'include_unpublished' into account.
*/
protected
function
currentUserCanViewOwnUnpublishedContent
()
{
return
$this
->
configuration
[
'include_unpublished'
]
&&
$this
->
currentUser
->
hasPermission
(
'view own unpublished content'
);
}
}
Loading