Skip to content

Commit

Permalink
sync external identity...
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed May 4, 2025
1 parent 19bd196 commit 130d506
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 55 deletions.
4 changes: 3 additions & 1 deletion app/plugins/EnvSource/templates/EnvSources/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ if($vv_action == 'edit') {
]);
}

print "<h3>" . __d('env_source', 'information.header.map') . "</h3>\n";
// Print a title
$title = __d('env_source', 'information.header.map');
print $this->element('form/h3Inject', compact('title'));

$defaultNames = [
'env_identifier_sourcekey' => 'ENV_SOURCE_KEY',
Expand Down
20 changes: 19 additions & 1 deletion app/plugins/OrcidSource/resources/locales/en_US/orcid_source.po
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,22 @@ msgstr "Inherit Scope"
msgid "field.OrcidSources.api_tier"
msgstr "API Tier"

msgid "information.orcid_source.linked"
msgid "field.OrcidSources.name_type_id"
msgstr "Name Type"

msgid "field.OrcidSources.telephone_number_type_id"
msgstr "Telephone Number Type"

msgid "field.OrcidSources.address_type_id"
msgstr "Address Type"

msgid "field.OrcidSources.default_affiliation_type_id"
msgstr "Default Affiliation Type"

msgid "field.OrcidSources.email_address_type_id"
msgstr "Email Address Type"

msgid "information.OrcidSources.linked"
msgstr "Obtained ORCID {0} via authenticated OAuth flow"

msgid "information.orcid_source.identifier"
Expand All @@ -82,6 +97,9 @@ msgstr "Authenticate with ORCID"
msgid "information.OrcidSourceCollectors.sign_in"
msgstr "Sign in with your ORCID account to securely verify your ORCID iD."

msgid "information.OrcidSources.default.types"
msgstr "Select Default Types for ORCID Fields"

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

Expand Down
81 changes: 66 additions & 15 deletions app/plugins/OrcidSource/src/Model/Table/OrcidSourcesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\Validation\Validator;
use CoreServer\Model\Table\Oauth2ServersTable;
use OrcidSource\Lib\Enum\{OrcidSourceApiEnum, OrcidSourceTierEnum};
use \App\Lib\Enum\EduPersonAffiliationEnum;
use \App\Lib\Enum\HttpStatusCodesEnum;
use \OrcidSource\Model\Entity\OrcidSource;

Expand Down Expand Up @@ -81,6 +81,26 @@ public function initialize(array $config): void {
// Define associations
$this->belongsTo('ExternalIdentitySources');
$this->belongsTo('Servers');
$this->belongsTo('AddressTypes')
->setClassName('Types')
->setForeignKey('address_type_id')
->setProperty('address_type');
$this->belongsTo('DefaultAffiliationTypes')
->setClassName('Types')
->setForeignKey('default_affiliation_type_id')
->setProperty('default_affiliation_type');
$this->belongsTo('EmailAddressTypes')
->setClassName('Types')
->setForeignKey('email_address_type_id')
->setProperty('email_address_type');
$this->belongsTo('NameTypes')
->setClassName('Types')
->setForeignKey('name_type_id')
->setProperty('name_type');
$this->belongsTo('TelephoneNumberTypes')
->setClassName('Types')
->setForeignKey('telephone_number_type_id')
->setProperty('telephone_number_type');

$this->hasMany('OrcidSource.OrcidTokens')
->setDependent(true)
Expand Down Expand Up @@ -132,6 +152,26 @@ public function initialize(array $config): void {
'type' => 'enum',
'class' => 'OrcidSource.OrcidSourceApiEnum'
],
'addressTypes' => [
'type' => 'type',
'attribute' => 'Addresses.type'
],
'defaultAffiliationTypes' => [
'type' => 'type',
'attribute' => 'PersonRoles.affiliation_type'
],
'emailAddressTypes' => [
'type' => 'type',
'attribute' => 'EmailAddresses.type'
],
'nameTypes' => [
'type' => 'type',
'attribute' => 'Names.type'
],
'telephoneNumberTypes' => [
'type' => 'type',
'attribute' => 'TelephoneNumbers.type'
]
]);

