Skip to content

Commit

Permalink
Merged feature/ICPCO-56 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Jan 26, 2021
2 parents 4336bae + 539aac5 commit b7243a8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 96 deletions.
2 changes: 2 additions & 0 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public function emailListInfo() {
));
}

//TODO - Need to combine this form with code below for groupCreate
public function groupCreateForm() {
$this->set('title', _txt('pl.grouperlite.title.groupcreate'));
$this->set('grouperstems', $this->GrouperGroup->getOwnerStems($this->userId));
}

public function groupCreate() {
Expand Down
112 changes: 48 additions & 64 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function getGrouperUser($queryData) {
if (isset($results['WsGetSubjectsResults']['wsSubjects'][0]['id']) && $results['WsGetSubjectsResults']['wsSubjects'][0]['id'] != NULL) {
return $results['WsGetSubjectsResults']['wsSubjects'][0]['id'];
}

return array();
}

Expand All @@ -91,7 +90,7 @@ public function getGrouperMemberOfGroups($queryData) {

public function grouperGroupLeaveOrJoin($queryData) {
$groupName = $queryData['conditions']['groupName'];
$subjectId = $queryData['conditions']['userId'];
$userId = $queryData['conditions']['userId'];
$groupLeaveOrJoin = $queryData['conditions']['LeaveJoin'];
$groupName = urlencode($groupName);

Expand All @@ -107,11 +106,11 @@ public function grouperGroupLeaveOrJoin($queryData) {
$groupToLeave = array(
$memberRequest => array(
"actAsSubjectLookup" => array(
"subjectId" => $subjectId
"subjectId" => $userId
),
"replaceAllExisting" => "F",
"subjectLookups" => array(
array("subjectId" => $subjectId)
array("subjectId" => $userId)
)
)
);
Expand All @@ -134,54 +133,69 @@ public function grouperGroupLeaveOrJoin($queryData) {

public function getOptinGroups($queryData) {
$queryData['conditions']['groupType'] = 'Optins';
return $this->getGrouperGroups($queryData);
$results = $this->useMembershipUrl($queryData);

if (isset($results['WsGetMembershipsResults']['wsGroups']) && $results['WsGetMembershipsResults']['wsGroups'] != NULL) {
return $results['WsGetMembershipsResults']['wsGroups'];
}

return array();
}

public function getOwnerGroups($queryData) {
$queryData['conditions']['groupType'] = 'Owner';
return $this->getGrouperGroups($queryData);
$results = $this->useMembershipUrl($queryData);

if (isset($results['WsGetMembershipsResults']['wsGroups']) && $results['WsGetMembershipsResults']['wsGroups'] != NULL) {
return $results['WsGetMembershipsResults']['wsGroups'];
}

return array();
}

public function getOwnerStems($queryData) {
$queryData['conditions']['groupType'] = 'StemOwner';
$results = $this->useMembershipUrl($queryData);

if (isset($results['WsGetMembershipsResults']['wsStems']) && $results['WsGetMembershipsResults']['wsStems'] != NULL) {
return $results['WsGetMembershipsResults']['wsStems'];
}

return array();
}

private function getGrouperGroups($queryData) {
private function useMembershipUrl($queryData) {
$groupType = $queryData['conditions']['groupType'];
$subjectID = $queryData['conditions']['userId'];
$userId = $queryData['conditions']['userId'];

if ($groupType == 'Optins') {
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => "optins",
"wsSubjectLookups" => array(
array("subjectId" => "GrouperAll")
)
)
);
$fieldName = "optins";
$subjectId = "GrouperAll";
} elseif ($groupType == 'Owner') {
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => "admin",
"wsSubjectLookups" => array(
array("subjectId" => $subjectID)
)
)
);
$fieldName = "admin";
$subjectId = $userId;
} elseif ($groupType == 'StemOwner') {
$fieldName = "stemAdmin";
$subjectId = $userId;
} else {
$groupsToShow = array();
return array();
//TODO - Throw error
}

$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId)
)
)
);

$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));

$connectionUrl = "{$this->config['fullUrl']}/memberships";

$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupsToShow));

if (isset($results['WsGetMembershipsResults']['wsGroups']) && $results['WsGetMembershipsResults']['wsGroups'] != NULL) {
return $results['WsGetMembershipsResults']['wsGroups'];
}

return array();
return $this->http->sendRequest('POST', $connectionUrl, json_encode($groupsToShow));
}


