Skip to content

Commit

Permalink
WIP: Site settings work
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Apr 23, 2024
1 parent 9c70072 commit d53b4d3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 41 deletions.
76 changes: 47 additions & 29 deletions classes/components/forms/context/OrcidSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

class OrcidSettingsForm extends FormComponent
{
public const ORCID_DEFAULT_GROUP = 'orcidDefaultGroup';
public const ORCID_SETTINGS_GROUP = 'orcidSettingsGroup';
public const DEFAULT_GROUP = 'orcidDefaultGroup';
public const SETTINGS_GROUP = 'orcidSettingsGroup';
public $id = 'orcidSettings';
public $method = 'PUT';
public Context $context;
Expand All @@ -40,50 +40,68 @@ public function __construct(string $action, array $locales, \PKP\context\Context
$this->locales = $locales;
$this->context = $context;

$this->addGroup(['id' => self::ORCID_DEFAULT_GROUP])
$this->addGroup(['id' => self::DEFAULT_GROUP])
->addGroup([
'id' => self::ORCID_SETTINGS_GROUP,
'id' => self::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'),
]));
]);

// TODO: Handle disabling form requirement when ORCID functionality is disabled.

$isEnabledValue = (bool) $context->getData(OrcidManager::ENABLED) ?? false;
if (OrcidManager::isGloballyConfigured()) {
$isEnabledValue = true;
}
$this->addField(new FieldOptions(OrcidManager::ENABLED, [
'label' => __('orcidProfile.fieldset'),
'groupId' => self::DEFAULT_GROUP,
'options' => [
// TODO: Remove temporary hard-coded string
[
'value' => true,
'label' => 'Enable ORCID Profile functionality',
'disabled' => OrcidManager::isGloballyConfigured(),
]
],
'value' => $isEnabledValue,
]));

$settingsDescriptionText = __('orcidProfile.manager.settings.description');
if (OrcidManager::isGloballyConfigured()) {
// TODO: Add text about globally configured restrictions
$settingsDescriptionText .= '<br><br>' . 'TODO: Add text about globally configured restrictions.';
}

$this->addField(new FieldHTML('settingsDescription', [
'groupId' => self::DEFAULT_GROUP,
'description' => $settingsDescriptionText,
]));


// ORCID API settings can be configured globally via the site settings form 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,
'groupId' => self::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,
'groupId' => self::SETTINGS_GROUP,
'label' => __('orcidProfile.manager.settings.orcidClientId'),
'description' => $site->getData(OrcidManager::CLIENT_ID),
]))
->addField(new FieldHTML(OrcidManager::CLIENT_SECRET, [
'groupId' => self::ORCID_SETTINGS_GROUP,
'groupId' => self::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,
'groupId' => self::SETTINGS_GROUP,
'isRequired' => true,
'options' => [
['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')],
Expand All @@ -95,13 +113,13 @@ public function __construct(string $action, array $locales, \PKP\context\Context
]))
->addField(new FieldText(OrcidManager::CLIENT_ID, [
'label' => __('orcidProfile.manager.settings.orcidClientId'),
'groupId' => self::ORCID_SETTINGS_GROUP,
'groupId' => self::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,
'groupId' => self::SETTINGS_GROUP,
'isRequired' => true,
'value' => $context->getData(OrcidManager::CLIENT_SECRET) ?? '',
]));
Expand All @@ -119,27 +137,27 @@ public function __construct(string $action, array $locales, \PKP\context\Context
return strcmp($a['label'], $b['label']);
});
$this->addField(new FieldSelect(OrcidManager::COUNTRY, [
'groupId' => self::ORCID_SETTINGS_GROUP,
'groupId' => self::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,
'groupId' => self::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,
'groupId' => self::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,
'groupId' => self::SETTINGS_GROUP,
'label' => __('orcidProfile.manager.settings.logSectionTitle'),
'description' => __('orcidProfile.manager.settings.logLevel.help'),
'options' => [
Expand Down
44 changes: 37 additions & 7 deletions classes/components/forms/site/OrcidSiteSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,67 @@
namespace APP\components\forms\site;

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\site\Site;

class OrcidSiteSettingsForm extends FormComponent
{
public const DEFAULT_GROUP = 'orcidDefaultGroup';
public const SETTINGS_GROUP = 'orcidSettingsGroup';
public $id = 'orcidSiteSettings';
public $method = 'PUT';

public function __construct(string $action, array $locales, Site $site)
{
parent::__construct($this->id, $this->method, $action, $locales);

$this->addGroup(['id' => self::DEFAULT_GROUP])
->addGroup([
'id' => self::SETTINGS_GROUP,
'showWhen' => OrcidManager::ENABLED,
]);

// 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'),
$this->addField(new FieldOptions(OrcidManager::ENABLED, [
'label' => __('orcidProfile.fieldset'),
'groupId' => self::DEFAULT_GROUP,
'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')],
// TODO: Remove temporary hard-coded string
['value' => true, 'label' => 'Enable ORCID Profile functionality']
],
'value' => $site->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION,
'value' => (bool) $site->getData(OrcidManager::ENABLED) ?? false,
]))
->addField(new FieldHTML('settingsDescription', [
'groupId' => self::DEFAULT_GROUP,
// TODO: Add site settings description text
'description' => 'TODO: Add site settings description text.',
]))
->addField(new FieldSelect(OrcidManager::API_TYPE, [
'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'),
'groupId' => self::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' => $site->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION,
]))
->addField(new FieldText(OrcidManager::CLIENT_ID, [
'label' => __('orcidProfile.manager.settings.orcidClientId'),
'groupId' => self::SETTINGS_GROUP,
'isRequired' => true,
'value' => $site->getData(OrcidManager::CLIENT_ID) ?? '',
]))
->addField(new FieldText(OrcidManager::CLIENT_SECRET, [
'label' => __('orcidProfile.manager.settings.orcidClientSecret'),
'groupId' => self::SETTINGS_GROUP,
'isRequired' => true,
'value' => $site->getData(OrcidManager::CLIENT_SECRET) ?? '',
]));
}
Expand Down
9 changes: 4 additions & 5 deletions classes/orcid/OrcidManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ class OrcidManager
public static function isGloballyConfigured(): bool
{
$site = Application::get()->getRequest()->getSite();
$apiType = $site->getData(self::API_TYPE);
$clientId = $site->getData(self::CLIENT_ID);
$clientSecret = $site->getData(self::CLIENT_SECRET);
return isset($apiType) && trim($apiType) && isset($clientId) && trim($clientId) &&
isset($clientSecret) && trim($clientSecret);
return $site->getData(self::ENABLED);
}

/**
Expand All @@ -84,6 +80,9 @@ public static function getIcon(): string
*/
public static function isEnabled(?Context $context = null): bool
{
if (self::isGloballyConfigured()) {
return true;
}
if ($context === null) {
$context = Application::get()->getRequest()->getContext();
}
Expand Down

0 comments on commit d53b4d3

Please sign in to comment.