From 130d506f32d6d0a54aca83a35d02b5efe1b12fec Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 4 May 2025 08:56:37 +0300 Subject: [PATCH] sync external identity... --- .../EnvSource/templates/EnvSources/fields.inc | 4 +- .../resources/locales/en_US/orcid_source.po | 20 ++++- .../src/Model/Table/OrcidSourcesTable.php | 81 +++++++++++++++---- .../View/Cell/OrcidSourceCollectorsCell.php | 71 ++++++++-------- .../OrcidSource/src/config/plugin.json | 7 +- .../templates/OrcidSources/fields.inc | 19 ++++- .../cell/OrcidSourceCollectors/display.php | 10 ++- app/templates/element/form/h3Inject.php | 49 +++++++++++ 8 files changed, 206 insertions(+), 55 deletions(-) create mode 100644 app/templates/element/form/h3Inject.php diff --git a/app/plugins/EnvSource/templates/EnvSources/fields.inc b/app/plugins/EnvSource/templates/EnvSources/fields.inc index 54fb0f882..073a6c39e 100644 --- a/app/plugins/EnvSource/templates/EnvSources/fields.inc +++ b/app/plugins/EnvSource/templates/EnvSources/fields.inc @@ -48,7 +48,9 @@ if($vv_action == 'edit') { ]); } - print "

" . __d('env_source', 'information.header.map') . "

\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', diff --git a/app/plugins/OrcidSource/resources/locales/en_US/orcid_source.po b/app/plugins/OrcidSource/resources/locales/en_US/orcid_source.po index bc59d655e..1c629a2ca 100644 --- a/app/plugins/OrcidSource/resources/locales/en_US/orcid_source.po +++ b/app/plugins/OrcidSource/resources/locales/en_US/orcid_source.po @@ -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" @@ -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}" diff --git a/app/plugins/OrcidSource/src/Model/Table/OrcidSourcesTable.php b/app/plugins/OrcidSource/src/Model/Table/OrcidSourcesTable.php index f72cacb91..029ab4519 100644 --- a/app/plugins/OrcidSource/src/Model/Table/OrcidSourcesTable.php +++ b/app/plugins/OrcidSource/src/Model/Table/OrcidSourcesTable.php @@ -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; @@ -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) @@ -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([ @@ -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 = []; @@ -232,15 +271,15 @@ 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; @@ -248,22 +287,22 @@ protected function resultToEntityData( 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' ]; @@ -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')])); } @@ -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'] diff --git a/app/plugins/OrcidSource/src/View/Cell/OrcidSourceCollectorsCell.php b/app/plugins/OrcidSource/src/View/Cell/OrcidSourceCollectorsCell.php index 2a4144509..f15d25003 100644 --- a/app/plugins/OrcidSource/src/View/Cell/OrcidSourceCollectorsCell.php +++ b/app/plugins/OrcidSource/src/View/Cell/OrcidSourceCollectorsCell.php @@ -40,41 +40,44 @@ */ class OrcidSourceCollectorsCell extends Cell { - /** - * List of valid options that can be passed into this - * cell's constructor. - * - * @var array - */ - protected $_validCellOptions = [ - 'vv_obj', - 'vv_step', - 'viewVars', - ]; + /** + * List of valid options that can be passed into this + * cell's constructor. + * + * @var array + */ + 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); + } } diff --git a/app/plugins/OrcidSource/src/config/plugin.json b/app/plugins/OrcidSource/src/config/plugin.json index 7d9d9aac9..d83f9ea59 100644 --- a/app/plugins/OrcidSource/src/config/plugin.json +++ b/app/plugins/OrcidSource/src/config/plugin.json @@ -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" ] } diff --git a/app/plugins/OrcidSource/templates/OrcidSources/fields.inc b/app/plugins/OrcidSource/templates/OrcidSources/fields.inc index 5f749c7f9..d2966deac 100644 --- a/app/plugins/OrcidSource/templates/OrcidSources/fields.inc +++ b/app/plugins/OrcidSource/templates/OrcidSources/fields.inc @@ -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 + ] + ]); +} \ No newline at end of file diff --git a/app/plugins/OrcidSource/templates/cell/OrcidSourceCollectors/display.php b/app/plugins/OrcidSource/templates/cell/OrcidSourceCollectors/display.php index fa1233929..6347ade5d 100644 --- a/app/plugins/OrcidSource/templates/cell/OrcidSourceCollectors/display.php +++ b/app/plugins/OrcidSource/templates/cell/OrcidSourceCollectors/display.php @@ -1,6 +1,6 @@ -

This is a test page

+orcid_identifier)): ?> +
    +
  • + orcid_identifier]) ?> +
  • +
+ diff --git a/app/templates/element/form/h3Inject.php b/app/templates/element/form/h3Inject.php new file mode 100644 index 000000000..9b53a9adf --- /dev/null +++ b/app/templates/element/form/h3Inject.php @@ -0,0 +1,49 @@ + + + + + +

+ +