Skip to content

Commit d4205c4

Browse files
committed
Merge branch 'selection_register_3_3_0' into 'stable-3_3_0'
Enable bulk submission See merge request softwares-pkp/plugins_ojs/thoth-omp-plugin!51
2 parents bdaad94 + 16eb6f6 commit d4205c4

21 files changed

Lines changed: 1060 additions & 72 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ After metadata is published, a link to the book on Thoth will appear at the top
6060

6161
![link](/images/link.png)
6262

63+
### Bulk register
64+
65+
On the Thoth page, you can bulk submit a selection of titles from OMP into Thoth.
66+
67+
![page](/images/page.png)
68+
6369
## OMP-Thoth Mapping
6470

6571
<details>

ThothPlugin.inc.php

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public function register($category, $path, $mainContextId = null)
3333
$success = parent::register($category, $path);
3434

3535
if ($success && $this->getEnabled()) {
36-
$this->addTemplateFilters();
36+
HookRegistry::register('TemplateManager::display', [$this, 'addScripts']);
37+
HookRegistry::register('TemplateManager::display', [$this, 'addTemplateFilters']);
38+
HookRegistry::register('TemplateManager::display', [$this, 'addMenu']);
39+
HookRegistry::register('LoadHandler', [$this, 'addHandlers']);
40+
3741
$this->addToSchema();
3842
$this->addFormConfig();
3943
$this->addEndpoints();
40-
$this->addScripts();
4144
$this->addListeners();
42-
$this->addHandlers();
4345
}
4446

4547
return $success;
@@ -115,21 +117,20 @@ public function manage($args, $request)
115117
return parent::manage($args, $request);
116118
}
117119

118-
public function addTemplateFilters()
120+
public function addTemplateFilters($hookName, $args)
119121
{
120-
HookRegistry::register('TemplateManager::display', function ($hookName, $args) {
121-
$templateMgr = $args[0];
122-
$template = $args[1];
122+
$templateMgr = $args[0];
123+
$template = $args[1];
123124

124-
$thothSectionFilter = new ThothSectionFilter();
125-
$thothSectionFilter->registerFilter($templateMgr, $template, $this);
126-
});
125+
$thothSectionFilter = new ThothSectionFilter();
126+
$thothSectionFilter->registerFilter($templateMgr, $template, $this);
127127
}
128128

129129
public function addToSchema()
130130
{
131131
$thothSchema = new ThothSchema();
132132
HookRegistry::register('Schema::get::submission', [$thothSchema, 'addWorkIdToSchema']);
133+
HookRegistry::register('Submission::getBackendListProperties::properties', [$thothSchema, 'addToBackendProps']);
133134
}
134135

135136
public function addFormConfig()
@@ -144,22 +145,20 @@ public function addEndpoints()
144145
HookRegistry::register('APIHandler::endpoints', [$thothEndpoint, 'addEndpoints']);
145146
}
146147

147-
public function addScripts()
148+
public function addScripts($hookName, $args)
148149
{
149-
HookRegistry::register('TemplateManager::display', function ($hookName, $args) {
150-
$templateMgr = $args[0];
151-
$template = $args[1];
152-
$request = Application::get()->getRequest();
153-
154-
$thothNotification = new ThothNotification();
155-
$thothNotification->addJavaScriptData($request, $templateMgr);
156-
$thothNotification->addJavaScript($request, $templateMgr, $this);
157-
158-
$thothSectionFilter = new ThothSectionFilter();
159-
$thothSectionFilter->addJavaScriptData($request, $templateMgr, $template);
160-
$thothSectionFilter->addJavaScript($request, $templateMgr, $this);
161-
$thothSectionFilter->addStyleSheet($request, $templateMgr, $this);
162-
});
150+
$templateMgr = $args[0];
151+
$template = $args[1];
152+
$request = Application::get()->getRequest();
153+
154+
$thothNotification = new ThothNotification();
155+
$thothNotification->addJavaScriptData($request, $templateMgr);
156+
$thothNotification->addJavaScript($request, $templateMgr, $this);
157+
158+
$thothSectionFilter = new ThothSectionFilter();
159+
$thothSectionFilter->addJavaScriptData($request, $templateMgr, $template);
160+
$thothSectionFilter->addJavaScript($request, $templateMgr, $this);
161+
$thothSectionFilter->addStyleSheet($request, $templateMgr, $this);
163162
}
164163

165164
public function addListeners()
@@ -172,16 +171,56 @@ public function addListeners()
172171
HookRegistry::register('Publication::edit', [$publicationEditListener, 'updateThothBook']);
173172
}
174173

175-
public function addHandlers()
174+
public function addHandlers($hookName, $args)
175+
{
176+
$page = $args[0];
177+
$op = $args[1];
178+
179+
if (!$this->getEnabled() || $page !== 'thoth') {
180+
return false;
181+
}
182+
183+
if ($op === 'register') {
184+
$this->import('controllers/modal/RegisterHandler');
185+
define('HANDLER_CLASS', 'RegisterHandler');
186+
return true;
187+
}
188+
189+
if ($op === 'index') {
190+
$this->import('pages/thoth/ThothHandler');
191+
define('HANDLER_CLASS', 'ThothHandler');
192+
return true;
193+
}
194+
195+
return false;
196+
}
197+
198+
public function addMenu($hookName, $args)
176199
{
177-
HookRegistry::register('LoadHandler', function ($hookName, $args) {
178-
$page = $args[0];
179-
if ($this->getEnabled() && $page === 'thoth') {
180-
$this->import('controllers/modal/RegisterHandler');
181-
define('HANDLER_CLASS', 'RegisterHandler');
182-
return true;
183-
}
200+
$templateMgr = $args[0];
201+
202+
$request = Application::get()->getRequest();
203+
$router = $request->getRouter();
204+
$userRoles = (array) $router->getHandler()->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
205+
206+
$menu = $templateMgr->getState('menu');
207+
208+
if (empty($menu)) {
184209
return false;
185-
});
210+
}
211+
212+
if (in_array(ROLE_ID_MANAGER, $userRoles)) {
213+
$menu = array_slice($menu, 0, 2, true) +
214+
[
215+
'thoth' => [
216+
'name' => __('plugins.generic.thoth.navigation.thoth'),
217+
'url' => $router->url($request, null, 'thoth'),
218+
'isCurrent' => $router->getRequestedPage($request) === 'thoth',
219+
]
220+
] +
221+
array_slice($menu, 2, null, true);
222+
}
223+
224+
$templateMgr->setState(['menu' => $menu]);
186225
}
187226
}

