Reviewed & tested by the community
Project:
Entity API
Version:
8.x-1.x-dev
Component:
Code - misc
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Jan 2019 at 21:45 UTC
Updated:
17 Aug 2026 at 12:08 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
themic8 commentedPatch attached.
Comment #3
themic8 commentedComment #5
themic8 commentedComment #6
themic8 commentedComment #7
markdcAlso in need of this. Is this patch suitable for prod?
Comment #8
megadesk3000 commentedHey together
In my opinion the patch is not doing the right thing. If the user has the permission "View any unpublished node" for example, the condition, that gets added, filters out all unpublished nodes that are owned by the user viewing the data, which is wrong.
In my opinion, if the user has the permission to view any unpublished entites of a specific type, neither the published condition nor the unpublished condition(s) need to be added here, since the user is able to see all entites no matter if they are published or unpublished.
What do others think about that?
Comment #9
megadesk3000 commentedFor now i created a new patch, that just removes the line, that filters out all entities owned by the user.
But as said above, it would be maybe better to not add those conditions at all. But cannot see, if this has other implications then.
Comment #11
themic8 commentedWith the way views are configured that line was needed to see everything.
Comment #12
themic8 commentedUpdated patch for latest entity module version -> 8.x-1.0-rc3
Comment #13
themic8 commentedThanks, megadesk3000, let me give it a try.
Comment #14
themic8 commentedMade a couple of updates and rerolled the patch.
Comment #15
manuel.adanThe entity ownership check is required to add the "view own unpublished ..." permission.
Here we have to add the "OR" rule to the conjunction, if not, only users with both permissions granted will have access.
This is required to properly check the "view own ..." permission.
Comment #16
piggito commentedThe cache context isn't the whole user entity but just user.permissions
I'm also fixing tests by adding the new
view any ...permission to the expected permissions in data provider.Comment #18
piggito commentedUpdating test as we now use
useranduser.permissionscache contexts when user is the owner of contentComment #20
piggito commentedFixing typo in last patch
Comment #21
andypostTests are there
Comment #22
ilya.no commentedAttaching patch with updated test for new permission.
Comment #23
siddhant.bhosale commentedComment #24
berdirseems like this could be put in the existing condition, but I'm not sure if this should be exposed unconditionally for every entity type, we don't really have a system to allow entity types to control that. but maybe we should.
the result of all this is then a condition that says (status = 0 OR status = 1). That's pretty pointless.
Instead, what we can do is add an extra condition to "if ($operation == 'view' && $has_published) {" that the user does not have the view any unpublished permission and if he does, we can simply skip all that logic.
Comment #25
mxr576@berdir can you add more details? What do you think it is missing exactly? I think this is something that "we should have" even if we do not have at this moment.
Thanks for the patch in #22, this was exactly what I was looking for.
Comment #26
berdirwhat I mean is that every entity type that uses the permission provider will get that new permission automatically, even if it is not useful, so with this and other extensions in the future, I'm wondering if we need more fine grained configuration to control what permissions you get.
Comment #27
mxr576Well, based on the current task that I am working on, I thought that "view any" would not be needed, then the client figured out that they need a new "viewer" role that can only view entities, also for content moderation the "view any" permission is needed. (Stay tuned, I am going to submit an issue/patch for that module too and reference it here ;) )
So I do not think that fine grained configuration is needed for this, if someone does not need it, it does not use it.
The
UncacheableEntityAccessControlHandleralso required some tweaking, since this is what I am using mostly in my code. Suggestions from #24 are still not included.Comment #28
mxr576...and the issue+patch for content moderation. As I saw there are quite some open issues related to how CM handles access checking.
Comment #29
s.messaris commentedThanks for the patch, I needed this for a project and #27 worked fine for me.
Comment #30
cobenashThanks.
#27 looks good for me.
Comment #31
introfini commentedThanks! #27 was what I need.
Comment #32
perfectcu.be commented#27 FTW! Thanks mxr576
Comment #33
simgui8 commented#27 works here too.
Thanks!
Comment #34
tr commentedUnassigned.
Comment #35
mglamanThis looks good. I don't think we need a flag for opting out this permission. It makes sense that someone could view any, edit any, but not delete any. Site builders should just ignore this permission, otherwise.
Per #24, we should optimize the condition which sets the $published_key to 1.
Keeping at NW despite the +1 due to query adjustments.
Comment #36
r0djer commentedHello mglaman, could you please explain what you mean by optimizing the condition for setting "$published_key" to 1?
Comment #37
jsacksick commentedI'm assuming that what @mglaman means, is that we should optimize the condition that already exists a little bit above, so that we fetch both published and unpublished product when the current user has the view any unpublished product permission.
(For reference, this is the current condition).
So when I think of it... It basically means that we can skip the condition alltogether in this case?
So perhaps the existing code can be refactored like this?
Oh but there's also this:
There's probably room for optimization for sure, but the current patch should also work.. It just seems that we can probably do better, and even just skip adding the status condition in some cases.
Comment #38
heshamkh commentedThanks, @mxr576 for your effort, but in some cases, the entity doesn't have an owner especially when the permission "view any unpublished entity_type"
so in this patch I removed the owner check :)
Comment #39
mglamanYes, I agreed w/ @Berdir that the query conditions could be optimized based on earlier logic checks.
If the user has the
view anypermisison, why do we care about$has_owner? This seems like a candidate for if/elseif/elseComment #40
s.messaris commentedOpened the issue fork and added a commit based on #27, implementing some of the optimization mglaman suggested in #39.
Leaving in "needs work" because I feel it can be optimized further.
Also we might want to add "view any unpubliched $bundle $type" permissions as well.
Comment #41
s.messaris commentedComment #42
khiminrm commentedCreated patch from the MR
Comment #43
khiminrm commentedHi! Could someone from the maintainers review the latest patch and leave feedback what's need to be done else e.g. https://www.drupal.org/project/entity/issues/3023527#comment-15157931 or it can be merged as is? Thanks!
Comment #44
fox mulder commented#42 works as expected
core: 10.2.3
entity: 8.x-1.4
Comment #45
batal commentedHi
I am also tested, and #42 wroks!
Comment #46
vmarchukThe patch from #42 works fine.
Comment #47
alexdoma commentedupdate patch to changes in 1.5 version
Comment #48
tomsaw commentedNice patch! #47 worked over here.
Thanks community ☺️
Comment #49
octaviosch commentedIt doesn't work on core 10.2.7. Any help pls?
Comment #50
ahlam aljawahreh commentedre-roll #47 and remove $has_owner check from the permission "view any unpublished entity_type"
Comment #54
nicxvan commentedI'm going to see if I can refresh this and take a look if the feedback has been addressed.
I'm hiding the patches so we can make sure the work stays in the same MR the patches seem to have diverged from the MR so I created a new one starting with patch in 50.
Comment #56
nicxvan commentedOk I hope it is ok to still mark this, I only updated test variables to the ones they were clearly meant to be.
I went through it and it looks right.
I manually tested it too.
The cache contexts look like they were updated properly
I did change the variables in the test because they were named wrong.
Tests pass and the test only job fails.
Comment #57
jsacksick commentedThe patch looks good at first glance, haven't manually tested it, but just noting that I'd like Commerce to leverage the change for its Product entity (See #3262938: View any unpublished commerce_product).
Comment #58
nicxvan commentedUnfortunately I think this needs to be addressed in core, @berdir mentioned this is minimally maintained and this is not a security issue. I've been meaning to find the corresponding core issue but I haven't had the time yet.
Comment #59
aurelianzaha commentedAttached is the patch file for MR 39
In case someone needs a static patch
Comment #60
liquidcms commentedNot exactly the way this is supposed to be managed but there was a release yesterday bringing this module to 1.6.0 and it looks like this work has been committed there.
Comment #61
berdirNo, this is definitely not in the release. It might conflict with that though, I didn't test that.
Comment #62
manar olimat commentedupdate patch to changes in 1.6 version
Comment #63
nicxvan commentedPlease update the mr
Comment #64
jsacksick commentedHi @berdir, I saw you RTBCED this, any reason not to go ahead and commit this? (I don't have commit access myself).
Comment #66
megachrizThe plain diff no longer applied correctly. I merged 8.x-1.x into 3023527-view-any-unpublished to resolve this.
New patch attached, which is the same as the plain diff.
Comment #68
klausiUpdated for entity 8.x-1.x branch changes.