<commit_before><?php

/**
 * Afsplitsing van nl.sp.geostelsel met nieuwe functies
 * om CiviCRM beter af te schermen voor SP-afdelingsgebruikers,
 * en juist een aantal kleine extra knopjes toe te voegen.
 */

require_once 'accesscontrol.civix.php';

function accesscontrol_civicrm_apiWrappers(&$wrappers, $apiRequest) {
  //&apiWrappers is an array of wrappers, you can add your(s) with the hook.
  // You can use the apiRequest to decide if you want to add the wrapper (eg. only wrap api.Contact.create)
  if ($apiRequest['entity'] == 'MessageTemplate' && in_array($apiRequest['action'], CRM_Accesscontrol_MessageTemplates_ApiWrapper::validActions())) {
    $wrappers[] = new CRM_Accesscontrol_MessageTemplates_ApiWrapper();
  }
  
  if ($apiRequest['entity'] == 'OptionValue' && $apiRequest['action'] == 'get') {
    $wrappers[] = new CRM_Accesscontrol_CiviMail_ApiWrapper();
  }
}

function accesscontrol_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
  CRM_Accesscontrol_Acl::alterApiPermissions($permissions);
  if ($entity == 'activity' and $action == 'create') {
    //check contacts in activity create
    $allContactsAllowed = true;
    foreach($params['target_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    foreach($params['assignee_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    foreach($params['source_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    if ($allContactsAllowed) {
      $params['check_permissions'] = false;
    }
  }
}

function accesscontrol_civicrm_pre( $op, $objectName, $id, &$params ) {
  // Set group to reserved when Standaard Afdelingsgroep is set to 'Yes'
  CRM_Accesscontrol_StandardGroup_Groups::pre($op, $objectName, $id, $params);
}

/**
 * Implementation of hook_civicrm_aclWhereClause
 * Voegt where-clause / restricties toe aan alle queries van deze gebruiker.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_aclWhereClause
 */
function accesscontrol_civicrm_aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
  CRM_Accesscontrol_Acl::aclWhereClause($type, $tables, $whereTables, $contactID, $where);
}

/**
 * Implementation of hook_civicrm_aclGroup
 * Beperkt de groepen die voor deze gebruiker zichtbaar zijn.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_aclGroup
 */
function accesscontrol_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
  CRM_Accesscontrol_Acl::aclGroupList($type, $contactID, $tableName, $allGroups, $currentGroups);
  CRM_Accesscontrol_Event::aclGroup($type, $contactID, $tableName, $allGroups, $currentGroups);
}

/**
 * Implementation of hook_civicrm_tabs
 * Geeft een aantal tabs op het contactoverzicht eigen permissies.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tabs
 */
function accesscontrol_civicrm_tabs(&$tabs, $contactID) {
  CRM_Accesscontrol_UI::restrictTabs($tabs, $contactID);
}

function accesscontrol_civicrm_customFieldOptions($customFieldID, &$options, $detailedFormat) {
  CRM_Accesscontrol_Event::optionValues($customFieldID, $options, $detailedFormat);
}

/**
 * Implementation of hook_civicrm_permission
 * Voegt extra permissies toe die gebruikt worden door deze extensie.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission
 */
function accesscontrol_civicrm_permission(&$permissions) {<commit_msg>bugfix: afzender adressen waren niet goed bij e-mail sturen via actie<commit_after><?php

/**
 * Afsplitsing van nl.sp.geostelsel met nieuwe functies
 * om CiviCRM beter af te schermen voor SP-afdelingsgebruikers,
 * en juist een aantal kleine extra knopjes toe te voegen.
 */

require_once 'accesscontrol.civix.php';

function accesscontrol_civicrm_apiWrappers(&$wrappers, $apiRequest) {
  //&apiWrappers is an array of wrappers, you can add your(s) with the hook.
  // You can use the apiRequest to decide if you want to add the wrapper (eg. only wrap api.Contact.create)
  if ($apiRequest['entity'] == 'MessageTemplate' && in_array($apiRequest['action'], CRM_Accesscontrol_MessageTemplates_ApiWrapper::validActions())) {
    $wrappers[] = new CRM_Accesscontrol_MessageTemplates_ApiWrapper();
  }
  
  if ($apiRequest['entity'] == 'OptionValue' && $apiRequest['action'] == 'get') {
    $wrappers[] = new CRM_Accesscontrol_CiviMail_ApiWrapper();
  }
}

function accesscontrol_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
  CRM_Accesscontrol_Acl::alterApiPermissions($permissions);
  if ($entity == 'activity' and $action == 'create') {
    //check contacts in activity create
    $allContactsAllowed = true;
    foreach($params['target_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    foreach($params['assignee_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    foreach($params['source_contact_id'] as $cid) {
      if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::VIEW)) {
        $allContactsAllowed = false;
      }
    }
    if ($allContactsAllowed) {
      $params['check_permissions'] = false;
    }
  }
}

function accesscontrol_civicrm_pre( $op, $objectName, $id, &$params ) {
  // Set group to reserved when Standaard Afdelingsgroep is set to 'Yes'
  CRM_Accesscontrol_StandardGroup_Groups::pre($op, $objectName, $id, $params);
}

/**
 * Implementation of hook_civicrm_aclWhereClause
 * Voegt where-clause / restricties toe aan alle queries van deze gebruiker.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_aclWhereClause
 */
function accesscontrol_civicrm_aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
  CRM_Accesscontrol_Acl::aclWhereClause($type, $tables, $whereTables, $contactID, $where);
}

/**
 * Implementation of hook_civicrm_aclGroup
 * Beperkt de groepen die voor deze gebruiker zichtbaar zijn.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_aclGroup
 */
function accesscontrol_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
  CRM_Accesscontrol_Acl::aclGroupList($type, $contactID, $tableName, $allGroups, $currentGroups);
  CRM_Accesscontrol_Event::aclGroup($type, $contactID, $tableName, $allGroups, $currentGroups);
}

/**
 * Implementation of hook_civicrm_tabs
 * Geeft een aantal tabs op het contactoverzicht eigen permissies.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tabs
 */
function accesscontrol_civicrm_tabs(&$tabs, $contactID) {
  CRM_Accesscontrol_UI::restrictTabs($tabs, $contactID);
}

/**
 * Implementation of hook_civicrm_optionValues
 * Verwijdert voor afdelingsgebruikers de standaard-afzendadressen uit CiviMail.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_optionValues
 */
function accesscontrol_civicrm_optionValues(&$options, $name) {
  if ($name == 'from_email_address') {
    CRM_Accesscontrol_CiviMail_FromMailAddresses::optionValues($options, $name);
  }
}

function accesscontrol_civicrm_customFieldOptions($customFieldID, &$options, $detailedFormat) {
  CRM_Accesscontrol_Event::optionValues($customFieldID, $options, $detailedFormat);
}

/**
 * Implementation of hook_civicrm_permission
 * Voegt extra permissies toe die gebruikt worden door deze extensie.
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission
 */
function accesscontrol_civicrm_permission(&$permissions) {
{'fraction_non_alphanumeric': 0.12138364779874214, 'fraction_numerical': 0.0, 'mean_word_length': 5.631359466221851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3694388', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2679, 'n_words': 518}