Skip to content

Commit

Permalink
Merge branch 'staging' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
horcsinbalint committed Jan 15, 2025
2 parents 3ca27bf + 430ae5e commit cc66020
Show file tree
Hide file tree
Showing 71 changed files with 1,552 additions and 314 deletions.
18 changes: 10 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
],
"service": "mars_dev",
"workspaceFolder": "/workspace/mars",
"settings": {},
"extensions": [
// "mikestead.dotenv",
// "amiralizadeh9480.laravel-extra-intellisense",
// "ryannaddy.laravel-artisan",
// "onecentlin.laravel5-snippets",
// "onecentlin.laravel-blade"
],
"customizations": {
"vscode": {
"settings": {
"php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer"
},
"extensions": [
"junstyle.php-cs-fixer"
]
}
},
"remoteUser": "ubuntu",
"postCreateCommand": "make build"
// "forwardPorts": [],
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ seed:
php artisan db:seed

serve:
php artisan serve --host=0.0.0.0
php artisan serve --host=0.0.0.0

clear_cache:
php artisan cache:clear
php artisan view:clear
php artisan config:clear
php artisan event:clear
php artisan route:clear
40 changes: 40 additions & 0 deletions app/Console/Commands/FinalizeSemesterEvaluation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Http\Controllers\Secretariat\SemesterEvaluationController;
use Illuminate\Support\Facades\App;
use App\Models\Semester;

class FinalizeSemesterEvaluation extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:finalize-semester-evaluation {year} {part}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Finalizes the semester evaluation, deactivates collegists who has not set their new status.';

