Skip to content

Commit

Permalink
#1660 set used recommendation uneditable
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jan 6, 2025
1 parent fb6a0ad commit 0008656
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
*
* @class ReviewerRecommendationController
*
* @brief
* @brief API controller class to handle actions on reviewer recommendations
*
*/

namespace PKP\API\v1\reviewers\recommendations;

use Illuminate\Http\JsonResponse;
use PKP\API\v1\reviewers\recommendations\formRequests\UpdateStatusReviewerRecommendation;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\API\v1\reviewers\recommendations\formRequests\UpdateStatusReviewerRecommendation;
use PKP\API\v1\reviewers\recommendations\resources\ReviewerRecommendationResource;
use PKP\submission\reviewer\recommendation\ReviewerRecommendation;
use PKP\API\v1\reviewers\recommendations\formRequests\AddReviewerRecommendation;
Expand Down Expand Up @@ -98,6 +97,9 @@ public function getGroupRoutes(): void
->whereNumber(['contextId', 'recommendationId']);
}

/**
* Get specific recommendation response
*/
public function get(Request $illuminateRequest): JsonResponse
{
$recommendation = ReviewerRecommendation::find($illuminateRequest->route('recommendationId'));
Expand All @@ -114,6 +116,9 @@ public function get(Request $illuminateRequest): JsonResponse
);
}

/**
* Get all recommendations response
*/
public function getMany(Request $illuminateRequest): JsonResponse
{
$recommendations = ReviewerRecommendation::query()
Expand All @@ -126,6 +131,9 @@ public function getMany(Request $illuminateRequest): JsonResponse
], Response::HTTP_OK);
}

/**
* Add new recommendation
*/
public function add(AddReviewerRecommendation $illuminateRequest): JsonResponse
{
$validateds = $illuminateRequest->validated();
Expand All @@ -139,12 +147,21 @@ public function add(AddReviewerRecommendation $illuminateRequest): JsonResponse
);
}

