Answers.Body: <p>Perhaps a case for a normal civi ACL - perhaps using CiviRules to put your Volunteer Managers in to the ACL Group which then has access to see those in the Volunteer Group.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-12T03:52:03.440Z
Answers.LastActivityDate: 2022-01-12T03:52:03.440Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>Use the Silent User Registration extension <a href="https://lab.civicrm.org/extensions/silentuserreg" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/silentuserreg</a> This will create the user in Drupal</p>
  <p>Before you install the extension, replace the Createcmsuser.php file in CRM &gt; Silentuserreg &gt; CivirulesAction with the code below. This will create the UF Match that you are looking for to link it to the user in Civi</p>
  <p>Follow the extension instructions to set it up. I would have your CiviRule trigger off When contact is added to group or something like that.</p>
  <pre><code>&lt;?php
  </code></pre>
  <p>/**</p>
  <ul>
  <li>Carls Notes</li>
  <li>This file is to create a CRMUser and then a UFMatch record. File Location=secure/sites/all/files/civicrm/extensionsions/silentuserreg-master/CRM/Silentuserreg/Silentuserreg
  <em>/
  /</em>*</li>
  <li>Class for CiviRules Create User Action</li>
  <li></li>
  <li>@author Jon Goldberg (jon@megaphonetech.com)</li>
  <li>@license AGPL-3.0
  */
  class CRM_Silentuserreg_CivirulesAction_Createcmsuser extends CRM_Civirules_Action {</li>
  </ul>
  <p>/**</p>
  <ul>
  <li>Method processAction to execute the action</li>
  <li></li>
  <li>@param CRM_Civirules_TriggerData_TriggerData $triggerData</li>
  <li>@access public</li>
  <li></li>
  </ul>
  <p><em>/
  public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) {
  $cid = $triggerData-&gt;getContactId();
  $userInfo = \Civi\Api4\Email::get()
  -&gt;addSelect('id', 'email', 'contact.display_name', 'is_primary')
  -&gt;addWhere('is_primary', '=', TRUE)
  -&gt;addWhere('contact_id', '=', $cid)
  -&gt;setCheckPermissions(FALSE)
  -&gt;execute()
  -&gt;first();
  $userExists = (bool) count(\Civi\Api4\UFMatch::get()
  -&gt;addWhere('contact_id', '=', $cid)
  -&gt;setCheckPermissions(FALSE)
  -&gt;execute());
  if (!$userExists) {
  $userParams['cms_name'] = $userParams['nickname'] = $userInfo['contact.display_name'];
  $userParams['email'] = $userInfo['email'];
  $userParams['cms_pass'] = CRM_Silentuserreg_Util::randomPassword();
  $nid=CRM_Core_BAO_CMSUser::create($userParams, 'email');
  // create the UF Match record
  $ufmatch['uf_id'] = $nid;
  $ufmatch['contact_id'] = $cid;
  $ufmatch['uf_name'] = $userInfo['email'];
  CRM_Core_BAO_UFMatch::create($ufmatch);
  }
  }
  /</em>*</p>
  <ul>
  <li>Method to return the url for additional form processing for action</li>
  <li>and return false if none is needed</li>
  <li></li>
  <li>@param int $ruleActionId</li>
  <li>@return bool</li>
  <li>@access public
  */
  public function getExtraDataInputUrl($ruleActionId) {
  return FALSE;
  }</li>
  </ul>
  <p>}</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-17T22:58:07.260Z
Answers.Text: Thanks. But how this process would create relationships?
Answers.UserDisplayName: Tapash
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-17T23:59:49.573Z
Answers.Text: My bad. I misunderstood. I was thinking Create relationship between Drupal user and Civi Users
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-17T22:56:34.223Z
Answers.LastActivityDate: 2020-12-17T22:56:34.223Z
Answers.UserDisplayName: Iowa Boy
Body: <p>I have webform where volunteers signup for newsletter. They land on group called &quot;Volunteer&quot;.</p>
  <p>Our volunteer co-ordinator users are in a drupal role called &quot;Coordinator&quot;</p>
  <p>What I want is, those &quot;Coordinator&quot; users would ONLY be able to access the contacts from the group &quot;Volunteer&quot;. I can easily achieve this by using related permission extension <a href="https://github.com/eileenmcnaughton/nz.co.fuzion.relatedpermissions" rel="nofollow noreferrer">https://github.com/eileenmcnaughton/nz.co.fuzion.relatedpermissions</a> .</p>
  <p>But I am failing to automate the process of creating a relationship between the volunteers and Drupal users. If any new Drupal user is added to the same role, the relationship would automatically be created. I am open to alternatives. Any suggestion would be greatly appreciated. Thanks</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-18T03:06:43.790Z