classes/api/ThothEndpoint.inc.php

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,68 +33,98 @@ public function addEndpoints($hookName, $args)
3333
array_unshift(
3434
$endpoints['PUT'],
3535
[
36-
'pattern' => $handler->getEndpointPattern() . '/{submissionId}/publications/{publicationId}/register',
37-
'handler' => [$this, 'addThothBook'],
36+
'pattern' => $handler->getEndpointPattern() . '/{submissionId}/register',
37+
'handler' => [$this, 'register'],
3838
'roles' => [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR],
3939
]
4040
);
4141

42-
$handler->requiresSubmissionAccess[] = 'addThothBook';
42+
$handler->requiresSubmissionAccess[] = 'register';
4343

4444
return false;
4545
}
4646

47-
public function addThothBook($slimRequest, $response, $args)
47+
public function register($slimRequest, $response, $args)
4848
{
4949
$request = Application::get()->getRequest();
5050
$handler = $request->getRouter()->getHandler();
5151
$submission = $handler->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
52-
$publication = Services::get('publication')->get((int) $args['publicationId']);
5352
$params = $slimRequest->getParsedBody();
5453

5554
if (empty($params['imprint'])) {
5655
return $response->withStatus(400)->withJson(['imprint' => [__('plugins.generic.thoth.imprint.required')]]);
5756
}
5857

59-
if (!$publication) {
58+
if (!$submission) {
6059
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
6160
}
6261

63-
if ($submission->getId() !== $publication->getData('submissionId')) {
64-
return $response->withStatus(403)->withJsonError('api.publications.403.submissionsDidNotMatch');
62+
if (!$request->getContext()) {
63+
return $response->withStatus(403)->withJsonError('api.submissions.403.contextRequired');
6564
}
6665

6766
if ($submission->getData('thothWorkId')) {
6867
return $response->withStatus(403)->withJsonError('plugins.generic.thoth.api.403.alreadyRegistered');
6968
}
7069

71-
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
70+
$publication = $submission->getCurrentPublication();
71+
72+
$failure = [
73+
'id' => $submission->getId(),
74+
'errors' => []
75+
];
7276

73-
$submissionContext = $request->getContext();
74-
if (!$submissionContext || $submissionContext->getId() !== $submission->getData('contextId')) {
75-
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
77+
try {
78+
$failure['errors'] = ThothService::book()->validate($publication);
79+
} catch (Exception $e) {
80+
$failure['errors'][] = __('plugins.generic.thoth.connectionError');
7681
}
7782

78-
$thothNotification = new ThothNotification();
83+
if ($failure['errors']) {
84+
return $response->withStatus(400)->withJson($failure);
85+
}
86+
87+
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
88+
89+
$disableNotification = $params['disableNotification'];
7990
try {
8091
$thothBookId = ThothService::book()->register($publication, $params['imprint']);
8192
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
82-
$thothNotification->notifySuccess($request, $submission);
93+
$this->handleNotification($request, $submission, true, $disableNotification);
8394
} catch (QueryException $e) {
84-
$thothNotification->notifyError($request, $submission, $e->getMessage());
85-
return $response->withStatus(403)->withJsonError('plugins.generic.thoth.register.error');
95+
$this->handleNotification($request, $submission, false, $disableNotification, $e->getMessage());
96+
$failure['errors'][] = __('plugins.generic.thoth.register.error.log', ['reason' => $e->getMessage()]);
97+
return $response->withStatus(403)->withJson($failure);
8698
}
8799

88100
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');
89101

90-
$publicationProps = Services::get('publication')->getFullProperties(
91-
$publication,
92-
[
93-
'request' => $request,
94-
'userGroups' => $userGroupDao->getByContextId($submission->getData('contextId'))->toArray(),
95-
]
96-
);
102+
$submissionProps = Services::get('submission')->getFullProperties($submission, [
103+
'request' => $request,
104+
'slimRequest' => $slimRequest,
105+
'userGroups' => $userGroupDao->getByContextId($submission->getData('contextId'))->toArray(),
106+
]);
107+
108+
return $response->withJson($submissionProps, 200);
109+
}
110+
111+
112+
public function handleNotification($request, $submission, $success, $disableNotification, $errorMessage = null)
113+
{
114+
$thothNotification = new ThothNotification();
115+
116+
if ($disableNotification) {
117+
$thothNotification->logInfo(
118+
$request,
119+
$submission,
120+
$success ? 'plugins.generic.thoth.register.success.log' : 'plugins.generic.thoth.register.error.log',
121+
$errorMessage
122+
);
123+
return;
124+
}
97125

98-
return $response->withJson($publicationProps, 200);
126+
$success
127+
? $thothNotification->notifySuccess($request, $submission)
128+
: $thothNotification->notifyError($request, $submission, $errorMessage);
99129
}
100130
}

0 commit comments

Comments
 (0)