Skip to content

Commit

Permalink
Merge pull request #474 from OpenSynergic/improve-submission-workflow
Browse files Browse the repository at this point in the history
feat: improve submission workflow
  • Loading branch information
rahmanramsi authored Dec 26, 2024
2 parents 05171e1 + 8dbf5cc commit ec9fbe6
Show file tree
Hide file tree
Showing 32 changed files with 583 additions and 406 deletions.
2 changes: 1 addition & 1 deletion app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class Application extends LaravelApplication
{
public const APP_VERSION = '1.2.0-beta.1';
public const APP_VERSION = '1.2.0-beta.2';

public const PHP_MIN_VERSION = '8.1';

Expand Down
33 changes: 32 additions & 1 deletion app/Models/Enums/SubmissionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ enum SubmissionStatus: string implements HasColor, HasLabel

case Incomplete = 'Incomplete';
case Queued = 'Queued';
case OnPayment = 'On Payment';
case OnReview = 'On Review';
case OnPayment = 'On Payment';
case OnPresentation = 'On Presentation';
case Editing = 'Editing';
case Published = 'Published';
Expand All @@ -26,6 +26,37 @@ public function getLabel(): ?string
return $this->name;
}

public function getOrder(): int
{
return match ($this) {
self::Incomplete => 1,
self::Queued => 2,
self::OnReview => 3,
self::OnPayment => 4,
self::OnPresentation => 5,
self::Editing => 6,
self::Published => 7,
self::PaymentDeclined => 8,
self::Declined => 9,
self::Withdrawn => 10,
};
}

public function isBefore(SubmissionStatus $status): bool
{
return $this->getOrder() < $status->getOrder();
}

public function isAfter(SubmissionStatus $status): bool
{
return $this->getOrder() > $status->getOrder();
}

public function isFinal(): bool
{
return in_array($this, [self::Published, self::PaymentDeclined, self::Declined, self::Withdrawn]);
}

public function getColor(): string|array|null
{
return match ($this) {
Expand Down
22 changes: 2 additions & 20 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,14 @@ public static function getDefaultPermissionsAttribute(): array
'StaticPage:delete',
'StaticPage:update',
'StaticPage:viewAny',
'Submission:acceptAbstract',
'Submission:submitAs',
'Submission:acceptPaper',
'Submission:approvePayment',
'Submission:assignParticipant',
'Submission:assignReviewer',
'Submission:cancelReviewer',
'Submission:declineAbstract',
'Submission:declinePaper',
'Submission:declinePayment',
'Submission:delete',
'Submission:editing',
'Submission:editReviewer',
'Submission:emailReviewer',
'Submission:publish',
'Submission:reinstateReviewer',
'Submission:requestRevision',
Expand Down Expand Up @@ -202,19 +197,13 @@ public static function getDefaultPermissionsAttribute(): array
'StaticPage:delete',
'StaticPage:update',
'StaticPage:viewAny',
'Submission:acceptAbstract',
'Submission:submitAs',
'Submission:acceptPaper',
'Submission:approvePayment',
'Submission:assignParticipant',
'Submission:assignReviewer',
'Submission:cancelReviewer',
'Submission:declineAbstract',
'Submission:declinePaper',
'Submission:declinePayment',
'Submission:delete',
'Submission:editing',
'Submission:editReviewer',
'Submission:emailReviewer',
'Submission:preview',
'Submission:publish',
'Submission:reinstateReviewer',
Expand Down Expand Up @@ -269,19 +258,12 @@ public static function getDefaultPermissionsAttribute(): array
'Session:delete',
],
UserRole::TrackEditor->value => [
'Submission:acceptAbstract',
'Submission:acceptPaper',
'Submission:approvePayment',
'Submission:assignParticipant',
'Submission:assignReviewer',
'Submission:cancelReviewer',
'Submission:declineAbstract',
'Submission:declinePaper',
'Submission:declinePayment',
'Submission:delete',
'Submission:editing',
'Submission:editReviewer',
'Submission:emailReviewer',
'Submission:preview',
'Submission:publish',
'Submission:reinstateReviewer',
Expand Down
49 changes: 20 additions & 29 deletions app/Models/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ protected static function booted(): void
$submission->reviews->each->delete();
$submission->media->each->delete();
});

