Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ _ide_helper_models.php
*.DS_Store
.vscode
.php-cs-fixer.cache
/composer.phar
18 changes: 10 additions & 8 deletions app/Http/Controllers/Auth/AdmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class AdmissionController extends Controller

public function __construct()
{
$this->underlyingControllerName =
\App\Http\Controllers\Auth\ApplicationController::class;
$this->underlyingControllerName
= \App\Http\Controllers\Auth\ApplicationController::class;
}

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ public function index(Request $request)
{
$request->validate([
'status_filter' => 'in:everybody,unsubmitted,submitted,called_in,admitted',
'return_excel' => 'nullable|boolean'
'return_excel' => 'nullable|boolean',
]);
$authUser = $request->user();
$this->authorize('viewSome', Application::class);
Expand Down Expand Up @@ -132,7 +132,7 @@ public function index(Request $request)
'workshops' => \App\Policies\ApplicationPolicy::getAccessibleWorkshops($authUser), //workshops that can be chosen to filter
'status_filter' => $status_filter,
'applicationDeadline' => $this->getDeadline(),
'periodicEvent' => $this->periodicEvent()
'periodicEvent' => $this->periodicEvent(),
]);
}

Expand Down Expand Up @@ -177,15 +177,15 @@ public function update(Request $request, Application $application): RedirectResp
$this->authorize('editSubmissionStatus', Application::class);
$application->update(
[
"submitted" => 1
"submitted" => 1,
]
);
}
if ($request->has('unsubmit')) {
$this->authorize('editSubmissionStatus', Application::class);
$application->update(
[
"submitted" => 0
"submitted" => 0,
]
);
}
Expand All @@ -204,7 +204,7 @@ public function indexFinalize(): View
$admitted = $this->getAdmitted();
return view('auth.admission.finalize', [
'semester' => $this->semester(),
'admitted_applications' => $admitted
'admitted_applications' => $admitted,
]);
}

Expand Down Expand Up @@ -243,6 +243,7 @@ public function finalize(): RedirectResponse
// soft deletes application, keep them for future reference
// (see https://github.com/EotvosCollegium/mars/issues/332#issuecomment-2014058021)
$application->delete();
$application->applicationWorkshops()->delete();
Comment thread
viktorcsimma marked this conversation as resolved.
} else {
$files = File::where('application_id', $application->id)
->orWhere('user_id', $application->user->id);
Expand All @@ -252,6 +253,7 @@ public function finalize(): RedirectResponse
$files->delete();
$application->forceDelete();
$application->user->forceDelete();
$application->applicationWorkshops()->forceDelete();
}
}

Expand All @@ -278,7 +280,7 @@ private function getFilteredWorkshop(Request $request): mixed

