Enable admin setting user for a system

This commit is contained in:
Deon George 2023-12-19 11:16:08 +11:00
parent ac2ee7df0c
commit 90206f2bb5
5 changed files with 320 additions and 242 deletions

View File

@ -16,7 +16,7 @@ use Illuminate\Support\ViewErrorBag;
use App\Classes\FTN\Message; use App\Classes\FTN\Message;
use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister}; use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister};
use App\Jobs\AddressPoll; use App\Jobs\AddressPoll;
use App\Models\{Address,Echoarea,Filearea,Netmail,Setup,System,SystemZone,Zone}; use App\Models\{Address,Echoarea,Filearea,Netmail,Setup,System,Zone};
use App\Notifications\Netmails\AddressLink; use App\Notifications\Netmails\AddressLink;
use App\Rules\{FidoInteger,TwoByteInteger}; use App\Rules\{FidoInteger,TwoByteInteger};
@ -49,6 +49,10 @@ class SystemController extends Controller
->transform(function($item) { $item['active'] = Arr::get($item,'active',FALSE); return $item; }); ->transform(function($item) { $item['active'] = Arr::get($item,'active',FALSE); return $item; });
$o->mailers()->sync($mailers); $o->mailers()->sync($mailers);
if ($request->post('users') && array_filter($request->post('users'),function($item) { return $item; }))
$o->users()->sync($request->post('users'));
else
$o->users()->detach();
return redirect()->to('system'); return redirect()->to('system');
} }

View File

@ -78,6 +78,7 @@ class SystemRegister extends FormRequest
'mailer_details.*.port' => 'nullable|digits_between:2,5', 'mailer_details.*.port' => 'nullable|digits_between:2,5',
'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so->exists ? $so->id : 0), 'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so->exists ? $so->id : 0),
'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))], 'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))],
'users' => 'nullable|array|min:1|max:2',
] : [], ] : [],
$so->exists ? [ $so->exists ? [
'active' => 'required|boolean', 'active' => 'required|boolean',

View File

@ -1,5 +1,37 @@
<!-- $o = System::class --> <!-- $o = System::class -->
<div class="row pt-0">
<div class="col-12">
<h4 class="mb-0 pb-2">System Users</h4>
<div class="row pt-0">
<!-- Users -->
<div class="col-4">
<label for="users" class="form-label">Owners</label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="bi bi-people-fill"></i></span>
<select style="width: 80%;" class="form-select @error('users') is-invalid @enderror" id="users" name="users[]">
<option value="">&nbsp;</option>
@foreach (\App\Models\User::orderBy('name')->active()->get() as $uo)
<option value="{{ $uo->id }}" @if(in_array($uo->id,old('users',$o->users->pluck('id')->toArray())))selected @endif>{{ $uo->name }} <small>({{ $uo->email }})</small></option>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@error('users')
{{ $message }}
@enderror
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-12">
<h4 class="mb-0 pb-2">System Details</h4>
<div class="row pt-0">
<!-- Name --> <!-- Name -->
<div class="col-4"> <div class="col-4">
<label for="name" class="form-label">BBS Name</label> <label for="name" class="form-label">BBS Name</label>
@ -47,9 +79,9 @@
</div> </div>
@endcan @endcan
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- Sysop --> <!-- Sysop -->
<div class="col-4"> <div class="col-4">
<label for="sysop" class="form-label">Sysop</label> <label for="sysop" class="form-label">Sysop</label>
@ -97,9 +129,9 @@
</div> </div>
@endcan @endcan
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- Address --> <!-- Address -->
<div class="col-5"> <div class="col-5">
<label for="address" class="form-label">Internet Address</label> <label for="address" class="form-label">Internet Address</label>
@ -151,6 +183,8 @@
</div> </div>
@endcan @endcan
</div> </div>
</div>
</div>
</div> </div>
<div class="row"> <div class="row">
@ -390,9 +424,19 @@
</div> </div>
</div> </div>
@section('page-css')
@css('select2')
@append
@section('page-scripts') @section('page-scripts')
@js('select2')
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#users').select2({
@cannot('admin')disabled: true @endcannot
/*multiple: true*/
});
$('#poll_normal').on('click',function() { $('#poll_normal').on('click',function() {
$('#heartbeat_option').removeClass('d-none'); $('#heartbeat_option').removeClass('d-none');
}) })

