Profile2 7.x-1.3 Address Field 7.x-1.0-beta5 Domain Access 7.x-3.11
Hello, I am attempting to use Profile2 module to create a separate user profile for my users. As soon as I add the new profile to a user, that user will always give an "access denied" when viewing that user's profile (except by user 1 and the user who's profile it is).
I have seen this question asked a couple times here but with no comments or answers. I believe that this is because it's almost impossible to tell what is really causing this error. That is why I installed the module "Access Denied Backtrace", which gave me a backtrace of the access denied error.
Please help me determine what in the backtrace is causing my problem..Thanks!
Here is the permissions relevant to the Profile2 module
Here is the "Deny Access Backtrace" UI for the report on the "deny access" incident.
Note that "There are no explicit access denied for this user.", which means that it was not the user trying to view the other user's profile which caused the access denied.
Here is part (only the very beginnng and the very end) of the backtrace report (it was too long to paste the whole thing) The full backtrace can be found here: Full Backtrace Report
Array
(
[18: drupal_deliver_page()] => Array
(
[file] => includes\common.inc:2563
[args] => Array
(
[0] => 3
)
)
[17: drupal_access_denied()] => Array
(
[file] => includes\common.inc:745
[args] => Array
(
)
)
[16: profile2_privacy_profile2_view()] => Array
(
[file] => sites\all\modules\profile2_privacy\profile2_privacy.module:167
[args] => Array
(
[0] => Profile Object
(
[pid] => 14
[type] => organization
[label] => Organization
[uid] => 83
[created] => 1403027279
[changed] => 1403027279
[entityType:protected] => profile2
[entityInfo:protected] => Array
(
[label] => Profile
[plural label] => Profiles
[description] => Profile2 user profiles.
[entity class] => Profile
[controller class] => EntityAPIController
[base table] => profile
[fieldable] => 1
[view modes] => Array
(
[account] => Array
(
[label] => User account
[custom settings] =>
)
)
[entity keys] => Array
(
[id] => pid
[bundle] => type
[label] => label
[revision] =>
[translations] => translations
)
[bundles] => Array
(
[organization] => Array
(
[label] => Organization
[admin] => Array
(
[path] => admin/structure/profiles/manage/%profile2_type
[real path] => admin/structure/profiles/manage/organization
[bundle argument] => 4
[access arguments] => Array
(
[0] => administer profiles
)
)
[rdf_mapping] => Array
(
)
)
)
[bundle keys] => Array
(
[bundle] => type
)
[label callback] => entity_class_label
[uri callback] => entity_class_uri
[access callback] => profile2_access
[module] => profile2
[metadata controller class] => Profile2MetadataController
[static cache] => 1
[field cache] => 1
[load hook] => profile2_load
[translation] => Array
(
[entity_translation] => Array
(
[class] => EntityTranslationDefaultHandler
)
)
[schema_fields_sql] => Array
(
[base table] => Array
(
[0] => pid
[1] => type
[2] => uid
[3] => label
[4] => created
[5] => changed
)
)
[configuration] =>
)
[idKey:protected] => pid
[nameKey:protected] => pid
[statusKey:protected] => status
[defaultLabel:protected] =>
[field_address] => Array
(
[en] => Array
(
[0] => Array
(
[country] => US
[administrative_area] => OR
[sub_administrative_area] =>
[locality] => Gold Hill
[dependent_locality] =>
[postal_code] => 97525
[thoroughfare] => 583 6th avenue
[premise] =>
[sub_premise] =>
[organisation_name] =>
[name_line] =>
[first_name] =>
[last_name] =>
[data] =>
)
)
)
[rdf_mapping] => Array
(
)
.....
.....
.....
EXTRA BACKTRACE DETAILS (SEE backtrace.txt file for full report)
.....
.....
***************UPDATE TO POSTING*********************** All of this update is in regards to me taking a deeper look at the backtrace and trying to step through the module code where it says the problem resides.**
In the Profile2_Privacy module we have the function:
function profile2_privacy_field_access($op, $field, $entity_type, $entity, $account) {......}
Which is where my backtrace says the error came from. I added a bunch of prints and var_dumps to find out where the problem lies....My analysis is below.
All of the below is in regards to the internal logic of the function profile2_privacy_field_access in the module Profile2_Privacy module.
$privacy_fields = array_keys(field_read_fields(array('type' => 'profile2_privacy')));
Initially the $privacy_fields was returning empty. I had to go to my new profile and add a new field called "profile2_privacy" to the profile2 profile After which $privacy_fields was returning
array (size=1)
0 => string 'field_privacy' (length=13)
Which is looped over to try and collect the roles
foreach ($privacy_fields as $privacy_field) {
if (isset($entity->{$privacy_field})) {
$pplid = isset($entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'])? $entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'] : 0;
$roles += profile2_privacy_get_field_roles($pplid, $field_instance['id']);
}
}
Which are then checked against the $account->roles.
$allowed_roles = array_intersect($roles, array_keys($account->roles));
The problem is that in that looping above, we get our id to find it is always zero,
$pplid = isset($entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'])? $entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'] : 0;
So $pplid is always returning zero, so when fed into this function, it is not returning a role
function profile2_privacy_get_field_roles($pplid, $fiid) {
return db_select('profile2_privacy_fields', 'ppf')
->fields('ppf', array('rid'))
->condition('pplid', $pplid)
->condition('fiid', $fiid)
->execute()
->fetchCol();
}
So when we check our empty roles array vs ones for the account
$allowed_roles = array_intersect($roles, array_keys($account->roles));
The allowed_roles count is zero, which makes the whole function returns false for the function. This then causes our Deny Access error.
I am stumped as to how to proceed from here.....Can anyone make any sense of this?
Here is the entity (profile) object which we check against in the function
$pplid = isset($entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'])? $entity->{$privacy_field}[LANGUAGE_NONE][0]['pplid'] : 0;
Note that the entity(profile) object has a "field_privacy" array, but it is empty and it cannot be empty unless you want an access denied error. I am not sure why the profile privacy module thinks there should be a "field_privacy" array, or why the profile privacy module is expecting a "profile_privacy" field to exist somewhere. I just added the field to my new profile, but was that correct? Is there some other place I am supposed to add that field?
object(Profile)[189]
public 'pid' => string '14' (length=2)
public 'type' => string 'organization' (length=12)
public 'label' => string 'Organization' (length=12)
public 'uid' => string '83' (length=2)
public 'created' => string '1403027279' (length=10)
public 'changed' => string '1403037588' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
'label' => string 'Profile' (length=7)
'plural label' => string 'Profiles' (length=8)
'description' => string 'Profile2 user profiles.' (length=23)
'entity class' => string 'Profile' (length=7)
'controller class' => string 'EntityAPIController' (length=19)
'base table' => string 'profile' (length=7)
'fieldable' => boolean true
'view modes' =>
array (size=1)
'account' =>
array (size=2)
...
'entity keys' =>
array (size=5)
'id' => string 'pid' (length=3)
'bundle' => string 'type' (length=4)
'label' => string 'label' (length=5)
'revision' => string '' (length=0)
'translations' => string 'translations' (length=12)
'bundles' =>
array (size=1)
'organization' =>
array (size=3)
...
'bundle keys' =>
array (size=1)
'bundle' => string 'type' (length=4)
'label callback' => string 'entity_class_label' (length=18)
'uri callback' => string 'entity_class_uri' (length=16)
'access callback' => string 'profile2_access' (length=15)
'module' => string 'profile2' (length=8)
'metadata controller class' => string 'Profile2MetadataController' (length=26)
'static cache' => boolean true
'field cache' => boolean true
'load hook' => string 'profile2_load' (length=13)
'translation' =>
array (size=1)
'entity_translation' =>
array (size=1)
...
'schema_fields_sql' =>
array (size=1)
'base table' =>
array (size=6)
...
'configuration' => boolean false
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_address' =>
array (size=1)
'en' =>
array (size=1)
0 =>
array (size=14)
...
public 'field_privacy' =>
array (size=0)
empty
public 'rdf_mapping' =>
array (size=0)
empty
public 'entity_view_prepared' => boolean true
public 'content' =>
array (size=5)
'#view_mode' => string 'account' (length=7)
'field_address' =>
array (size=16)
'#theme' => string 'field' (length=5)
'#weight' => int 0
'#title' => string 'Address' (length=7)
'#access' => boolean false
'#label_display' => string 'above' (length=5)
'#view_mode' => string 'account' (length=7)
'#language' => string 'en' (length=2)
'#field_name' => string 'field_address' (length=13)
'#field_type' => string 'addressfield' (length=12)
'#field_translatable' => string '1' (length=1)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'organization' (length=12)
'#object' =>
&object(Profile)[189]
'#items' =>
array (size=1)
...
'#formatter' => string 'addressfield_default' (length=20)
0 =>
array (size=6)
...
'#pre_render' =>
array (size=1)
0 => string '_field_extra_fields_pre_render' (length=30)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'organization' (length=12)