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) »
  • Limit Profile listing according to relationship
Pages: [1]

Author Topic: Limit Profile listing according to relationship  (Read 945 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Limit Profile listing according to relationship
October 17, 2011, 06:08:30 pm
Hi

I have a custom profile that certain users of type 'a' can use to create, edit and search for contacts.
I would like to limit the results in the search listings, so it only comes up with contacts that have the same relationship as the current logged in user.

How do I do that ?

Extra info: I have already made a little module that uses the hooks civicrm_buildForm and civicrm_postProcess - I'm using it to limit access to the profile to users of type 'a' and to give new contacs created with the profile the same relationship as the current logged-in user (the user using the profile) - it works great, but I'm a bit stuck with limiting the listings. I've already set the "Limit listings to a specific group" in the advanced profile settings - that is not the "solution" I'm looking for - relationship is the key for me here.
I've also made another module using civicrm_aclWhereClause to limit searches and contact forms to only display contacts with the same relationship as the current user. But this doesn't work for profiles as they ignore acl's ( ?right? - it doesn't work for me anyways), and with the aclWhereClause I have access to the where clause and wheretables - can I get that with  civicrm_buildForm or civicrm_postProcess ?

Thanks in advance for any help and/or pointers in the right direction :)

PS: Bonus question: I would like to share all the code from my modules, customizations etc. - where's the best place to do that ? here in the forums ?

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: Limit Profile listing according to relationship
October 18, 2011, 06:19:16 am

1. yes, profiles ignore ACL's (since the goal is to expose data to a larger group that are not permissioned)

2. You should package your changes as a drupal module and share it thru drupal's git repository

3. regarding limiting the listings / query, i suspect we'll need another hook that allows a module to modify the profile query. Let me think about this and check the code

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

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Limit Profile listing according to relationship
October 23, 2011, 11:31:38 am
Thanks Lobo.

I guess another hook is something that will come in a future release - in the meantime do you have any pointers to where I could start myself - can I make some sort of temporary hack that could do this ?

Why do I need this? Well here is my case:
I have 200 schools (organisations) in civicrm, each one have between 100 and 1000 (on average 200) related students - that is students with a relationship "Student of" with contact a being the student and contact b being the school.
I have a group called "school coordinators", which are students who need to be able to edit the other students (contacts) from their own school. I could make a group for each school, and a profile for each school that limit listings to contacts from the school group, and then make ACL's for each school coordinator, so they can only edit the contacts from their own school. For me that would mean making 200 school groups, 200 profiles and close to a thousand ACL's (there are between 2 and 10 coordinators on each school). Then I should cutomize each profile to only allow the coordinators from a school to use the profile for the school.
All in all a lot of circling/working around the real (and simple) problem: if you are coordinator you should only be able to see and edit contacs with the same relationship as yourself.

I believe this is a very common scenario:
an admin in an organisation needs to be able to administer the other people in the organisation.

If anyone have suggestions of how to do this simpler that described above please enlighten me :)

PS: I have already made it so the school coordinators can only see and edit contact records with same relationship - it just doesn't work for profiles, and I don't want the coordinators to get lost in all the details of the contact records - I don't even want them in the civicrm system - they should just use profiles which are an easy way to view and edit contacts.

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: Limit Profile listing according to relationship
October 23, 2011, 01:09:24 pm
hi - you might want to search for 'acl hook'. It is something that came in to being after we needed to do something similar for political parties where X needed access to all the contacts in Branch Y for financial data, while Z needed access to the same Branch contacts but for a different reason. So a combination of ACL Hook and Roles for each 'type' of officer provided the granularity we needed.
So a custom Data field with all the Branches (schools) was used to then give X access to Branch Y, and B access to Branch C etc.
There may well be other solutions to your usage, but could be worth an explore.
Good luck
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: Limit Profile listing according to relationship
October 23, 2011, 04:54:55 pm

I spent some time looking at this and the code and I dont think we can do this with profiles (or acl hooks since they dont apply at the profile level)

I think the easiest solution would be to just use the contact edit form for the school coordinators and if needed simplfy that form a wee bit (u can do most of this via the settings screen to hide various sections)

Another alternative might be to use a combination of views + webform, but permissioning might still be an issue there

I would say 99% of orgs using civicrm are the one org model and hence the problem below is not as common as you think :)

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

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Limit Profile listing according to relationship
October 26, 2011, 05:43:25 am
Thanks Pete I'l try to look into it.

I just got another idea in the meantime: If I make a custom module and use the buildForm hook, can I then access the setting "Limit listings to a specific Group" in the code? (maybe $form->_gid:protected)
Because then I could make a group for each school and then dynamically set the "Limit listings to a specific Group" to match the logged in user's relation to a school.

 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Limit Profile listing according to relationship

This forum was archived on 2017-11-26.