Merge pull request #26 from okorpheus/auditionadmin-23
auditionadmin-23 Need ability to make a user an administrator or tab Closes #23
This commit is contained in:
commit
0101dcdeec
|
|
@ -50,7 +50,7 @@ class UserController extends Controller
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
request()->validate([
|
$validData = $request->validate([
|
||||||
'first_name' => ['required'],
|
'first_name' => ['required'],
|
||||||
'last_name' => ['required'],
|
'last_name' => ['required'],
|
||||||
'email' => ['required', 'email'],
|
'email' => ['required', 'email'],
|
||||||
|
|
@ -58,14 +58,18 @@ class UserController extends Controller
|
||||||
'judging_preference' => ['required'],
|
'judging_preference' => ['required'],
|
||||||
'school_id' => ['required', 'exists:schools,id'],
|
'school_id' => ['required', 'exists:schools,id'],
|
||||||
]);
|
]);
|
||||||
|
$validData['is_admin'] = $request->get('is_admin') == 'on' ? 1 : 0;
|
||||||
|
$validData['is_tab'] = $request->get('is_tab') == 'on' ? 1 : 0;
|
||||||
|
|
||||||
$user->update([
|
$user->update([
|
||||||
'first_name' => request('first_name'),
|
'first_name' => $validData['first_name'],
|
||||||
'last_name' => request('last_name'),
|
'last_name' => $validData['last_name'],
|
||||||
'email' => request('email'),
|
'email' => $validData['email'],
|
||||||
'cell_phone' => request('cell_phone'),
|
'cell_phone' => $validData['cell_phone'],
|
||||||
'judging_preference' => request('judging_preference'),
|
'judging_preference' => $validData['judging_preference'],
|
||||||
'school_id' => request('school_id'),
|
'school_id' => $validData['school_id'],
|
||||||
|
'is_admin' => $validData['is_admin'],
|
||||||
|
'is_tab' => $validData['is_tab'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return redirect('/admin/users');
|
return redirect('/admin/users');
|
||||||
|
|
@ -82,7 +86,7 @@ class UserController extends Controller
|
||||||
// Generate a random password
|
// Generate a random password
|
||||||
$randomPassword = Str::random(12);
|
$randomPassword = Str::random(12);
|
||||||
|
|
||||||
$user = \App\Models\User::make([
|
$user = User::make([
|
||||||
'first_name' => request('first_name'),
|
'first_name' => request('first_name'),
|
||||||
'last_name' => request('last_name'),
|
'last_name' => request('last_name'),
|
||||||
'email' => request('email'),
|
'email' => request('email'),
|
||||||
|
|
@ -104,12 +108,13 @@ class UserController extends Controller
|
||||||
return redirect('/admin/users');
|
return redirect('/admin/users');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Request $request, User $user)
|
public function destroy(User $user)
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) {
|
if (! Auth::user()->is_admin) {
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
$user->delete();
|
$user->delete();
|
||||||
|
|
||||||
return redirect()->route('admin.users.index')->with('success', 'User deleted successfully');
|
return redirect()->route('admin.users.index')->with('success', 'User deleted successfully');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
'password',
|
'password',
|
||||||
'profile_image_url',
|
'profile_image_url',
|
||||||
'school_id',
|
'school_id',
|
||||||
|
'is_tab',
|
||||||
|
'is_admin',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -122,33 +124,23 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
return $this->belongsToMany(BonusScoreDefinition::class, 'bonus_score_judge_assignment');
|
return $this->belongsToMany(BonusScoreDefinition::class, 'bonus_score_judge_assignment');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function advancementVotes(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(JudgeAdvancementVote::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isJudge(): bool
|
public function isJudge(): bool
|
||||||
{
|
{
|
||||||
return $this->judgingAssignments()->count() > 0 || $this->bonusJudgingAssignments()->count() > 0;
|
return $this->judgingAssignments()->count() > 0 || $this->bonusJudgingAssignments()->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of schools using the users email domain
|
|
||||||
*
|
|
||||||
* @return SchoolEmailDomain[]
|
|
||||||
*/
|
|
||||||
public function possibleSchools(): Collection
|
public function possibleSchools(): Collection
|
||||||
{
|
{
|
||||||
if ($this->school_id) {
|
if ($this->school_id) {
|
||||||
$return[] = $this->school;
|
$return[] = $this->school;
|
||||||
|
|
||||||
return $return;
|
return collect($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SchoolEmailDomain::with('school')->where('domain', '=', $this->emailDomain())->get();
|
return SchoolEmailDomain::with('school')->where('domain', '=', $this->emailDomain())->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canTab()
|
public function canTab(): bool
|
||||||
{
|
{
|
||||||
if ($this->is_admin) {
|
if ($this->is_admin) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,17 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</x-form.select>
|
</x-form.select>
|
||||||
|
<div class="col-span-3">
|
||||||
|
<x-form.checkbox name="is_admin" :checked="$user->is_admin">
|
||||||
|
<x-slot:label>Administrator</x-slot:label>
|
||||||
|
</x-form.checkbox>
|
||||||
|
</div>
|
||||||
|
<div class="col-span-3">
|
||||||
|
<x-form.checkbox name="is_tab" :checked="$user->is_tab">
|
||||||
|
<x-slot:label>Tabulator</x-slot:label>
|
||||||
|
</x-form.checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
</x-form.body-grid>
|
</x-form.body-grid>
|
||||||
<x-form.footer class="py-5">
|
<x-form.footer class="py-5">
|
||||||
<x-form.button>Update User</x-form.button>
|
<x-form.button>Update User</x-form.button>
|
||||||
|
|
|
||||||
|
|
@ -16,16 +16,24 @@
|
||||||
<x-table.th>Email</x-table.th>
|
<x-table.th>Email</x-table.th>
|
||||||
<x-table.th>Cell Phone</x-table.th>
|
<x-table.th>Cell Phone</x-table.th>
|
||||||
<x-table.th>Judging Preference</x-table.th>
|
<x-table.th>Judging Preference</x-table.th>
|
||||||
|
<x-table.th>Privileges</x-table.th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
@foreach($users as $user)
|
@foreach($users as $user)
|
||||||
<tr>
|
<tr class="hover:bg-gray-50">
|
||||||
<x-table.td><a href="{{ route('admin.users.edit',$user) }}">{{ $user->full_name(true) }}</a></x-table.td>
|
<x-table.td><a href="{{ route('admin.users.edit',$user) }}">{{ $user->full_name(true) }}</a></x-table.td>
|
||||||
<x-table.td>{{ $user->has_school() ? $user->school->name : ' ' }}</x-table.td>
|
<x-table.td>{{ $user->has_school() ? $user->school->name : ' ' }}</x-table.td>
|
||||||
<x-table.td>{{ $user->email }}</x-table.td>
|
<x-table.td>{{ $user->email }}</x-table.td>
|
||||||
<x-table.td>{{ $user->cell_phone }}</x-table.td>
|
<x-table.td>{{ $user->cell_phone }}</x-table.td>
|
||||||
<x-table.td>{{ $user->judging_preference }}</x-table.td>
|
<x-table.td>{{ $user->judging_preference }}</x-table.td>
|
||||||
|
<x-table.td>
|
||||||
|
@if($user->is_admin)
|
||||||
|
Admin
|
||||||
|
@elseif($user->is_tab)
|
||||||
|
Tabulator
|
||||||
|
@endif
|
||||||
|
</x-table.td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</x-table.body>
|
</x-table.body>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Models\JudgeAdvancementVote;
|
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Models\School;
|
use App\Models\School;
|
||||||
use App\Models\SchoolEmailDomain;
|
use App\Models\SchoolEmailDomain;
|
||||||
|
|
@ -91,21 +90,6 @@ it('has rooms also called judgingAssignments', function () {
|
||||||
->and($this->user->judgingAssignments->first())->toBeInstanceOf(Room::class);
|
->and($this->user->judgingAssignments->first())->toBeInstanceOf(Room::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has advancement votes', function () {
|
|
||||||
// Arrange
|
|
||||||
$entries = Entry::factory()->count(5)->create();
|
|
||||||
foreach ($entries as $entry) {
|
|
||||||
JudgeAdvancementVote::create([
|
|
||||||
'user_id' => $this->user->id,
|
|
||||||
'entry_id' => $entry->id,
|
|
||||||
'vote' => fake()->randomElement(['yes', 'no', 'dq']),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
// Act & Assert
|
|
||||||
expect($this->user->advancementVotes->count())->toBe(5)
|
|
||||||
->and($this->user->advancementVotes->first())->toBeInstanceOf(JudgeAdvancementVote::class);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('knows if it is a judge', function () {
|
it('knows if it is a judge', function () {
|
||||||
expect($this->user->isJudge())->toBeFalse();
|
expect($this->user->isJudge())->toBeFalse();
|
||||||
Room::factory()->create()->addJudge($this->user);
|
Room::factory()->create()->addJudge($this->user);
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ it('has all needed fields', function () {
|
||||||
'email',
|
'email',
|
||||||
'cell_phone',
|
'cell_phone',
|
||||||
'judging_preference',
|
'judging_preference',
|
||||||
|
'is_admin',
|
||||||
|
'is_tab',
|
||||||
];
|
];
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
$response = get(route('admin.users.edit', $this->users[0]));
|
$response = get(route('admin.users.edit', $this->users[0]));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue