Closed (fixed)
Project:
Private
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
24 Jan 2014 at 18:07 UTC
Updated:
27 Apr 2018 at 14:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kerasai commentedComment #2
kerasai commentedInitial dev for a port to D8 attached.
Notes:
Namespacing
Funny enough, "private" is a reserved word in PHP so anything requiring namespaces had to be moved to separate modules. For this I've created private_actions and private_views sub-modules within the project.
Disabling
There is a function called private_disabling() which prevents the module from writing node access records when being disabled. I'm not sure that this is actually needed. I've left it in place for the time being, but it sticks out as one of those things that sure would be nice to throw away.
Comment #3
darol100 commentedComment #4
swentel commentedI have an updated port ready on github, see https://github.com/swentel/private
I've removed the schema and used a boolean base field which means we don't have to worry about storage, views, rendering at all.
The 'key' image is gone for now, but could potentially come back with a dedicated formatter (if wanted).
The private keyword is indeed dramatic because it's kind of silly to have a dedicated submodule only for the actions. I'm also working on D6 to D8 migrate which is also a simple plugin. Same would apply in case we want to have a dedicated formatter. What if at some point access grants hook is removed (probably not in D8 cycle, but maybe in D9) ...
I see two options:
For now, I went for option two in my repo on github.
Tests, actions and migrate still need porting, coming up today and further this week.
Comment #5
swentel commentedTests & actions have been ported as well, this can now be reviewed further.
Comment #6
swentel commentedD6 to D8 migration is now available too - should be fine for a first alpha.
Comment #7
swentel commentedAdding credits
Comment #8
adamps commented@swentel Great news that you have done the port.
I have taken over as a new maintainer to bring some life back into this module. I am fixing some D7 bugs first of all, then will move on to take a look at D8.
Comment #9
adamps commented@swentel I have now done an initial review of the code and it's looking good. I hope that you are still interested in being involved with the D8 port.
Here are my first thoughts.
Private setting as field or pseudo-field
My intuition suggests that private is pseudo-field, which would lead to using hook_entity_extra_field_info, similar to D7.
Using a field for the private setting (hook_entity_base_field_info) has the advantage that it gives a lot of code 'for free'. The key question is whether it is the right code. I think it might become a little more tricky when it comes to integrating the fixes from 7.x-2.x due to challenges with the private field:
My mind is not yet made up and I'm keen to hear views from anyone else on the thread.
Comment #10
swentel commentedRight, duh, I don't know why I didn't think of that :)
I don't necessarily like pseudo fields, it's a bit clumsy imho. (I hope someday to kill those implementations). We can always expose the field with the base_field info hook too and should be able to use formatters then. The bonus is that the field formatters for private are used in views then automatically too.
Perhaps, we should then also create a new field type which gives more control on the default value that needs to be stored.
Let me think a bit about this some more.
Comment #11
swentel commentedSo funny: this is already exposed (it's been a while since I looked a the manage display configuration in the site). If we write more formatters we can alter the display easily, and in combination with a 'private' field type even target those formatters specific to the private field only.
Comment #12
adamps commented@swentel I have happy in principal for the D8 version to use a full field. However of course we need to ensure that everything works correctly and is secure.
The SA against 7.x.1.x is now public so I can now be explicit here - there were multiple security bugs in the 1.x version. The 8.x code needs to be reworked to be based on the 7.x.2.x version. Hopefully it won't be too hard - the entire module is fairly small, and it didn't take me all that long to write version 2.x in the first place.
If you are willing to take on the task of finishing off the D8 version then I will happily review and create a D8 release when it's ready. After that you could continue to be a maintainer if you are interested.
Comment #13
matt bA big thank you for creating a working D8 module for this! swentel's code worked fine for me on D8.4
Reading #12 I've tried to make some updates to swentel's code to align 7.x.2.x, but I get the error
Recoverable fatal error: Object of class Drupal\Core\Field\EntityReferenceFieldItemList could not be converted to string in Drupal\Core\Database\Statement->execute() (line 59 of /..../core/lib/Drupal/Core/Database/Statement.php)When the permissions are rebuilt.
I'm not sure I understand enough to move this any further forward.
Comment #14
adamps commented@Matt B thanks for getting involved. Please can you explain what your patch file is? Does it apply on top of the GitHub branch created by swentel? If so maybe you could clone that on GitHub and then commit your changes to your clone.
Comment #15
matt b@AdamPS - it applys on top of the GitHub branch created by swentel. You can find the changes here: https://github.com/MattB98/private/tree/rework7.x.2.x/private_content
Comment #16
adamps commentedI have created branches
8.x-1.x is copied from https://github.com/swentel/private (except fixed the directory structure). There will never be a supported release as the code has security bugs inherited from 7.x-1.x.
8.x-2.x is copied from v7.x-2.x so of course doesn't work for D8.
The remaining task is to merge these two.
@Matt B Thanks I'll take a look at your GitHub code next week when I get a chance.
Comment #17
matt bThank you.
I have just been using what now is the 8.x-1.x branch on a dev site, and noticed that if I grant a role "Edit private content" permission and that role has permissions set under the Node permissions section to Create, Edit,Delete,Revert a nodes of a specific content type (in my case, one I've created called Recording) a user assigned that role can also Edit (but not add) nodes of another content type that they do not have permission to Edit (eg nodes of content type Article), but that have been marked Private. I would expect the "Edit private content" permission to respect the Node permissions.
Is this related to the security issue that affects 8.x-1.x? If not we need to test for it in 8.x-2.x when it is developed further. Happy to raise a separate issue in either branch - please advise!
Comment #18
adamps commented@Matt B the 1.x branch has many security bugs and that looks like one of them. It would be a good idea to add more tests in 2.x to cover those so please feel free to raise an issue for that.
Comment #19
adamps commentedAm I missing something obvious? 8.x-1.x is not working for me. (I'm not talking about whether it's secure - it just doesn't work.)
Comment #20
matt bI don't see the private field in "manage form display"
-> agreed, but I'm happy with where it is placed (see below)
I don't see a private flag when editing a node
-> look under the Promotion Options tab on the right
I do see the private field in "manage display" but don't see any indicator when viewing the page
-> Agreed - I had no requirement to display it, but I just tested it and cannot see it on the page
Even when I set a content type to be "Hidden (always private)" I can still access it.
-> I've not tested this option as I don't want to hide it on my site.
The flag is also exposed in Drupal 8 views which is handy as well. I think 8.x-1.x has some gaps over and above security, but in general it works for me.
Comment #21
adamps commentedAha thanks for the explanation. I don't use "Promoted to front page" so had that disabled via "manage form display". It feels like the better Drupal 8 way would be to have a separate "manage form display" for private to match "promoted", "sticky".
As per #9 the field exposed in views is the last value stored (if any) - it doesn't respect the content type defaults (another v1 bug) and will be blank for nodes that have not been saved since private module was enabled.
Comment #22
adamps commented@swentel are you willing to spend time helping get this module working with fields? Without your extensive Drupal Core knowledge we be unsure in places and could find it easier to go back to pseudo-fields.
@Matt B, I think I can see your current problem. In your branch, in private_content_get_default you have code
$node->private = ...That's not allowed now it's a field. What is needed here is to create something like this:
then write code to control the loading of default value - I'm not exactly sure how off the top of my head, but I expect @swentel knows.
I am still unsure over "Private setting as field or pseudo-field". It might be better Drupal architecture, neater, etc, but it might also be more work. With v7.2, I have hopefully got a secure and largely bug free version based on pseudo-fields. If we switch to a real field we may need to solve some of the problems a second time.
@Matt B You have made a good start. How much more time do you have to help with the development?
Comment #23
matt bHi AdamPS. About an hour a week! Sorry, but too many other commitments around a full time job. I'm also not familiar enough with Drupal 8 yet. I can help with testing though!
Comment #24
adamps commentedEvery bit of help is welcome. Yes D8 is quite a jump - it gradually get's easier, but I'm still learning.
For the time being I propose we should just comment out the line
$node->private =and set a todo marker. The defaulting isn't the top priority.Comment #26
adamps commentedOK I created a first alpha release!
This started with v1.x work by @kerasai @swentel merged into v2.x by @Matt B, @AdamPS. Thanks everyone.
It's not yet ready for live use, but please do test. Note there are some @todo in the code - please check those before posting issues, in particular:
There are various parts that could be tidied up relating to widget and formatter settings. Probably we can make our own derived field with a formatter and widget.
Comment #27
matt bI get the following error when I go to add or edit content:
Comment #28
adamps commentedAh sorry it looks like a committed a change to dev but didn't make a new alpha release - please can you try dev?
Comment #29
matt b8.x-2.0-alpha1+1-dev works absolutely fine - including my test in #17 - thanks AdamPS!
Comment #30
adamps commentedGreat thanks for testing. I just made a new alpha
NB check the open issues.
Comment #31
matt b8.x-2.0-alpha2 tests fine. There is a minor issue with the naming of the module #2939567: Install smoothly with drush. When do you think this will be ready for production use?
Comment #32
adamps commentedI don't have any time at the moment to do more voluntary work on D8. So it needs either sponsors or people to contribute good quality patches. If anyone is interested then please get in touch.
Comment #33
adamps commentedD8 version is now in a separate project "Private content". The module was renamed for D8 because private is a reserved word in PHP so cannot be used as a name.