diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index ab4fa18..7517239 100755 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -484,7 +484,7 @@ public function getGroupsList(Request $request) // Format each group record $siteDir = env('VITE_SITE_DIR'); foreach ($groups as $group) { - $preLoadDefaultServerId = SaGroupsServers::where('group_id', $group->id)->first()->server_id; + $preLoadDefaultServerId = SaGroupsServers::where('group_id', $group->id)?->first()?->server_id; $formattedData[] = [ "id" => $group->id, "name" => "{$group->name}", @@ -508,39 +508,29 @@ public function groups() return view('admin.groups.list'); } - public function editGroup(Request $request, $group_id, $server_id) { - $groupServer = SaGroupsServers::with('groupsFlags') - ->where('server_id', $server_id) - ->where('group_id', $group_id) + public function editGroup(Request $request, $group_id) { + $groupFlags = SaGroupsFlags::where('group_id', $group_id) ->get(); - if ($groupServer->isEmpty()) { - return redirect()->route('groups.list')->with('error', 'Group does not exist for the selected server!. Add Group to the server!'); - } - $groupPermissions = $groupServer->pluck('groupsFlags.*.flag')->flatten()->toArray(); + $groupPermissions = $groupFlags->pluck('flag')->toArray(); $groupDetails = SaGroups::where('id', $group_id)->first(); $permissions = Permission::all(); - $servers = SaServer::all(); - return view('admin.groups.edit', compact('servers', 'permissions', 'groupDetails', 'groupPermissions', 'server_id')); + return view('admin.groups.edit', compact('permissions', 'groupDetails', 'groupPermissions')); } public function updateGroup(Request $request, $groupId) { $validated = $request->validate([ 'permissions' => 'required|array', 'permissions.*' => 'exists:permissions,permission', - 'server_id' => 'exists:sa_servers,id', 'immunity' => 'required', 'name' => 'required', ]); $submittedPermissions = $validated['permissions']; - $groupServer = SaGroupsServers::with('groupsFlags') - ->where('server_id',$validated['server_id']) - ->where('group_id', $groupId) + $groupFlags = SaGroupsFlags::where('group_id', $groupId) ->get(); // Fetch current permissions from the database - $currentPermissions = $groupServer->pluck('groupsFlags.*.flag')->flatten()->toArray(); - // Determine permissions to add and delete + $currentPermissions = $groupFlags->pluck('flag')->toArray(); // Determine permissions to add and delete $permissionsToAdd = array_diff($submittedPermissions, $currentPermissions); $permissionsToDelete = array_diff($currentPermissions, $submittedPermissions); @@ -571,6 +561,7 @@ public function showGroupDeleteForm(Request $request, $groupId) { public function deleteGroup(Request $request, $groupId) { $validated = $request->validate([ + 'server_ids' => 'required|array', 'server_ids.*' => [ 'required', function ($attribute, $value, $fail) { @@ -590,6 +581,7 @@ function ($attribute, $value, $fail) { SaAdmin::where('group_id', $groupId) ->whereIn('server_id', $validated['server_ids'])->delete(); + } return redirect()->route('groups.list')->with('success', 'Group deleted successfully.'); diff --git a/resources/views/admin/admins/delete.blade.php b/resources/views/admin/admins/delete.blade.php index fafee3c..90fd8c7 100755 --- a/resources/views/admin/admins/delete.blade.php +++ b/resources/views/admin/admins/delete.blade.php @@ -1,6 +1,9 @@ @extends('layouts.app') @section('content') + @if (session('error')) + + @endif
diff --git a/resources/views/admin/groups/delete.blade.php b/resources/views/admin/groups/delete.blade.php index ee49e23..81605c9 100644 --- a/resources/views/admin/groups/delete.blade.php +++ b/resources/views/admin/groups/delete.blade.php @@ -1,6 +1,15 @@ @extends('layouts.app') @section('content') + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif
@@ -10,6 +19,9 @@
@csrf +
+ Note: If you want to delete a group, select all servers. Selecting specific servers will only remove the group from those servers but will not delete the group itself. +
diff --git a/resources/views/admin/groups/edit.blade.php b/resources/views/admin/groups/edit.blade.php index e49952f..b26998e 100644 --- a/resources/views/admin/groups/edit.blade.php +++ b/resources/views/admin/groups/edit.blade.php @@ -30,21 +30,6 @@
- -
- - - -


diff --git a/routes/web.php b/routes/web.php index d53ef34..0036912 100755 --- a/routes/web.php +++ b/routes/web.php @@ -56,7 +56,7 @@ Route::prefix('group')->group(function () { Route::get('/create', [AdminController::class, 'createGroup'])->name('group.create')->middleware('superadmin'); Route::post('/store', [AdminController::class, 'storeGroup'])->name('group.store')->middleware('superadmin'); - Route::get('/edit/{group_id}/{server_id}', [AdminController::class, 'editGroup'])->name('group.edit')->middleware('superadmin'); + Route::get('/edit/{group_id}', [AdminController::class, 'editGroup'])->name('group.edit')->middleware('superadmin'); Route::put('/update/{id}', [AdminController::class, 'updateGroup'])->name('group.update')->middleware('superadmin'); Route::get('/delete/{id}', [AdminController::class, 'showGroupDeleteForm'])->name('group.deleteForm')->middleware('superadmin'); Route::post('/delete/{id}', [AdminController::class, 'deleteGroup'])->name('group.delete')->middleware('superadmin');