We have a customer that has a lot of paragraphs in their site and want to get some pages password protected. It works almost out of the box but the private files that are attached to a paragraph instead of straight to node's fields are accessible to anonymous when visiting the file link. Is this something that can be added as a feature or any suggestions how to get it to work? Or am I missing some setup here?

Comments

LauraRocks created an issue. See original summary.

grimreaper’s picture

Hello,

Thanks for the report.

In protected_node.module, protected_node_and_attachment() (http://cgit.drupalcode.org/protected_node/tree/protected_node.module#n345), there is some code for field_collection integration, I guess we can do something similar for paragraph integration.

I will see (next weekend) how to add a hook for that so other modules can add its own integration.

Or if you can provide a patch for that it would be great.

LauraRocks’s picture

Hi! Thank you!So, after short research, actually the "simple" paragraphs module integration can be done exactly like the field collection was made. I attached a very basic patch for that. But since there is only two lines that differ from the field collection; file usage type is either field_collection or paragraphs_item and then same with the entity_load, it's pretty much duplicate code. The query part would be easy to join but I don't know about the entity_load part.

And the paragraphs part only works when the paragraph is attached directly to the node. Actually if the hostEntity is not a node, but another paragraph, then gathering the "nids" would only cause problems so that's why I added the check

if ($paragraphs_item ->hostEntityType() == "node")

Then there is a question when someone has both of these in their site...

grimreaper’s picture

Status: Active » Needs work

Hello,

Thank you very much for your patch.

I am sorry but I won't have much time this weekend to go further in the issue.

But is there a function in the paragraphs module to recursively get the host entities in case of paragraphs inside paragraphs?

Also before commiting the patch, it would be nice to write an automated test. If you do not have the time for that I will do it before merging the patch I will do it.

Thanks again for your contribution.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new4.33 KB
new4.22 KB

Hello,

I have tested your patch and it failed.

I don't why but on my environment the $paragraphs_item->hostEntityType() and other hosEntity methods returned NULL.

Here is a patch that fixes the bug, I managed the case of paragraphs inside paragraphs.

Also I fixed some coding standards mistake.

Can you please test this last patch?

And let's trigger the automated tests.

LauraRocks’s picture

Thank you for your work on this, this was actually my second patch ever, first one I did one day before, so I am not at all surprised that there was coding standard mistakes, I will look into them more in future. As for how I got my patch to actually work is a wonder, now with another fresh install, it didn't work for me either.

However, your patch is working great! And it indeed handles the case of nested paragraphs also. But as I really don't know how to write tests (another thing to look into), I just tested this manually.

I still wonder, should we consider the situation where both of those modules is installed...? I have never used them both in same project, but I don't know if there is some use cases where that would be needed...

grimreaper’s picture

Status: Needs review » Needs work

Thanks for testing.

Currently the tests on this project are broken on the testbot, I never managed to figure out why. So I will try to have tests that pass locally.

I think I will commit your patch so you can be credited for your efforts and then my changes to have something working ;)

About the situation of both modules enabled, I don't think it will be a problem.

Back to "needs work" to remember to write the tests.

  • Grimreaper committed 573c771 on 7.x-1.x
    Issue #2876631 by Grimreaper: Automated tests for Paragraphs module...
  • Grimreaper committed 6a8f412 on 7.x-1.x authored by LauraRocks
    Issue #2876631 by Grimreaper, LauraRocks: Support for Paragraphs module
    
grimreaper’s picture

Status: Needs work » Fixed

Hello,

Patch commited.

I made some automated tests that are green locally.

Also I found a warning message during my tests due to the paragraph module. A fix is already commited but not in the last version: http://cgit.drupalcode.org/paragraphs/commit/?id=68343ef8da09d8427c8936b...

I will publish a new version soon.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.