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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Creating inherited 'permissioned relationships'
Pages: [1]

Author Topic: Creating inherited 'permissioned relationships'  (Read 825 times)

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
Creating inherited 'permissioned relationships'
December 01, 2009, 11:34:37 am
So, what do we need to look at to achieve the following.

Person A is 'Main Contact' for Org A

Persons B,C and D, are Employees of Org A.

Person A has "permissioned relationships' to edit Org A.

Org A has permissioned relationships to edit Persons B,C and D

So when someone becomes the Main Contact we want them to inherit permissions to edit B,C and D without having to create a relationship with each of them, or have it automatically create the permissioned relationship 'Contact for' persons B, C and D

ie if Person A has permissions relationship X with Org B, then Person A also has permissioned relationship Y with all Org B's employees.

The purpose of this would be to then have B, C and D show on the Dashboard of A so they can see and update their details.

Can you suggest which is the better approach (or are they the same)?
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: Creating inherited 'permissioned relationships'
December 01, 2009, 12:37:06 pm

you can modify the function relationship in CRM/Contact/BAO/Contact/Permission.php

and apply the below rules

alternatively u can do it via acl hooks and send in the right clause for a specific contact id (i suspect hacking the former is easier).

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Creating inherited 'permissioned relationships'
December 10, 2009, 03:23:35 am
This revised version of the relationship function in permission.php allows the edit permission to be transitive in current employer relationships only. It only covers that relationship because that was the requirement we had and also because there could be extra complexities around other relationships


Code: [Select]
    /**
      * Function to get the permission base on its relationship
      *
      * @param int $selectedContactId contact id of selected contact
      * @param int $contactId contact id of the current contact
      * @param int $masquerade contact id of the current contact
      *
      * @return booleab true if logged in user has permission to view
      * selected contact record else false
      * @static
      */
    static function relationship ( $selectedContactID, $contactID = null )
    {
   
        $session   =& CRM_Core_Session::singleton( );
        if ( ! $contactID ) {
            $contactID =  $session->get( 'userID' );
            if ( ! $contactID ) {
                return false;
            }
        }
        if (  $contactID == $selectedContactID ) {
            return true;
        } else {
         
          //get relationships between given contact IDs where $contactID
          // has permission over the $selectedContactID
         $query = "
SELECT id
FROM   civicrm_relationship
WHERE  ( contact_id_a = %1 AND contact_id_b = %2 AND is_permission_a_b = 1 ) OR
       ( contact_id_a = %2 AND contact_id_b = %1 AND is_permission_b_a = 1 )
 
";
            $params = array( 1 => array( $contactID        , 'Integer' ),
                             2 => array( $selectedContactID, 'Integer' ) );
            //Fuzion edit starts
            //if contact has edit permission over related contact return true             
            $result =  CRM_Core_DAO::singleValueQuery( $query, $params );
            if ($result){
            return $result;
                   
            }else{
                /* otherwise check for a transitive relationship - i.e. one where they
                * have edit over the employer & the employer has edit over another
                * contact. NB it is difficult to see how else you would apply an
                * employer having permission as they don't log on.
                */
                $contactIds = array($contactID);
                $employer = CRM_Contact_BAO_Relationship::getCurrentEmployer($contactIds);
                $params = array( 1 => array( $contactID        , 'Integer' ),
                                  2 => array( $employer[$contactID ][org_id] , 'Integer' ) );
   
                //does contact have permission to edit their own employer? If not return false   
                // if so proceed to next check             
                $result =  CRM_Core_DAO::singleValueQuery( $query, $params );
   
                if (!$result){
                return $result;
                       
                }else{
               
                     //does contact's employer have permission to edit the secondary contact?
                    //if not return false
                    $params = array( 1 => array( $employer[$contactID ][org_id]       , 'Integer' ),
                                 2 => array( $selectedContactID, 'Integer' ) );
                    $result =  CRM_Core_DAO::singleValueQuery( $query, $params );
   
                    return $result;
             
                }
            }
           
           
            }
        }
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Creating inherited 'permissioned relationships'

This forum was archived on 2017-11-26.