-
Notifications
You must be signed in to change notification settings - Fork 15
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
Decouple periodic events from controller names #555
Open
kdmnk
wants to merge
14
commits into
development
Choose a base branch
from
decouple-periodic-events
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b0ae69c
Decouple periodic events from controller names
kdmnk 42074e1
Use Laravel events instead of retrieving classes
kdmnk 07c0cb1
style: format code with PHP CS Fixer
deepsource-autofix[bot] 65ca69f
rename event_model to event_name
kdmnk f5e88b2
style: format code with PHP CS Fixer
deepsource-autofix[bot] e1211b4
cleanup
kdmnk aac214e
style: format code with PHP CS Fixer
deepsource-autofix[bot] 76b862d
fix test
kdmnk 82c6fe2
Merge branch 'development' into decouple-periodic-events
kdmnk b4a7a49
Merge branch 'development' into decouple-periodic-events
kdmnk 98fd23e
fix phpstan issues
kdmnk 44fa941
Merge remote-tracking branch 'origin/development' into decouple-perio…
kdmnk 1a9cca5
fix admmissioncontroller
kdmnk 8f66c0c
fix tests
kdmnk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\PeriodicEvent; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class SemesterEvaluationPeriodEnd | ||
{ | ||
use Dispatchable; | ||
use InteractsWithSockets; | ||
use SerializesModels; | ||
|
||
public PeriodicEvent $periodicEvent; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(PeriodicEvent $periodicEvent) | ||
{ | ||
$this->periodicEvent = $periodicEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\PeriodicEvent; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class SemesterEvaluationPeriodReminder | ||
{ | ||
use Dispatchable; | ||
use InteractsWithSockets; | ||
use SerializesModels; | ||
|
||
public PeriodicEvent $periodicEvent; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(PeriodicEvent $periodicEvent) | ||
{ | ||
$this->periodicEvent = $periodicEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\PeriodicEvent; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class SemesterEvaluationPeriodStart | ||
{ | ||
use Dispatchable; | ||
use InteractsWithSockets; | ||
use SerializesModels; | ||
|
||
public PeriodicEvent $periodicEvent; | ||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(PeriodicEvent $periodicEvent) | ||
{ | ||
$this->periodicEvent = $periodicEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,32 @@ | |
|
||
namespace App\Http\Controllers\Secretariat; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Jobs\PeriodicEventsProcessor; | ||
use App\Mail\EvaluationFormAvailable; | ||
use App\Mail\EvaluationFormAvailableDetails; | ||
use App\Mail\EvaluationFormClosed; | ||
use App\Mail\EvaluationFormReminder; | ||
use App\Mail\StatusDeactivated; | ||
use App\Models\Faculty; | ||
use App\Models\GeneralAssemblies\GeneralAssembly; | ||
use App\Models\Question; | ||
use App\Models\PeriodicEvent; | ||
use App\Models\Role; | ||
use App\Models\RoleUser; | ||
use App\Models\Semester; | ||
use App\Models\SemesterEvaluation; | ||
use App\Models\SemesterStatus; | ||
use App\Models\User; | ||
use App\Models\Workshop; | ||
use App\Utils\HasPeriodicEvent; | ||
use App\Utils\PeriodicEventController; | ||
use Carbon\Carbon; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Auth\AuthenticationException; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\Rule; | ||
|
||
class SemesterEvaluationController extends Controller | ||
class SemesterEvaluationController extends PeriodicEventController | ||
{ | ||
use HasPeriodicEvent; | ||
public function __construct() | ||
{ | ||
parent::__construct(PeriodicEvent::SEMESTER_EVALUATION_PERIOD); | ||
} | ||
|
||
/** | ||
* Update the PeriodicEvent for the evaluation form. | ||
|
@@ -66,73 +61,11 @@ public function updateEvaluationPeriod(Request $request): RedirectResponse | |
return back()->with('message', __('general.successful_modification')); | ||
} | ||
|
||
/** | ||
* Send email that the form is available. | ||
* @return void | ||
*/ | ||
public function handlePeriodicEventStart(): void | ||
{ | ||
Mail::to(config('contacts.mail_membra'))->queue(new EvaluationFormAvailable($this->getDeadline())); | ||
if (User::secretary()) { | ||
Mail::to(User::secretary())->queue(new EvaluationFormAvailableDetails(User::secretary()->name, $this->getDeadline())); | ||
} | ||
if (User::president()) { | ||
Mail::to(User::president())->queue(new EvaluationFormAvailableDetails(User::president()->name, $this->getDeadline())); | ||
} | ||
} | ||
|
||
/** | ||
* Send reminder that the form is available. | ||
* @param int $daysBeforeEnd | ||
* @return void | ||
*/ | ||
public function handlePeriodicEventReminder(int $daysBeforeEnd): void | ||
{ | ||
if($daysBeforeEnd < 3) { | ||
$userCount = $this->usersHaventFilledOutTheForm()->count(); | ||
Mail::to(config('contacts.mail_membra'))->queue(new EvaluationFormReminder($userCount, $this->getDeadline())); | ||
} | ||
} | ||
|
||
/** | ||
* Send email about results and deactivate collegists who did not fill out the form. | ||
*/ | ||
public function handlePeriodicEventEnd() | ||
{ | ||
$users = $this->usersHaventFilledOutTheForm(); | ||
$users_names = $users->pluck('name')->toArray(); | ||
|
||
if (User::secretary()) { | ||
Mail::to(User::secretary())->queue(new EvaluationFormClosed(User::secretary()->name, $users_names)); | ||
} | ||
if (User::president()) { | ||
Mail::to(User::president())->queue(new EvaluationFormClosed(User::president()->name, $users_names)); | ||
} | ||
if (User::director()) { | ||
Mail::to(User::director())->queue(new EvaluationFormClosed(User::director()->name, $users_names)); | ||
} | ||
foreach (User::workshopLeaders() as $user) { | ||
Mail::to($user)->queue(new EvaluationFormClosed($user->name)); | ||
} | ||
|
||
|
||
foreach ($users as $user) { | ||
try { | ||
Mail::to($user)->queue(new StatusDeactivated($user->name)); | ||
RoleUser::withoutEvents(function () use ($user) { | ||
self::deactivateCollegist($user); | ||
}); | ||
} catch (\Exception $e) { | ||
Log::error('Error deactivating collegist: ' . $user->name . ' - ' . $e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Show the evaluation form. | ||
* @throws AuthenticationException|AuthorizationException | ||
*/ | ||
public function show() | ||
public function show(): View | ||
{ | ||
$this->authorize('fillOrManage', SemesterEvaluation::class); | ||
|
||
|
@@ -141,20 +74,20 @@ public function show() | |
'user' => user(), | ||
'faculties' => Faculty::all(), | ||
'workshops' => Workshop::all(), | ||
'evaluation' => user()->semesterEvaluations()->where('semester_id', Semester::current()->id)->first(), | ||
'evaluation' => user()->semesterEvaluations()->where('semester_id', self::semester()->id)->first(), | ||
'general_assemblies' => GeneralAssembly::all()->sortByDesc('closed_at')->take(2), | ||
'community_services' => user()->communityServiceRequests()->where('semester_id', Semester::current()->id)->get(), | ||
'community_services' => user()->communityServiceRequests()->where('semester_id', self::semester()->id)->get(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
'position_roles' => user()->roles()->whereIn('name', Role::STUDENT_POSTION_ROLES)->get(), | ||
'periodicEvent' => $this->periodicEvent(), | ||
'users_havent_filled_out' => user()->can('manage', SemesterEvaluation::class) ? $this->usersHaventFilledOutTheForm() : null, | ||
'users_havent_filled_out' => user()->can('manage', SemesterEvaluation::class) ? User::doesntHaveStatusFor(self::semester()->succ())->get() : null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here: ($this->periodicEvent()?->semester()->id ?? Semester::current())->succ() |
||
]); | ||
} | ||
|
||
/** | ||
* Update form information. | ||
* @throws \Exception | ||
*/ | ||
public function store(Request $request) | ||
public function store(Request $request): RedirectResponse | ||
{ | ||
$this->authorize('fill', SemesterEvaluation::class); | ||
|
||
|
@@ -221,7 +154,10 @@ public function store(Request $request) | |
] | ||
)); | ||
if ($request->next_status == Role::ALUMNI) { | ||
self::deactivateCollegist($user); | ||
RoleUser::withoutEvents(function () use ($user) { | ||
$user->removeRole(Role::collegist()); | ||
$user->addRole(Role::alumni()); | ||
}); | ||
return redirect()->route('home')->with('message', __('general.successful_modification')); | ||
} else { | ||
if (!isset($request->next_status)) { | ||
|
@@ -239,24 +175,4 @@ public function store(Request $request) | |
|
||
return back()->with('message', __('general.successful_modification'))->with('section', $request->section); | ||
} | ||
|
||
/** | ||
* @return User[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection | ||
*/ | ||
public function usersHaventFilledOutTheForm() | ||
{ | ||
return User::withRole(Role::COLLEGIST)->verified()->whereDoesntHave('semesterStatuses', function ($query) { | ||
$query->where('semester_id', $this->semester()?->succ()?->id); | ||
})->get(); | ||
} | ||
|
||
/** | ||
* Deactivate a collegist and set alumni role. | ||
* @param User $user | ||
*/ | ||
public static function deactivateCollegist(User $user) | ||
{ | ||
$user->removeRole(Role::collegist()); | ||
$user->addRole(Role::alumni()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Static
semester()
Method Not Foundsemester()
method is not defined withinSemesterEvaluationController
or its parent classes.🔗 Analysis chain
Verify accessibility of
self::semester()
methodThe use of
self::semester()
assumes that a staticsemester()
method is available within the class hierarchy. Please ensure that this method exists and returns the expectedSemester
instance.To confirm the existence and accessibility of the
semester()
method, you may run:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 6556
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdmnk this is indeed true; what about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.