$this->setPermissions([
Expand Down Expand Up @@ -221,7 +261,6 @@ protected function resultToEntityData(
OrcidSource $OrcidSource,
array $result
): array {
$typesTable = TableRegistry::getTableLocator()->get('Types');
// Build the External Identity as an array
$eidata = [];

Expand All @@ -232,38 +271,38 @@ protected function resultToEntityData(
$role = [
// We only support one role per record
'role_key' => '1',
'affiliation' => 'member'
'affiliation' => $this->DefaultAffiliationTypes->getTypeLabel($OrcidSource->default_affiliation_type_id)
];

$eidata['external_identity_roles'][] = $role;

$name = [
'type' => 'official',
'given' => $result["name"]["given-names"]["value"],
'family' => $result["name"]["family-names"]["value"]
'type' => $this->NameTypes->getTypeLabel($OrcidSource->name_type_id),
'given' => $result['name']['given-names']['value'],
'family' => $result['name']['family-name']['value']
];

$eidata['names'][] = $name;

foreach($result['emails']["email"] as $m) {
$eidata['email_addresses'][] = [
'mail' => $m['email'],
'type' => 'official',
'type' => $this->EmailAddressTypes->getTypeLabel($OrcidSource->email_address_type_id),
'verified' => $m['verified']
];
}

if (!empty($result['addresses']['address'])) {
$address = [];
$address['type'] = 'office';
foreach($result['addresses']["address"] as $ad) {
$address['country'][] = $ad['country']['value'];
$address['type'] = $this->AddressTypes->getTypeLabel($OrcidSource->address_type_id);
foreach($result['addresses']['address'] as $ad) {
$address['country'] = $ad['country']['value'];
}
$eidata['addresses'][] = $address;
}

$eidata['identifiers'][] = [
'identifier' => $result['name']["path"],
'identifier' => $result['name']['path'],
'type' => 'orcid'
];

Expand Down Expand Up @@ -475,6 +514,9 @@ protected function orcidConnect(
])
->first();

// Set the CO ID
$this->setCurCoId($this->orcidSource->server->co_id);

if ( empty($this->orcidSource->id)) {
throw new \InvalidArgumentException(__d('error', 'notfound', [__d('core_server', 'controller.Oauth2Servers')]));
}
Expand Down Expand Up @@ -507,10 +549,19 @@ protected function orcidConnect(
public function validationDefault(Validator $validator): Validator {
$schema = $this->getSchema();

$validator->add('external_source_identity_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString('external_source_identity_id');
foreach([
'external_source_identity_id',
'default_affiliation_type_id',
'address_type_id',
'email_address_type_id',
'name_type_id',
'telephone_number_type_id'
] as $field) {
$validator->add($field, [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString($field);
}

$validator->add('server_id', [
'content' => ['rule' => 'isInteger']
Expand Down
71 changes: 37 additions & 34 deletions app/plugins/OrcidSource/src/View/Cell/OrcidSourceCollectorsCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,44 @@
*/
class OrcidSourceCollectorsCell 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',
];
/**
* 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
{
}
/**
* 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.2.0
*/
public function display(int $petitionId): void
{
$OrcidTokens = $this->fetchTable('OrcidSource.OrcidTokens');
/**
* Default display method.
*
* @param int $petitionId
* @return void
* @since COmanage Registry v5.2.0
*/
public function display(int $petitionId): void
{
$vv_oi = $this->fetchTable('CoreSource.PetitionOrcids')
->find()
->where(['petition_id' => $this->vv_obj->id])
->first();

$this->set('vv_orcid_token',[]);
$this->set('vv_step', $this->vv_step);
$this->set('vv_obj', $this->vv_obj);
}
$this->set('vv_orcid', $vv_oi);;

$this->set('vv_step', $this->vv_step);
$this->set('vv_obj', $this->vv_obj);
}
}
7 changes: 6 additions & 1 deletion app/plugins/OrcidSource/src/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
"server_id": { "type": "integer", "foreignkey": { "table": "servers", "column": "id" }, "notnull": false },
"scope_inherit": { "type": "boolean" },
"api_tier": { "type": "string", "size": "3" },
"api_type": { "type": "string", "size": "3" }
"api_type": { "type": "string", "size": "3" },
"default_affiliation_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"address_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"email_address_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"name_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"telephone_number_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } }
},
"indexes": {
"orcid_sources_i1": { "columns": [ "external_identity_source_id" ] }
Expand Down
19 changes: 18 additions & 1 deletion app/plugins/OrcidSource/templates/OrcidSources/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,26 @@ if (filter_var($vv_obj->scope_inherit, FILTER_VALIDATE_BOOLEAN)) {
// Render active scopes
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'redirect_uri',
'fieldName' => 'Scope',
'fieldOptions' => [
'readOnly' => true,
'default' => $vv_inherited_scopes
]
]]);

// Print a title
$title = __d('orcid_source', 'information.OrcidSources.default.types');
print $this->element('form/h3Inject', compact('title'));

foreach([
'address_type_id',
'default_affiliation_type_id',
'email_address_type_id',
'name_type_id',
] as $field) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => $field
]
]);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* COmanage Registry EnvSource Collectors Cell Display
* COmanage Registry ORCID Source Collectors Cell Display
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand Down Expand Up @@ -29,4 +29,10 @@

?>

<p>This is a test page</p>
<?php if(!empty($vv_orcid->orcid_identifier)): ?>
<ul>
<li>
<?= __d('orcid_source', 'result.OrcidSourceCollector.collected', [$vv_orcid->orcid_identifier]) ?>
</li>
</ul>
<?php endif; ?>
49 changes: 49 additions & 0 deletions app/templates/element/form/h3Inject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* COmanage Registry Inject H3 Element to a list
*
* 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.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/


declare(strict_types=1);

// View vars
// $title
// $vv_action

if (empty($title)) {
return;
}

$unique = md5($title);

?>

<!-- Close the previous one-->
</ul>
<!-- Add the header -->
<h3><?= $title ?></h3>
<!-- Start a the new one -->
<ul id="<?= $vv_action . '_' . $this->name . '_' . $unique?>" class="fields form-list">

0 comments on commit 130d506

Please sign in to comment.