static::created(function (Submission $submission) {
$submission->participants()->create([
'user_id' => $submission->user_id,
'role_id' => Role::withoutGlobalScopes()->where('conference_id', $submission->conference_id)->where('name', UserRole::Author->value)->first()->getKey(),
]);
});
}

public function proceeding(): BelongsTo
Expand Down Expand Up @@ -190,7 +183,7 @@ public function participants()
public function editors()
{
return $this->participants()
->whereHas('role', fn (Builder $query) => $query->whereIn('name', [UserRole::ScheduledConferenceEditor, UserRole::TrackEditor]));
->whereHas('role', fn(Builder $query) => $query->whereIn('name', [UserRole::ScheduledConferenceEditor, UserRole::TrackEditor, UserRole::ConferenceManager]));
}

public function isPublishedOnExternal()
Expand All @@ -217,33 +210,17 @@ public function registration(): HasOne

public function isParticipantEditor(User $user): bool
{
$isParticipantEditor = $this->editors()
return $this->editors
->where('user_id', $user->getKey())
->limit(1)
->first();

if (! $isParticipantEditor) {
return false;
}

return true;
->count() > 0;
}

public function isParticipantAuthor(User $user): bool
{
$isParticipantAuthor = $this->participants()
->whereHas('role', function (Builder $query) {
$query->where('name', UserRole::Author->value);
})
return $this->participants()
->where('user_id', $user->getKey())
->limit(1)
->first();

if (! $isParticipantAuthor) {
return false;
}

return true;
->whereHas('role', fn(Builder $query) => $query->whereIn('name', [UserRole::Author]))
->count() > 0;
}

public function scopePublished(Builder $query)
Expand Down Expand Up @@ -324,4 +301,18 @@ public function registerMediaConversions(?Media $media = null): void
->width(500)
->height(500);
}

public function isParticipant(User $user): bool
{
return $this->participants()
->where('user_id', $user->getKey())
->exists();
}

public function getParticipantRole(User $user): ?Role
{
return $this->participants()
->where('user_id', $user->getKey())
->first()?->role;
}
}
6 changes: 5 additions & 1 deletion app/Models/Timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Timeline extends Model
];

protected $casts = [
'roles' => 'array',
'date' => 'datetime',
'hide' => 'boolean',
];
Expand Down Expand Up @@ -66,6 +65,11 @@ public static function isSubmissionOpen(): bool
return false;
}

public function scopeType($query, $type)
{
return $query->where('type', $type);
}

public static function isRegistrationOpen(): bool
{
$timelineRegistrationOpen = self::where('type', self::TYPE_REGISTRATION_OPEN)->first();
Expand Down
9 changes: 9 additions & 0 deletions app/Observers/ConferenceObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use App\Actions\Authors\AuthorRolePopulateDefaultDataAction;
use App\Actions\Roles\RolePopulateConferenceAction;
use App\Models\Conference;
use App\Models\Enums\UserRole;
use App\Models\NavigationMenu;
use App\Models\NavigationMenuItem;
use App\Models\Role;
use App\Models\User;

class ConferenceObserver
{
Expand Down Expand Up @@ -109,6 +112,12 @@ public function created(Conference $conference): void
]);

RolePopulateConferenceAction::run($conference);


