You've already forked isop-mirror
fix: restrict DEFENDED and NOT_DEFENDED status for admins based on report confirmation
This commit is contained in:
@@ -9,11 +9,12 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class InternshipStatusController extends Controller
|
class InternshipStatusController extends Controller
|
||||||
{
|
{
|
||||||
public function get(int $id) {
|
public function get(int $id)
|
||||||
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$internship_statuses = InternshipStatus::whereInternshipId($id)->orderByDesc('changed')->get()->makeHidden(['created_at', 'updated_at', 'id']);
|
$internship_statuses = InternshipStatus::whereInternshipId($id)->orderByDesc('changed')->get()->makeHidden(['created_at', 'updated_at', 'id']);
|
||||||
|
|
||||||
if(!$internship_statuses) {
|
if (!$internship_statuses) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'No such internship exists.'
|
'message' => 'No such internship exists.'
|
||||||
], 400);
|
], 400);
|
||||||
@@ -31,11 +32,12 @@ class InternshipStatusController extends Controller
|
|||||||
return response()->json($internship_statuses);
|
return response()->json($internship_statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_next_states(int $id) {
|
public function get_next_states(int $id)
|
||||||
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$internship = Internship::find($id);
|
$internship = Internship::find($id);
|
||||||
|
|
||||||
if(!$internship) {
|
if (!$internship) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'No such internship exists.'
|
'message' => 'No such internship exists.'
|
||||||
], 400);
|
], 400);
|
||||||
@@ -46,7 +48,7 @@ class InternshipStatusController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$currentStatus = $this->currentInternshipStatus($internship);
|
$currentStatus = $this->currentInternshipStatus($internship);
|
||||||
$nextPossibleStatuses = $this->possibleNewStatuses($currentStatus->status, $user->role);
|
$nextPossibleStatuses = $this->possibleNewStatuses($currentStatus->status, $user->role, $internship->report_confirmed);
|
||||||
|
|
||||||
return response()->json($nextPossibleStatuses);
|
return response()->json($nextPossibleStatuses);
|
||||||
}
|
}
|
||||||
@@ -99,7 +101,7 @@ class InternshipStatusController extends Controller
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$internship = Internship::find($id);
|
$internship = Internship::find($id);
|
||||||
|
|
||||||
if(!$internship) {
|
if (!$internship) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'No such internship exists.'
|
'message' => 'No such internship exists.'
|
||||||
], 400);
|
], 400);
|
||||||
@@ -110,7 +112,7 @@ class InternshipStatusController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$internshipStatus = $this->currentInternshipStatus($internship);
|
$internshipStatus = $this->currentInternshipStatus($internship);
|
||||||
$newStatusValidator = 'in:' . implode(',', $this->possibleNewStatuses($internshipStatus->status, $user->role));
|
$newStatusValidator = 'in:' . implode(',', $this->possibleNewStatuses($internshipStatus->status, $user->role, $internship->report_confirmed));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'status' => ['required', 'string', 'uppercase', $newStatusValidator],
|
'status' => ['required', 'string', 'uppercase', $newStatusValidator],
|
||||||
@@ -136,8 +138,10 @@ class InternshipStatusController extends Controller
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
private function possibleNewStatuses(string $current_status, string $userRole) {
|
private function possibleNewStatuses(string $current_status, string $userRole, bool $report_confirmed)
|
||||||
if($userRole === "STUDENT") return [];
|
{
|
||||||
|
if ($userRole === "STUDENT")
|
||||||
|
return [];
|
||||||
|
|
||||||
switch ($current_status) {
|
switch ($current_status) {
|
||||||
case 'SUBMITTED':
|
case 'SUBMITTED':
|
||||||
@@ -146,7 +150,12 @@ class InternshipStatusController extends Controller
|
|||||||
if ($userRole === 'EMPLOYER') {
|
if ($userRole === 'EMPLOYER') {
|
||||||
return ['DENIED'];
|
return ['DENIED'];
|
||||||
}
|
}
|
||||||
return ['SUBMITTED', 'DENIED', 'DEFENDED', 'NOT_DEFENDED'];
|
|
||||||
|
if ($report_confirmed) {
|
||||||
|
return ['SUBMITTED', 'DENIED', 'DEFENDED', 'NOT_DEFENDED'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['SUBMITTED', 'DENIED'];
|
||||||
case 'DENIED':
|
case 'DENIED':
|
||||||
if ($userRole === 'EMPLOYER') {
|
if ($userRole === 'EMPLOYER') {
|
||||||
return ['CONFIRMED'];
|
return ['CONFIRMED'];
|
||||||
@@ -160,7 +169,8 @@ class InternshipStatusController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function currentInternshipStatus(Internship $internship) {
|
private function currentInternshipStatus(Internship $internship)
|
||||||
|
{
|
||||||
return InternshipStatus::whereInternshipId($internship->id)->orderByDesc('changed')->firstOrFail();
|
return InternshipStatus::whereInternshipId($internship->id)->orderByDesc('changed')->firstOrFail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ async function submit() {
|
|||||||
<!-- Chybová hláška -->
|
<!-- Chybová hláška -->
|
||||||
<ErrorAlert v-if="load_error" :error="`Nepodarilo sa načítať stavy: ${save_error}`" />
|
<ErrorAlert v-if="load_error" :error="`Nepodarilo sa načítať stavy: ${save_error}`" />
|
||||||
|
|
||||||
|
<!-- Chybová hláška -->
|
||||||
|
<ErrorAlert v-else-if="data?.length === 0" :error="`Nepodarilo sa načítať stavy: ${save_error}`" />
|
||||||
|
|
||||||
<v-form v-else v-model="isValid" @submit.prevent="submit" :disabled="loading">
|
<v-form v-else v-model="isValid" @submit.prevent="submit" :disabled="loading">
|
||||||
<v-select v-model="new_state" label="Stav" :items="data" item-value="value"></v-select>
|
<v-select v-model="new_state" label="Stav" :items="data" item-value="value"></v-select>
|
||||||
<v-text-field v-model="note" :rules="[rules.required]" label="Poznámka"></v-text-field>
|
<v-text-field v-model="note" :rules="[rules.required]" label="Poznámka"></v-text-field>
|
||||||
|
|||||||
Reference in New Issue
Block a user