/**
* Update existing recommendation
*/
public function edit(EditReviewerRecommendation $illuminateRequest): JsonResponse
{
$validated = $illuminateRequest->validated();

$recommendation = ReviewerRecommendation::find($illuminateRequest->route('recommendationId'));

if (!$recommendation->removable) {
return response()->json([
'error' => __('api.406.notAcceptable'),
], Response::HTTP_NOT_ACCEPTABLE);
}

if (!$recommendation->update($validated)) {
return response()->json([
'error' => __('api.409.resourceActionConflict'),
Expand All @@ -158,11 +175,27 @@ public function edit(EditReviewerRecommendation $illuminateRequest): JsonRespons
);
}

/**
* Update the status of existing recommendation
*/
public function updateStatus(UpdateStatusReviewerRecommendation $illuminateRequest): JsonResponse
{
return $this->edit($illuminateRequest);
$validated = $illuminateRequest->validated();

$recommendation = ReviewerRecommendation::find($illuminateRequest->route('recommendationId'));

$recommendation->update($validated);

return response()->json(
(new ReviewerRecommendationResource($recommendation->refresh()))
->toArray($illuminateRequest),
Response::HTTP_OK
);
}

/**
* Delete existing recommendation
*/
public function delete(Request $illuminateRequest): JsonResponse
{
$recommendation = ReviewerRecommendation::find($illuminateRequest->route('recommendationId'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @class AddReviewerRecommendation
*
* @brief
* @brief Form request class to validation storing of resource
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @class EditReviewerRecommendation
*
* @brief
* @brief Form request class to validation updating of resource
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @class UpdateStatusReviewerRecommendation
*
* @brief
* @brief Form request class to validation updating of resource status
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @class ReviewerRecommendationResource
*
* @brief
* @brief API resource class
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @class ReviewerRecommendationForm
*
* @brief
* @brief Form to configure/add/edit reviewer recommendation
*/

namespace PKP\components\forms\context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @class ReviewerRecommendationsListPanel
*
* @brief
* @brief A ListPanel component for displaying reviewer recommendations in workflow settings
*/

namespace PKP\components\listPanels;
Expand Down
11 changes: 10 additions & 1 deletion classes/migration/install/ReviewerRecommendationsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @class ReviewerRecommendationsMigration
*
* @brief
* @brief Describe database table structures .
*/

namespace PKP\migration\install;
Expand All @@ -19,10 +19,19 @@

abstract class ReviewerRecommendationsMigration extends \PKP\migration\Migration
{
/**
* Get the context table name
*/
abstract public function contextTable(): string;

/**
* Get the context settings table name
*/
abstract public function settingTable(): string;

/**
* Get the context primary key name
*/
abstract public function contextPrimaryKey(): string;

/**
Expand Down
21 changes: 10 additions & 11 deletions classes/migration/upgrade/v3_6_0/I1660_ReviewerRecommendations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @class I1660_ReviewerRecommendations
*
* @brief
* @brief Upgrade migration add recommendations
*/

namespace PKP\migration\upgrade\v3_6_0;
Expand All @@ -23,8 +23,6 @@

abstract class I1660_ReviewerRecommendations extends \PKP\migration\Migration
{
abstract protected function systemDefineNonRemovableRecommendations(): array;

protected ReviewerRecommendationsMigration $recommendationInstallMigration;

/**
Expand All @@ -39,6 +37,11 @@ public function __construct(Installer $installer, array $attributes)

parent::__construct($installer, $attributes);
}

/**
* Get the pre-seeded reviewer recommendations to add on migration update
*/
abstract protected function systemDefineNonRemovableRecommendations(): array;

/**
* Run the migration.
Expand All @@ -58,14 +61,15 @@ public function down(): void
$this->recommendationInstallMigration->down();
}

// TODO : Optimize the process if possible
/**
* Seed the existing recommendations with context mapping on upgrade
*/
protected function seedNonRemovableRecommendations(array $nonRemovablerecommendations): void
{
if (empty($nonRemovablerecommendations)) {
return;
}

// $currentLocale = Locale::getLocale();
$contextSupportedLocales = DB::table($this->recommendationInstallMigration->contextTable())
->select($this->recommendationInstallMigration->contextPrimaryKey())
->addSelect([
Expand Down Expand Up @@ -107,9 +111,6 @@ protected function seedNonRemovableRecommendations(array $nonRemovablerecommenda
DB::beginTransaction();

foreach ($allContextSupportLocales as $locale) {

// Locale::setLocale($locale);

foreach ($nonRemovablerecommendations as $recommendationValue => $translatableKey) {
$recommendations[$recommendationValue]['title'][$locale] = Locale::get(
$translatableKey,
Expand All @@ -118,8 +119,6 @@ protected function seedNonRemovableRecommendations(array $nonRemovablerecommenda
);
}
}

// Locale::setLocale($currentLocale);

$contextSupportedLocales->each(
fn (array $supportedLocales, int $contextId) => collect($recommendations)->each(
Expand All @@ -143,7 +142,7 @@ protected function seedNonRemovableRecommendations(array $nonRemovablerecommenda
} catch (Throwable $exception) {

DB::rollBack();
// Locale::setLocale($currentLocale);

ReviewerRecommendation::reguard();

throw $exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/**
* @file lib/pkp/classes/submission/reviewer/recommendation/ReviewerRecommendation.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 ReviewerRecommendation
*
* @brief ReviewerRecommendation model class
*/

namespace PKP\submission\reviewer\recommendation;

use APP\facades\Repo;
Expand Down Expand Up @@ -103,6 +115,9 @@ public function getMultilingualProps(): array
];
}

/**
* Set the recommendation value attribute
*/
protected function value(): Attribute
{
return Attribute::make(
Expand Down Expand Up @@ -140,6 +155,9 @@ protected function value(): Attribute
);
}

/**
* Get attribute value removable for this recommendation
*/
protected function removable(): Attribute
{
return Attribute::make(
Expand All @@ -152,7 +170,7 @@ protected function removable(): Attribute
}

/**
*
* Get associated context details as attribute
*/
protected function context(): Attribute
{
Expand All @@ -161,6 +179,9 @@ protected function context(): Attribute
)->shouldCache();
}

/**
* Get associated review assignments details as attribute
*/
protected function reviewAssignments(): Attribute
{
return Attribute::make(
Expand All @@ -172,18 +193,24 @@ protected function reviewAssignments(): Attribute
}

/**
*
* Scope a query to filter by context id.
*/
public function scopeWithContextId(Builder $query, int $contextId): Builder
{
return $query->where('context_id', $contextId);
}

/**
* Scope a query to filter by recommendation active status.
*/
public function scopeWithActive(Builder $query, bool $active = true): Builder
{
return $query->where('status', $active);
}

/**
* Scope a query to filter by recommendation value
*/
public function scopeWithRecommendation(Builder $query, int $recommendation): Builder
{
return $query->where('value', $recommendation);
Expand Down
4 changes: 2 additions & 2 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -1988,13 +1988,13 @@ msgid "manager.reviewerRecommendations.confirmDelete"
msgstr "Are you sure you want to delete the recommendation {$title}"

msgid "manager.reviewerRecommendations.confirmActivate"
msgstr "Are you sure you want to activate the recommendation {$title}"
msgstr "Are you sure you want to activate the recommendation <b>{$title}</b>"

msgid "manager.reviewerRecommendations.activate.title"
msgstr "Activate Reviewer Recommendation"

msgid "manager.reviewerRecommendations.confirmDeactivate"
msgstr "Are you sure you want to deactivate the recommendation {$title}"
msgstr "Are you sure you want to deactivate the recommendation <b>{$title}</b>"

msgid "manager.reviewerRecommendations.deactivate.title"
msgstr "Deactivate Reviewer Recommendation"
Expand Down

0 comments on commit 0008656

Please sign in to comment.