Problem/Motivation

entity_metadata_taxonomy_access (callback for entity_access) is incomplete.

Proposed resolution

Improve entity_metadata_taxonomy_access

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Reroll the patch if it no longer applies. Instructions
Update the issue summary Instructions
Add automated tests Instructions
Add steps to reproduce the issue Novice Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions

User interface changes

No.

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Weaver’s picture

Attached patch expands entity_metadata_taxonomy_access to correctly deal with each $op for entity_type of taxonomy_vocabulary and taxonomy_term.

Let me know whats needed to get this committed.

Weaver’s picture

Issue summary: View changes
joachim’s picture

Status: Active » Needs work

Looks like the right approach, but needs cleaning up for coding standards and there are a few code errors too.

  1. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +  if (user_access('administer taxonomy', $account)) return TRUE;
    

    if statements should always have a block, even if a single line.

  2. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        return taxonomy_term_edit_access($entity);
    

    There's a security hole here if $account is set and is not the same as the global $user, as taxonomy_term_edit_access() ALWAYS returns access for the current user.

  3. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +      break;
    

    You don't need to break if you've returned.

  4. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        //Check for taxonomy_access_fix which adds permissions to create new terms in a given vocab
    

    Comments need to be wrapped to 80 chars. Also, they need to end with a full stop and they need a space after the //.

  5. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        if(function_exists('taxonomy_access_fix_access')) {
    

    if takes a space before the ().

  6. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        } else {
    

    elses should not be coddled.

  7. +++ b/modules/callbacks.inc
    @@ -795,14 +795,31 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        return user_access("delete terms in $entity->vid");
    

    $account should be passed in to any calls to user_access().

Weaver’s picture

Many thanks for the feedback, patch re-rolled.

joachim’s picture

Getting there! Still a few more things to fix:

  1. +++ b/modules/callbacks.inc
    @@ -795,14 +795,34 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +  if (user_access('administer taxonomy', $account)) return TRUE;
    

    This still needs to be a block.

    Worth adding a comment too, to the effect that this is letting the admin through for everything.

  2. +++ b/modules/callbacks.inc
    @@ -795,14 +795,34 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        return user_access("edit terms in $entity->vid", $account) || user_access('administer taxonomy', $account);
    

    You don't need that here; if the account has 'admin taxo' permission, they've already been let in at the very top.

  3. +++ b/modules/callbacks.inc
    @@ -795,14 +795,34 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        //Check for taxonomy_access_fix contrib module which adds additional
    +        //permissions to create new terms in a given vocabulary.
    

    You still need to add a space after the // here.

  4. +++ b/modules/callbacks.inc
    @@ -795,14 +795,34 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        } ¶
    

    Stray whitespace here.

  5. +++ b/modules/callbacks.inc
    @@ -795,14 +795,34 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
    +        else {
    +          return user_access('administer taxonomy', $account);
    +        }
    

    Same as earlier -- it's redundant to check that permission here. We know if we get this far, the user doesn't have that permission.

Weaver’s picture

Thanks. Whats next?

Weaver’s picture

Status: Needs work » Needs review
drumm’s picture

Issue tags: +affects drupal.org

This seems to be affecting Drupal.org, as reported at #2344265: Excessive access control on field collection entities.

drumm’s picture

I don't see anything specifically testing this in entity.test. Since this is access-checking code, good test coverage is especially important. I recommend writing tests.

lex0r’s picture

Rerolled for 7.x-1.6

Status: Needs review » Needs work

The last submitted patch, 10: entity-entity_metadata_taxonomy_access-2323619-10.patch, failed testing.

YesCT’s picture

YesCT’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Issue summary: View changes
Issue tags: +Needs issue summary update, +Needs tests, +Needs reroll
YesCT’s picture

Issue tags: -Needs reroll

applies cleanly to 7.x-1.x-dev #10 unable to apply must have been that it was not applicable on the version in the meta data of the issue 1.5. I will send it for a retest.

Status: Needs work » Needs review
klausi’s picture

Status: Needs review » Needs work

Patch makes sense, please add test coverage.

a.milkovsky’s picture

Status: Needs work » Needs review
FileSize
4.9 KB

Added test coverage

omarlopesino’s picture

Patch #17 worked for me.
Thanks!

fago’s picture

Title: Improve entity_metadata_taxonomy_access » Improve entity_metadata_taxonomy_access to cover existing permissions
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

I reviewed the patch and it seems fine + tested it on a site.

  • fago committed 1fa8f2d on 7.x-1.x authored by Weaver
    Issue #2323619 by Weaver, lex0r, a.milkovsky, fago: Improve...
fago’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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