Comments.Text: "I am failing to automate the process of creating a relationship between the volunteers and Drupal users" is not conceptually correct. You would want to be creating a Relatinships between Contact X and Contact Y and would not be using Groups. You could connect Contact X to Contact G (being eg Volunteers) and then connect Contact G to your Coordinators. that is how that extension could help. Otherwise you could look at Rules.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-18T03:07:09.327Z
Comments.Text: but to be honest, your first two paragraphs sound like an obvious case for a normal civi ACL.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-18T06:06:22.723Z
Comments.Text: @petednz-fuzion thanks. My end goal is to limit the coordinator’s access to see only volunteer  contacts. And I need that process to be automated. How can I do that?
Comments.UserDisplayName: Tapash
Tags: <contacts><permissions><relationships><acl><user>
Title: How to automatically create relationship between Drupal role user and a group of civi contacts?
ThreadText: # How to automatically create relationship between Drupal role user and a group of civi contacts?
  
  (Asked by: username_0 on 2020-12-17)
  
  I have webform where volunteers signup for newsletter. They land on group called "Volunteer".
  
  Our volunteer co-ordinator users are in a drupal role called "Coordinator"
  
  What I want is, those "Coordinator" users would ONLY be able to access the contacts from the group "Volunteer". I can easily achieve this by using related permission extension <https://github.com/eileenmcnaughton/nz.co.username_1.relatedpermissions> .
  
  But I am failing to automate the process of creating a relationship between the volunteers and Drupal users. If any new Drupal user is added to the same role, the relationship would automatically be created. I am open to alternatives. Any suggestion would be greatly appreciated. Thanks
  
  **Tags:** contacts, permissions, relationships, acl, user
  
  > **Comments:**
  > **username_1**: "I am failing to automate the process of creating a relationship between the volunteers and Drupal users" is not conceptually correct. You would want to be creating a Relatinships between Contact X and Contact Y and would not be using Groups. You could connect Contact X to Contact G (being eg Volunteers) and then connect Contact G to your Coordinators. that is how that extension could help. Otherwise you could look at Rules.  
  > **username_1**: but to be honest, your first two paragraphs sound like an obvious case for a normal civi ACL.  
  > **username_0**: @username_1 thanks. My end goal is to limit the coordinator’s access to see only volunteer  contacts. And I need that process to be automated. How can I do that?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-01-12. Score: 1
  
  Perhaps a case for a normal civi ACL - perhaps using CiviRules to put your Volunteer Managers in to the ACL Group which then has access to see those in the Volunteer Group.
  
  
  ---
  
  ### Answer by username_2 on 2020-12-17. Score: 0
  
  Use the Silent User Registration extension <https://lab.civicrm.org/extensions/silentuserreg> This will create the user in Drupal
  
  Before you install the extension, replace the Createcmsuser.php file in CRM > Silentuserreg > CivirulesAction with the code below. This will create the UF Match that you are looking for to link it to the user in Civi
  
  Follow the extension instructions to set it up. I would have your CiviRule trigger off When contact is added to group or something like that.
  
  ```
  <?php
  
  ```
  
  /\*\*
  
  * Carls Notes
  * This file is to create a CRMUser and then a UFMatch record. File Location=secure/sites/all/files/civicrm/extensionsions/silentuserreg-master/CRM/Silentuserreg/Silentuserreg
    */
    /*\*
  * Class for CiviRules Create User Action
  * @author Jon Goldberg (jon@megaphonetech.com)
  * @license AGPL-3.0
    \*/
    class CRM\_Silentuserreg\_CivirulesAction\_Createcmsuser extends CRM\_Civirules\_Action {
  
  /\*\*
  
  * Method processAction to execute the action
  * @param CRM\_Civirules\_TriggerData\_TriggerData $triggerData
  * @access public
  
  */
  public function processAction(CRM\_Civirules\_TriggerData\_TriggerData $triggerData) {
  $cid = $triggerData->getContactId();
  $userInfo = \Civi\Api4\Email::get()
  ->addSelect('id', 'email', 'contact.display\_name', 'is\_primary')
  ->addWhere('is\_primary', '=', TRUE)
  ->addWhere('contact\_id', '=', $cid)
  ->setCheckPermissions(FALSE)
  ->execute()
  ->first();
  $userExists = (bool) count(\Civi\Api4\UFMatch::get()
  ->addWhere('contact\_id', '=', $cid)
  ->setCheckPermissions(FALSE)
  ->execute());
  if (!$userExists) {
  $userParams['cms\_name'] = $userParams['nickname'] = $userInfo['contact.display\_name'];
  $userParams['email'] = $userInfo['email'];
  $userParams['cms\_pass'] = CRM\_Silentuserreg\_Util::randomPassword();
  $nid=CRM\_Core\_BAO\_CMSUser::create($userParams, 'email');
  // create the UF Match record
  $ufmatch['uf\_id'] = $nid;
  $ufmatch['contact\_id'] = $cid;
  $ufmatch['uf\_name'] = $userInfo['email'];
  CRM\_Core\_BAO\_UFMatch::create($ufmatch);
  }
  }
  /*\*
  
  * Method to return the url for additional form processing for action
  * and return false if none is needed
  * @param int $ruleActionId
  * @return bool
  * @access public
    \*/
    public function getExtraDataInputUrl($ruleActionId) {
    return FALSE;
    }
  
  }
  
  > **Comments:**
  > **username_0**: Thanks. But how this process would create relationships?  
  > **username_2**: My bad. I misunderstood. I was thinking Create relationship between Drupal user and Civi Users  
  
  ---
  
  