Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO-2752_Case_Insensitive_Identifier_Searching #589

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Config/Schema/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,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'] = '%' . strtolower($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 @@ -1663,6 +1663,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']['Identifier.identifier'] = $q;
$CoSetting = ClassRegistry::init('CoSetting');
if($CoSetting->identifierISearchEnabled($coId)) {
$args['conditions']['LOWER(Identifier.identifier) LIKE'] = '%' . strtolower($q) . '%';
} else {
$args['conditions']['Identifier.identifier'] = $q;
}
$args['conditions']['OR'] = array(
'CoPerson.co_id' => $coId,
'CoGroup.co_id' => $coId
Expand Down