Comments

sg88 created an issue. See original summary.

sgurlt’s picture

Status: Active » Needs review
StatusFileSize
new2.53 KB

Status: Needs review » Needs work

The last submitted patch, 2: entity_print-entity_type_access-2623942-1.patch, failed testing.

benjy’s picture

Why don't we generate the permissions in hook_permission() by looping over the entity types and adding a "view entity print $type" permission?

sgurlt’s picture

Status: Needs work » Needs review

Yeah I also thought about doing it in this way. But for me it feels like the community is more used to do it in the way I implemented it, then setting a lot of permissions. Sure with the permission way you could split it out more and set up more specific access rights, but I just didnt need this for my project :)

Another plus for my implementation is that you just have to export one varibale instead of a lot of permissions.
Anyway, if you say you wanna have this set up with permissions, I could rewrite it, just let me know.

benjy’s picture

Status: Needs review » Needs work

Yeah I also thought about doing it in this way. But for me it feels like the community is more used to do it in the way I implemented it,

Sorry, I don't agree. Drupal provides permissions as the system to control access, I don't want to try introduce our own concept in a non-standard place.

There are already limitations in your approach, for example it cannot be controlled per role.

I think we should generate one permission per entity type and we'll also need an update hook to add the permissions to all users who have the "entity print access" permission currently.

sgurlt’s picture

Hm you got me, I will rewrite the patch. Before I do this just one last question. Do you wanna have it on entity types, as it currently is, or should I break it down to entity bundles?

benjy’s picture

Yeah, I think bundles would be good.

sgurlt’s picture

Status: Needs work » Needs review
StatusFileSize
new3.85 KB

Alright here we go. Instead of removing the original permission "entity print access" permissions, this now is a global allow for all entity types and bundles which saved me from writting a hook_update_N().
In addition to that I added permissions for entity types and bundles. You can decide if you want to allow all bundles of a specific type, or you could choose just the bundles you want.

I hope you like it ;)

Status: Needs review » Needs work

The last submitted patch, 9: entity_print-entity_type_access-2623942-9.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: entity_print-entity_type_access-2623942-9.patch, failed testing.

benjy’s picture

Thanks!, the patch doesn't apply for some reason, are you branching of 7.x-1.x?

Also, do you fancy trying to add some tests for this?

+++ docroot/sites/all/modules/modified/entity_print/entity_print.module	(revision )
@@ -245,20 +260,37 @@
+      'title' => t('Use entity print for all bundles of type "'.$entity['label'].'"'),
...
+        'title' => t('Use entity print for bundle "'.$entity['label'].' - '.$entity_bundle['label'].'"'),

t() supports placeholders, we should use them here.

sgurlt’s picture

Yes i was using 7.x-1.x and created the patch with the PHPStorm interface and also applied it using the interface for test proposal.
It worked good in my case, strange that the patch wont apply. I will later recreate it later using the terminal.
The hint about t() is a good point, just forgot about this :). I will change this before recreating the patch.

sgurlt’s picture

Status: Needs work » Needs review
StatusFileSize
new8 KB

Alright, patch number three.
This time created with command line git, variables for t() and "fancy" tests ;-)

Status: Needs review » Needs work

The last submitted patch, 15: entity_print-entity_type_access-2623942-15.patch, failed testing.

benjy’s picture

This time created with command line git, variables for t() and "fancy" tests ;-)

"Do you fancy" is an expression that means, "if you want to do it" :) I wasn't referring to the tests :)

Patch still doesn't apply, once that's done and the testbot runs i'll review again.

sgurlt’s picture

Status: Needs work » Needs review
StatusFileSize
new7.99 KB

Ok another test...

Ok I really dont get this, I send you a private message, maybe you can give me some help with that.

Status: Needs review » Needs work

The last submitted patch, 18: entity_print-entity_type_access-2623942-17.patch, failed testing.

sgurlt’s picture

Status: Needs work » Needs review
StatusFileSize
new7.62 KB

Ok I think i found it out by my self, sorry for spamming.

sgurlt’s picture

benjy’s picture