/**
* Helper function to get admittted applications.
* @return array
* @return \Illuminate\Database\Eloquent\Collection<int, Application>
*/
private function getAdmitted()
{
Expand Down
22 changes: 12 additions & 10 deletions app/Http/Controllers/StudentsCouncil/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ class QuestionController extends Controller
/**
* Saves a new question.
*/
protected function createQuestion(Request $request, Semester|GeneralAssembly $parent = null, $opened_at = null, $closed_at = null): Question
protected function createQuestion(Request $request, Semester|GeneralAssembly|null $parent = null, $opened_at = null, $closed_at = null): Question
{
$fn_is_selection_or_ranking = fn () => $request['question_type'] == Question::SELECTION || $request['question_type'] == Question::RANKING;
$fn_not_selection_or_ranking = fn () => !$fn_is_selection_or_ranking();
$fn_is_selection_or_ranking = fn() => $request['question_type'] == Question::SELECTION || $request['question_type'] == Question::RANKING;
$fn_not_selection_or_ranking = fn() => !$fn_is_selection_or_ranking();
$validator = Validator::make($request->all(), [
'title' => 'required|string',
'question_type' => [
'required',
Rule::in(Question::QUESTION_TYPES)
Rule::in(Question::QUESTION_TYPES),
],
'max_options' => [Rule::requiredIf($fn_is_selection_or_ranking), Rule::excludeIf($fn_not_selection_or_ranking), 'min:1', 'integer'],
'options' => [Rule::requiredIf($fn_is_selection_or_ranking), Rule::excludeIf($fn_not_selection_or_ranking), 'min:1', 'array'],
'options.*' => [Rule::requiredIf($fn_is_selection_or_ranking), Rule::excludeIf($fn_not_selection_or_ranking), 'min:1', 'max:255', 'string'],
]);
$validatedData = $validator->safe()->only(['question_type', 'options']);
$options = array();
$options = [];
if ($validatedData['question_type'] == Question::SELECTION || $validatedData['question_type'] == Question::RANKING) {
$options = array_filter($validatedData['options'], function ($s) {
return $s != null;
Expand All @@ -55,7 +55,7 @@ protected function createQuestion(Request $request, Semester|GeneralAssembly $pa

$question = $parent->questions()->create([
'title' => $validatedData['title'],
'max_options' => isset($validatedData['max_options']) ? $validatedData['max_options'] : null,
'max_options' => $validatedData['max_options'] ?? null,
'question_type' => $validatedData['question_type'],
'opened_at' => $opened_at,
'closed_at' => $closed_at,
Expand All @@ -64,7 +64,7 @@ protected function createQuestion(Request $request, Semester|GeneralAssembly $pa
foreach ($options as $option) {
$question->options()->create([
'title' => $option,
'votes' => 0
'votes' => 0,
]);
}
}
Expand All @@ -76,13 +76,15 @@ protected function saveVoteForQuestion(Question $question, $validatedData, ?Answ
// validation ensures we have answers
// to all of these questions
$answer = $validatedData[$question->formKey()];
if ($question->question_type == Question::TEXT_ANSWER ||
$question->question_type == Question::RANKING) {
if ($question->question_type == Question::TEXT_ANSWER
|| $question->question_type == Question::RANKING) {
$question->storeAnswers(user(), $answer, $answerSheet);
} elseif ($question->question_type == Question::SELECTION) {
if ($question->isMultipleChoice()) {
$options = array_map(
function (int $id) {return QuestionOption::find($id);},
function (int $id) {
return QuestionOption::find($id);
},
$answer
);
$question->storeAnswers(user(), $options, $answerSheet);
Expand Down
10 changes: 6 additions & 4 deletions app/Mail/CaesarProxyTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ public function __construct()

protected function doSend(SentMessage $sentMessage): void
{
// Symfony would expect Message instead of RawMessage, but it works this way as well. So:
// @phpstan-ignore argument.type
$email = MessageConverter::toEmail($sentMessage->getOriginalMessage());

$headers = $email->getPreparedHeaders();
$headers->remove('To');
$headers->remove('Subject');

$bcc = implode("\r\n", array_map(fn (Address $addr) => 'Bcc: ' . $addr->toString(), $email->getBcc()));
$bcc = implode("\r\n", array_map(fn(Address $addr) => 'Bcc: ' . $addr->toString(), $email->getBcc()));
if ($bcc) {
$bcc .= "\r\n";
}

$data = json_encode([
'to' => implode(',', array_map(fn (Address $addr) => $addr->toString(), $email->getTo())),
'to' => implode(',', array_map(fn(Address $addr) => $addr->toString(), $email->getTo())),
'subject' => $email->getSubject(),
'message' => $email->getBody()->bodyToString(),
'headers' => $headers->toString() . $bcc . $email->getBody()->getPreparedHeaders()->toString(),
Expand All @@ -43,8 +45,8 @@ protected function doSend(SentMessage $sentMessage): void

$options = [
'http' => [
'header' => "Content-Type: application/json\r\n" .
"X-Signature: $signature\r\n",
'header' => "Content-Type: application/json\r\n"
. "X-Signature: $signature\r\n",
'method' => 'POST',
'content' => $data,
],
Expand Down
2 changes: 1 addition & 1 deletion app/Mail/EvaluationFormClosed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EvaluationFormClosed extends Mailable
*
* @return void
*/
public function __construct(string $recipient, array $deactivated = null)
public function __construct(string $recipient, ?array $deactivated = null)
{
$this->recipient = $recipient;
$this->deactivated = $deactivated;
Expand Down
10 changes: 5 additions & 5 deletions app/Models/AnonymousQuestions/AnswerSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AnswerSheet extends Model
public $timestamps = false;

protected $fillable = [
'year_of_acceptance'
'year_of_acceptance',
];

/**
Expand Down Expand Up @@ -62,14 +62,14 @@ public function longAnswers(): HasMany
* with their anonymous data.
* The default semester is the current one.
*/
public static function createForUser(User $user, Semester $semester = null): AnswerSheet
public static function createForUser(User $user, ?Semester $semester = null): AnswerSheet
{
if (is_null($semester)) {
$semester = Semester::current();
}

return $semester->answerSheets()->create([
'year_of_acceptance' => $user->educationalInformation->year_of_acceptance
'year_of_acceptance' => $user->educationalInformation->year_of_acceptance,
]);
}

Expand All @@ -78,7 +78,7 @@ public static function createForUser(User $user, Semester $semester = null): Ans
* with their anonymous data.
* The default semester is the current one.
*/
public static function createForCurrentUser(Semester $semester = null): AnswerSheet
public static function createForCurrentUser(?Semester $semester = null): AnswerSheet
{
return self::createForUser(user(), $semester);
}
Expand All @@ -94,7 +94,7 @@ public function toArray(): array
{
$row = [
$this->semester->tag,
$this->year_of_acceptance
$this->year_of_acceptance,
];
foreach ($this->semester->questions()->orderBy('id')->get() as $question) {
if ($question->question_type == Question::TEXT_ANSWER) {
Expand Down
Loading