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

Expose publication forms via API #10336

Closed
7 tasks
jardakotesovec opened this issue Aug 26, 2024 · 15 comments
Closed
7 tasks

Expose publication forms via API #10336

jardakotesovec opened this issue Aug 26, 2024 · 15 comments
Assignees
Labels
Enhancement:2:Moderate A new feature or improvement that can be implemented in less than 4 weeks.
Milestone

Comments

@jardakotesovec
Copy link
Contributor

jardakotesovec commented Aug 26, 2024

Describe the issue
There are challenges when the forms are both manipulated client and server side. In future we might shift to client side form building. But for current efforts with new submission listing and workflow, it will be best to just expose the forms as private API. More detail discussion is available here - #10331

Proposed solution
This is based on the discussion linked above. I am ok with details being different (different url, multiple forms together or individual, etc) as long as I can get to them via API.

I propose example following url, that would expose individual forms
GET /submissions/{submissionId}/publications/{publicationId}/_components/titleAbstract

Which would return json from titleAbstractForm->getConfig().

Publicaton forms
Following forms needs to be exposed

  • Title & Abstract: TitleAbstractForm (pkp-lib) + some additional logic in WorkflowHandler.php for wordLimit, which is specific for OJS
  • Metadata: PKPMetadataForm (pkp-lib)
  • References: PKPCitationsForm (pkp-lib)
  • Identifiers: PKPPublicationIdentifiersForm (pkp-lib)
  • Permissions & Disclosure: PKPPublicationLicenseForm (pkp-lib
  • Issue: IssueEntryForm (ojs)
  • submission payment form - SubmissionPaymentsForm (ojs)

In terms of implementation its mostly about cherry-picking from PKPWorkflowHandler.php for common forms, and WorkflowHandler.php for ojs specific forms + this handler might modify some of the pkp-lib forms.

Considerations
In terms of the permissions - publications forms are presented to editors and authors, not reviewers. But in general following permissions that are in place for given /publications/{$publicationId} should be good starting point.

What application are you using?
OJS version 3.5

@jardakotesovec jardakotesovec added the Enhancement:2:Moderate A new feature or improvement that can be implemented in less than 4 weeks. label Aug 26, 2024
@jardakotesovec jardakotesovec added this to the 3.5.0 LTS milestone Aug 26, 2024
@ewhanson
Copy link
Collaborator

Hey @jardakotesovec, I've done some initial testing with this and this approach seems good. With the endpoint returning the JSON from $form->getConfig(), what else needs to be done on the UI library side of things for it to be used? Is that within the scope of this issue? Additionally, are you ready to have the old PHP-instantiated forms removed at this point or should they stick around until the submission workflow work is complete?

@jardakotesovec
Copy link
Contributor Author

@ewhanson This issue is just expose via API. I will use that on ui-library side of things.

Workflow handlers eventually will be removed completely. Once we have all apps moved to the side modal workflow.

@ewhanson
Copy link
Collaborator

Perfect, thanks @jardakotesovec.

@ewhanson
Copy link
Collaborator

ewhanson commented Aug 27, 2024

Implementation overview

Copy over existing form creation to an API endpoint and return as JSON the results of $form->getConfig(). The scope of this issue is only to add the new endpoints, not remove the old ones yet. This will need to be completed for all the publication forms described above.

I did some initial exploring with the TitleAbstract form, and was able to generate the desired results as described below. Note, this example does not consider that the primary logic for this endpoint will be in pkp-lib with some additional functionality that is specific to ojs as noted above. This is an example of the rough shape of the implementation.

Example

  1. Create an endpoint in PKPSubmissionController under the appropriate roleAuthorizer middleware group, e.g.:
Route::get('{submissionId}/publications/{publicationId}/_components/titleAbstract', $this->getTitleAbstractComponent(...))
    ->name('submission.publication.components.titleAbstract')
    ->whereNumber(['submissionId', 'publicationId']);
  1. Move any code needed to instantiate the form to the endpoint: note the example below does not consider separation between pkp-lib and ojs specific code nor does it include all the necessary authorization/sanity checks. In this case, most of this is directly from WorkflowHandler::getTitleAbstractForm() from OJS and the necessary setup for the arguments passed into it. Also note that to use $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION), the endpoint function name must be added to the $requiresSubmissionAccess array.
