When using the "Allow the selected user / contact to access this profile, plus anyone with the selected permission" setting it always returns FALSE for the selected user.

Here is the logic that causes it to happen (from crm_core_profile_access()):

$has_permission = TRUE;

...

// Now that we know the true user id, let's do some checking if this
// user does not have access to this profile, hide the form.
if ($true_user->uid !== arg($user_check)) {
  $has_permission = FALSE;
}

// If we are also checking for permissions, check that here if the
// current user has the right permission, let them see the form.
if ($has_permission === FALSE && $profile->access_control === 'selected_user_or_contact_and_admins') {
  $has_permission = $perm_check;
}

Let's say we have a profile we want the user to be able to edit (autopopulated with their contact record) and we also want admins (with the "admin users" permission) to be able to edit everyone's profile.

$has_permission starts TRUE for our user. The first check will confirm that the user has the same $user->uid as the $user_check variable and so $has_permission stays TRUE. Then the second check will confirm that the user does not have the special permission to view any random profile. $has_permission is now FALSE.

The user can not see his own profile, even though he should be able to.

For the admin, the first check will set $has_permission to FALSE, as it should, but the send check will set it to TRUE, as it should. No problems here.

What needs to happen is that the second check only takes place the $has_permission variable is FALSE. Here is a quick diff of the one line patch required:

@@ -763,10 +763,9 @@ function crm_core_profile_access($profile) {
       if ($true_user->uid !== arg($user_check)) {
         $has_permission = FALSE;
       }

       // If we are also checking for permissions, check that here if the
       // current user has the right permission, let them see the form.
-      if ($profile->access_control === 'selected_user_or_contact_and_admins') {
+      if ($has_permission === FALSE && $profile->access_control === 'selected_user_or_contact_and_admins') {
         $has_permission = $perm_check;
       }

I will attach this change as a patch file but it would be nice if someone could verify my problem and confirm it does not beak any of the other settings.

Comments

dieuwe created an issue. See original summary.

dieuwe’s picture

rosk0’s picture

Version: 7.x-1.0-beta10 » 7.x-1.x-dev

Can you please confirm that this is still an issue for the latest dev version?