$conferenceManager = Role::withoutGlobalScopes()->where('name', UserRole::ConferenceManager)->where('conference_id', $conference->getKey())->first();
if($conferenceManager && auth()->id()) {
$conferenceManager->users()->attach(auth()->id(), ['conference_id' => $conference->getKey()]);
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Panel/Administration/Resources/ConferenceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Actions\Conferences\ConferenceUpdateAction;
use App\Models\Conference;
use App\Models\Enums\UserRole;
use App\Models\Role;
use App\Panel\Administration\Resources\ConferenceResource\Pages;
use App\Tables\Columns\IndexColumn;
use Filament\Forms\Components\TextInput;
Expand Down
2 changes: 1 addition & 1 deletion app/Panel/ScheduledConference/Livewire/AuthorGuidance.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function form(Form $form): Form
return $form
->model(app()->getCurrentScheduledConference())
->schema([
Section::make()
Section::make(__('general.author_guidance'))
->columns(1)
->schema([
TinyEditor::make('meta.author_guidelines')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

use App\Actions\ScheduledConferences\ScheduledConferenceUpdateAction;
use App\Forms\Components\TinyEditor;
use App\Models\Timeline;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class RegistrationSetting extends Component implements HasForms
Expand All @@ -21,23 +26,36 @@ class RegistrationSetting extends Component implements HasForms
public function mount(): void
{
$this->form->fill([
'meta' => app()->getCurrentScheduledConference()->getAllMeta(),
'open_date' => Timeline::type(Timeline::TYPE_REGISTRATION_OPEN)->value('date'),
'close_date' => Timeline::type(Timeline::TYPE_REGISTRATION_CLOSE)->value('date'),
'hide_from_timeline' => Timeline::type(Timeline::TYPE_REGISTRATION_OPEN)->value('hide') || Timeline::type(Timeline::TYPE_REGISTRATION_CLOSE)->value('hide'),
'meta' => [
'registration_policy' => app()->getCurrentScheduledConference()->getMeta('registration_policy'),
]
]);
}

public function form(Form $form): Form
{
return $form
->disabled(fn() => auth()->user()->cannot('RegistrationSetting:update'))
->schema([
Section::make(null)
Section::make()
->schema([
DatePicker::make('open_date')
->label(__('general.registration_setting.open_date')),
DatePicker::make('close_date')
->afterOrEqual('open_date')
->label(__('general.registration_setting.close_date')),
Toggle::make('hide_from_timeline')
->label(__('general.submission_setting.hide_from_timeline'))
->label('Hide from timeline'),
TinyEditor::make('meta.registration_policy')
->label(__('general.registration_policy'))
->plugins('advlist autoresize codesample directionality emoticons fullscreen hr image imagetools link lists media table toc wordcount code')
->toolbar('undo redo removeformat | formatselect fontsizeselect | bold italic | rtl ltr | alignjustify alignright aligncenter alignleft | numlist bullist | forecolor backcolor | blockquote table hr | image link code')
->minHeight(300),
])
->disabled(fn () => auth()->user()->cannot('RegistrationSetting:update')),
]),
Actions::make([
Action::make('Save changes')
->label(__('general.save_changes'))
Expand All @@ -46,14 +64,44 @@ public function form(Form $form): Form
->action(function (Action $action) {
$formData = $this->form->getState();
try {
DB::beginTransaction();

if(data_get($formData, 'open_date')) {
Timeline::updateOrCreate([
'type' => Timeline::TYPE_REGISTRATION_OPEN,
], [
'name' => 'Registration Open',
'date' => Date::parse(data_get($formData, 'open_date')),
'hide' => data_get($formData, 'hide_from_timeline'),
]);
} else {
Timeline::type(Timeline::TYPE_REGISTRATION_OPEN)->delete();
}

if(data_get($formData, 'close_date')) {
Timeline::updateOrCreate([
'type' => Timeline::TYPE_REGISTRATION_CLOSE,
], [
'name' => 'Registration Close',
'date' => Date::parse(data_get($formData, 'close_date')),
'hide' => data_get($formData, 'hide_from_timeline'),
]);
} else {
Timeline::type(Timeline::TYPE_REGISTRATION_CLOSE)->delete();
}

ScheduledConferenceUpdateAction::run(app()->getCurrentScheduledConference(), $formData);

DB::commit();

$action->sendSuccessNotification();
} catch (\Throwable $th) {
$action->failureNotificationTitle($th->getMessage());
$action->sendFailureNotification();
DB::rollBack();
throw $th;
}
})
->authorize('RegistrationSetting:update'),
}),
])->alignRight(),
])->statePath('formData');
}
Expand Down
Loading

0 comments on commit ec9fbe6

Please sign in to comment.