While trying to theme my content, I use content_format or content_view_field function to display a field in a custom block/panel but I think it would be usefull to have a function which take care of field permissions.

Or maybe there's a better way to handle this ? I'm not quite sure on how to build a custom block/panel with some fields I'll get from a node_load...

CommentFileSizeAuthor
#2 cck_access.patch5.43 KByched

Comments

yched’s picture

Hm, true, content_view_field() should probably be access aware. Maybe content_format() too, needs some thinking.

Problem is that our access checks are currently not too consistent :
- widgets visibility in node forms is done by content.module in content_field_form(), using hook_field_access()
- fields visibility in node view is done by content_permissions.module in its hook_nodeapi('view'), using hardcoded permission-based access rules.
- fields visibility in Views is done by content_permissions.module's content_views_access_callback(), using hardcoded permission-based access rules

I think it would be more consistent to reintegrate content_permissions_nodeapi() and content_views_access_callback() into content.module, and state that
- content.module takes care of access checks, through hook_field_access() calls.
- content_permissions.module simply provides one, permission-based, implementation of hook_field_access().

Moshe, what do you think ?

yched’s picture

Status: Active » Needs review
StatusFileSize
new5.43 KB

Attached patch does what I described in #1 above (backport of what I recently committed in the 'Fields in D7 core' repository). I'd feel safer to have Moshe's review before committing to the D6 branch.

moshe weitzman’s picture

Looks like a good cleanup to me. I gave it a good read.

yched’s picture

Committed the patch in #2.

yched’s picture

Status: Needs review » Fixed

Going back to tostinni's original request :
- content_view_field() automatically gained field-access check (since it's just a wrapper around the regular view op for a given field)
- I added a check for content_access('view') in content_format.

markfoodyburton’s picture

Surely this line should include the $op?
+ $field_access = module_invoke_all('field_access', $field, $account);
as in
+ $field_access = module_invoke_all('field_access', $op, $field, $account);

Or am I missing something?

Cheers

Mark.

yched’s picture

Hem, surely indeed. Fixed.
Thanks.

Status: Fixed » Closed (fixed)

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