Allow admin to set users to have no school.

Fixes #112
This commit is contained in:
Matt Young 2025-10-25 22:21:10 -05:00
parent 550614a317
commit 6ca05bf4d5
2 changed files with 13 additions and 4 deletions

View File

@ -8,19 +8,27 @@ use App\Models\User;
class AssignUserToSchool class AssignUserToSchool
{ {
public function __invoke(User $user, School|int $school): void public function __invoke(User $user, School|int|null $school): void
{ {
$this->assign($user, $school); $this->assign($user, $school);
} }
public function assign(User $user, School|int $school, bool $addDomainToSchool = true): void public function assign(User $user, School|int|null $school, bool $addDomainToSchool = true): void
{ {
if (! User::where('id', $user->id)->exists()) {
throw new AuditionAdminException('User does not exist');
}
if (is_int($school)) { if (is_int($school)) {
$school = School::find($school); $school = School::find($school);
} }
if (! User::where('id', $user->id)->exists()) { if (is_null($school)) {
throw new AuditionAdminException('User does not exist'); $user->update([
'school_id' => null,
]);
return;
} }
if (is_null($school) || ! School::where('id', $school->id)->exists()) { if (is_null($school) || ! School::where('id', $school->id)->exists()) {

View File

@ -64,6 +64,7 @@ class UserController extends Controller
$profileUpdater->update($user, $profileData); $profileUpdater->update($user, $profileData);
// Deal with school assignment // Deal with school assignment
dump($request->get('school_id'));
if ($user->school_id != $request->get('school_id')) { if ($user->school_id != $request->get('school_id')) {
$schoolAssigner($user, $request->get('school_id')); $schoolAssigner($user, $request->get('school_id'));
} }