Skip to content

Commit

Permalink
pkp/pkp-lib#10336 Expose publication forms Via API
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham authored Sep 6, 2024
2 parents 3d8ba0f + 9ffc670 commit ee3de0f
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
134 changes: 134 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,119 @@ 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());

// 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,
$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.paymentFeesNotEnabled'),
], 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);
}
}
2 changes: 1 addition & 1 deletion lib/pkp
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.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."

0 comments on commit ee3de0f

Please sign in to comment.