Skip to content

Commit

Permalink
#4787 WIP : Reviewer suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Oct 10, 2024
1 parent 0476029 commit 304c66c
Show file tree
Hide file tree
Showing 8 changed files with 593 additions and 1 deletion.
169 changes: 169 additions & 0 deletions api/v1/reviewerSuggestions/ReviewerSuggestionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

/**
* @file api/v1/reviewerSuggestions/ReviewerSuggestionController.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 ReviewerSuggestionController
*
* @brief
*
*/

namespace PKP\API\v1\reviewerSuggestions;

use APP\core\Application;
use PKP\API\v1\reviewerSuggestions\formRequests\AddReviewerSuggestion;

use PKP\security\authorization\internal\SubmissionIncompletePolicy;
use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\core\PKPApplication;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\log\EmailLogEntry;
use PKP\log\SubmissionEmailLogEventType;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\SubmissionAccessPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\submissionFile\SubmissionFile;

class ReviewerSuggestionController extends PKPBaseController
{
/**
* @copydoc \PKP\core\PKPBaseController::getHandlerPath()
*/
public function getHandlerPath(): string
{
return 'reviewerSuggestions';
}

/**
* @copydoc \PKP\core\PKPBaseController::getRouteGroupMiddleware()
*
* @throws \Exception
*/
public function getRouteGroupMiddleware(): array
{
return [
'has.user',
'has.context',
self::roleAuthorizer([
Role::ROLE_ID_SITE_ADMIN,
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_AUTHOR,
]),
];
}

/**
* @throws \Exception
*/
public function getGroupRoutes(): void
{
Route::get('{suggestionId}', $this->get(...))
->name('reviewer.suggestions.get')
->whereNumber('suggestionId');

Route::get('submission/{submissionId}', $this->getMany(...))
->name('reviewer.suggestions.getMany')
->whereNumber('submissionId');

Route::post('submission/{submissionId}', $this->add(...))
->name('reviewer.suggestions.add');

Route::put('{suggestionId}', $this->edit(...))
->name('reviewer.suggestions.edit')
->whereNumber('suggestionId');

Route::delete('{suggestionId}', $this->delete(...))
->name('reviewer.suggestions.delete')
->whereNumber('suggestionId');

Route::post('{suggestionId}', $this->approve(...))
->name('reviewer.suggestions.approve')
->whereNumber('suggestionId');
}

/**
* @copydoc \PKP\core\PKPBaseController::authorize()
*/
public function authorize(PKPRequest $request, array &$args, array $roleAssignments): bool
{
$illuminateRequest = $args[0]; /** @var \Illuminate\Http\Request $illuminateRequest */
$actionName = static::getRouteActionName($illuminateRequest);

$this->addPolicy(new UserRolesRequiredPolicy($request), true);
$this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));

if (in_array($actionName, ['add', 'edit', 'delete'])) {
$this->addPolicy(new SubmissionIncompletePolicy($request, $args));
}

return parent::authorize($request, $args, $roleAssignments);
}

public function get(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}

public function getMany(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}

public function add(AddReviewerSuggestion $illuminateRequest): JsonResponse
{
$validateds = $illuminateRequest->validated();
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}

public function edit(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}

public function delete(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}

public function approve(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

return response()->json([], Response::HTTP_OK);
}
}
65 changes: 65 additions & 0 deletions api/v1/reviewerSuggestions/formRequests/AddReviewerSuggestion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace PKP\API\v1\reviewerSuggestions\formRequests;

use Illuminate\Foundation\Http\FormRequest;

class AddReviewerSuggestion extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'familyName' => [
'required',
'string',
'max:255',
],
'givenName' => [
'required',
'string',
'max:255',
],
'email' => [
'required',
'email',
],
];
}

/**
* 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'),
];
}
}
32 changes: 31 additions & 1 deletion classes/components/forms/context/PKPReviewSetupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PKP\components\forms\FieldSlider;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use PKP\services\PKPSchemaService;
use PKP\submission\reviewAssignment\ReviewAssignment;

class PKPReviewSetupForm extends FormComponent
Expand Down Expand Up @@ -50,7 +51,8 @@ public function __construct($action, $locales, $context)

$this
->addDefaultFields($context)
->addReminderFields($context);
->addReminderFields($context)
->addReviewSuggestionControl($context);
}

/**
Expand Down Expand Up @@ -174,4 +176,32 @@ protected function addReminderFields(Context $context): static

return $this;
}

/**
* Add review suggestion control field
*/
protected function addReviewSuggestionControl(Context $context): static
{
$schema = app()->get('schema'); /** @var \PKP\services\PKPSchemaService $schema */

if (!collect($schema->get("context")->properties)->has("reviewerSuggestionEnabled")) {
return $this;
}

$this->addField(
new FieldOptions('reviewerSuggestionEnabled', [
'label' => __('manager.setup.reviewOptions.reviewerSuggestionEnabled'),
'description' => __('manager.setup.reviewOptions.reviewerSuggestionEnabled.description'),
'type' => 'checkbox',
'value' => $context->getData('reviewerSuggestionEnabled'),
'options' => [
['value' => true, 'label' => __('manager.setup.reviewOptions.reviewerSuggestionEnabled.label')],
],
'groupId' => self::REVIEW_SETTINGS_GROUP,
]),
[FIELD_POSITION_AFTER, 'reviewerAccessKeysEnabled']
);

return $this;
}
}
10 changes: 10 additions & 0 deletions classes/core/PKPContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public function render($request, Throwable $exception)
$pkpRouter = Application::get()->getRequest()->getRouter();

if($pkpRouter instanceof APIRouter && app('router')->getRoutes()->count()) {

if ($exception instanceof \Illuminate\Validation\ValidationException) {

return response()
->json($exception->errors(), $exception->status)
->send();
}

return response()->json(
[
'error' => $exception->getMessage()
Expand Down Expand Up @@ -179,6 +187,8 @@ public function registerConfiguredProviders(): void
$this->register(new InvitationServiceProvider($this));
$this->register(new ScheduleServiceProvider($this));
$this->register(new ConsoleCommandServiceProvider($this));
$this->register(new \Illuminate\Validation\ValidationServiceProvider($this));
$this->register(new \Illuminate\Foundation\Providers\FormRequestServiceProvider($this));
}

/**
Expand Down
Loading

0 comments on commit 304c66c

Please sign in to comment.