diff --git a/app/Http/Controllers/DashboardAdminController.php b/app/Http/Controllers/DashboardAdminController.php index b86a01de..aba90ab4 100644 --- a/app/Http/Controllers/DashboardAdminController.php +++ b/app/Http/Controllers/DashboardAdminController.php @@ -134,6 +134,36 @@ public function editUser(IlluminateRequest $request): RedirectResponse return Redirect::back(); } + /** + * Submit delete a user + */ + public function deleteUser(IlluminateRequest $request): RedirectResponse + { + $user = User::find($request->user); + + if (! $user) { + Session::flash('error', 'Der angegebene User existiert nicht'); + + return Redirect::back(); + } + + // check if user has super admin role + if ($user->hasRole('super admin')) { + + Session::flash('error', 'Der User kann nicht zu Super Admin gemacht werden'); + } + + // copy user to temp user variable + $userTemp = $user; + + // delete the user + $user->delete(); + + Session::flash('success', 'Der Account '.$userTemp->email.' wurde erfolgreich gelöscht. Die Tabelle aktualisiert sich in wenigen Sekunden automatisch.'); + + return Redirect::back(); + } + /** * Display the dashboard admin registrations page */ diff --git a/database/seeders/RoleSeeder.php b/database/seeders/RoleSeeder.php index 2ffdaa8d..d19edd64 100644 --- a/database/seeders/RoleSeeder.php +++ b/database/seeders/RoleSeeder.php @@ -21,6 +21,7 @@ public function run(): void 'manage events', 'manage users', 'manage random generator', + 'delete users', ] as $permission) { if (! Permission::where('name', $permission)->exists()) { Permission::create(['name' => $permission]); @@ -70,6 +71,7 @@ public function run(): void $superAdminRole->givePermissionTo($permissions['manage events']); $superAdminRole->givePermissionTo($permissions['manage random generator']); $superAdminRole->givePermissionTo($permissions['manage users']); + $superAdminRole->givePermissionTo($permissions['delete users']); // create special role if it doesn't exist if (! Role::where('name', 'special')->exists()) { diff --git a/resources/js/components/user/DeleteModal.vue b/resources/js/components/user/DeleteModal.vue new file mode 100644 index 00000000..2977cb35 --- /dev/null +++ b/resources/js/components/user/DeleteModal.vue @@ -0,0 +1,98 @@ + + + diff --git a/resources/js/components/user/Table.vue b/resources/js/components/user/Table.vue index 9f3853dc..67ea695c 100644 --- a/resources/js/components/user/Table.vue +++ b/resources/js/components/user/Table.vue @@ -52,16 +52,16 @@ -