notify groups (check validation needed)

This commit is contained in:
1day2die 2023-05-07 22:36:50 +02:00
parent b07238cbed
commit 3d8a1cf53f
2 changed files with 25 additions and 7 deletions

View file

@ -272,7 +272,9 @@ class UserController extends Controller
{
$this->checkPermission(self::NOTIFY_PERMISSION);
return view('admin.users.notifications');
$roles = Role::all();
return view('admin.users.notifications')->with(["roles" => $roles]);
}
/**
@ -288,12 +290,14 @@ class UserController extends Controller
{
$this->checkPermission(self::NOTIFY_PERMISSION);
//TODO: reimplement the required validation on all,users and roles . didnt work -- required_without:users,roles
$data = $request->validate([
'via' => 'required|min:1|array',
'via.*' => 'required|string|in:mail,database',
'all' => 'required_without:users|boolean',
'users' => 'required_without:all|min:1|array',
'users.*' => 'exists:users,id',
'all' => 'boolean',
'users' => 'min:1|array',
'roles' => 'min:1|array',
'roles.*' => 'required_without:all,users|exists:roles,id',
'title' => 'required|string|min:1',
'content' => 'required|string|min:1',
]);
@ -312,7 +316,13 @@ class UserController extends Controller
->line(new HtmlString($data['content']));
}
$all = $data['all'] ?? false;
$users = $all ? User::all() : User::whereIn('id', $data['users'])->get();
if(!$data["roles"]){
$users = $all ? User::all() : User::whereIn('id', $data['users'])->get();
} else{
$users = User::role($data["roles"])->get();
}
try {
Notification::send($users, new DynamicNotification($data['via'], $database, $mail));
} catch (Exception $e) {

View file

@ -33,13 +33,20 @@
@method('POST')
<div class="form-group">
<label>{{__('Users')}}</label><br>
<input id="all" name="all"
type="checkbox" value="1"
onchange="toggleClass('users-form', 'd-none')">
<label for="all">{{__('All')}}</label>
<label for="all">{{__('All')}}</label><br>
<div id="users-form">
<label>{{__('Users')}}</label><br>
<select id="users" name="users[]" class="form-control" multiple></select>
<label>{{__('Roles')}}</label><br>
<select id="roles" name="roles[]" onchange="toggleClass('users', 'd-none')" class="form-control" multiple>
@foreach($roles as $role)
<option value="{{$role->id}}">{{$role->name}}</option>
@endforeach
</select>
</div>
@error('all')
<div class="invalid-feedback d-block">
@ -126,6 +133,7 @@
})
function initUserSelect(data) {
$('#roles').select2();
$('#users').select2({
ajax: {
url: '/admin/users.json',