Skip to content

Commit

Permalink
Pub workflow (#889)
Browse files Browse the repository at this point in the history
* feat(seeder): add editor and chief editor users to LocalTestDataSeeder
* fix(locales): update 'ready-to-marked-published' text for clarity in English and French
* refactor: remove duplicate import statement in ManuscriptRecordPage.vue
* refactor: clean up imports in CreatePublicationDialog.vue
* feat: secondary publishing workflow
* chore: bump
  • Loading branch information
vincentauger authored Dec 27, 2024
1 parent a76c28d commit a71ca33
Show file tree
Hide file tree
Showing 36 changed files with 1,005 additions and 707 deletions.
1 change: 1 addition & 0 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ APP_URL=http://127.0.0.1:8000/
FRONTEND_URL=http://127.0.0.1:8000/

ALLOWED_REGISTRATION_EMAIL_DOMAINS="example.com"
MANUSCRIPT_SUBMISSION_EMAIL="[email protected]"

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ APP_URL=http://localhost
FRONTEND_URL=http://localhost/

ALLOWED_REGISTRATION_EMAIL_DOMAINS=example.com
MANUSCRIPT_SUBMISSION_EMAIL=""

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down
33 changes: 0 additions & 33 deletions app/Events/ManuscriptRecordAccepted.php

This file was deleted.

33 changes: 0 additions & 33 deletions app/Events/ManuscriptRecordSubmitted.php

This file was deleted.

20 changes: 14 additions & 6 deletions app/Http/Controllers/ManuscriptRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
use App\Actions\DeleteManuscriptRecord;
use App\Enums\ManuscriptRecordStatus;
use App\Enums\ManuscriptRecordType;
use App\Events\ManuscriptRecordAccepted;
use App\Events\ManuscriptRecordSubmitted;
use App\Events\ManuscriptRecordToReviewEvent;
use App\Events\ManuscriptRecordWithdrawnByAuthor;
use App\Http\Resources\ManuscriptRecordMetadataResource;
use App\Http\Resources\ManuscriptRecordResource;
use App\Mail\ManuscriptRecordSubmittedToDFO;
use App\Models\Journal;
use App\Models\ManagementReviewStep;
use App\Models\ManuscriptRecord;
Expand All @@ -21,6 +20,7 @@
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Enum;

Expand Down Expand Up @@ -160,8 +160,6 @@ public function submitted(Request $request, ManuscriptRecord $manuscriptRecord):
$manuscriptRecord->submitted_to_journal_on = $validated['submitted_to_journal_on'];
$manuscriptRecord->save();

ManuscriptRecordSubmitted::dispatch();

return $this->defaultResource($manuscriptRecord);
}

Expand All @@ -177,6 +175,14 @@ public function accepted(Request $request, ManuscriptRecord $manuscriptRecord):
'journal_id' => 'required|exists:journals,id',
]);

// Ensure the journal selected matches the manuscript record type.
$journal = Journal::find($validated['journal_id']);
if ($manuscriptRecord->type === ManuscriptRecordType::SECONDARY && ! $journal->isDfoSeries()) {
abort(422, 'Secondary MRFs must be published in a DFO series journal.');
} elseif ($manuscriptRecord->type === ManuscriptRecordType::PRIMARY && $journal->isDfoSeries()) {
abort(422, 'Primary MRFs cannot be published in a DFO series journal.');
}

$manuscriptRecord->status = ManuscriptRecordStatus::ACCEPTED;
// if the submitted to journal date is given, set it.
if ($validated['submitted_to_journal_on']) {
Expand All @@ -186,10 +192,12 @@ public function accepted(Request $request, ManuscriptRecord $manuscriptRecord):
$manuscriptRecord->save();

// create the accepted publication
$journal = Journal::findOrFail($validated['journal_id']);
CreatePublicationFromManuscript::handle($manuscriptRecord, $journal);

ManuscriptRecordAccepted::dispatch();
// if the manuscript is a secondary, send an email to the submissions team
if ($manuscriptRecord->type === ManuscriptRecordType::SECONDARY) {
Mail::queue(new ManuscriptRecordSubmittedToDFO($manuscriptRecord));
}

return $this->defaultResource($manuscriptRecord);
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/ManuscriptRecordMetadataResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function toArray(Request $request): array
'id' => $this->id,
'ulid' => $this->ulid,
'region_id' => $this->region_id,
'type' => $this->type,
'reviewed_at' => $this->reviewed_at,
],
'can' => [
Expand Down
71 changes: 71 additions & 0 deletions app/Mail/ManuscriptRecordSubmittedToDFO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Mail;

use App\Models\ManuscriptRecord;
use App\Models\Publication;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;

class ManuscriptRecordSubmittedToDFO extends Mailable
{
use Queueable, SerializesModels;

public Publication $publication;

/**
* Create a new message instance.
*/
public function __construct(public ManuscriptRecord $manuscriptRecord)
{
$manuscriptRecord->load('user', 'manuscriptAuthors.author', 'publication');
$this->publication = $manuscriptRecord->publication;

}

/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
$to = config('osp.manuscript_submission_email');
if (empty($to)) {
throw new \Exception('The manuscript submission email address is not set.');
}
$cc = collect($this->manuscriptRecord->manuscriptAuthors)
->pluck('author.email')
->add($this->manuscriptRecord->user->email)
->filter(fn ($email) => Str::of($email)->endsWith(config('osp.allowed_registration_email_domains')))
->unique()->toArray();

return new Envelope(
subject: 'Manuscript Submitted - Manuscrit soumis: '.$this->manuscriptRecord->title,
to: [$to],
cc: $cc,
);
}

/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'mail.manuscriptRecord.manuscript-submitted-to-dfo',
);
}

/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
2 changes: 1 addition & 1 deletion app/Mail/ManuscriptRecordToReviewMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function build()
->forget($this->user->email) // don't send to the user twice
->toArray());

return $this->markdown('mail.manuscriptRecord.manuscriptRecordSubmitted');
return $this->markdown('mail.manuscriptRecord.manuscriptRecordToReview');
}
}
4 changes: 2 additions & 2 deletions app/Mail/ManuscriptWithheldMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Str;
use Illuminate\Support\Str;

class ManuscriptWithheldMail extends Mailable
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public function build()
merge($this->reviewUsers->pluck('email'))->
unique()->
filter(fn ($email) => $email !== $this->user->email)-> // don't send to the user twice
filter(fn ($email) => Str::of($email)->contains('@dfo-mpo.gc.ca'))-> // only send to DFO emails
filter(fn ($email) => Str::of($email)->contains(config('osp.allowed_registration_email_domains')))-> // only send to authorized email domains
toArray());

return $this->markdown('mail.manuscriptRecord.manuscript-withheld-mail');
Expand Down
11 changes: 11 additions & 0 deletions app/Models/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ public function scopeDfoSeries($query)
return $query->where('publisher', Journal::$dfoPublisher);
}

/** Create a scope for DFO series */
public function scopeNotDfoSeries($query)
{
return $query->where('publisher', '!=', Journal::$dfoPublisher);
}

public function publications(): HasMany
{
return $this->hasMany(Publication::class);
}

public function isDfoSeries(): bool
{
return $this->publisher === Journal::$dfoPublisher;
}
}
1 change: 1 addition & 0 deletions app/Queries/JournalListQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct()
AllowedFilter::partial('title'),
AllowedFilter::custom('search', new MultiColumnFilter('title', 'issn')),
AllowedFilter::scope('dfo_series'),
AllowedFilter::scope('not_dfo_series'),
]);
}
}
Loading

0 comments on commit a71ca33

Please sign in to comment.