Expand All @@ -207,15 +221,15 @@ public function createUpdateGroup($queryData) {

$groupName = $queryData['conditions']['groupName'];
$stemName = $queryData['conditions']['stemName'];
$subjectId = $queryData['conditions']['userId'];
$userId = $queryData['conditions']['userId'];
$groupDescription = $queryData['conditions']['groupDescription'];

$newGroupToSave = $stemName . $groupName;

$groupToSave = array(
"WsRestGroupSaveRequest" => array(
"actAsSubjectLookup" => array(
"subjectId" => $subjectId
"subjectId" => $userId
),
"wsGroupToSaves" => array(
array(
Expand Down Expand Up @@ -245,36 +259,6 @@ public function createUpdateGroup($queryData) {
return false;
}

public function getStemGroups($queryData) {
//Tried using UUID query but only returned me the specific stem that the UUID asked for, no children

// Need to pass in the full stem path, so thing like sandbox:app:sympa are good!
$stemName = $queryData['conditions']['stemName'];
$subjectId = $queryData['conditions']['userId'];

$stemToFind = array(
"WsRestFindStemsRequest" => array(
"actAsSubjectLookup" => array(
"subjectId" => $subjectId
),
"wsStemQueryFilter" => array(
"stemQueryFilterType" => "FIND_BY_STEM_NAME_APPROXIMATE",
"stemName" => $stemName
)
)
);

$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
$connectionUrl = "{$this->config['fullUrl']}/stems";

$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($stemToFind));

if (isset($results['WsFindStemsResults']['stemResults']) && $results['WsFindStemsResults']['stemResults'] != NULL) {
return $results['WsFindStemsResults']['stemResults'];
}
return array();
}

public function getGroupAttributes($queryData) {
// Need to pass in the full stem path, so thing like sandbox:app:sympa are good!
$groupName = $queryData['conditions']['groupName'];
Expand Down
57 changes: 25 additions & 32 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,9 @@ public function ownerGroups($userId) {

$ownGroups = $this->grouperAPI->getOwnerGroups($args);

//Now for each group need to pull in friendly name attribute.
foreach ($ownGroups as &$ownGroup) {
$ownGroup['friendlyName'] = $ownGroup['displayName'];
$attributes = $this->grouperAPI->getGroupAttributes(array('conditions' => array('groupName' => $ownGroup['displayName'])));
foreach ($attributes as $attribute) {
if ($attribute['attributeDefNameName'] == $this->friendly) {
if (isset($attribute['wsAttributeAssignValues'][0]['valueSystem'])) {
$ownGroup['friendlyName'] = $attribute['wsAttributeAssignValues'][0]['valueSystem'];
}
break;
}
}
}
return $ownGroups;
$ownerGroups = $this->getFriendlyName($ownGroups);

return $ownerGroups;

}

Expand All @@ -127,22 +116,9 @@ public function optinGroups($userId) {
}
}
}
$groupsToOptin = $this->getFriendlyName($joinOrLeave);

//Now for each group need to pull in friendly name attribute.
foreach ($joinOrLeave as &$jol) {
$jol['friendlyName'] = $jol['displayName'];
$attributes = $this->grouperAPI->getGroupAttributes(array('conditions' => array('groupName' => $jol['displayName'])));
foreach ($attributes as $attribute) {
if ($attribute['attributeDefNameName'] == $this->friendly) {
if (isset($attribute['wsAttributeAssignValues']['valueSystem'])) {
$jol['friendlyName'] = $attribute['wsAttributeAssignValues']['valueSystem'];
}
break;
}
}
}

return $joinOrLeave;
return $groupsToOptin;
}

public function createGroup($userId, $groupName, $stemName, $groupDesc) {
Expand All @@ -156,12 +132,29 @@ public function createGroup($userId, $groupName, $stemName, $groupDesc) {
return $this->grouperAPI->createUpdateGroup($args);
}

public function getStemGroup($userId, $stemName) {
public function getOwnerStems($userId) {
$args = array();
$args['conditions']['userId'] = $userId;
$args['conditions']['stemName'] = $stemName;

return $this->grouperAPI->getStemGroups($args);
return $this->grouperAPI->getOwnerStems($args);
}

private function getFriendlyName($groups) {

foreach ($groups as &$group) {
$group['friendlyName'] = $group['displayName'];
$attributes = $this->grouperAPI->getGroupAttributes(array('conditions' => array('groupName' => $group['displayName'])));
foreach ($attributes as $attribute) {
if ($attribute['attributeDefNameName'] == $this->friendly) {
if (isset($attribute['wsAttributeAssignValues']['valueSystem'])) {
$group['friendlyName'] = $attribute['wsAttributeAssignValues']['valueSystem'];
}
break;
}
}
}

return $groups;
}

/**
Expand Down

0 comments on commit b7243a8

Please sign in to comment.