Skip to content

Commit

Permalink
Select all servers while adding admin
Browse files Browse the repository at this point in the history
  • Loading branch information
hobsRKM committed Apr 23, 2024
1 parent a159a50 commit 6a9a172
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/Helpers/PermissionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function hasUnBanPermission(int $serverId=null)
} elseif ($serverId && self::hasValidPermission($user, $serverId, '@css/unban')) {
// has permission on the server
$allowed = true;
} elseif ($user && !$serverId && $user->permissions()->whereIn('flag', ['@css/chat', '@css/unban'])->exists()) {
} elseif ($user && !$serverId && $user->permissions()->whereIn('flag', ['@css/root', '@css/unban'])->exists()) {
// Check perms exists for atleast one of the server - For UI Actions
$allowed = true;
}
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function store(StoreAdminRequest $request)
{
$validatedData = $request->validated();
try {
if(in_array('all', $validatedData['server_ids'])) {
$validatedData['server_ids'] = SaServer::all()->pluck('id')->toArray();
}
$adminAddedToServerCount = [];
foreach ($validatedData['server_ids'] as $server_id) {
foreach ($validatedData['permissions'] as $permissionId) {
Expand Down
11 changes: 10 additions & 1 deletion app/Http/Requests/StoreAdminRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;

class StoreAdminRequest extends FormRequest
{
Expand All @@ -20,7 +22,14 @@ public function rules()
'steam_id' => 'required|numeric|digits:17',
'player_name' => 'required',
'server_ids' => 'required|array',
'server_ids.*' => 'exists:sa_servers,id',
'server_ids.*' => [
'required',
function ($attribute, $value, $fail) {
if ($value !== 'all' && !DB::table('sa_servers')->where('id', $value)->exists()) {
$fail($attribute.' is invalid.');
}
},
],
'permissions' => 'required|array',
'permissions.*' => 'exists:permissions,id',
'ends' => 'required_without:permanent|date|after:today',
Expand Down
7 changes: 4 additions & 3 deletions resources/views/admin/admins/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
<div data-mdb-input-init class="form-outline mb-3">
<select multiple="multiple" class="form-select" id="server_id" name="server_ids[]" required>
<option value="">Select Server</option>
<option value="all">All Servers</option>
@foreach($servers as $server)
<option value="{{ $server->id }}">{{ $server->hostname }}</option>
@endforeach
</select>
<option value="{{ $server->id }}">{{ $server->hostname }}</option>
@endforeach
</select>
</div>
<hr/>
<div class="mb-3">
Expand Down

0 comments on commit 6a9a172

Please sign in to comment.