Skip to content

Cfm 324 attribute collector save attributes - improvements #294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -123,10 +123,10 @@ public function initialize(array $config): void {
}

/**
* Perform steps necessary to finalize the Petition.
* Perform steps necessary to hydrate the Person record as part of Petition finalization.
*
* @param int $id Attribute Collector ID
* @param Petition $petition
* @param \App\Model\Entity\Petition $petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/
Expand Down Expand Up @@ -166,7 +166,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
})->toArray();
$personRoleAttributes = array_keys($personRoleAttributes);

// Get all the fields/values required to build the PrersonRole
// Get all the fields/values required to build the PersonRole
$fieldsForPersonRole = $attributesCollection->filter(function($attr, $key) use ($personRoleAttributes) {
return in_array($attr['enrollment_attribute']['attribute'], $personRoleAttributes);
})->toArray();
Expand Down Expand Up @@ -213,7 +213,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
);

/****** PERSON ******/
// Filter the MVEAS Attributes and keep the field name
// Keep the person attributes
$personAttributes = (new Collection($supportedAttributes))->filter(function($attr, $key) {
return isset($attr['model']) && $attr['model'] == 'Person';
})->toArray();
Expand All @@ -224,11 +224,38 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
return in_array($attr['enrollment_attribute']['attribute'], $personAttributes);
})->toArray();

