Skip to content

Commit

Permalink
pkp#5717 Add queued payment action to accept decision and move action…
Browse files Browse the repository at this point in the history
… validation to decision type
  • Loading branch information
NateWr committed Oct 7, 2021
1 parent c901b38 commit 18cda63
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 137 deletions.
2 changes: 1 addition & 1 deletion api/v1/submissions/PKPSubmissionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ public function addDecision($slimRequest, $response, $args)
$params['editorId'] = $request->getUser()->getId();
$params['stageId'] = $type->getStageId();

$errors = Repo::decision()->validate($params, $type, $submission);
$errors = Repo::decision()->validate($params, $type, $submission, $request->getContext());

if (!empty($errors)) {
return $response->withStatus(400)->withJson($errors);
Expand Down
63 changes: 0 additions & 63 deletions classes/components/forms/decision/RecommendDiscussionForm.inc.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @file classes/components/form/decision/RequestPaymentDecisionForm.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class RequestPaymentDecisionForm
* @ingroup classes_controllers_form
*
* @brief A form to request or waive an APC payment when making an editorial decision
*/

namespace PKP\components\forms\decision;

use PKP\components\forms\FieldOptions;
use PKP\components\forms\FormComponent;
use PKP\context\Context;

define('FORM_REQUEST_PAYMENT_DECISION', 'requestPaymentDecision');

class RequestPaymentDecisionForm extends FormComponent
{
/** @copydoc FormComponent::$id */
public $id = FORM_REQUEST_PAYMENT_DECISION;

/** @copydoc FormComponent::$action */
public $action = FormComponent::ACTION_EMIT;

/**
* Constructor
*/
public function __construct(Context $context)
{
$this->addField(new FieldOptions('requestPayment', [
'label' => __('common.payment'),
'type' => 'radio',
'options' => [
[
'value' => true,
'label' => __(
'payment.requestPublicationFee',
['feeAmount' => $context->getData('publicationFee') . ' ' . $context->getData('currency')]
),
],
[
'value' => false,
'label' => __('payment.waive'),
],
],
'value' => true,
'groupId' => 'default',
]));
}
}
7 changes: 4 additions & 3 deletions classes/decision/Repository.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\LazyCollection;
use PKP\context\Context;
use PKP\core\Core;
use PKP\db\DAORegistry;
use PKP\log\PKPSubmissionEventLogEntry;
Expand Down Expand Up @@ -113,7 +114,7 @@ public function getSchemaMap(): maps\Schema
*
* @return array A key/value array with validation errors. Empty if no errors
*/
public function validate(array $props, Type $type, Submission $submission): array
public function validate(array $props, Type $type, Submission $submission, Context $context): array
{
AppLocale::requireComponents(
LOCALE_COMPONENT_PKP_EDITOR,
Expand Down Expand Up @@ -145,7 +146,7 @@ public function validate(array $props, Type $type, Submission $submission): arra
[]
);

$validator->after(function ($validator) use ($props, $type, $submission) {
$validator->after(function ($validator) use ($props, $type, $submission, $context) {

// The decision stage id must match the decision type's stage id
// and the submission's current workflow stage
Expand Down Expand Up @@ -185,7 +186,7 @@ public function validate(array $props, Type $type, Submission $submission): arra
}

// Allow the decision type to add validation checks
$type->validate($props, $submission, $validator, isset($reviewRound) ? $reviewRound->getId() : null);
$type->validate($props, $submission, $context, $validator, isset($reviewRound) ? $reviewRound->getId() : null);
});

$errors = [];
Expand Down
90 changes: 81 additions & 9 deletions classes/decision/Type.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
use APP\facades\Repo;
use APP\submission\Submission;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Validation\Validator;
use PKP\context\Context;
use PKP\db\DAORegistry;
use PKP\security\Role;
use PKP\services\PKPSchemaService;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submission\reviewRound\ReviewRoundDAO;
use PKP\user\User;
use PKP\validation\ValidatorFactory;

abstract class Type
{
Expand Down Expand Up @@ -112,17 +115,13 @@ public function isInReview(): bool
}

/**
* A callback method that is fired when a decision
* of this type is being validated
*
* Use this method to validate any custom data that may be
* required for this decision.
*
* Add a validation error:
* Validate this decision
*
* $validator->errors()->add('requestPayment', __('validator.required'));
* The default decision properties will already be validated. Use
* this method to validate data for this decision's actions, or
* to apply any additional restrictions for this decision.
*/
public function validate(array $props, Submission $submission, Validator $validator)
public function validate(array $props, Submission $submission, Context $context, Validator $validator, ?int $reviewRoundId = null)
{
// No validation checks are performed by default
}
Expand Down Expand Up @@ -225,6 +224,79 @@ protected function getCompletedReviewerIds(Submission $submission, int $reviewRo
return $userIds;
}

/**
* Validate the properties of an email action
*
* @return array Empty if no errors
*/
protected function validateEmailAction(array $emailAction): array
{
$schema = (object) [
'bcc' => (object) [
'type' => 'array',
'items' => (object) [
'type' => 'string',
'validation' => [
'email_or_localhost',
],
],
],
'body' => (object) [
'type' => 'string',
'validation' => [
'required',
],
],
'cc' => (object) [
'type' => 'array',
'items' => (object) [
'type' => 'string',
'validation' => [
'email_or_localhost',
],
],
],
'id' => (object) [
'type' => 'string',
'validation' => [
'alpha',
'required',
],
],
'subject' => (object) [
'type' => 'string',
'validation' => [
'required',
],
],
'to' => (object) [
'type' => 'array',
'items' => (object) [
'type' => 'integer',
],
],
];

$schemaService = App::make(PKPSchemaService::class);
$rules = [];
foreach ($schema as $propName => $propSchema) {
$rules = $schemaService->addPropValidationRules($rules, $propName, $propSchema);
}

$validator = ValidatorFactory::make(
$emailAction,
$rules,
);

$errors = [];

if ($validator->fails()) {
$errors = $schemaService->formatValidationErrors($validator->errors());
}

return $errors;
}

/**
* Set an error message for invalid recipients
*
Expand Down
Loading

0 comments on commit 18cda63

Please sign in to comment.