Closed (fixed)
Project:
Entity Clone
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Dec 2017 at 20:47 UTC
Updated:
22 Dec 2022 at 09:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
awm commentedI am in need of this as well, wonder if this is easily achievable
Comment #3
awm commentedI added a small utility module that:
1. Alter the clone node route
2. add an access controller
3. Add permission for cloning per bundle.
4. Alter operations for node based on permission.
The module can be incorporated as a submodule or I can possible release it in a sandbox. Patch attaced.
To test:
1. Apply patch:
2. enable eclone_extras
Comment #4
awm commentedupdated patch
Comment #5
awm commentedComment #6
awm commentedComment #7
trevorbradley commentedI get the following error when attempting to enable Entity Clone Extras:
If I resubmit the page, it seems to go through.
Afterward, I don't see any obvious way to restrict entity cloning by bundle. My /admin/people/permissions page still only has "Clone all X" type entries. What should I be looking for to restrict by bundle?
Comment #8
trevorbradley commentedOK, that was super weird. I went down the route of reimplementing large chunks of this patch on my own to try to understand it, thought "I'm just reinventing the wheel here" and went back to figure out what was wrong with this patch.
When I tried reinstalling it on a fresh install, I got no errors, and the bundle level permissions showed up properly.
I don't trust my good fortune here. I'm going to try to roll this patch again and ensure it deploys correctly. If so, i'm going to flag this as "reviewed at tested".
Comment #9
trevorbradley commentedComment #10
trevorbradley commentedFor some reason, the original patch refuses to create the EntityCloneSubscriber file on my machine. I've tried creating this revised patch to see if it clears things up...
Comment #11
trevorbradley commentedAha, now that I've added the file back, I see what you were doing. Most of your Event Subscriber is logging, but it looks like there's debug code in there too. Here's an alternate patch that removes the EntityCloneSubscriber entirely.
Comment #12
awm commentedPatch #4 adds a module the define permissions for each bundle of and only of the node entity type. You can still have Clone All or take the clone all permission away and give users permission to clone per bundle.
Please add an interdiff to know what changed between the patches so it's easier to review.
Comment #13
Anonymous (not verified) commentedTested #4, got the same error as listed above.
Patch #11 works.
Would be cool if this could be extended to be configurable per entity type, instead of only focusing on nodes. That being said, nodes will cover 90% of use-cases out there. Thanks for the patches!
Comment #14
emek commentedPatch #11 works for me.
Comment #15
trevorbradley commented#11 been working great for me also.(Wait, that's my patch... lol)Comment #16
emek commentedThe patch seems to have stopped working with the latest version of this module (8.x-1.0-beta2).
I have the permissions set but I can no longer clone.
Update: It does work, but you have to set the permission "clone node entity" as well.
Update 2: But with that permission it is of course possible to clone all nodes of all content types.
Comment #17
trevorbradley commentedI can verify the patch doesn't apply to 1.0-beta2.
However, it does apply to 1.x-dev (51cb014 - as of Feb 22), and appears to still work.
Any ideas what happened here with beta2?
Comment #18
trevorbradley commentedUpdate - I'm now convinced this might not be working. I'm getting errors of the type:
Notice: Undefined index: is_circular in Drupal\entity_clone\EntityClone\Content\ContentEntityCloneBase->cloneReferencedEntities() (line 154 of modules/contrib/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php)
Looking into it...
Comment #19
trevorbradley commentedComment #20
trevorbradley commentedSorry for all the spammy comments above. I did more testing, I need to reestablish a few facts:
Patch #11 applies against both 1.x-dev and 1.0.0-beta2 without error
My is_circular issue above is a different issue, not related to this patch.
Using both 1.0.0-beta2 AND 1.x-dev, the module no longer functions as expected. Non-admin users lose the ability to clone entity types that they have permission to on 1.0.0-beta1.
Early testing suggests that eclone_extras_entity_operation_alter() isn't even called anymore.
Comment #21
trevorbradley commentedI've verified this was broken by the addition of #2743379: Clone operation shows regardless of permission into 1.0-beta2. Specifically, the change in RouteSubscriber::getEntityCloneRoute():
(A note you need to clear your cache for the change to take effect).
I've created a patch to undo this permissions requirement temporarily. Note that this is NOT a proper fix of beta3 - rather it's a short term workaround. eclone_extras permissions needs to be reworked to handle 1.0-beta3's new permission requirements. Which is why I'm leaving this as "Needs Work" for now.
Comment #22
emek commentedI've had some time to look at this again and reviewed the change that broke this functionality. I noticed a hook_entity_access was added, so I added a hook like that in eclone_extras with the new permissions that are created in the submodule.
It seems to work well for me. I have added a new patch, with this addition:
Comment #23
awm commented@all it would be great if you guys add interdiff (diff the patches) so we can understand what is changing between the patches. I would like to see an interdiff for patch 4 and 11, 11 and 22. see https://www.drupal.org/documentation/git/interdiff
Also, now I see that patch #4 has some issues. Just looking at the patch file, I fear I may have not generated it properly.
Comment #24
emek commentedI have made interdiffs between the different patches.
Comment #25
kbrodej commentedReviewed the patch from 22, found some coding standard issues which are fixed in #25.
Comment #26
dwwDrive-by review of the interdiff in #25, not the full patch (yet)...
I think it's a problem that the submodule uses the "eclone_extras" namespace, not "entity_clone_extras".
The operations array is the first argument, passed by reference. So yes, we shouldn't document it as @return, but it should be the first @param documented, not just completely removed.
That satisfies the robots, but is totally unhelpful as a class comment. ;)
Same here.
Thanks,
-Derek
Comment #27
kbrodej commentedHi. I agree that passed by reference should be documented in @param tag, I only noticed it now.
For the 3,4 it is indeed to please the robots. I did not want to repeat documentation in class doc, since both of them implement only one method other than construct and create, which is very well documented.
Comment #28
matthiasm11 commentedI can confirm patch #25 works for me. (using 1.x-dev)
Comment #29
ezeedub commentedFixes for comments in #26.
Comment #30
ezeedub commentedShoot missed a file. Let's try that again.
Comment #31
nace_fr commentedHi. I have took some time to test this and patch from #30 seems to be working as expected. Patch applied successfully, it works as described and there is also no deprecated code. I'm changing status to RTBC.
Comment #32
vpeltot commentedIt would be better to add this submodule in a "modules" folder.
This hook is no longer required.
No hook_form_alter is implemented.
There is no necessary to alter routes to add a custom access.
Only Entity operations and hook_entity_access are necessary
Comment #33
vpeltot commentedComment #34
ngkoutsaik commentedComment #35
ngkoutsaik commentedHi,
I removed the uneccesairy files. As suggested the patch still works, but I will put it for review.
Comment #36
ngkoutsaik commentedComment #37
ngkoutsaik commentedHere is the correctly created patch.
Comment #38
awm commented@vpeltot
If we don't then, correct me if I am wrong, the clone operation will display regardless of the users permission and the access denied would only happen when a user attempt to clone.
it's been a long time since I first wrote the initial patch so this may have changed.
@ngkoutsaik could you verify the above?
Update: oh I see, this issue may have been addressed in https://www.drupal.org/project/entity_clone/issues/2743379
Comment #39
ngkoutsaik commentedI tested this with the latest patch applied. I created a user with permission to clone articles. The clone operation does not show on the other content types.
This is on the latest branch.
Comment #40
s3b0un3tAdding Drupal 9 compatibility.
Comment #41
szhu commentedI noticed patch #40 has a bug - if a vocabulary machine name is the same as a node type's machine name, and the content type is enabled for cloning, it is possible to clone the terms in the vocabulary too; even though the permission of clone taxonomy term is not enabled.
Steps to reproduce:
I've added an additional condition to make sure it only applies to content types not other entity types.
Comment #42
maursilveira commentedI applied the patch in #41, installed the submodule created by it, and I was able to configure the permissions by node bundle. It works as expected.
Thank you @szhu.
Comment #43
mparker17@maursilveira could you mark the issue as "Reviewed & tested by the community"?
Comment #44
maursilveira commentedHey Matt, sure thing.
Issue status updated to RTBC.
Comment #45
mparker17@maursilveira awesome, thanks!
Comment #46
colanThis is looking good! It just needs some minor documentation fixes. (Please provide an interdiff when fixing this.)
Better grammar: "Allow for bundle-level permissions for Node entity types"
I don't believe we need a "." at the end of descriptions.
Same here. Also: missing capitalization.
Shouldn't this be "Implements hook_entity_operation_alter()." as per the coding standards? See that coding standard for details.
Comment #47
guilhermevp commentedSending patch addressing #46. Please review.
Comment #48
emek commentedThe patch in #47 works well in our environment.
Comment #49
featherbelly+1 patch #47 working.
Comment #50
nicolas s. commentedPatch #47 works with a Drupal 9.3
Comment #52
rajeshreeputraComment #54
stefan.kornIt seems to me this patch is not working correctly, because the permission for cloning all node entities gets in and makes the bundle specific permission not applicable.
If the permission for all node entities is not set, the bundle specific permission will not apply (permission for all node entities forbits, and then it is forbidden for all node entities regardless of bundle permission).
If the permission for all node entities is set and specific bundle permission is also set, it will be allowed for all node entities and not only the specific bundle (which is correct imho).
I suppose we need to go into entity_clone_entity_access too to make this work.
Proposing patch (i have also included bundle specific permission for media type, since I needed that and removed an old part that is related to an issue already fixed #2743379: Clone operation shows regardless of permission.
Interdiff is to #53
Comment #55
stefan.kornentity_clone_extras module needs dependency to media module now. Added this with this patch.
Interdiff to #53 included
Comment #56
WebbehNow we have both a MR and a patch list, can we consolidate on one or the other?
Is the Media dependency necessary? That seems to enable an unnecessary dependency for installs, and I suspect folks with Media entities would already have Media enabled?
Comment #57
stefan.kornAs far as I can tell, the MR is not working as expected (see #54). So IMHO the MR is not be considered a fix for this issue. Maybe I am wrong but did somewhat thorough testing, though I am wondering that some people report the changes from MR is working for them. The part that needs to be added to make it work is this:
So that is the really necessary difference between MR and patch from #55.
I additionally added the media bundle permission, because I needed it and I do not see why only node bundle permissions should be added, since the module is "all entity". Ideally a generic solution for any entity can be found, but this seems a bit more difficult, so I only put in Media for the moment. I am not sure about the dependency to media. For someone that does not use Media and only want the entity clone extra module for node permission, it is probably annoying. But I have a installation profile and put the entity clone extra module there and then the installation failed saying media is needed. Therefore I thought media dependency would be necessary. I guess it is about this part:
Thinking some more about this, it might probably be better to add a condition around this that looks if Media module is enabled instead of the media dependency. I will gladly change the patch accordingly, but maybe we can have opinion about the difference between MR and patch and the added media feature first?
Comment #58
emek commentedWe need this functionality and the MR did not work in our environment. The patch in #54 does work for us.
Comment #59
rajeshreeputra@stefan.korn, @ emek can we have MR updated accordingly, then request review.
Comment #60
WebbehI would recommend this route, for those that do not use Media (and I suspect there are folks in that scenario).
Can we get these changes (see think-aloud of next steps in #57 and patch in #54) placed into the MR, and return this to Needs Review?
Please consolidate on one code contribution method (MR or patch) so we can keep this issue moving forward.
Comment #62
tim-dielsFixed permissions issue as described in #54.
Will add support for media now.
Comment #63
tim-dielsAdded support for media entities.
And made it easier to allow to support other entity types.
So I've included the needed changes mentioned in #54
So from now on, the patches list is not needed anymore and the MR can be used.
Comment #64
tim-dielsSeeing some not correct code comments and other issues.
Will take this up
Comment #65
tim-dielsUpdate module description to reflect the media support
Removed the AccessController file as this is never used and is handled in entity_clone_extras_entity_access
Comment #66
tim-dielsComment #67
stefan.kornI added a small fix for entity_operation_alter hook, because the clone operation got removed even if user has the "clone entity type entity" permission.
It was the first time I used the new issue fork workflow and I have got it wrong at first I suppose. There is now a "merge commit" that I did not want and need, but the result of the MR should be fine now.
Comment #68
rajeshreeputraThis is realy great work done, here can anyone please review this as second eyes/hands.
Also can we add tests to this is possible?
Once its RTBS will merge followed by release.
Comment #69
tim-dielsI can confirm the latest change is working. It would be awesome to have tests in, but don't have the time for this.
I hope this can be committed and maybe a follow up ticket can be created to add tests?
Comment #71
rajeshreeputraMerged, created new ticket to add tests for entity_clone_extras submodule.
Comment #72
coaston commentedHi All,
May I know why Media module needs to be enabled to use this enhancement ? I don't want use media, can I just remove dependency in my case ?
Comment #73
stefan.kornMedia module is not needed, dependency was only in an early patch, but in current HEAD https://git.drupalcode.org/project/entity_clone/-/blob/19d7920fb7691c84d... no dependency on media module.