Skip to content

Commit

Permalink
Dispatch and Hydrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed May 3, 2025
1 parent 357e5c9 commit 57183cf
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ msgstr "Access token not configured (try resaving configuration)"
msgid "error.param.notfound"
msgstr "{0} was not found"

msgid "error.orcid_source.no_orcid"
msgstr "ORCID identifier missing from response."

msgid "field.OrcidSources.api_type"
msgstr "API Type"

Expand All @@ -79,4 +82,8 @@ msgstr "Authenticate with ORCID"
msgid "information.OrcidSourceCollectors.sign_in"
msgstr "Sign in with your ORCID account to securely verify your ORCID iD."

msgid "result.OrcidSourceCollector.collected"
msgstr "Obtained ORCID Identifier {0}"

msgid "result.orcid.saved"
msgstr "ORCID Token recorded"
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@
namespace OrcidSource\Controller;

use App\Controller\StandardEnrollerController;
use App\Lib\Enum\PetitionActionEnum;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Http\Response;
use Cake\ORM\TableRegistry;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use OrcidSource\Lib\Enum\OrcidSourceScopeEnum;

class OrcidSourceCollectorsController extends StandardEnrollerController {
protected $OrcidSources;
protected $PetitionOrcids;

public $paginate = [
'order' => [
Expand All @@ -57,6 +56,7 @@ class OrcidSourceCollectorsController extends StandardEnrollerController {
public function beforeFilter(\Cake\Event\EventInterface $event)
{
$this->OrcidSources = TableRegistry::getTableLocator()->get('OrcidSource.OrcidSources');
$this->PetitionOrcids = TableRegistry::getTableLocator()->get('OrcidSource.PetitionOrcids');

return parent::beforeFilter($event);
}
Expand Down Expand Up @@ -92,7 +92,6 @@ public function beforeRender(EventInterface $event) {
public function dispatch(string $id) {
$request = $this->getRequest();
$session = $request->getSession();
$username = $session->read('Auth.external.user');

$op = $this->requestParam('op');
$code = $this->getRequest()->getQuery('code') ?? null;
Expand Down Expand Up @@ -124,7 +123,7 @@ public function dispatch(string $id) {
// Let's authenticate first
if ($op == 'authenticate') {
$this->authenticate($id, $PluginServerEntity);
} else if (!empty($code)) {
} else if (!empty($code) && $op !== 'savetoken') {
$response = $PluginServersTable->exchangeCode(
$id,
$code,
Expand All @@ -134,21 +133,36 @@ public function dispatch(string $id) {
'?' => ['petition_id' => $petition->id],
]
),
false
);

// Use the response and save the data to petitions table
if(empty($response->orcid)) {
throw new \RuntimeException(__d('orcid_source', 'error.orcid_source.no_orcid'));
}
$this->set('vv_orcid', $response->orcid);
$this->set('vv_token', $response);
} if (!empty($code) && $op === 'savetoken') {
$orcid_token = $this->requestParam('orcid_token');
$this->PetitionOrcids->record(
petitionId: $petition->id,
enrollmentFlowStepId: $oricdSourceEntity->enrollment_flow_step_id,
orcidToken: $orcid_token,
orcidSourceCollectorId: (int)$id,
);
// On success, indicate the step is completed and generate a redirect
// to the next step

return $this->finishStep(
enrollmentFlowStepId: $oricdSourceEntity->enrollment_flow_step_id,
petitionId: $petition->id,
comment: __d('orcid_source', 'result.orcid.saved')
);
} else {
// Fall Through. Let the view render
}

}
catch(\OverflowException $e) {
// The requested Source Key is already attached to an External Identity, so we throw
// an error now rather than wait until finalization

// Flag the Petition as a duplicate
$Petitions = TableRegistry::getTableLocator()->get("Petitions");
}
catch(\Exception $e) {
$this->Flash->error($e->getMessage());
}
Expand All @@ -165,8 +179,6 @@ public function dispatch(string $id) {
* @param string|int $id ID of the collector
* @param EntityInterface $serverCfg ORCID Server configuration
* @return void
* @throws \Exception If authentication fails
* @throws \OverflowException If source key is already attached
* @since COmanage Registry v5.2.0
*/
protected function authenticate(string|int $id, EntityInterface $serverCfg): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* COmanage Registry Env Sources Controller
* COmanage Registry Orcid Sources Controller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand Down
49 changes: 49 additions & 0 deletions app/plugins/OrcidSource/src/Model/Entity/PetitionOrcid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* COmanage Registry Petition Orcid Entity
*
* 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-plugins
* @since COmanage Registry v5.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace OrcidSource\Model\Entity;

use Cake\ORM\Entity;

class PetitionOrcid extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
Loading

0 comments on commit 57183cf

Please sign in to comment.