-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4787 Reviewer suggestions api update
- Loading branch information
1 parent
304c66c
commit c2c4775
Showing
21 changed files
with
814 additions
and
167 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
api/v1/reviewerSuggestions/formRequests/AddReviewerSuggestion.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
api/v1/reviewers/suggestions/formRequests/AddReviewerSuggestion.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace PKP\API\v1\reviewers\suggestions\formRequests; | ||
|
||
use APP\core\Application; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class AddReviewerSuggestion extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @copydoc \Illuminate\Foundation\Http\FormRequest::validated() | ||
*/ | ||
public function validated($key = null, $default = null) | ||
{ | ||
$validated = parent::validated($key, $default); | ||
|
||
return collect($validated)->map( | ||
fn($value) => is_array($value) ? array_filter($value) : $value | ||
)->toArray(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'submissionId' => [ | ||
'required', | ||
'integer', | ||
Rule::exists('submissions', 'submission_id'), | ||
], | ||
'suggestingUserId' => [ | ||
'sometimes', | ||
'nullable', | ||
'integer', | ||
Rule::exists('users', 'user_id'), | ||
], | ||
'familyName' => [ | ||
'required', | ||
'array', | ||
], | ||
'givenName' => [ | ||
'required', | ||
'array', | ||
], | ||
'email' => [ | ||
'required', | ||
'email', | ||
], | ||
'affiliation' => [ | ||
'required', | ||
'array', | ||
], | ||
'suggestionReason' => [ | ||
'required', | ||
'array', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Get the error messages for the defined validation rules. | ||
* | ||
* @return array<string, string> | ||
*/ | ||
public function messages(): array | ||
{ | ||
return [ | ||
'familyName.required' => 'family name is required', | ||
]; | ||
} | ||
|
||
/** | ||
* Get custom attributes for validator errors. | ||
* | ||
* @return array<string, string> | ||
*/ | ||
public function attributes(): array | ||
{ | ||
return [ | ||
'familyName' => __('user.familyName'), | ||
'givenName' => __('user.givenName'), | ||
'email' => __('user.email'), | ||
]; | ||
} | ||
|
||
/** | ||
* Prepare the data for validation. | ||
*/ | ||
protected function prepareForValidation(): void | ||
{ | ||
$this->merge([ | ||
'suggestingUserId' => Application::get()->getRequest()?->getUser()?->getId(), | ||
'submissionId' => $this->route('submissionId'), | ||
]); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/v1/reviewers/suggestions/resources/ReviewerSuggestionResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace PKP\API\v1\reviewers\suggestions\resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ReviewerSuggestionResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
*/ | ||
public function toArray(Request $request) | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'submissionId' => $this->submissionId, | ||
'suggestingUserId' => $this->suggestingUserId, | ||
'familyName' => $this->familyName, | ||
'givenName' => $this->givenName, | ||
'fullName' => $this->fullname, | ||
'email' => $this->email, | ||
'orcidId' => $this->orcidId, | ||
'affiliation' => $this->affiliation, | ||
'suggestionReason' => $this->suggestionReason, | ||
]; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
classes/components/forms/publication/ReviewerSuggestionsForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* @file classes/components/form/publication/ReviewerSuggestionsForm.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class ReviewerSuggestionsForm | ||
* | ||
* @brief | ||
*/ | ||
|
||
namespace PKP\components\forms\publication; | ||
|
||
use APP\submission\Submission; | ||
use PKP\components\forms\FieldOrcid; | ||
use PKP\components\forms\FieldRichTextarea; | ||
use PKP\components\forms\FieldText; | ||
use PKP\components\forms\FormComponent; | ||
use PKP\context\Context; | ||
use PKP\orcid\OrcidManager; | ||
|
||
class ReviewerSuggestionsForm extends FormComponent | ||
{ | ||
public const FORM_CONTRIBUTOR = 'reviewerSuggestions'; | ||
|
||
/** | ||
* @copydoc FormComponent::$id | ||
*/ | ||
public $id = self::FORM_CONTRIBUTOR; | ||
|
||
/** | ||
* @copydoc FormComponent::$method | ||
*/ | ||
public $method = 'POST'; | ||
|
||
public Submission $submission; | ||
public Context $context; | ||
|
||
public function __construct(string $action, array $locales, Submission $submission, Context $context) | ||
{ | ||
$this->action = $action; | ||
$this->locales = $locales; | ||
$this->submission = $submission; | ||
$this->context = $context; | ||
|
||
$this | ||
->addField(new FieldText('givenName', [ | ||
'label' => __('user.givenName'), | ||
'isMultilingual' => true, | ||
'isRequired' => true, | ||
])) | ||
->addField(new FieldText('familyName', [ | ||
'label' => __('user.familyName'), | ||
'isMultilingual' => true, | ||
'isRequired' => true, | ||
])) | ||
->addField(new FieldText('email', [ | ||
'label' => __('user.email'), | ||
'isRequired' => true, | ||
])) | ||
->addField(new FieldText('affiliation', [ | ||
'label' => __('user.affiliation'), | ||
'isRequired' => true, | ||
'isMultilingual' => true, | ||
])) | ||
->addField(new FieldRichTextarea('suggestionReason', [ | ||
'label' => __('reviewerSuggestion.suggestionReason'), | ||
'description' => __('reviewerSuggestion.suggestionReason.description'), | ||
'isRequired' => true, | ||
'isMultilingual' => true, | ||
])); | ||
|
||
if (OrcidManager::isEnabled()) { | ||
$this->addField(new FieldOrcid('orcid', [ | ||
'label' => __('user.orcid'), | ||
'tooltip' => __('orcid.about.orcidExplanation'), | ||
]), [FIELD_POSITION_AFTER, 'email']); | ||
} | ||
} | ||
} |
Oops, something went wrong.