-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace APP\API\v1\orcid; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Route; | ||
use PKP\core\PKPBaseController; | ||
|
||
class OrcidController extends PKPBaseController | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getHandlerPath(): string | ||
{ | ||
return 'orcid'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getRouteGroupMiddleware(): array | ||
{ | ||
// TODO: See what middleware should be used here | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getGroupRoutes(): void | ||
{ | ||
Route::post('authorize', $this->authorizeOrcid(...)) | ||
->name('orcid.authorize'); | ||
Route::post('verify', $this->verify(...)) | ||
->name('orcid.verify'); | ||
} | ||
|
||
public function authorizeOrcid(Request $illuminateRequest): JsonResponse | ||
{ | ||
return response()->json([], Response::HTTP_OK); | ||
} | ||
|
||
public function verify(Request $illuminateRequest): JsonResponse | ||
{ | ||
return response()->json([], Response::HTTP_OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
return new \PKP\handler\APIHandler(new \APP\API\v1\orcid\OrcidController()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace APP\components\forms\context; | ||
|
||
use APP\core\Application; | ||
use APP\orcid\OrcidManager; | ||
use PKP\components\forms\FieldHTML; | ||
use PKP\components\forms\FieldOptions; | ||
use PKP\components\forms\FieldSelect; | ||
use PKP\components\forms\FieldText; | ||
use PKP\components\forms\FormComponent; | ||
use PKP\context\Context; | ||
use PKP\facades\Locale; | ||
|
||
class OrcidSettingsForm extends FormComponent | ||
{ | ||
public const ORCID_DEFAULT_GROUP = 'orcidDefaultGroup'; | ||
public const ORCID_SETTINGS_GROUP = 'orcidSettingsGroup'; | ||
public $id = 'orcidSettings'; | ||
public $method = 'PUT'; | ||
public Context $context; | ||
|
||
public function __construct(string $action, array $locales, \PKP\context\Context $context) | ||
{ | ||
$this->action = $action; | ||
$this->locales = $locales; | ||
$this->context = $context; | ||
|
||
$this->addGroup(['id' => self::ORCID_DEFAULT_GROUP]) | ||
->addGroup([ | ||
'id' => self::ORCID_SETTINGS_GROUP, | ||
'showWhen' => OrcidManager::ENABLED | ||
]) | ||
// TODO: Handle disabling form requirement when ORCID functionality is disabled. | ||
->addField(new FieldOptions(OrcidManager::ENABLED, [ | ||
'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), | ||
'groupId' => self::ORCID_DEFAULT_GROUP, | ||
'options' => [ | ||
// TODO: Remove temporary hard-coded string | ||
['value' => true, 'label' => 'Enable ORCID Profile functionality'] | ||
], | ||
'value' => (bool) $context->getData(OrcidManager::ENABLED) ?? false | ||
])) | ||
->addField(new FieldHTML('settingsDescription', [ | ||
'groupId' => self::ORCID_DEFAULT_GROUP, | ||
'description' => __('orcidProfile.manager.settings.description'), | ||
])); | ||
|
||
// ORCID API settings can be configured globally via config file or from this settings form | ||
if (OrcidManager::isGloballyConfigured()) { | ||
$site = Application::get()->getRequest()->getSite(); | ||
|
||
$this->addField(new FieldHTML(OrcidManager::API_TYPE, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), | ||
'description' => $this->getLocalizedApiTypeString($site->getData(OrcidManager::API_TYPE)) | ||
])) | ||
->addField(new FieldHTML(OrcidManager::CLIENT_ID, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.orcidClientId'), | ||
'description' => $site->getData(OrcidManager::CLIENT_ID), | ||
])) | ||
->addField(new FieldHTML(OrcidManager::CLIENT_SECRET, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.orcidClientSecret'), | ||
'description' => $site->getData(OrcidManager::CLIENT_SECRET), | ||
])); | ||
|
||
} else { | ||
$this->addField(new FieldSelect(OrcidManager::API_TYPE, [ | ||
'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'isRequired' => true, | ||
'options' => [ | ||
['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')], | ||
['value' => OrcidManager::API_PUBLIC_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.publicSandbox')], | ||
['value' => OrcidManager::API_MEMBER_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.member')], | ||
['value' => OrcidManager::API_MEMBER_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.memberSandbox')], | ||
], | ||
'value' => $context->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION, | ||
])) | ||
->addField(new FieldText(OrcidManager::CLIENT_ID, [ | ||
'label' => __('orcidProfile.manager.settings.orcidClientId'), | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'isRequired' => true, | ||
'value' => $context->getData(OrcidManager::CLIENT_ID) ?? '', | ||
])) | ||
->addField(new FieldText(OrcidManager::CLIENT_SECRET, [ | ||
'label' => __('orcidProfile.manager.settings.orcidClientSecret'), | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'isRequired' => true, | ||
'value' => $context->getData(OrcidManager::CLIENT_SECRET) ?? '', | ||
])); | ||
} | ||
|
||
// TODO: Labeled as OJS-specific in settingsForm.tpl. Check status | ||
$countries = []; | ||
foreach (Locale::getCountries() as $country) { | ||
$countries[] = [ | ||
'value' => $country->getAlpha2(), | ||
'label' => $country->getLocalName(), | ||
]; | ||
} | ||
usort($countries, function ($a, $b) { | ||
return strcmp($a['label'], $b['label']); | ||
}); | ||
$this->addField(new FieldSelect(OrcidManager::COUNTRY, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.country'), | ||
'description' => __('orcidProfile.manager.settings.review.help'), | ||
'options' => $countries, | ||
'value' => $context->getData(OrcidManager::COUNTRY) ?? '', | ||
])) | ||
->addField(new FieldText(OrcidManager::CITY, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => 'orcidProfile.manager.settings.city', | ||
'value' => $context->getData(OrcidManager::CITY) ?? '', | ||
])) | ||
->addField(new FieldOptions(OrcidManager::SEND_MAIL_TO_AUTHORS_ON_PUBLICATION, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.mailSectionTitle'), | ||
'options' => [ | ||
['value' => true, 'label' => __('orcidProfile.manager.settings.sendMailToAuthorsOnPublication')] | ||
], | ||
'value' => (bool) $context->getData(OrcidManager::SEND_MAIL_TO_AUTHORS_ON_PUBLICATION) ?? false, | ||
])) | ||
->addField(new FieldSelect(OrcidManager::LOG_LEVEL, [ | ||
'groupId' => self::ORCID_SETTINGS_GROUP, | ||
'label' => __('orcidProfile.manager.settings.logSectionTitle'), | ||
'description' => __('orcidProfile.manager.settings.logLevel.help'), | ||
'options' => [ | ||
['value' => 'ERROR', 'label' => __('orcidProfile.manager.settings.logLevel.error')], | ||
['value' => 'ALL', 'label' => __('orcidProfile.manager.settings.logLevel.all')], | ||
], | ||
'value' => $context->getData(OrcidManager::LOG_LEVEL) ?? 'ERROR', | ||
])); | ||
} | ||
|
||
private function getLocalizedApiTypeString(string $apiType): string | ||
{ | ||
return match ($apiType) { | ||
OrcidManager::API_PUBLIC_PRODUCTION => __('orcidProfile.manager.settings.orcidProfileAPIPath.public'), | ||
OrcidManager::API_PUBLIC_SANDBOX => __('orcidProfile.manager.settings.orcidProfileAPIPath.publicSandbox'), | ||
OrcidManager::API_MEMBER_PRODUCTION => __('orcidProfile.manager.settings.orcidProfileAPIPath.member'), | ||
OrcidManager::API_MEMBER_SANDBOX => __('orcidProfile.manager.settings.orcidProfileAPIPath.memberSandbox'), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace APP\components\forms\site; | ||
|
||
use APP\orcid\OrcidManager; | ||
use PKP\components\forms\FieldSelect; | ||
use PKP\components\forms\FieldText; | ||
use PKP\components\forms\FormComponent; | ||
use PKP\site\Site; | ||
|
||
class OrcidSiteSettingsForm extends FormComponent | ||
{ | ||
public $id = 'orcidSiteSettings'; | ||
public $method = 'PUT'; | ||
|
||
public function __construct(string $action, array $locales, Site $site) | ||
{ | ||
parent::__construct($this->id, $this->method, $action, $locales); | ||
|
||
// TODO: How to handle all should be blank or completed (all or nothing) | ||
$this->addField(new FieldSelect(OrcidManager::API_TYPE, [ | ||
'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), | ||
'options' => [ | ||
['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')], | ||
['value' => OrcidManager::API_PUBLIC_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.publicSandbox')], | ||
['value' => OrcidManager::API_MEMBER_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.member')], | ||
['value' => OrcidManager::API_MEMBER_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.memberSandbox')], | ||
], | ||
'value' => $site->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION, | ||
])) | ||
->addField(new FieldText(OrcidManager::CLIENT_ID, [ | ||
'label' => __('orcidProfile.manager.settings.orcidClientId'), | ||
'value' => $site->getData(OrcidManager::CLIENT_ID) ?? '', | ||
])) | ||
->addField(new FieldText(OrcidManager::CLIENT_SECRET, [ | ||
'label' => __('orcidProfile.manager.settings.orcidClientSecret'), | ||
'value' => $site->getData(OrcidManager::CLIENT_SECRET) ?? '', | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace APP\migration\upgrade\v3_5_0; | ||
|
||
use APP\facades\Repo; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Str; | ||
use PKP\migration\Migration; | ||
|
||
class OrcidMigration extends Migration | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function up(): void | ||
{ | ||
$q = DB::table('plugin_settings') | ||
->where('plugin_name', '=', 'orcidprofileplugin') | ||
->where('context_id', '<>', 0) | ||
->select(['context_id', 'setting_name', 'setting_value']); | ||
|
||
$results = $q->get(); | ||
$mappedResults = $results->map(function ($item) { | ||
if(!Str::startsWith($item->setting_name, 'orcid')) { | ||
$item->setting_name = 'orcid' . Str::ucfirst($item->setting_name); | ||
} | ||
$item->journal_id = $item->context_id; | ||
unset($item->context_id); | ||
|
||
return (array) $item; | ||
}); | ||
|
||
DB::table('journal_settings') | ||
->insert($mappedResults->toArray()); | ||
|
||
// TODO: To be tested still. Keeping in plugin_settings during dev. | ||
// DB::table('plugin_settings') | ||
// ->where('plugin_name', '=', 'orcidprofileplugin') | ||
// ->delete(); | ||
|
||
Repo::emailTemplate()->dao->installEmailTemplates( | ||
Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), | ||
[], | ||
'ORCID_COLLECT_AUTHOR_ID', | ||
true, | ||
); | ||
Repo::emailTemplate()->dao->installEmailTemplates( | ||
Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), | ||
[], | ||
'ORCID_REQUEST_AUTHOR_AUTHORIZATION', | ||
true, | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function down(): void | ||
{ | ||
// TODO: Implement down() method. | ||
} | ||
} |
Oops, something went wrong.