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

795 add peer reviewers to internal mrfs #826

Merged
merged 7 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions app/Http/Controllers/ManuscriptPeerReviewerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Http\Controllers;

use App\Enums\ManuscriptRecordType;
use App\Http\Resources\ManuscriptPeerReviewerResource;
use App\Models\ManuscriptPeerReviewer;
use App\Models\ManuscriptRecord;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\ValidationException;

class ManuscriptPeerReviewerController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(ManuscriptRecord $manuscriptRecord): JsonResource
{
Gate::authorize('view', $manuscriptRecord);

return ManuscriptPeerReviewerResource::collection($manuscriptRecord->peerReviewers()->with(['author.organization', 'manuscriptRecord'])->get());

}

/**
* Store a newly created resource in storage.
*/
public function store(ManuscriptRecord $manuscriptRecord, Request $request): JsonResource
{
Gate::authorize('update', $manuscriptRecord);

if ($manuscriptRecord->type === ManuscriptRecordType::PRIMARY) {
throw ValidationException::withMessages(['manuscript_record_id' => 'A third-party primary manuscript cannot have peer reviewers']);
}

$validated = $request->validate([
'author_id' => 'required|exists:authors,id',
]);

if($manuscriptRecord->peerReviewers()->where('author_id', $validated['author_id'])->exists()) {
throw ValidationException::withMessages(['author_id' => 'This author is already a peer reviewer for this manuscript']);
}

if($manuscriptRecord->manuscriptAuthors()->where('author_id', $validated['author_id'])->exists()) {
throw ValidationException::withMessages(['author_id' => 'This author is already on the list of manuscript authors']);
}

$manuscriptPeerReviewer = new ManuscriptPeerReviewer($validated);
$manuscriptPeerReviewer->manuscript_record_id = $manuscriptRecord->id;
$manuscriptPeerReviewer->review_date = now();
$manuscriptPeerReviewer->save();

return new ManuscriptPeerReviewerResource($manuscriptPeerReviewer);

}

/**
* Display the specified resource.
*/
public function show(ManuscriptRecord $manuscriptRecord, ManuscriptPeerReviewer $manuscriptPeerReviewer)
{
Gate::authorize('view', $manuscriptPeerReviewer);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(ManuscriptRecord $manuscriptRecord, ManuscriptPeerReviewer $manuscriptPeerReviewer)
{
Gate::authorize('delete', $manuscriptPeerReviewer);

$manuscriptPeerReviewer->delete();

return response()->noContent();
}
}
12 changes: 12 additions & 0 deletions app/Http/Integrations/Orcid/Enums/PeerReviewRole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Http\Integrations\Orcid\Enums;

enum PeerReviewRole: string
{
case CHAIR = 'chair';
case EDITOR = 'editor';
case MEMBER = 'member';
case ORGANIZER = 'organizer';
case REVIEWER = 'reviewer';
}
9 changes: 9 additions & 0 deletions app/Http/Integrations/Orcid/Enums/PeerReviewType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Http\Integrations\Orcid\Enums;

enum PeerReviewType: string
{
case REVIEW = 'review';
case EVALUATION = 'evaluation';
}
31 changes: 31 additions & 0 deletions app/Http/Resources/ManuscriptPeerReviewerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;

class ManuscriptPeerReviewerResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'data' => [
'id' => $this->id,
'manuscript_record_id' => $this->manuscript_record_id,
'author_id' => $this->author_id,
'author' => AuthorResource::make($this->whenLoaded('author')),
],
'can' => [
'update' => Auth::user()->can('update', $this->resource),
'delete' => Auth::user()->can('delete', $this->resource),
],
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ public function employments(): HasMany
{
return $this->hasMany('App\Models\AuthorEmployment');
}

public function peerReviews(): HasMany
{
return $this->hasMany('App\Models\ManuscriptPeerReviewer');
}
}
45 changes: 45 additions & 0 deletions app/Models/ManuscriptPeerReviewer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Models;

use App\Http\Integrations\Orcid\Enums\PeerReviewRole;
use App\Http\Integrations\Orcid\Enums\PeerReviewType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ManuscriptPeerReviewer extends Model
{
/** @use HasFactory<\Database\Factories\ManuscriptPeerReviewerFactory> */
use HasFactory;

protected $fillable = [
'manuscript_record_id',
'author_id',
'review_date',
];

protected $attributes = [
'role' => PeerReviewRole::REVIEWER,
'type' => PeerReviewType::REVIEW,
];

public function casts(): array
{
return [
'review_date' => 'date',
'type' => PeerReviewType::class,
'role' => PeerReviewRole::class,
];
}

public function manuscriptRecord(): BelongsTo
{
return $this->belongsTo(ManuscriptRecord::class);
}

public function author(): BelongsTo
{
return $this->belongsTo(Author::class);
}
}
9 changes: 9 additions & 0 deletions app/Models/ManuscriptRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public function managementReviewSteps(): HasMany
return $this->hasMany('App\Models\ManagementReviewStep');
}

/**
* A manuscript has no to many peer reviewers. Only
* internal publications have peer reviewers.
*/
public function peerReviewers(): HasMany
{
return $this->hasMany(ManuscriptPeerReviewer::class);
}

/**
* A manuscript can have one publication
*/
Expand Down
49 changes: 49 additions & 0 deletions app/Policies/ManuscriptPeerReviewerPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Policies;

use App\Models\ManuscriptPeerReviewer;
use App\Models\User;

class ManuscriptPeerReviewerPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return false;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, ManuscriptPeerReviewer $manuscriptPeerReviewer): bool
{
return $user->can('view', $manuscriptPeerReviewer->manuscriptRecord);
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return false;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, ManuscriptPeerReviewer $manuscriptPeerReviewer): bool
{
return $user->can('update', $manuscriptPeerReviewer->manuscriptRecord);
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ManuscriptPeerReviewer $manuscriptPeerReviewer): bool
{
return $user->can('update', $manuscriptPeerReviewer->manuscriptRecord);
}
}
Loading
Loading