CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Only show a certain Civi profile to certain Drupal roles in My account > Edit
Pages: [1]

Author Topic: Only show a certain Civi profile to certain Drupal roles in My account > Edit  (Read 2359 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 27, 2011, 02:21:53 pm
I have a Drupal6/Civi3.4 site with 4 different types of users, and each user has a role.

There are four different CiviCRM profiles, each with custom data relevant only to users of a certain role.

I have clicked view/edit Drupal my account on each of the 4 CiviCRM profiles, but all the profiles show up for each user.

I wish to restrict it so that only a single profile shows on the "my account" > "edit" page of the Drupal user, the profile that is relevant only to that user role.

Can this be accomplished with existing functionality that I don't know about?  If not, what is the best way to accomplish this, in your opinion?  Thanks!

 :)
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 05:14:47 am
I think you will need to code this, using the user hooks in Drupal:

http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_user/6
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 06:35:02 am

You can implement it via ACL's but that seems a bit like over-kill for this situation

one easy hack for now might be to edit the function: _civicrm_categories_access in drupal/civicrm.module

(which is where the ACL permissioning takes place). Get it working via a hack and then we can chat if we can generailize it / see how other drupal modules potentially generalize a situation like this

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 10:40:36 am
I took a look at the code and it's over my head.  I don't understand what it's doing or how.

If either of you would like to work on this the client needs it so $ is available.  I'd rather have an expert tackle this one.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 10:48:06 am
Quote from: Donald Lobo on November 28, 2011, 06:35:02 am
one easy hack for now might be to edit the function: _civicrm_categories_access in drupal/civicrm.module

lobo, can you explain briefly what you mean exactly?

Seems we could add a permission in hook_perm for each profile and then add the check for those in _civicrm_categories_access. Is that what you meant?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 11:37:58 am

i meant literally "hack" the code :)

i.e. go in and implement your own permissioning in "_civicrm_categories_access"

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 28, 2011, 02:03:43 pm
Stoob we have had at least one client ask about this - we hadn't done anything towards resolving it - but thought i should at least flag myself as a 'watcher' on this topic  :P
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
November 30, 2011, 09:38:39 pm

This has come up a few times and i felt compelled to investigate and scratch the itch. Here is a sample implementation of the ACL hook that suppresses profiles. Note that none of the roles involved can have the global profile view or edit permssion since those permissions trump the ACL. Also for sanity sake, these profiles should probably be restricted only to the My Account scenario:

Code: [Select]

function civicrm_civicrm_aclGroup( $type, $contactID, $tableName, &$allGroups, &$currentGroups ) {
    global $user;
    $userRoles = $user->roles;

    // based on the above value, choose which profile                                                                                       
    // to retain for this user                                                                                                             
    // role name => profile name                                                                                                           
    $allProfiles = array( 'member'    => 'Member Profile',
                          'supporter' => 'Supporter Profile',
                          'major'     => 'Major Donor Profile',
                          'real big'  => 'Real Big Donor Profile'
                          );

    // first find the ids of all the profiles                                                                                               
    $profileIDs = array( );
    foreach ( $allProfiles as $roleName => $profileName ) {
        $profileIDs[$profileName] = array_search( $profileName, $allGroups );
    }

    foreach ( $allProfiles as $roleName => $profileName ) {
        if ( array_search( $roleName, $userRoles ) !== false ) {
            unset( $profileIDs[$profileName] );
        }
    }

    $currentGroups = array_diff( array_keys  ( $allGroups ),
                                 array_values( $profileIDs ) );
}
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
December 04, 2011, 10:11:38 pm
Lobo,

I copied your code into a Drupal module, renamed the function, replaced the profile/roles listed with the real profile/roles and enabled.  It did not have a positive effect.   The profiles appeared disabled and renamed on the profile listing page (attached image), and it didn't affect the profiles in the Drupal my account section.

I don't know enough about these hooks and functions to debug this issue.   If you could enlighten me and/or Hershel on what may have happened and what should change, that would be wonderful, thanks.  One of us will make the changes.

thanks!






Try CiviTeacher: the online video tutorial CiviCRM learning library.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
December 04, 2011, 10:57:49 pm
Stoob, Lobo's code is setup so that the array

Code: [Select]
    $allProfiles = array( 'member'    => 'Member Profile',
is of the form

Code: [Select]
$roleName => $profileName
So what you do is make sure you have such Drupal roles, and then check with a user who has some of those roles. You can use whatever text for member etc. you want--but just make them match Drupal roles.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
December 05, 2011, 09:58:35 am
Hi Hershel.  Thanks... but that's exactly what I did.  The roles and array were already setup.  Check the code snippet in the previous post.  I logged in with a user of role "Venue" and there was no change to the visible profiles.  I checked permissions to view and edit all profiles were not set as well.
« Last Edit: December 05, 2011, 10:00:19 am by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
December 05, 2011, 03:30:15 pm

i would probably make a few more mods to the above:

1. Based on the 'q' variable, i would only do the above for "my account" pages (so if q = user/NUMBER).

2. add debugging statements to the code and see what profiles are returned for what roles

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Only show a certain Civi profile to certain Drupal roles in My account > Edit
December 15, 2011, 02:05:41 pm
On Stoob's D6 C 3.4.7 site I didn't see function civicrm_civicrm_aclGroup even being called, despite the user not having "View All Contacts" AND "Edit All Contacts" in permissions

So I coded it using the D6 method described here http://drupal.org/node/68792l and it works.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Only show a certain Civi profile to certain Drupal roles in My account > Edit

This forum was archived on 2017-11-26.