Thanks for all your work on this, below is some feedback :)

  1. +++ b/entity_print.module
    @@ -54,16 +54,31 @@ function entity_print_menu()  {
    +  // Check if the user is allowed to use entity print for all entity types and bundles.
    ...
    +  // Check if the user is allowed to use entity print for the currently viewed entity type.
    ...
    +  // Check if the user is allowed to use entity print for the currently viewed bundle.
    

    Coding standards say that comments need to be <80chars in length.

  2. +++ b/entity_print.module
    @@ -54,16 +54,31 @@ function entity_print_menu()  {
    +  if (user_access('entity print access type '.$entity_type)) {
    

    Please add spaces around . to comply with coding standards.

  3. +++ b/entity_print.module
    @@ -54,16 +54,31 @@ function entity_print_menu()  {
    +  if (user_access('entity print access bundle '.$entity->type)) {
    

    ->type doesn't always related to the bundle, use
    list($id, $vid, $bundle) entity_extract_ids()

  4. +++ b/entity_print.module
    @@ -245,20 +260,44 @@ function entity_print_theme($existing, $type, $theme, $path) {
    +  $permissions['entity print access'] = array(
    

    I wonder if this should be called bypass entity print access now? We'd need an upgrade path then so i'm not too worried about that.

  5. +++ b/tests/entity_print.test
    @@ -20,7 +20,7 @@ class EntityPrintTest extends DrupalWebTestCase {
    +      'description' => t('Entity print css and permission tests.'),
    

    The tests are looking great, nice work. Just one suggestion, we should add some negative tests as well, e.g. Assert that a user that can view the page bundle cannot view the article bundle, and a user that can view the user entity type cannot view the node entity type.

sgurlt’s picture

StatusFileSize
new8.73 KB

Alright, thanks for the feedback. I worked on all your mentioned points (including the upgrade path), except the last one, as I already had added negative tests.

// User with different entity type access permission and entity view.
    $account = $this->drupalCreateUser(array('entity print access type user', 'access content'));
    $this->drupalLogin($account);
    $this->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
    $this->assertResponse(403, 'User with different entity print type and access content permission is not allowed to see the content.');

and

// User with different bundle permission and entity view.
    $account = $this->drupalCreateUser(array('entity print access bundle user', 'access content'));
    $this->drupalLogin($account);
    $this->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
    $this->assertResponse(403, 'User with different entity print bundle and access content permission is not allowed to see the content.');

:)

EDIT: Forgot to adjust the permission names inside the tests... doing this now.

Status: Needs review » Needs work

The last submitted patch, 23: entity_print-better_access_permissions-2623942-23.patch, failed testing.

benjy’s picture

Great, looking good, just one more thing.

  1. +++ b/entity_print.module
    @@ -54,16 +54,34 @@ function entity_print_menu()  {
    -
    -  return FALSE;
    

    Why do we remove this, don't we want to deny access in this case?

sgurlt’s picture

Status: Needs work » Needs review
StatusFileSize
new9.57 KB

Alright, patch is adjusted.
You are right, that return FALSE shouldnt be removed.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

I think this is good now, I need to apply the patch and give it a test but other than that, i'll try commit later in the week.

Thanks for all your hard work on this, appreciated.

sgurlt’s picture

Sure I really liked working on that :)
What is the status of permissions for your Drupal 8 release?

benjy’s picture

The Drupal 8 module was a straight port from D7 so it is likely pretty similar. I'd be more than happy to accept the same changes for the 8.x-1.x branch if you're want to give it a go.

sgurlt’s picture

I think I will start with it in the upcoming week.

sgurlt’s picture

Title: Better access permissions » Better access permissions D7
benjy’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new3 KB

Thanks for all your work here, i've just committed the patch. I made a few changes on commit (interdiff.txt attached), mainly just some wording to be more consistent with how the node module formats its permission strings as well.

Thanks again!

  • benjy committed e7d9ad8 on 7.x-1.x authored by sg88
    Issue #2623942 by sg88: Better access permissions D7
    
sgurlt’s picture

You are welcome :)
I am activly working on the D8 version of that patch. Just making slow progress as I havent done so much for now with D8, but I am on it :)

benjy’s picture

OK, well feel free to ask any questions.

Status: Fixed » Closed (fixed)

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

nithinkolekar’s picture

Category: Bug report » Feature request
Status: Closed (fixed) » Active

by default Drupal doesn't provide permission like "view own content " for authenticated user. This will grant authenticated user with permission "Use Entity Print" to generate pdf of any content and thus leads to all or none scenario. So it would be nice to have "entityprint own content" permission.

benjy’s picture

Status: Active » Closed (fixed)

Could you please open a new issue for your described permission. Thanks!