View File

@ -11,6 +11,8 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="greyframe titledbox shadow0xb0"> <div class="greyframe titledbox shadow0xb0">
<div class="row pt-0">
<div class="col-12">
<h2 class="cap">@if($o->exists) Update @else Add @endif User</h2> <h2 class="cap">@if($o->exists) Update @else Add @endif User</h2>
<div class="row"> <div class="row">
@ -128,6 +130,31 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div class="row pt-5">
<div class="col-12">
<h3>Systems</h3>
<table class="table monotable">
<thead>
<tr>
<th>System</th>
</tr>
</thead>
<tbody>
@foreach ($o->systems as $o)
<tr>
<th><a href="{{ url('system/addedit',[$o->id]) }}">{{ $o->name }}</a></th>
<th class="text-end">{!! $o->akas->pluck('ftn')->join('<br>') !!}</th>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</form> </form>
@endsection @endsection

View File

@ -6,12 +6,12 @@
@section('content') @section('content')
<div class="row"> <div class="row">
<div class="row"> <div class="row">
<div class="col-9"> <div class="col-12">
<h2>System Users</h2> <h2>System Users</h2>
</div> </div>
</div> </div>
<div class="col-9"> <div class="col-12">
<p>This system is aware of the following users @can('admin',(new \App\Models\User))(you can <a href="{{ url('user/addedit') }}">add</a> more)@endcan:</p> <p>This system is aware of the following users @can('admin',(new \App\Models\User))(you can <a href="{{ url('user/addedit') }}">add</a> more)@endcan:</p>
<table class="table monotable" id="user"> <table class="table monotable" id="user">
<thead> <thead>
@ -22,11 +22,12 @@
<th>Active</th> <th>Active</th>
<th>Verified</th> <th>Verified</th>
<th>Last On</th> <th>Last On</th>
<th class="text-end">Systems</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (\App\Models\User::orderBy('email')->cursor() as $oo) @foreach (\App\Models\User::orderBy('email')->with(['systems'])->get() as $oo)
<tr class="{{ $oo->admin ? 'admin' : '' }}"> <tr class="{{ $oo->admin ? 'admin' : '' }}">
<td><a href="{{ url('user/addedit',[$oo->id]) }}">{{ $oo->id }}</a> @if($user->admin && ($user->id !== $oo->id))<span class="float-end"><a href="{{ url('admin/switch/start',[$oo->id]) }}"><i class="bi bi-person-bounding-box"></i></a></span>@endif</td> <td><a href="{{ url('user/addedit',[$oo->id]) }}">{{ $oo->id }}</a> @if($user->admin && ($user->id !== $oo->id))<span class="float-end"><a href="{{ url('admin/switch/start',[$oo->id]) }}"><i class="bi bi-person-bounding-box"></i></a></span>@endif</td>
<td>{{ $oo->email }}</td> <td>{{ $oo->email }}</td>
@ -34,6 +35,7 @@
<td>{{ $oo->active ? 'YES' : 'NO' }}</td> <td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->email_verified_at ? $oo->email_verified_at->format('Y-m-d') : '-' }}</td> <td>{{ $oo->email_verified_at ? $oo->email_verified_at->format('Y-m-d') : '-' }}</td>
<td>{{ $oo->last_on ? $oo->last_on->toDateTimeString() : 'Unknown' }}</td> <td>{{ $oo->last_on ? $oo->last_on->toDateTimeString() : 'Unknown' }}</td>
<td class="text-end">{{ number_format($oo->systems->count()) }}</td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>