Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/stable 3 4 0/276 drop self disable behavior #277

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @file
# .travis.yml - PKP Plugins Integration

dist: bionic
dist: focal
os: linux
language: php

Expand All @@ -19,6 +19,7 @@ sudo: required
php:
- 8.0
- 8.1.0
- 8.2.0

env:
matrix:
Expand Down
251 changes: 117 additions & 134 deletions OrcidProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,136 +95,142 @@ public function register($category, $path, $mainContextId = null)
if (Application::isUnderMaintenance()) {
return true;
}
if ($success && $this->getEnabled($mainContextId)) {
$contextId = ($mainContextId === null) ? $this->getCurrentContextId() : $mainContextId;

Hook::add('ArticleHandler::view', [&$this, 'submissionView']);
Hook::add('PreprintHandler::view', [&$this, 'submissionView']);

// Insert the OrcidProfileHandler to handle ORCID redirects
Hook::add('LoadHandler', [$this, 'setupCallbackHandler']);

// Register callback for Smarty filters; add CSS
Hook::add('TemplateManager::display', [$this, 'handleTemplateDisplay']);
if (!$success || !$this->getEnabled($mainContextId)) {
return $success;
}

// Add "Connect ORCID" button to PublicProfileForm
Hook::add('User::PublicProfile::AdditionalItems', [$this, 'handleUserPublicProfileDisplay']);
$contextId = $mainContextId ?? $this->getCurrentContextId();
$validator = new OrcidValidator($this);

// Display additional ORCID access information and checkbox to send e-mail to authors in the AuthorForm
Hook::add('authorform::display', [$this, 'handleFormDisplay']);
$clientId = $this->getSetting($contextId, 'orcidClientId');
$clientSecret = $this->getSetting($contextId, 'orcidClientSecret');

// Send email to author, if the added checkbox was ticked
Hook::add('authorform::execute', [$this, 'handleAuthorFormExecute']);
if (!$validator->validateClientSecret($clientSecret) || !$validator->validateClientId($clientId)) {
error_log(new Exception('The ORCID plugin is enabled, but its settings are invalid. In order to fix, access the plugin settings and try to save the form'));
return $success;
}

// Handle ORCID on user registration
Hook::add('registrationform::execute', [$this, 'collectUserOrcidId']);
Hook::add('ArticleHandler::view', [&$this, 'submissionView']);
Hook::add('PreprintHandler::view', [&$this, 'submissionView']);

// Send emails to authors without ORCID id upon submission
//TODO Hook::add('submissionsubmitstep3form::execute', [$this, 'handleSubmissionSubmitStep3FormExecute']);
// Insert the OrcidProfileHandler to handle ORCID redirects
Hook::add('LoadHandler', [$this, 'setupCallbackHandler']);

// Send emails to authors without authorised ORCID access on promoting a submission to copy editing. Not included in OPS.
if ($this->getSetting($contextId, 'sendMailToAuthorsOnPublication')) {
Hook::add('EditorAction::recordDecision', [$this, 'handleEditorAction']);
}
// Register callback for Smarty filters; add CSS
Hook::add('TemplateManager::display', [$this, 'handleTemplateDisplay']);

Hook::add('Publication::publish', [$this, 'handlePublicationStatusChange']);
// Add "Connect ORCID" button to PublicProfileForm
Hook::add('User::PublicProfile::AdditionalItems', [$this, 'handleUserPublicProfileDisplay']);

Hook::add('ThankReviewerForm::thankReviewer', [$this, 'handleThankReviewer']);
// Display additional ORCID access information and checkbox to send e-mail to authors in the AuthorForm
Hook::add('authorform::display', [$this, 'handleFormDisplay']);

// Add more ORCiD fields to author Schema
Hook::add('Schema::get::author', function ($hookName, $args) {
$schema = &$args[0];
// Send email to author, if the added checkbox was ticked
Hook::add('authorform::execute', [$this, 'handleAuthorFormExecute']);

$schema->properties->orcidSandbox = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessScope = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidRefreshToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessExpiresOn = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessDenied = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidEmailToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidWorkPutCode = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
});
// Handle ORCID on user registration
Hook::add('registrationform::execute', [$this, 'collectUserOrcidId']);

// Add more ORCiD fields to user Schema
Hook::add('Schema::get::user', function ($hookName, $args) {
$schema = &$args[0];
// Send emails to authors without ORCID id upon submission
//TODO Hook::add('submissionsubmitstep3form::execute', [$this, 'handleSubmissionSubmitStep3FormExecute']);

$schema->properties->orcidAccessToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessScope = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidRefreshToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessExpiresOn = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessDenied = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidReviewPutCode = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
});
Services::get('schema')->get(PKPSchemaService::SCHEMA_USER, true);
// Send emails to authors without authorised ORCID access on promoting a submission to copy editing. Not included in OPS.
if ($this->getSetting($contextId, 'sendMailToAuthorsOnPublication')) {
Hook::add('EditorAction::recordDecision', [$this, 'handleEditorAction']);
}

Hook::add('Mailer::Mailables', [$this, 'addMailable']);
Hook::add('Publication::publish', [$this, 'handlePublicationStatusChange']);
Hook::add('ThankReviewerForm::thankReviewer', [$this, 'handleThankReviewer']);

Hook::add('Author::edit', [$this, 'handleAuthorFormExecute']);
// Add more ORCiD fields to author Schema
Hook::add('Schema::get::author', function ($hookName, $args) {
$schema = &$args[0];

Hook::add('Form::config::before', [$this, 'addOrcidFormFields']);
$schema->properties->orcidSandbox = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessScope = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidRefreshToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessExpiresOn = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessDenied = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidEmailToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidWorkPutCode = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
});

// Add more ORCiD fields to user Schema
Hook::add('Schema::get::user', function ($hookName, $args) {
$schema = &$args[0];

Hook::add('Installer::postInstall', [$this, 'updateSchema']);
$schema->properties->orcidAccessToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessScope = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidRefreshToken = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessExpiresOn = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidAccessDenied = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
$schema->properties->orcidReviewPutCode = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
});
Services::get('schema')->get(PKPSchemaService::SCHEMA_USER, true);

Hook::add('Publication::validatePublish', [$this, 'validate']);
}
Hook::add('Mailer::Mailables', [$this, 'addMailable']);
Hook::add('Author::edit', [$this, 'handleAuthorFormExecute']);
Hook::add('Form::config::before', [$this, 'addOrcidFormFields']);
Hook::add('Installer::postInstall', [$this, 'updateSchema']);
Hook::add('Publication::validatePublish', [$this, 'validate']);