public function getTitleAbstractComponent(Request $illuminateRequest): JsonResponse
{
    $submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
    $context = $this->getRequest()->getContext();

    if ($submission->getData('contextId') !== $context->getId()) {
        $context = app()->get('context')->get($submission->getData('contextId'));
    }

    $publication = Repo::publication()->get((int) $illuminateRequest->route('publicationId'));

    $locales = collect($context->getSupportedSubmissionMetadataLocaleNames() + $submission->getPublicationLanguageNames())
        ->map(fn (string $name, string $locale) => ['key' => $locale, 'label' => $name])
        ->sortBy('key')
        ->values()
        ->toArray();

    $latestPublicationApiUrl = $this->getRequest()->getDispatcher()->url($this->getRequest(), Application::ROUTE_API, $context->getData('urlPath'), 'submissions/' . $submission->getId() . '/publications/' . $publication->getId());

    $section = Repo::section()->get($publication->getData('sectionId'), $context->getId());
    $titleAbstractForm = new TitleAbstractForm(
        $latestPublicationApiUrl,
        $locales,
        $publication,
        (int) $section->getData('wordCount'),
        !$section->getData('abstractsNotRequired')
    );

    return response()->json($titleAbstractForm->getConfig(), Response::HTTP_OK);
}
  1. All existing authorization and role checks will need to be preserved and the usual API endpoint sanity checks will be required as well.

@ewhanson
Copy link
Collaborator

Hey @taslangraham, could you have a look at this issue? I've tried to capture all the relevant details above, but if anything is unclear, please let me know. Thanks!

@jardakotesovec
Copy link
Contributor Author

@ewhanson Thank you!

@taslangraham
Copy link
Contributor

@ewhanson sure thing!

taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 29, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 29, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 29, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Aug 29, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 29, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 30, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Aug 30, 2024
…tleAbstractForm, & IssueEntryForm) via API
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Aug 30, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 2, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 2, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 2, 2024
…tleAbstractForm, & IssueEntryForm) via API
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 2, 2024
…tleAbstractForm, & IssueEntryForm) via API
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 3, 2024
…tleAbstractForm, & IssueEntryForm) via API
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 3, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 3, 2024
@taslangraham
Copy link
Contributor

Ready for review @ewhanson

PRs

  • PKP-Lib:
    • Added individual endpoint for each component along with the necessary role, authorization, and sanity checks
  • OJS
    • Implement OJS specific logic for endpoints returning TitleAbstractForm, IssueEntryForm, SubmissionPaymentsForm forms
  • OPS:
    • Add app logic for handler returning TitleAbstractForm as OPS also has additional logic((here and here) in WorkflowHandler.php for wordLimit
    • Add endpoint to return IssueEntryForm in OPS as I observed that OPS' WorkflowHandler.php also adds IssueEntryForm
  • OMP
    • submodule update

@ewhanson
Copy link
Collaborator

ewhanson commented Sep 5, 2024

Looks really good @taslangraham! Just a few comments, but otherwise ready to go!

taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 6, 2024
taslangraham added a commit to taslangraham/pkp-lib that referenced this issue Sep 6, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 6, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 6, 2024
taslangraham added a commit to taslangraham/ops that referenced this issue Sep 6, 2024
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 6, 2024
…tleAbstractForm, & IssueEntryForm) via API
taslangraham added a commit to taslangraham/ojs that referenced this issue Sep 6, 2024
@taslangraham
Copy link
Contributor

Thanks for the review @ewhanson! I've made the changes you suggested. If there are no objections, I'll go ahead and merge

@ewhanson
Copy link
Collaborator

ewhanson commented Sep 6, 2024

Looks good @taslangraham. Feel free to merge!

@jardakotesovec
Copy link
Contributor Author

@taslangraham @ewhanson Thanks guys! Great work.. will connect it with the UI once its merged and let you know if there are any issues, but looking promising! :-)

taslangraham added a commit to pkp/ojs that referenced this issue Sep 6, 2024
taslangraham added a commit to pkp/ops that referenced this issue Sep 6, 2024
taslangraham added a commit to pkp/omp that referenced this issue Sep 6, 2024
@taslangraham
Copy link
Contributor

All merged @jardakotesovec @ewhanson

@jardakotesovec
Copy link
Contributor Author

jardakotesovec commented Sep 9, 2024

Just notice that if I hit this endpoint I get following PHP warnings.. but no idea whether its concern or not..

2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] PHP Notice:  Only variables should be passed by reference in /Users/jarda/git/pkp/pkp-main-2/ojs-main-2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] PHP Notice:  Only variables should be passed by reference in /Users/jarda/git/pkp/pkp-main-2/ojs-main-2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] PHP Notice:  Only variables should be passed by reference in /Users/jarda/git/pkp/pkp-main-2/ojs-main-2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] PHP Notice:  Only variables should be passed by reference in /Users/jarda/git/pkp/pkp-main-2/ojs-main-2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] PHP Notice:  Only variables should be passed by reference in /Users/jarda/git/pkp/pkp-main-2/ojs-main-2/lib/pkp/classes/middleware/traits/HasRequiredMiddleware.php on line 63
[Mon Sep  9 15:37:36 2024] [::1]:63901 [200]: GET /index.php/publicknowledge/api/v1/submissions/7/publications/8/_components/titleAbstract

@jardakotesovec
Copy link
Contributor Author

Actually this seems to be present for almost any request.. Therefore not related to this one. Sorry for noise..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement:2:Moderate A new feature or improvement that can be implemented in less than 4 weeks.
Projects
None yet
Development

No branches or pull requests

3 participants