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 @@
-
+
- {{ user.firstname }}
+ {{ userData.firstname }}
|
- {{ user.lastname }}
+ {{ userData.lastname }}
|
- {{ user.email }}
+ {{ userData.email }}
|
- {{ user.course.abbreviation }}
+ {{ userData.course.abbreviation }}
|
-
-
+
+
@@ -138,7 +141,7 @@
'whitespace-nowrap px-3 py-4 text-sm font-medium text-gray-900 dark:text-gray-100',
]"
>
- {{ user.avatarUrl ? "Ja" : "Nein" }}
+ {{ userData.avatarUrl ? "Ja" : "Nein" }}
|
- {{ user.firstname }}
- {{ user.lastname }}
+ {{ userData.firstname }}
+ {{ userData.lastname }}
bearbeiten
+
+
+
+ {{ userData.firstname }}
+ {{ userData.lastname }}
+
+ löschen
+
+
|
@@ -180,6 +203,13 @@
@close="clearUserToEdit"
@submit="submitUserEdit"
/>
+
+
@@ -206,6 +236,7 @@ const props = defineProps({
});
const userToEdit = ref(null);
+const userToDelete = ref(null);
const clearUserToEdit = () => {
userToEdit.value = null;
@@ -216,4 +247,14 @@ const selectUserToEdit = async (user: Models.User) => {
const submitUserEdit = async () => {
clearUserToEdit();
};
+
+const clearUserToDelete = () => {
+ userToDelete.value = null;
+};
+const selectUserToDelete = async (user: Models.User) => {
+ userToDelete.value = user;
+};
+const submitUserDelete = async () => {
+ clearUserToDelete();
+};
diff --git a/resources/js/types/components.d.ts b/resources/js/types/components.d.ts
index 2cbebf33..1354f1f3 100644
--- a/resources/js/types/components.d.ts
+++ b/resources/js/types/components.d.ts
@@ -16,6 +16,7 @@ declare module "vue" {
CardContainer: typeof import("./../components/card/Container.vue")["default"];
CardLayout: typeof import("./../layouts/CardLayout.vue")["default"];
ColorModeButton: typeof import("./../components/color/mode/Button.vue")["default"];
+ copy: typeof import("./../components/user/EditModal copy.vue")["default"];
CourseBox: typeof import("./../components/course/Box.vue")["default"];
DashboardCardLayout: typeof import("./../layouts/DashboardCardLayout.vue")["default"];
DashboardLayout: typeof import("./../layouts/DashboardLayout.vue")["default"];
@@ -41,6 +42,7 @@ declare module "vue" {
UiMessage: typeof import("./../components/ui/Message.vue")["default"];
UiTimeString: typeof import("./../components/ui/TimeString.vue")["default"];
UserBox: typeof import("./../components/user/Box.vue")["default"];
+ UserDeleteModal: typeof import("./../components/user/DeleteModal.vue")["default"];
UserEditModal: typeof import("./../components/user/EditModal.vue")["default"];
UserTable: typeof import("./../components/user/Table.vue")["default"];
}
diff --git a/routes/web.php b/routes/web.php
index 6c4912bb..67d4d237 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -67,6 +67,10 @@
Route::get('/users', [DashboardAdminController::class, 'users'])->name('dashboard.admin.users');
Route::post('/user/{user}', [DashboardAdminController::class, 'editUser'])->name('dashboard.admin.editUser');
+ Route::group(['middleware' => ['can:delete users']], function () {
+ Route::delete('/user/{user}', [DashboardAdminController::class, 'deleteUser'])->name('dashboard.admin.deleteUser');
+ });
+
Route::get('/register', [DashboardAdminController::class, 'register'])->name('dashboard.admin.register');
Route::post('/register', [DashboardAdminController::class, 'registerUser'])->name('dashboard.admin.registerUser');
Route::post('/assign', [DashboardAdminController::class, 'assignUser'])->name('dashboard.admin.assignUser');