The view I am creating.

- I have setup a store profile has a image, text field and text-area on it nice and simple.
- View is as follow.
- View of type profile
- Have a block that is using an argument / contextual filter (on the text field of the profile).
- Fields I am displaying are the image and text-area.

When I am an administrator I get to view my view no errors.
When I am not an admin (have granted view access to anon and auth users) get this error.

MESSAGE BOX

Notice: Undefined property: views_plugin_query_default::$fields in views_plugin_query_default->query() (line 1142 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).
Warning: Invalid argument supplied for foreach() in views_plugin_query_default->compile_fields() (line 1060 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).
Notice: Undefined property: views_plugin_query_default::$fields in views_plugin_query_default->query() (line 1142 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).
Warning: Invalid argument supplied for foreach() in views_plugin_query_default->query() (line 1144 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).
Warning: Invalid argument supplied for foreach() in views_plugin_query_default->compile_fields() (line 1060 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).

DEBUG

Debug:
'Exception: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'FROM 
profile profile
INNER JOIN profile_type profile_type_profile ON profile.ty\' at line 1'
in views_plugin_query_default->execute() (line 1362 of /Users/jucallme/Sites/drupal-7.0/sites/etsy.holly.lan/modules/views/plugins/views_plugin_query_default.inc).

Even if i set the view access to none that does not work either.
I have opened the bug here is may very well be a entity api issue but ill start at the root.

Versions
- Entity API 7.x-1.x-dev (2011-May-03)
- 7.x-1.x-dev (2011-Apr-27)

Comments

roam2345’s picture

[removed]

roam2345’s picture

Status: Active » Closed (duplicate)

This is looking like a duplicate of http://drupal.org/node/1051550 closing issue

roam2345’s picture

I have a view that does the following (using a block).
- I get the UID off the url (contextual filter)
- I add the relationship with the profile for the user.
- I try and show any field off the profile (using the relationship).
- Set the view access permissions to (None) or (permission | View published content) has same effect.
- BOOM! I can view the field as an admin, other users in any other role that have the permissions to view the field do not see it.

Been told its best to reopen this here... I am of the understanding is a permissions error propagating from http://drupal.org/node/1051550.

joachim’s picture

Status: Closed (duplicate) » Active

I don't think it's related to #1051550: users always see their own profiles -- that is to do with hook_user_view permissions, whereas Views has its own system for its fields.

roam2345’s picture

Title: Field permission issues when using relationships. » Profile2 fields are not displayed not matter how I build a view.

NOTE I have kept the issue open and adjusted according to the error. Please ignore initial description

Have setup a blank test site only the following modules enabled.

- Entity API 7.x-1.x-dev (2011-May-03)
- Profile2 7.x-1.x-dev (2011-May-10)
- Views 7.x-3.x-dev (2011-May-12)
- ctools 7.x-1.x-dev (2011-May-11)

EXPORT OF VIEW

$view = new view;
$view->name = 'store_details';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'profile';
$view->human_name = 'Store Details';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Profile: Profile ID */
$handler->display->display_options['fields']['pid']['id'] = 'pid';
$handler->display->display_options['fields']['pid']['table'] = 'profile';
$handler->display->display_options['fields']['pid']['field'] = 'pid';
/* Field: Profile: Store Name */
$handler->display->display_options['fields']['field_name']['id'] = 'field_name';
$handler->display->display_options['fields']['field_name']['table'] = 'field_data_field_name';
$handler->display->display_options['fields']['field_name']['field'] = 'field_name';
$handler->display->display_options['fields']['field_name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_name']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_name']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_name']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_name']['field_api_classes'] = 0;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$translatables['store_details'] = array(
  t('Master'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('Profile ID'),
  t('.'),
  t(','),
  t('Store Name'),
  t('Block'),
);

EXPORT OF PROFILE2

{
  "userCategory" : false,
  "userView" : false,
  "type" : "store",
  "label" : "store",
  "weight" : "0",
  "data" : { "registration" : 0, "use_page" : 1 },
  "rdf_mapping" : []
}

I think the export of the profile2 is missing the underlying field, I added a text field with the machine name of field_name...

PERMISSIONS ENABLED.
- View user profiles (all roles)
- store: View any profile (all roles)

ENABLE THE BLOCK.
- notice the store name field does not appear if you are a authenticated or anon user.
- notice the store name field does appear if you are the admin.

Steven.Pescador’s picture

Hi guys,

Have come across this issue myself where I was wanting to show a profile2 field in a view but only the admin could view it.

The below function is where viewing the field is being disallowed... as $profile is not set and therefore FALSE is returned.

function profile2_field_access($op, $field, $entity_type, $profile = NULL, $account = NULL) {
  if ($entity_type == 'profile2' && $op == 'view' && !user_access('administer profiles', $account)) {
    // For profiles, deny general view access.
    if (!isset($profile)) {
      return FALSE;
    }
    // Also deny view access, if someone else views a private field.
    $account = isset($account) ? $account : $GLOBALS['user'];
    if ($account->uid != $profile->uid && !empty($field['settings']['profile2_private'])) {
      return FALSE;
    }
  }
}

No idea where to go from here, but just thought I'd add this and subscribe at the same time.

joelstein’s picture

