Skip to content

Commit

Permalink
pkp/pkp-lib#10336 Expose publication forms(SubmissionPaymentsForm, Ti…
Browse files Browse the repository at this point in the history
…tleAbstractForm, & IssueEntryForm) via API
  • Loading branch information
taslangraham committed Sep 2, 2024
1 parent 11beda6 commit 5161d60
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
145 changes: 145 additions & 0 deletions api/v1/submissions/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -40,4 +59,130 @@ 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']);
});

}

protected function getPublicationIssueForm(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = Repo::publication()->get((int)$illuminateRequest->route('publicationId'));

if (!$publication || !$submission) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

if ($submission->getId() !== $publication->getData('submissionId')) {
return response()->json([
'error' => __('api.publications.403.submissionsDidNotMatch'),
], Response::HTTP_FORBIDDEN);
}

$submissionContext = $this->getContext($request, $submission);
$publicationApiUrl = $this->getPublicationUrl($request, $submissionContext, $submission, $publication);
$locales = $this->getPublicationFormLocales($submissionContext, $submission);
$temporaryFileApiUrl = $request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), 'temporaryFiles');

$publicFileManager = new PublicFileManager();
$baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($submissionContext->getId());

$issueEntryForm = new IssueEntryForm(
$publicationApiUrl,
$locales,
$publication,
$submissionContext,
$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();
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = Repo::publication()->get((int)$illuminateRequest->route('publicationId'));
$submissionContext = $this->getContext($request, $submission);

$paymentManager = Application::getPaymentManager($submissionContext);

if (!$paymentManager->publicationEnabled()) {
return response()->json([
'error' => __('api.publications.403.noEnabledPaymentMethods'),
], Response::HTTP_FORBIDDEN);
}


if (!$publication || !$submission) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

if ($submission->getId() !== $publication->getData('submissionId')) {
return response()->json([
'error' => __('api.publications.403.submissionsDidNotMatch'),
], Response::HTTP_FORBIDDEN);
}

$submissionPaymentsForm = new SubmissionPaymentsForm(
$request->getDispatcher()->url($request, Application::ROUTE_API, $submissionContext->getPath(), '_submissions/' . $submission->getId() . '/payment'),
$submission,
$request->getContext()
);

return response()->json($submissionPaymentsForm->getConfig(), Response::HTTP_OK);
}

/**
* @copydoc \PKP\api\v1\submissions\PKPSubmissionController::getPublicationTitleAbstractFormComponent()
*/
protected function getPublicationTitleAbstractFormComponent(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*/
$submissionContext = $data['context']; /** @var Context $submissionContext*/
$publicationApiUrl = $data['publicationApiUrl']; /** @var String $publicationApiUrl*/

$section = Repo::section()->get($publication->getData('sectionId'), $submissionContext->getId());
$locales = $this->getPublicationFormLocales($submissionContext, $submission);

$titleAbstract = new TitleAbstractForm(
$publicationApiUrl,
$locales,
$publication,
$section->getData('wordCount'),
!$section->getData('abstractsNotRequired')
);
return response()->json($titleAbstract->getConfig(), Response::HTTP_OK);
}
}
3 changes: 3 additions & 0 deletions locale/en/api.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 5161d60

Please sign in to comment.