Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from Ioannis/Improve_people_picker
Improve_people_picker
aaschenbrener committed Feb 23, 2024
2 parents 8505de5 + 7459512 commit a522187
Showing 18 changed files with 405 additions and 369 deletions.
142 changes: 24 additions & 118 deletions Controller/GrouperGroupsController.php
@@ -155,20 +155,14 @@ public function groupSubscribers(): void
$groupName = urldecode($this->request->query['groupname']);
$subscribers = 0;

//Need to see if coming from AdHoc or from a WG (Working Group)
$groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users'
: $groupName;
//Set initial
$scope = [
'groupName' => $groupNameFormatted
];
// //Need to see if coming from AdHoc or from a WG (Working Group)
// $groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users'
// : $groupName;

try {
$subscribers = $this->GrouperGroup->membersInGroup($scope,
$this->userId,
$this->CoGrouperLiteWidget->getConfig());
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($subscribers, true));

$subscribers = $this->GrouperGroup->getGrouperGroupMembers($this->userId,
$groupName,
$this->CoGrouperLiteWidget->getConfig());
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

@@ -198,15 +192,14 @@ public function addSubscriber(): void
$resultAdd = false;

//Need to see if coming from AdHoc or from a WG (Working Group)
$groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users'
: $groupName;
// $groupNameFormatted = strpos($groupName, ':') === false ? 'ref:incommon-collab:' . $groupName . ':users'
// : $groupName;

try {
$resultAdd = $this->GrouperGroup->addGrouperGroupMember($this->userId,
$groupNameFormatted,
$groupName,
$addUserId,
$this->CoGrouperLiteWidget->getConfig());
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultAdd, true));
} catch (Exception $e) {
// $this->restResponse(HttpStatusCodesEnum::HTTP_UNAUTHORIZED, ErrorsEnum::NotAdded);
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
@@ -219,109 +212,27 @@ public function addSubscriber(): void
}

/**
* The majority of this code is copied from the find() function in the CoPeopleController that was added by
* Arlen. Eventually this will become a component, so for now just tweaking the code needed for the Grouper plugin
* to work.
* Perform a "keyword" search for CO People, sort of like the CO Dashboard
* cross controller search, but intended specifically for "people finder"
* search while you type API calls.
*
* @since COmanage Registry v3.3.0
*/
public function findSubscriber() {
$findUserId = urldecode($this->request->query['term']);
$co = urldecode($this->request->query['co']);

$mode = urldecode($this->request->query['mode']);

// jquery Autocomplete sends the search as url?term=foo
$coPersonIds = array();
if(!empty($findUserId)) {
// Leverage model specific keyword search

// Note EmailAddress and Identifier don't support substring search
foreach(array('Name', 'EmailAddress', 'Identifier') as $m) {
$hits = $this->CoPerson->$m->search($co, $findUserId, 25);
public function findSubscriber(): void
{
$this->request->allowMethod('ajax');
$this->layout = 'ajax';

foreach($hits as $hit) {
if ($hit['CoPerson']['status'] == 'A') {
$coPersonIds[] = $hit['CoPerson']['id'];
}
}
// $coPersonIds = array_merge($coPersonIds, Hash::extract($hits, '{n}.CoPerson.id'));
}
// What search mode should we use?
if(empty($this->request->query['mode'])) {
$this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_BAD_REQUEST, 'Mode Not Specified');
return;
}

$coPersonIds = array_unique($coPersonIds);

// Look up additional information to provide hints as to which person is which.
// We only do this when there are relatively small numbers of results to
// avoid making a bunch of database queries early in the search.

$matches = array();

if(count($coPersonIds) > 100) {
// We don't return large sets to avoid slow performance

$this->response->type('json');
$this->response->statusCode(401);
$this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'Too Many Results')));
$this->response->send();
$matches = '';
} else {
$people = $this->CoPerson->filterPicker($co, $coPersonIds, $mode);
$pickerEmailType = $this->Co->CoSetting->getPersonPickerEmailType($co);
$pickerIdentifierType = $this->Co->CoSetting->getPersonPickerIdentifierType($co);
$pickerDisplayTypes = $this->Co->CoSetting->getPersonPickerDisplayTypes($co);

foreach($people as $p) {
$label = generateCn($p['Name'][0]);
$idArr = $p['Identifier'];
$emailArr = $p['EmailAddress'];
$email = '';
$emailLabel = '';
$id = '';
$idLabel = '';

// Iterate over the email array
if(!empty($emailArr) && !empty($pickerEmailType)) {
if(!empty($pickerDisplayTypes)) {
$emailLabel = _txt('fd.extended_type.generic.label', array(_txt('fd.email_address.mail'), $pickerEmailType));
}
else {
$emailLabel = _txt('fd.email_address.mail') . ': ';
}
foreach($emailArr as $e) {
if($e['type'] == $pickerEmailType) {
$email = $e['mail'];
break;
}
}
}

// Set the identifier for display (and limit it to 30 characters max)
if(!empty($idArr[0]['identifier']) && !empty($pickerIdentifierType)) {
if(!empty($pickerDisplayTypes)) {
$idLabel = _txt('fd.extended_type.generic.label', array(_txt('fd.identifier.identifier'), $pickerIdentifierType));
}
else {
$idLabel = _txt('fd.identifier.identifier') . ': ';
}
foreach($idArr as $i) {
if($i['type'] == $pickerIdentifierType) {
//$id = mb_strimwidth($i['identifier'], 0, 30, '...');
$id = $i['identifier'];
break;
}
}
}

$matches[] = array(
'value' => $p['CoPerson']['id'],
'label' => $label,
'email' => $email,
'emailLabel' => $emailLabel,
'identifier' => $id,
'identifierLabel' => $idLabel
);
}
}
$matches = $this->GrouperGroup->findForPicker($this->cur_co['Co']['id'],
$this->request->query['mode'],
$this->request->query['term'] ?? null);

$this->set(compact('matches'));
$this->set('_serialize', 'matches');
@@ -331,8 +242,6 @@ public function findSubscriber() {
* Remove a member from a group
* Called from all pages via AJAX call
*
* TODO: We should probably save extra metadata in a data attribute and then pass that attribute to the request and not
* the Human Readable name
* TODO: We need to appropriately handle Unathenticated call. We have to bubble up the response and do something.
*/
public function removeSubscriber(): void
@@ -350,8 +259,6 @@ public function removeSubscriber(): void
$groupNameFormatted,
$remUserId,
$this->CoGrouperLiteWidget->getConfig());

CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($resultRemove, true));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
}
@@ -389,7 +296,6 @@ public function groupOwnerApi() {
$func = $scope['method'];
$groupowners = $this->GrouperGroup->$func($scope,
$this->CoGrouperLiteWidget->getConfig());
CakeLog::write('debug', __METHOD__ . "::response: " . var_export($groupowners, true));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . "::{$errorHint}: " . var_export($e->getMessage(), true));
$this->restResponse(HttpStatusCodesEnum::HTTP_INTERNAL_SERVER_ERROR, ErrorsEnum::Exception);

0 comments on commit a522187

Please sign in to comment.