Title: Profile2 fields are not displayed not matter how I build a view. » Permissions not working for Views fields without "administer profiles"
Status: Active » Needs work
StatusFileSize
new600 bytes

Part of the problem was that hook_field_access is supposed to receive a $field array, whereas until #1124298-12: Views does not check hook_field_access()? was committed, only the field name was being passed. Now, $field is actually an array (in the latest Views dev). Yet, no $profile value is passed.

At this point we can figure out which bundles the field belongs to in $field['bundles']['profile2']. However, since a field could belong to multiple bundles, we don't know which profile type to load, unless there is only one bundle.

So, here's a patch which respects the "view any profile" if the field is attached to only one bundle. If the field is attached to more than one, it will deny access.

It's a start, at least. Until the $profile entity is passed, there's no way to check "view own profile" permissions.

vitalie’s picture

Subscribe. Thanks, #7 worked for me.

fago’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB

The "private" option isn't bundle-specific, so we can just restrict access to those fields.
Patch attached. Please test.

This doesn't change the behaviour for private fields though, it's up to views to pass an entity.

fago’s picture

Status: Needs review » Fixed

I've committed that patch, please re-open if there any troubles with it.

roam2345’s picture

Gave this a real work out and seems to be water tight thanks fago.

Status: Fixed » Closed (fixed)

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

strr’s picture

This issue is still not solved for me in: 7.x-1.3 and in 7.x-1.x-dev.

1. I add a relationship for profile
2. I add a profile 2 field to the view
-> result is only visable for admin

strr’s picture

Only user with the Permissions: Administer profiles see the profiles2 fields on their own profile in that view.

Alpinist1974’s picture

Just following up on this:

If, when configuring your Profile2 fields (in Profile types » [Profile Type] » Manage fields) you check the box labelled "Make the content of this field private," you will NOT be able to access these fields in Views, even when the view is configured in such a way that the view is only accessible to the owner of the profile.

This caused me no end of grief, but glad I finally figured it out after looking at some of the access patches posted. I'm posting this so that hopefully someone else will avoid the same pitfall.

Anonymous’s picture

Experiencing this problem today with latest dev release installed. Only Admin user can view any image file uploaded using the profile2 edit. Images are uploaded normally using an image field type and are stored in the expected directory. Tried all sorts of profile2 page display options, nothing works. Other non-image fields are accessible, and displayed normally.

Anonymous’s picture

Status: Closed (fixed) » Active
MKorostoff’s picture

StatusFileSize
new110.41 KB

This took me a long time to workout, but the basic problem is that Profile2 field permissions fail when using the "Fields" Views row style. You *can* get it working, but only by outputting the rendered entity:

profile2 working

This isn't ideal of course, because it means you can only manipulate these fields with php templating, custom field formatters, or DisplaySuite, but strictly speaking Profile2 fields are accessible to Views (only in a slightly inconvenient way).

MKorostoff’s picture

Here's a patch for the above described issue.

To test this, I did the following:
1. I configured a view which shows user profile2 fields, and uses the "Fields" row style.
Result: Working as desired. Authenticated users were able to see their own fields, but not the private fields of other users. Users with the "administer profiles" permission were able to view all profile fields.

2. I configured a view which shows user profile2 fields, and uses the "Rendered Entity" row style.
Result: Identical to #1 above.

3. Logged in as a user with the role "authenticated user". I attempted to view another user's private field by navigating directly to /user/:uid/:profile_type. I was not able to view the user's private fields.

If anyone out there would like to implement this in a minimally invasive way, without patching profile2, for the time being you can create a custom module that does the following:

/**
 * Implements hook_field_access().
 */
function yourmodule_field_access($op, $field, $entity_type, $profile = NULL, $account = NULL) {
  if ($entity_type == 'profile2' && $op == 'view' && !empty($field['settings']['profile2_private']) && !user_access('administer profiles', $account)) {

    // Deny view access, if someone else views a private field.
    if (isset($profile)) {
      $account = isset($account) ? $account : $GLOBALS['user'];
      if ($account->uid != $profile->uid) {
        return FALSE;
      }
    }
  }

}

/**
 * Remove faulty field_access implementation from profile2.
 * 
 * See https://www.drupal.org/node/1149808
 */
function yourmodule_module_implements_alter(&$implementations, $hook) {
  if ($hook === 'field_access') {
    unset($implementations['profile2']);
  }
}
MKorostoff’s picture

Status: Active » Needs review
solenity’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Status: Needs review » Reviewed & tested by the community

The patch in comment #19 worked for me.

MKorostoff’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
spleshka’s picture

Status: Reviewed & tested by the community » Fixed

Strange, but I missed this issue. Anyway, today I found it and tested it - patch works! Thanks MKorostoff for detailed description and for your patch. It is your second patch for profile2 module, and both times I exited about your work.

@solenity, also thank you for testing this. Without RTBC status I could not find it for quite a long time :-)

  • Spleshka committed 1eddad6 on 7.x-1.x authored by MKorostoff
    Issue #1149808 by MKorostoff, Spleshka, solenity: fix access behavior...
roball’s picture

Priority: Normal » Critical
Status: Fixed » Needs work
spleshka’s picture

Status: Needs work » Fixed

Thanks for the report. I will fix it in the related issue. Closing this one.

Status: Fixed » Closed (fixed)

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