Problem/Motivation

We need to reach a decision about how to handle field permissions in the Fields in Core patch. One important place this will be needed is when we try to port Profile fields to the new system, since some of them will need permission control.

Proposed resolution

The decision has been postponed.

Remaining tasks

We need to reach a decision at some point. Preferably, this would be soon enough so we can get it into d8.

User interface changes

A UI for field permissions would need to be added.

API changes

None.

Comments

bjaspan’s picture

We didn't *completely* punt; we have this in field.module:

/**
 * Determine whether the user has access to a given field.
 *
 * @param $op
 *   The operation to be performed. Possible values:
 *   - "edit"
 *   - "view"
 * @param $field
 *   The field on which the operation is to be performed.
 * @param $account
 *   (optional) The account to check, if not given use currently logged in user.
 * @return
 *   TRUE if the operation is allowed;
 *   FALSE if the operation is denied.
 */
function field_access($op, $field, $account = NULL) {
  global $user;

  if (is_null($account)) {
    $account = $user;
  }

  $field_access = module_invoke_all('field_access', $op, $field, $account);
  foreach ($field_access as $value) {
    if ($value === FALSE) {
      return FALSE;
    }
  }
  return TRUE;
}

I haven't looked at D6 field access functionality but I'm sure there is more to it. :-) As a trivial detail, we should de-$op-ify.

yched’s picture

What we have in there is small but consistent and should be working pretty fine - we'd need to write tests :-)
What is not possible right now is stuff like 'limited visibility' that profile.module offers : view my own, edit my own...

That would imply passing the $object as a param to the access hooks - this also implies that the module that implements this '$op my own' stuff knows how to recognize who's the 'owner' of the object : assume $object->uid ?

bjaspan’s picture

If Field API, or hooks it calls, need access to owner information, ISTM we should extend field_attach_extract_ids() to return it.

Perhaps that would be false generality. The "owner" would be assumed to be a Drupal user id, so it would pretty much always be $object->uid. However, since we already have field_attach_extract_ids() it would seem odd not to use it.

We should put uid in the list of return values from field_attach_extract_ids() based on its frequency of use relative to the other returned values. I'd either put it last or just before 'cacheable'.

yched’s picture

Agreed on field_attach_extract_ids().
Sidenote : shouldn't we move field_attach_extract_ids() to return a structured, keyed array of ['key' => value] pairs ?.

I'm not sure I understand whether you want an 'owner key' => 'uid' entry in hook_fieldable_info(), though.
'id key', 'revision key', etc... are precisely a workaround for the current lack of consistency between $node->nid, $user->uid, $term->tid, ... Ideally, we should (some day... ?) move to unified, predictable keys : $obj_type . '_id', etc... If there's *one* property where we can assume consistency ("owner is $object->uid"), then we should be happy :-)
Ok, that's nitpicking. 'owner id' should be fine..

I'm not sure about de-opifying field_access(). The $op in field_access($op) is not like the one in pre-D7's nodeapi($op). It's the name of the grant you're checking. Most of the time, the same mechanism will be used to retrieve the grant, so it's not bound to end up in separate switch branches that are better off as separate functions with their specific sets of arguments. node_access($op) has not been de-opified in D7. Unless it does, I think we're more consistent where we are now.

bjaspan’s picture

I could go either way on assuming $obj->uid vs. having extract_ids() do it. I agree it would be great if we had consistent names for primary id properties across objects.

The reason extract_ids() returns a numerically-indexed array and not a hashtable is so this is possible:

  list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);

Otherwise, our code will look like:

  $ids = field_attach_extract_ids($obj_type, $object);

  if ($ids['id']) { ... }

which I think is uglier. Not a deal breaker, though.

Unfortunately, the list() syntax does not work with hashtables:

% php -r 'list($a,$b) = array("a"=>"a", "b"=>"b"); print "$a, $b\n";'
, 
yoroy’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +permissions

Tagging to collect some permissions related stuff I see bubbling up

swentel’s picture

Marked #501404: Field Permissions in Core as a duplicate of this.

andypost’s picture

So what is a state of the issue?
https://drupal.org/node/1928882 New entity field access control and hooks
https://drupal.org/node/1903124 Entity types now have a generic way to deal with permission granularity

It looks like we have no UI just now

AndyLicht’s picture

Issue summary: View changes

Hi,
when could this module be used in Drupal 8? It would be a great featue in D8! I am not good enough to develop this modul.
Thanks for every answear.
Andy

MickL’s picture

+1

andypost’s picture

Title: Field Permissions » Field Permissions UI
Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed
Issue tags: +Needs issue summary update

let's postpone that and properly title

toamit’s picture

It will be nice to have field permit UI included in core ASAP

toamit’s picture

Any interest in making this happen now that D8 is out ? Please consider updating this to a major issue.

areke’s picture

Issue summary: View changes

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

AlexBorsody’s picture

Status: Postponed » Needs work
ExTexan’s picture

+1 on this. I feel it should be (should have been) part of core anyway, not handled by a contrib module (that is not D8-ready).

ybabel’s picture

+1

yoroy’s picture

If you need this, look into how you can help make it happen. "+1" voting alone does not make things happen.

Instead: Come up with a plan: what needs to happen, what needs to happen first? Can you or your company commit resources to this effort? Would you be able to sponsor a developer who does have time and expertise? etc.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

anavarre’s picture

Issue tags: +Field API

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.