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)
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | profile2-allow-access-in-views-1149808-19.patch | 1.42 KB | MKorostoff |
Comments
Comment #1
roam2345 commented[removed]
Comment #2
roam2345 commentedThis is looking like a duplicate of http://drupal.org/node/1051550 closing issue
Comment #3
roam2345 commentedI 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.
Comment #4
joachim commentedI 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.
Comment #5
roam2345 commentedNOTE 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
EXPORT OF PROFILE2
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.
Comment #6
Steven.Pescador commentedHi 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.
No idea where to go from here, but just thought I'd add this and subscribe at the same time.
Comment #7
joelstein commentedPart 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.
Comment #8
vitalie commentedSubscribe. Thanks, #7 worked for me.
Comment #9
fagoThe "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.
Comment #10
fagoI've committed that patch, please re-open if there any troubles with it.
Comment #11
roam2345 commentedGave this a real work out and seems to be water tight thanks fago.
Comment #13
strr commentedThis 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
Comment #14
strr commentedOnly user with the Permissions: Administer profiles see the profiles2 fields on their own profile in that view.
Comment #15
Alpinist1974 commentedJust 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.
Comment #16
Anonymous (not verified) commentedExperiencing 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.
Comment #17
Anonymous (not verified) commentedComment #18
MKorostoff commentedThis 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:
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).
Comment #19
MKorostoff commentedHere'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:
Comment #20
MKorostoff commentedComment #21
solenity commentedThe patch in comment #19 worked for me.
Comment #22
MKorostoff commentedComment #23
spleshkaStrange, 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 :-)
Comment #25
roball commentedThe commit actually introduced #2376123: Missing parenthese in the last dev version.
Comment #26
spleshkaThanks for the report. I will fix it in the related issue. Closing this one.