From 19f4b210fc52113a95622287a7e8fb48dbc18e1f Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Thu, 29 Aug 2024 15:04:00 -0500 Subject: [PATCH 1/3] pkp/pkp-lib#10336 Expose publication forms(SubmissionPaymentsForm, TitleAbstractForm, & IssueEntryForm) via API --- api/v1/submissions/SubmissionController.php | 132 ++++++++++++++++++++ locale/en/api.po | 3 + 2 files changed, 135 insertions(+) diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index db4c846f387..a5b396f0ef6 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -17,10 +17,29 @@ namespace APP\API\v1\submissions; +use APP\components\forms\publication\IssueEntryForm; +use APP\components\forms\publication\SubmissionPaymentsForm; +use APP\core\Application; +use APP\facades\Repo; +use APP\file\PublicFileManager; +use APP\publication\Publication; use APP\submission\Collector; +use APP\submission\Submission; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; +use Illuminate\Http\Response; +use Illuminate\Support\Facades\Route; +use PKP\components\forms\publication\TitleAbstractForm; +use PKP\context\Context; +use PKP\security\Role; class SubmissionController extends \PKP\API\v1\submissions\PKPSubmissionController { + public function __construct() + { + array_push($this->requiresSubmissionAccess, 'getPublicationIssueForm', 'getSubmissionPaymentForm'); + } + /** @copydoc PKPSubmissionHandler::getSubmissionCollector() */ protected function getSubmissionCollector(array $queryParams): Collector { @@ -40,4 +59,117 @@ protected function getSubmissionCollector(array $queryParams): Collector return $collector; } + + /** + * @copydoc \PKP\core\PKPBaseController::getGroupRoutes() + */ + public function getGroupRoutes(): void + { + parent::getGroupRoutes(); + + Route::middleware([ + self::roleAuthorizer([Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_ASSISTANT]), + ])->group(function () { + Route::prefix('{submissionId}/publications/{publicationId}/_components')->group(function () { + Route::get('issue', $this->getPublicationIssueForm(...))->name('submission.publication._components.issue'); + Route::get('submissionPayment', $this->getSubmissionPaymentForm(...))->name('submission.publication._components.submissionPayment'); + + })->whereNumber(['submissionId', 'publicationId']); + }); + + } + + /** + * Get IssueEntryForm form component + */ + protected function getPublicationIssueForm(Request $illuminateRequest): JsonResponse + { + $data = $this->getSubmissionAndPublicationData($illuminateRequest); + + if (isset($data['error'])) { + return response()->json([ 'error' => $data['error'],], $data['status']); + } + + $request = $this->getRequest(); + $submission = $data['submission']; /** @var Submission $submission */ + $publication = $data['publication']; /** @var Publication $publication*/ + $context = $data['context']; /** @var Context $context*/ + $publicationApiUrl = $data['publicationApiUrl']; /** @var String $publicationApiUrl*/ + $locales = $this->getPublicationFormLocales($context, $submission); + $temporaryFileApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $context->getPath(), 'temporaryFiles'); + + $publicFileManager = new PublicFileManager(); + $baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId()); + + $issueEntryForm = new IssueEntryForm( + $publicationApiUrl, + $locales, + $publication, + $context, + $baseUrl, + $temporaryFileApiUrl + ); + + return response()->json($this->getLocalizedForm($issueEntryForm, $submission->getData('locale'), $locales), Response::HTTP_OK); + } + + /** + * Get SubmissionPaymentsForm + */ + protected function getSubmissionPaymentForm(Request $illuminateRequest): JsonResponse + { + $request = $this->getRequest(); + $data = $this->getSubmissionAndPublicationData($illuminateRequest); + + if (isset($data['error'])) { + return response()->json([ 'error' => $data['error'],], $data['status']); + } + + $submission = $data['submission']; /** @var Submission $submission */ + $context = $data['context']; /** @var Context $context*/ + $paymentManager = Application::getPaymentManager($context); + + if (!$paymentManager->publicationEnabled()) { + return response()->json([ + 'error' => __('api.publications.403.noEnabledPaymentMethods'), + ], Response::HTTP_FORBIDDEN); + } + + $submissionPaymentsForm = new SubmissionPaymentsForm( + $request->getDispatcher()->url($request, Application::ROUTE_API, $context->getPath(), '_submissions/' . $submission->getId() . '/payment'), + $submission, + $context + ); + + return response()->json($submissionPaymentsForm->getConfig(), Response::HTTP_OK); + } + + /** + * @copydoc \PKP\api\v1\submissions\PKPSubmissionController::getPublicationTitleAbstractForm() + */ + protected function getPublicationTitleAbstractForm(Request $illuminateRequest): JsonResponse + { + $data = $this->getSubmissionAndPublicationData($illuminateRequest); + + if (isset($data['error'])) { + return response()->json([ 'error' => $data['error'],], $data['status']); + } + + $submission = $data['submission']; /** @var Submission $submission */ + $publication = $data['publication']; /** @var Publication $publication*/ + $context = $data['context']; /** @var Context $context*/ + $publicationApiUrl = $data['publicationApiUrl']; /** @var String $publicationApiUrl*/ + + $section = Repo::section()->get($publication->getData('sectionId'), $context->getId()); + $locales = $this->getPublicationFormLocales($context, $submission); + + $titleAbstract = new TitleAbstractForm( + $publicationApiUrl, + $locales, + $publication, + $section->getData('wordCount'), + !$section->getData('abstractsNotRequired') + ); + return response()->json($titleAbstract->getConfig(), Response::HTTP_OK); + } } diff --git a/locale/en/api.po b/locale/en/api.po index 668b86232b4..2aab44d9510 100644 --- a/locale/en/api.po +++ b/locale/en/api.po @@ -76,5 +76,8 @@ msgstr "The publication that you requested is not part of this submission." msgid "api.submissionFiles.400.badRepresentationAssocType" msgstr "You can not associated a file from this file stage with a galley." +msgid "api.publications.403.noEnabledPaymentMethods" +msgstr "Submission payments form is unavailable as there are no enabled payment methods." + msgid "api.submission.400.inactiveSection" msgstr "This section is no longer receiving submissions." From ac9176ed91df7fa263a220f0f59125f5310b79b6 Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 3 Sep 2024 11:39:32 -0500 Subject: [PATCH 2/3] pkp/pkp-lib#10336 update locales --- api/v1/submissions/SubmissionController.php | 4 +++- locale/en/api.po | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index a5b396f0ef6..2e1d4048aa4 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -101,6 +101,8 @@ protected function getPublicationIssueForm(Request $illuminateRequest): JsonResp $publicFileManager = new PublicFileManager(); $baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId()); + // This form provides Issue details for a submission's publication. + // This includes fields to change the Issue and section that the submission the publication is linked to, cover image, page and publication date details. $issueEntryForm = new IssueEntryForm( $publicationApiUrl, $locales, @@ -131,7 +133,7 @@ protected function getSubmissionPaymentForm(Request $illuminateRequest): JsonRes if (!$paymentManager->publicationEnabled()) { return response()->json([ - 'error' => __('api.publications.403.noEnabledPaymentMethods'), + 'error' => __('api.publications.403.paymentFeesNotEnabled'), ], Response::HTTP_FORBIDDEN); } diff --git a/locale/en/api.po b/locale/en/api.po index 2aab44d9510..6d3039b5b0a 100644 --- a/locale/en/api.po +++ b/locale/en/api.po @@ -76,8 +76,8 @@ msgstr "The publication that you requested is not part of this submission." msgid "api.submissionFiles.400.badRepresentationAssocType" msgstr "You can not associated a file from this file stage with a galley." -msgid "api.publications.403.noEnabledPaymentMethods" -msgstr "Submission payments form is unavailable as there are no enabled payment methods." +msgid "api.publications.403.paymentFeesNotEnabled" +msgstr "Submission payments form is unavailable as publication payment fees are not enabled." msgid "api.submission.400.inactiveSection" msgstr "This section is no longer receiving submissions." From 9ffc670193eac65c19de256a92efc8f831608863 Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Thu, 5 Sep 2024 19:44:49 -0500 Subject: [PATCH 3/3] submodule update --- lib/pkp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkp b/lib/pkp index 0d8b72e2f39..9bac544bf85 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 0d8b72e2f39a1304e6b8528db7fad0cd49e52d80 +Subproject commit 9bac544bf858c39150bdb430f66767205e905062