return $success;
}
Expand Down Expand Up @@ -1059,29 +1065,6 @@ public function getDisplayName()
return __('plugins.generic.orcidProfile.displayName');
}

public function setEnabled($enabled)
{
$contextId = $this->getCurrentContextId();
$request = Application::get()->getRequest();
$validator = new OrcidValidator($this);

if ($this->isSitePlugin()) {
$contextId = 0;
}
if ($request->getUserVar('save') == 1) {
$clientId = $request->getUserVar('orcidClientId');
$clientSecret = $request->getUserVar('orcidClientSecret');
} else {
$clientId = $this->getSetting($contextId, 'orcidClientId');
$clientSecret = $this->getSetting($contextId, 'orcidClientSecret');
}

if (!$validator->validateClientSecret($clientSecret) or !$validator->validateClientId($clientId)) {
$enabled = false;
}
$this->updateSetting($contextId, 'enabled', $enabled, 'bool');
}

public function manage($args, $request)
{
$context = $request->getContext();
Expand Down
4 changes: 1 addition & 3 deletions classes/form/OrcidProfileSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ public function _checkPrerequisites()
if (!$this->validator->validateClientSecret($clientSecret)) {
$messages[] = __('plugins.generic.orcidProfile.manager.settings.orcidClientSecret.error');
}
if (strlen($clientId) == 0 or strlen($clientSecret) == 0) {
$this->plugin->setEnabled(false);
}

return $messages;
}
}