if($People->saveAttributes($person->id, $fieldsForPerson) === false) {

try {
$People->saveAttributes($person->id, $fieldsForPerson);
} catch (\Exception $e) {
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
$cxn->rollback();
throw new \RuntimeException(__d('error', 'save', ['Person']));
}


/****** GROUP ******/
// Filter the MVEAS Attributes and keep the field name
$groupAttributes = (new Collection($supportedAttributes))->filter(function($attr, $key) {
return isset($attr['model']) && $attr['model'] == 'Group';
})->toArray();
$groupAttributes = array_keys($groupAttributes);

// Get all the fields/values required to build the PrersonRole
$fieldsForGroup = $attributesCollection->filter(function($attr, $key) use ($groupAttributes) {
return in_array($attr['enrollment_attribute']['attribute'], $groupAttributes);
})->toArray();


try {
$groupMemberObj = TableRegistry::getTableLocator()->get('GroupMembers');
$groupMemberObj->saveAttributes($person->id, $fieldsForGroup);
} catch (\Exception $e) {
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
$cxn->rollback();
throw new \RuntimeException(__d('error', 'save', ['GroupMembers']));
}

// Save the Date Of Birth. This is the only one that is single valued
// and goes under the Person

Expand Down
Expand Up @@ -133,12 +133,12 @@ public function initialize(array $config): void {
}

/**
* Perform steps necessary to finalize the Petition.
*
* @since COmanage Registry v5.1.0
* Perform steps necessary to hydrate the Person record as part of Petition finalization.
*
* @param int $id Basic Attribute Collector ID
* @param Petition $petition Petition
* @param \App\Model\Entity\Petition $petition Petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, \App\Model\Entity\Petition $petition) {
Expand Down
Expand Up @@ -280,12 +280,12 @@ public function assembleVerifiableAddresses(
}

/**
* Perform steps necessary to finalize the Petition.
*
* @since COmanage Registry v5.1.0
* Perform steps necessary to hydrate the Person record as part of Petition finalization.
*
* @param int $id Invitation Accepter ID
* @param Petition $petition Petition
* @param \App\Model\Entity\Petition $petition Petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, \App\Model\Entity\Petition $petition) {
Expand Down
Expand Up @@ -119,12 +119,12 @@ public function initialize(array $config): void {
}

/**
* Perform steps necessary to finalize the Petition.
*
* @since COmanage Registry v5.1.0
* Perform steps necessary to hydrate the Person record as part of Petition finalization.
*
* @param int $id Invitation Accepter ID
* @param Petition $petition Petition
* @param \App\Model\Entity\Petition $petition Petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, \App\Model\Entity\Petition $petition) {
Expand Down
Expand Up @@ -112,12 +112,12 @@ public function initialize(array $config): void {
}

/**
* Perform steps necessary to finalize the Petition.
*
* @since COmanage Registry v5.1.0
* Perform steps necessary to hydrate the Person record as part of Petition finalization.
*
* @param int $id Invitation Accepter ID
* @param Petition $petition Petition
* @param \App\Model\Entity\Petition $petition Petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, \App\Model\Entity\Petition $petition) {
Expand Down
Expand Up @@ -121,24 +121,6 @@ public function dispatch(string $id) {
$this->render('/Standard/dispatch');
}

/**
* Display information about this Step.
*
* @since COmanage Registry v5.1.0
* @param string $id Attribute Collector ID
*/

public function display(string $id) {
$petition = $this->getPetition();

$this->set('vv_petition_env_identities', $this->EnvSourceCollectors
->PetitionEnvIdentities
->find()
->where(['PetitionEnvIdentities.petition_id' => $petition->id])
->contain(['EnvSourceIdentities'])
->firstOrFail());
}

/**
* Indicate whether this Controller will handle some or all authnz.
*
Expand Down
85 changes: 85 additions & 0 deletions app/plugins/EnvSource/src/View/Cell/EnvSourceCollectorsCell.php
@@ -0,0 +1,85 @@
<?php
/*
* COmanage Registry EnvSource Collectors Cell
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*
* This generic modal dialog stub is used for confirmations, e.g. when deleting a record.
* The text of the box is overridden with JavaScript, and the confirm button is intended to
* click a CakePHP postLink or postButton in the DOM. Use jsConfirmGeneric() to call it.
*/

declare(strict_types=1);

namespace EnvSource\View\Cell;

use Cake\View\Cell;

/**
* EnvSourceCollectors cell
*/
class EnvSourceCollectorsCell extends Cell
{
/**
* List of valid options that can be passed into this
* cell's constructor.
*
* @var array<string, mixed>
*/
protected $_validCellOptions = [
'vv_obj',
'vv_step',
'viewVars',
];

/**
* Initialization logic run at the end of object construction.
*
* @return void
*/
public function initialize(): void
{
}

/**
* Default display method.
*
* @param int $petitionId
* @return void
* @since COmanage Registry v5.1.0
*/
public function display(int $petitionId): void
{
$EnvSourceCollectors = $this->fetchTable('EnvSourceCollectors');

$this->set('vv_petition_env_identities', $EnvSourceCollectors
->PetitionEnvIdentities
->find()
->where(['PetitionEnvIdentities.petition_id' => $petitionId])
->contain(['EnvSourceIdentities'])
->firstOrFail());

$this->set('vv_step', $this->vv_step);
$this->set('vv_obj', $this->vv_obj);
}
}
@@ -0,0 +1,40 @@
<?php
/**
* COmanage Registry EnvSource Collectors Cell Display
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

$env_attributes = json_decode($vv_petition_env_identities->env_source_identity->env_attributes);

?>

<ul>
<li>Env Source Identity ID: <?= $vv_petition_env_identities->env_source_identity->id ?></li>
<li>Source Key: <?= $vv_petition_env_identities->env_source_identity->source_key ?></li>
<?php foreach($env_attributes as $k => $v): ?>
<li><?= __d('env_source', 'field.EnvSources.'.$k) . ": " . $v ?></li>
<?php endforeach ?>
</ul>

This file was deleted.

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);

namespace EnvSource\Test\TestCase\View\Cell;

use Cake\TestSuite\TestCase;
use EnvSource\View\Cell\EnvSourceCollectorsCell;

/**
* EnvSource\View\Cell\EnvSourceCollectorsCell Test Case
*/
class EnvSourceCollectorsCellTest extends TestCase
{
/**
* Request mock
*
* @var \Cake\Http\ServerRequest|\PHPUnit\Framework\MockObject\MockObject
*/
protected $request;

/**
* Response mock
*
* @var \Cake\Http\Response|\PHPUnit\Framework\MockObject\MockObject
*/
protected $response;

/**
* Test subject
*
* @var \EnvSource\View\Cell\EnvSourceCollectorsCell
*/
protected $EnvSourceCollectors;

/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->request = $this->getMockBuilder('Cake\Http\ServerRequest')->getMock();
$this->response = $this->getMockBuilder('Cake\Http\Response')->getMock();
$this->EnvSourceCollectors = new EnvSourceCollectorsCell($this->request, $this->response);
}

/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->EnvSourceCollectors);

parent::tearDown();
}
}
4 changes: 1 addition & 3 deletions app/src/Model/Behavior/TimezoneBehavior.php
Expand Up @@ -64,9 +64,7 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti
if(!empty($data[$f])) {
// This returns a DateTime object adjusting for localTZ
$offsetDT = new \DateTime($data[$f], $this->tz);

// strftime converts a timestamp according to server localtime (which should be UTC)
$data[$f] = strftime("%F %T", $offsetDT->getTimestamp());
$data[$f] = date("Y-m-d H:i:s", $offsetDT->getTimestamp());
}
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/Model/Table/AddressesTable.php
Expand Up @@ -316,7 +316,6 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel,
$address['person_role_id'] = $roleId;
}

// We need to get this from CoSettings??
foreach($fields as $fld) {
$address[$fld->column_name] = $fld->value;
}
Expand Down