/**
* Execute the console command.
*/
public function handle()
{
$year = $this->argument('year');
$part = $this->argument('part');


$semester = Semester::where('year', $year)->where('part', $part)->first();

App::setLocale('hu');
app(SemesterEvaluationController::class)->finalize($semester);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private function paginatorFrom(Builder $printJobs, array $columns)
$paginator = TabulatorPaginator::from($printJobs)->sortable($columns)->filterable($columns)->paginate();

// Process the data before showing it in a table.
// @phpstan-ignore-next-line
$paginator->getCollection()->append([
'translated_cost',
'translated_state',
Expand Down
23 changes: 14 additions & 9 deletions app/Http/Controllers/Secretariat/SemesterEvaluationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ public function handlePeriodicEventStart(): void
public function handlePeriodicEventReminder(int $daysBeforeEnd): void
{
if($daysBeforeEnd < 3) {
$userCount = $this->usersHaventFilledOutTheForm()->count();
$userCount = SemesterEvaluationController::usersHaventFilledOutTheForm($this->semester())->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()
public static function finalize($semester)
{
$users = $this->usersHaventFilledOutTheForm();
$users = SemesterEvaluationController::usersHaventFilledOutTheForm($semester);
$users_names = $users->pluck('name')->toArray();

if (User::secretary()) {
Expand Down Expand Up @@ -137,7 +137,6 @@ public function show()
$this->authorize('fillOrManage', SemesterEvaluation::class);

return view('secretariat.evaluation-form.app', [
'phd' => user()->educationalInformation->isSenior(),
'user' => user(),
'faculties' => Faculty::all(),
'workshops' => Workshop::all(),
Expand All @@ -146,7 +145,7 @@ public function show()
'community_services' => user()->communityServiceRequests()->where('semester_id', Semester::current()->id)->get(),
'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) ? SemesterEvaluationController::usersHaventFilledOutTheForm($this->semester()) : null,
]);
}

Expand Down Expand Up @@ -243,11 +242,17 @@ public function store(Request $request)
/**
* @return User[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
*/
public function usersHaventFilledOutTheForm()
public static function usersHaventFilledOutTheForm($semester)
{
return User::withRole(Role::COLLEGIST)->verified()->whereDoesntHave('semesterStatuses', function ($query) {
$query->where('semester_id', $this->semester()?->succ()?->id);
})->get();
return User::withRole(Role::COLLEGIST)
->whereDoesntHave('roles', function ($query) {
$query->where('name', Role::SENIOR);
})
->verified()
->whereDoesntHave('semesterStatuses', function ($query) use ($semester) {
$query->where('semester_id', $semester?->succ()?->id);
})
->get();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Secretariat/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function updateEducationalInformation(Request $request, User $user): Redi
'study_lines' => 'array',
'study_lines.*.name' => 'required|string|max:255',
'study_lines.*.level' => ['required', Rule::in(array_keys(StudyLine::TYPES))],
'study_lines.*.training_code' => 'string|max:255',
'study_lines.*.minor' => 'nullable|string|max:255',
'study_lines.*.start' => 'required',
'email' => [
Expand Down Expand Up @@ -209,7 +210,6 @@ public function updateEducationalInformation(Request $request, User $user): Redi

if ($request->has('workshop')) {
$user->workshops()->sync($request->input('workshop'));
WorkshopBalance::generateBalances(Semester::current());
}

if ($request->has('faculty')) {
Expand All @@ -223,6 +223,7 @@ public function updateEducationalInformation(Request $request, User $user): Redi
'name' => $studyLine["name"],
'type' => $studyLine["level"],
'minor' => $studyLine["minor"] ?? null,
'training_code' => $studyLine["training_code"],
'start' => $studyLine["start"],
'end' => $studyLine["end"] ?? null,
]);
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/StudentsCouncil/EconomicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ public static function payKKTNetregLogic(User $payer, User $receiver, int $kkt_a
'moved_to_checkout' => null,
]);

WorkshopBalance::generateBalances(Semester::current());

$new_expiry_date = $payer->internetAccess->extendInternetAccess();

return [$kkt, $netreg, $new_expiry_date];
Expand Down
5 changes: 3 additions & 2 deletions app/Models/EducationalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;

use App\Models\Semester;
use App\Models\Role;

/**
* Either B2 or C1.
Expand Down Expand Up @@ -113,11 +114,11 @@ public function languageExamsBeforeAcceptance()
}

/**
* Whether the user is a senior (i.e. currently has a PhD study line).
* Whether the user is a senior
*/
public function isSenior(): bool
{
return $this->studyLines()->currentlyEnrolled()->where('type', 'phd')->exists();
return $this->user->isSenior();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Models/FreePages.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function printAccount()

/**
* Wether the free pages are still available.
* @return bool
* @return Attribute
*/
protected function available(): Attribute
{
Expand Down
4 changes: 2 additions & 2 deletions app/Models/PrintAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function freePages()

/**
* The free pages which are currently available. Sorts the free pages by their deadline.
* @return Collection
* @return Collection|FreePages[]
*/
public function availableFreePages()
{
Expand Down Expand Up @@ -131,7 +131,7 @@ public function updateHistory(bool $useFreePages, int $cost)
$availableFreePages = $this->availableFreePages()->where('amount', '>', 0);

// Subtract the pages from the free pages pool, as many free pages as necessary
/** @var FreePages */
/** @var FreePages $freePages */
foreach ($availableFreePages as $freePages) {
$subtractablePages = $freePages->calculateSubtractablePages($freePagesToSubtract);
$freePages->subtractPages($subtractablePages);
Expand Down
13 changes: 12 additions & 1 deletion app/Models/PrintAccountHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

// Note: the elements of this class should no be changed manually.
// Note: the elements of this class should not be changed manually.
// Observers for updating entries are set up.
/**
* App\Models\PrintAccountHistory
Expand Down Expand Up @@ -45,11 +46,21 @@ class PrintAccountHistory extends Model
'modified_at',
];


/**
* `User` whose balance is affected by this change.
* @return BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}


/**
* `User` who initiated this change.
* @return BelongsTo
*/
public function modifier()
{
return $this->belongsTo(User::class, 'modified_by');
Expand Down
5 changes: 4 additions & 1 deletion app/Models/PrintJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class PrintJob extends Model
'used_free_pages' => 'boolean',
];

/**
* `User` that sent this `PrintJob`.
* @return BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
Expand Down Expand Up @@ -116,7 +120,6 @@ public function translatedState(): Attribute

/**
* Attemts to cancel the given `PrintJob`. Returns wether it was successful.
* @param PrintJob $this
* @return PrinterCancelResult
*/
public function cancel()
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function printJobs()
* @param string $originalName
* @param bool $twoSided
* @param int $copyNumber
* @return Model
* @return PrintJob
* @throws AuthenticationException
* @throws PrinterException
* @throws MassAssignmentException
Expand All @@ -73,13 +73,13 @@ public function createPrintJob(bool $useFreePages, int $cost, string $filePath,
* @param bool $twoSided
* @param int $copies
* @param string $path
* @return int The `jobId` belonging to the printjob
* @return string The `jobId` belonging to the printjob
* @throws PrinterException If the printing fails
*/
public function print(bool $twoSided, int $copies, string $path)
{
if (config('app.debug')) {
return -1;
return "not_submitted";
}
$jobId = null;
try {
Expand Down Expand Up @@ -135,7 +135,7 @@ public function getCompletedPrintJobs()
*/
public function updateCompletedPrintJobs()
{
return DB::transaction(function () {
DB::transaction(function () {
PrintJob::where('state', PrintJobStatus::QUEUED)->whereIn(
'job_id',
$this->getCompletedPrintJobs()
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Role extends Model
public const ETHICS_COMMISSIONER = 'ethics-commissioner';
public const ALUMNI = 'alumni';
public const RECEPTIONIST = 'receptionist';
public const SENIOR = 'senior';

//Students' Committe role's objects
public const PRESIDENT = 'president';
Expand Down Expand Up @@ -111,6 +112,7 @@ class Role extends Model
public const ALL = [
self::SYS_ADMIN,
self::COLLEGIST,
self::SENIOR,
self::TENANT,
self::WORKSHOP_ADMINISTRATOR,
self::WORKSHOP_LEADER,
Expand Down Expand Up @@ -311,6 +313,7 @@ public function color(): string
self::ETHICS_COMMISSIONER => 'green lighten-2',
self::ALUMNI => 'grey darken-1',
self::RECEPTIONIST => 'brown',
self::SENIOR => 'teal',
default => 'grey',
};
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Semester.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static function current(): Semester
}
$current = Semester::getOrCreate($year, $part);

Cache::put('semester.current.' . $today, $current, Carbon::tomorrow());
Cache::put('semester.current.' . $today, $current, $seconds = 10);
}

return Cache::get('semester.current.' . $today);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StudyLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @property string $name
* @property string $minor
* @property string $type
* @property string $training_code
* @property Semester $startSemester
* @property ?Semester $endSemester
* @property int $id
Expand Down Expand Up @@ -47,6 +48,7 @@ class StudyLine extends Model
'name',
'minor',
'type',
'training_code',
'start',
'end'
];
Expand Down Expand Up @@ -109,6 +111,9 @@ public function getNameWithYear(): string
if ($this->start) {
$name .= ' (' . $this->startSemester->tag . ' - ' . $this->endSemester?->tag . ')';
}
if ($this->training_code) {
$name .= ' - ' . $this->training_code;
}
return $name;
}

Expand Down
6 changes: 5 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ public function scopeVerified(Builder $query): Builder
return $query->where('users.verified', 1);
}

public function isSenior(): bool
{
return $this->hasRole(Role::SENIOR);
}

/**
* Scope a query to only include users whose data can be accessed by the given user.
* @param Builder $query
Expand Down Expand Up @@ -768,7 +773,6 @@ public function setCollegist($objectName): void
$this->addRole($role, $object);

Cache::forget('collegists');
WorkshopBalance::generateBalances(Semester::current());
}

/**
Expand Down
Loading

0 comments on commit cc66020

Please sign in to comment.