Skip to content

Commit

Permalink
Merge pull request #40 from mjwconsult/551fix
Browse files Browse the repository at this point in the history
Fix install on CiviCRM 5.51+
  • Loading branch information
eileenmcnaughton authored Aug 23, 2022
2 parents dcba509 + d9e5596 commit 1a04062
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 224 deletions.
33 changes: 26 additions & 7 deletions CRM/Relatedpermissions/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function create_custom_fields() {
civicrm_api3('OptionValue', 'create', [
'option_group_id' => 'cg_extend_objects',
'name' => 'civicrm_relationship_type',
'label' => ts('Relationship Type'),
'label' => E::ts('Relationship Type'),
'value' => 'RelationshipType',
]);
}
Expand All @@ -36,22 +36,25 @@ public function create_custom_fields() {
'extends' => 'RelationshipType',
'name' => E::SHORT_NAME,
'title' => E::ts('Related Permissions Settings'),
'is_active' => 1,
'is_reserved' => 1,
]);
}
$customFields = civicrm_api3('CustomField', 'get', [
'custom_group_id' => $customGroups['id'],
]);
if (!$customFields['count']) {
$newFields[] = civicrm_api3('CustomField', 'create', [
civicrm_api3('CustomField', 'create', [
'custom_group_id' => $customGroups['id'],
'name' => 'permission_a_b',
'label' => E::ts('Permission that A has over B'),
'weight' => 1,
'data_type' => 'Int',
'html_type' => 'Radio',
'option_values' => CRM_Core_SelectValues::getPermissionedRelationshipOptions(),
'option_values' => $this->getPermissionedRelationshipOptions(),
'is_active' => 1,
]);
$newFields[] = civicrm_api3('CustomField', 'create', [
civicrm_api3('CustomField', 'create', [
'custom_group_id' => $customGroups['id'],
'name' => 'permission_a_b_mode',
'label' => E::ts('Permission A over B mode'),
Expand All @@ -62,17 +65,19 @@ public function create_custom_fields() {
'required' => 1,
'default_value' => 0,
'option_values' => [E::ts('Default'), E::ts('Override')],
'is_active' => 1,
]);
$newFields[] = civicrm_api3('CustomField', 'create', [
civicrm_api3('CustomField', 'create', [
'custom_group_id' => $customGroups['id'],
'name' => 'permission_b_a',
'label' => E::ts('Permission that B has over A'),
'weight' => 3,
'data_type' => 'Int',
'html_type' => 'Radio',
'option_values' => CRM_Core_SelectValues::getPermissionedRelationshipOptions(),
'option_values' => $this->getPermissionedRelationshipOptions(),
'is_active' => 1,
]);
$newFields[] = civicrm_api3('CustomField', 'create', [
civicrm_api3('CustomField', 'create', [
'custom_group_id' => $customGroups['id'],
'name' => 'permission_b_a_mode',
'label' => E::ts('Permission B over A mode'),
Expand All @@ -83,6 +88,7 @@ public function create_custom_fields() {
'required' => 1,
'default_value' => 0,
'option_values' => [E::ts('Default'), E::ts('Override')],
'is_active' => 1,
]);
}
}
Expand All @@ -96,4 +102,17 @@ public function upgrade_1502() {
return TRUE;
}

/**
* See https://github.com/civicrm/civicrm-core/pull/23865
*
* @return array
*/
private function getPermissionedRelationshipOptions() {
return [
CRM_Contact_BAO_Relationship::NONE => ts('None'),
CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
CRM_Contact_BAO_Relationship::EDIT => ts('View and update')
];
}

}
10 changes: 7 additions & 3 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
<author>Eileen McNaughton</author>
<email>[email protected]</email>
</maintainer>
<releaseDate>2021-12-29</releaseDate>
<version>1.9</version>
<releaseDate>2022-08-22</releaseDate>
<version>1.9.1</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.44</ver>
<ver>5.49</ver>
</compatibility>
<comments>This extension makes the permission flag on a relationship work as a true ACL. In core CiviCRM that flag only allows the user to see the contact dashboard. However, in many cases it is a useful mechanism to give people permission to view contact records and search for contacts.
This version also allows relationship types to be forced to being permissioned (via the relationship config screen) </comments>
<civix>
<namespace>CRM/Relatedpermissions</namespace>
<format>22.05.2</format>
</civix>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
</extension>
159 changes: 2 additions & 157 deletions relatedpermissions.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ function _relatedpermissions_civix_civicrm_config(&$config = NULL) {
}
$configured = TRUE;

$template =& CRM_Core_Smarty::singleton();
$template = CRM_Core_Smarty::singleton();

$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extRoot = __DIR__ . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';

if (is_array($template->template_dir)) {
Expand All @@ -107,19 +107,6 @@ function _relatedpermissions_civix_civicrm_config(&$config = NULL) {
set_include_path($include_path);
}

/**
* (Delegated) Implements hook_civicrm_xmlMenu().
*
* @param $files array(string)
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
*/
function _relatedpermissions_civix_civicrm_xmlMenu(&$files) {
foreach (_relatedpermissions_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
}

/**
* Implements hook_civicrm_install().
*
Expand Down Expand Up @@ -217,136 +204,6 @@ function _relatedpermissions_civix_upgrader() {
}
}

/**
* Search directory tree for files which match a glob pattern.
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: Delegate to CRM_Utils_File::findFiles(), this function kept only
* for backward compatibility of extension code that uses it.
*
* @param string $dir base dir
* @param string $pattern , glob pattern, eg "*.txt"
*
* @return array
*/
function _relatedpermissions_civix_find_files($dir, $pattern) {
return CRM_Utils_File::findFiles($dir, $pattern);
}

/**
* (Delegated) Implements hook_civicrm_managed().
*
* Find any *.mgd.php files, merge their content, and return.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function _relatedpermissions_civix_civicrm_managed(&$entities) {
$mgdFiles = _relatedpermissions_civix_find_files(__DIR__, '*.mgd.php');
sort($mgdFiles);
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = E::LONG_NAME;
}
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
$entities[] = $e;
}
}
}

/**
* (Delegated) Implements hook_civicrm_caseTypes().
*
* Find any and return any files matching "xml/case/*.xml"
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
*/
function _relatedpermissions_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {
return;
}

foreach (_relatedpermissions_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
$name = preg_replace('/\.xml$/', '', basename($file));
if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
$errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = [
'module' => E::LONG_NAME,
'name' => $name,
'file' => $file,
];
}
}

/**
* (Delegated) Implements hook_civicrm_angularModules().
*
* Find any and return any files matching "ang/*.ang.php"
*
* Note: This hook only runs in CiviCRM 4.5+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
*/
function _relatedpermissions_civix_civicrm_angularModules(&$angularModules) {
if (!is_dir(__DIR__ . '/ang')) {
return;
}

$files = _relatedpermissions_civix_glob(__DIR__ . '/ang/*.ang.php');
foreach ($files as $file) {
$name = preg_replace(':\.ang\.php$:', '', basename($file));
$module = include $file;
if (empty($module['ext'])) {
$module['ext'] = E::LONG_NAME;
}
$angularModules[$name] = $module;
}
}

/**
* (Delegated) Implements hook_civicrm_themes().
*
* Find any and return any files matching "*.theme.php"
*/
function _relatedpermissions_civix_civicrm_themes(&$themes) {
$files = _relatedpermissions_civix_glob(__DIR__ . '/*.theme.php');
foreach ($files as $file) {
$themeMeta = include $file;
if (empty($themeMeta['name'])) {
$themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
}
if (empty($themeMeta['ext'])) {
$themeMeta['ext'] = E::LONG_NAME;
}
$themes[$themeMeta['name']] = $themeMeta;
}
}

/**
* Glob wrapper which is guaranteed to return an array.
*
* The documentation for glob() says, "On some systems it is impossible to
* distinguish between empty match and an error." Anecdotally, the return
* result for an empty match is sometimes array() and sometimes FALSE.
* This wrapper provides consistency.
*
* @link http://php.net/glob
* @param string $pattern
*
* @return array
*/
function _relatedpermissions_civix_glob($pattern) {
$result = glob($pattern);
return is_array($result) ? $result : [];
}

/**
* Inserts a navigation menu item at a given place in the hierarchy.
*
Expand Down Expand Up @@ -429,18 +286,6 @@ function _relatedpermissions_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $
}
}

/**
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function _relatedpermissions_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
$metaDataFolders[] = $settingsDir;
}
}

/**
* (Delegated) Implements hook_civicrm_entityTypes().
*
Expand Down
57 changes: 0 additions & 57 deletions relatedpermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ function relatedpermissions_civicrm_config(&$config) {
_relatedpermissions_civix_civicrm_config($config);
}

/**
* Implements hook_civicrm_xmlMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function relatedpermissions_civicrm_xmlMenu(&$files) {
_relatedpermissions_civix_civicrm_xmlMenu($files);
}

/**
* Implements hook_civicrm_install().
*
Expand Down Expand Up @@ -75,54 +66,6 @@ function relatedpermissions_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL)
return _relatedpermissions_civix_civicrm_upgrade($op, $queue);
}

/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
*/
function relatedpermissions_civicrm_managed(&$entities) {
_relatedpermissions_civix_civicrm_managed($entities);
}

/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function relatedpermissions_civicrm_caseTypes(&$caseTypes) {
_relatedpermissions_civix_civicrm_caseTypes($caseTypes);
}

/**
* Implements hook_civicrm_angularModules().
*
* Generate a list of Angular modules.
*
* Note: This hook only runs in CiviCRM 4.5+. It may
* use features only available in v4.6+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
*/
function relatedpermissions_civicrm_angularModules(&$angularModules) {
_relatedpermissions_civix_civicrm_angularModules($angularModules);
}

/**
* Implements hook_civicrm_alterSettingsFolders().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
*/
function relatedpermissions_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_relatedpermissions_civix_civicrm_alterSettingsFolders($metaDataFolders);
}

/**
* Implements hook_civicrm_entityTypes().
*
Expand Down

0 comments on commit 1a04062

Please sign in to comment.