Skip to content

Commit

Permalink
Introduce Identifier case insensitive configuration option and functi…
Browse files Browse the repository at this point in the history
…onality
  • Loading branch information
ioigoume committed Mar 6, 2024
1 parent 3aeb1cb commit f23ce19
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/Config/Schema/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,7 @@
<field name="group_validity_sync_window" type="I" />
<field name="garbage_collection_interval" type="I" />
<field name="enable_normalization" type="L" />
<field name="enable_ident_isearch" type="L" />
<field name="enable_empty_cou" type="L" />
<field name="invitation_validity" type="I" />
<field name="permitted_fields_name" type="C" size="160" />
Expand Down
11 changes: 10 additions & 1 deletion app/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,16 @@ public function index() {
if(!empty($this->request->query['search_identifier'])) {
// XXX temporary implementation -- need more general approach (CO-1053)
$args = array();
$args['conditions']['Identifier.identifier'] = $this->request->query['search_identifier'];
// search.identifier is supported by CoDepartment, OrgIdentity, CoGroup, CoPerson API. All these requests
// require the coId as a query parameter
$CoSetting = ClassRegistry::init('CoSetting');
if(!empty($this->request->query['coid'])
&& $CoSetting->identifierISearchEnabled($this->request->query['coid'])
) {
$args['conditions']['LOWER(Identifier.identifier) LIKE'] = '%' . $this->request->query['search_identifier'] . '%';
} else {
$args['conditions']['Identifier.identifier'] = $this->request->query['search_identifier'];
}

$orgPooled = $this->CmpEnrollmentConfiguration->orgIdentitiesPooled();
if(!empty($this->params['url']['coid']) && !$orgPooled) {
Expand Down
1 change: 1 addition & 0 deletions app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@
'fd.id.seq' => 'ID',
'fd.id.val' => 'ID: %1$s',
// The next set must be named fd.model.validation-field
'fd.identifier.caseinsensitive.search.enable' => 'Enable Case Insensitive Identifier Searching',
'fd.identifier.description' => 'Description',
'fd.identifier.identifier' => 'Identifier',
'fd.identifier.login' => 'Login',
Expand Down
18 changes: 18 additions & 0 deletions app/Model/CoSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class CoSetting extends AppModel {
'required' => false,
'allowEmpty' => true
),
'enable_ident_isearch' => array(
'rule' => 'boolean',
'required' => false,
'allowEmpty' => true
),
'enable_nsf_demo' => array(
'rule' => 'boolean',
'required' => false,
Expand Down Expand Up @@ -202,6 +207,7 @@ class CoSetting extends AppModel {
'group_create_admin_only' => false,
'enable_normalization' => true,
'enable_nsf_demo' => false,
'enable_ident_isearch' => false,
'group_validity_sync_window' => DEF_GROUP_SYNC_WINDOW,
'invitation_validity' => DEF_INV_VALIDITY,
'garbage_collection_interval' => DEF_GARBAGE_COLLECT_INTERVAL,
Expand Down Expand Up @@ -495,6 +501,18 @@ public function getTAndCLoginMode($coId) {
return $this->lookupValue($coId, 't_and_c_login_mode');
}

/**
* Determine if Identifier Case Insensitise search is enabled for the specified CO.
*
* @since COmanage Registry 4.3.3
* @param integer $coId CO ID
* @return boolean True if enabled, false otherwise
*/

public function identifierISearchEnabled($coId) {
return (boolean)$this->lookupValue($coId, 'enable_ident_isearch');
}

/**
* Obtain a single CO setting.
*
Expand Down
9 changes: 7 additions & 2 deletions app/Model/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,17 @@ public function findCoForRecord($id) {
* @param integer $coId CO ID to constrain search to
* @param string $q String to search for
* @param integer $limit Search limit
* @return Array Array of search results, as from find('all)
* @return Array Array of search results, as from find('all')
*/

public function search($coId, $q, $limit) {
$args = array();
$args['conditions']['LOWER(Identifier.identifier) LIKE'] = '%' . strtolower($q) . '%';
$CoSetting = ClassRegistry::init('CoSetting');
if($CoSetting->identifierISearchEnabled($coId)) {
$args['conditions']['LOWER(Identifier.identifier) LIKE'] = '%' . $q . '%';
} else {
$args['conditions']['Identifier.identifier'] = $q;
}
$args['conditions']['OR'] = array(
'CoPerson.co_id' => $coId,
'CoGroup.co_id' => $coId
Expand Down

0 comments on commit f23ce19

Please sign in to comment.