Ticket information | notify groups (#821)

This commit is contained in:
Dennis 2023-05-07 22:37:46 +02:00 committed by GitHub
commit 72fbd34a57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 11 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

@ -23,9 +23,10 @@ class TicketsController extends Controller
{
const READ_PERMISSION = 'user.ticket.read';
const WRITE_PERMISSION = 'user.ticket.write';
public function index(LocaleSettings $locale_settings)
public function index(LocaleSettings $locale_settings, TicketSettings $ticketSettings)
{
return view('ticket.index', [
'ticketsettings' => $ticketSettings,
'tickets' => Ticket::where('user_id', Auth::user()->id)->paginate(10),
'ticketcategories' => TicketCategory::all(),
'locale_datatables' => $locale_settings->datatables

View file

@ -7,6 +7,7 @@ use Spatie\LaravelSettings\Settings;
class TicketSettings extends Settings
{
public bool $enabled;
public ?string $information;
public static function group(): string
{
@ -21,6 +22,7 @@ class TicketSettings extends Settings
{
return [
'enabled' => 'nullable|boolean',
'information' => 'nullable|string',
];
}
@ -38,6 +40,11 @@ class TicketSettings extends Settings
'type' => 'boolean',
'description' => 'Enable or disable the ticket system.',
],
'information' => [
'label' => 'Ticket Information',
'type' => 'textarea',
'description' => 'Message shown on the right side when users create a new ticket.',
],
];
}
}

View file

@ -11,7 +11,6 @@ class CreateTicketSettings extends SettingsMigration
// Get the user-set configuration values from the old table.
$this->migrator->add('ticket.enabled', $table_exists ? $this->getOldValue('SETTINGS::TICKET:ENABLED') : 'all');
$this->migrator->add('ticket.notify', $table_exists ? $this->getOldValue('SETTINGS::TICKET:NOTIFY') : 'all');
}
public function down(): void

View file

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('ticket.information', "Can't start your server? Need an additional port? Do you have any other questions? Let us know by opening a ticket.");
}
};

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',

View file

@ -66,8 +66,7 @@
</div>
<div class="card-body">
<p>{{__("Can't start your server? Need an additional port? Do you have any other questions? Let us know by
opening a ticket.")}}</p>
<p>{!! $ticketsettings->information !!}</p>
</div>
</div>