users menu listing
This commit is contained in:
@@ -27,7 +27,7 @@ final class Ticket extends Model
|
|||||||
|
|
||||||
protected $table = 'helpdesk_tickets';
|
protected $table = 'helpdesk_tickets';
|
||||||
|
|
||||||
protected $with = ['user'];
|
protected $with = ['user', 'agent'];
|
||||||
|
|
||||||
/** @var list<string> */
|
/** @var list<string> */
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ final class AutomationRuleService
|
|||||||
/** @param array<string, mixed> $context */
|
/** @param array<string, mixed> $context */
|
||||||
public function apply(Ticket $ticket, array $context = []): Ticket
|
public function apply(Ticket $ticket, array $context = []): Ticket
|
||||||
{
|
{
|
||||||
$sender = (string) ($context['sender'] ?? $ticket->owner?->email ?? '');
|
$sender = (string) ($context['sender'] ?? $ticket->user?->email ?? '');
|
||||||
$mailbox = (string) ($context['mailbox'] ?? '');
|
$mailbox = (string) ($context['mailbox'] ?? '');
|
||||||
|
|
||||||
AutomationRule::query()
|
AutomationRule::query()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ final class CannedResponseRenderer
|
|||||||
'{{ ticket.category }}' => (string) ($ticket->category?->name ?? ''),
|
'{{ ticket.category }}' => (string) ($ticket->category?->name ?? ''),
|
||||||
'{{ ticket.project }}' => (string) ($ticket->project?->title ?? ''),
|
'{{ ticket.project }}' => (string) ($ticket->project?->title ?? ''),
|
||||||
'{{ ticket.team }}' => (string) ($ticket->team?->name ?? ''),
|
'{{ ticket.team }}' => (string) ($ticket->team?->name ?? ''),
|
||||||
'{{ requester.name }}' => (string) ($ticket->owner?->name ?? ''),
|
'{{ requester.name }}' => (string) ($ticket->user?->name ?? ''),
|
||||||
'{{ agent.name }}' => (string) ($ticket->agent?->name ?? ''),
|
'{{ agent.name }}' => (string) ($ticket->agent?->name ?? ''),
|
||||||
'{{ actor.name }}' => (string) ($actor?->name ?? ''),
|
'{{ actor.name }}' => (string) ($actor?->name ?? ''),
|
||||||
'{{ ticket.url }}' => route('helpdesk.tickets.show', ['ticket' => $ticket->getKey()]),
|
'{{ ticket.url }}' => route('helpdesk.tickets.show', ['ticket' => $ticket->getKey()]),
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\UserManagement\Console;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
final class EnsureAdminCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'users:ensure-admin {user=1 : User ID to grant administrator access}';
|
||||||
|
|
||||||
|
protected $description = 'Ensure a user has Helpdesk administrator and agent access';
|
||||||
|
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$user = User::query()->find((int) $this->argument('user'));
|
||||||
|
|
||||||
|
if ($user === null) {
|
||||||
|
$this->error('User not found.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->forceFill([
|
||||||
|
'helpdesk_admin' => true,
|
||||||
|
'helpdesk_agent' => true,
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
$this->info("{$user->name} is now a Helpdesk administrator.");
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
! Schema::hasTable('users')
|
||||||
|
|| ! Schema::hasColumn('users', 'helpdesk_admin')
|
||||||
|
|| ! Schema::hasColumn('users', 'helpdesk_agent')
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DB::table('users')->where('helpdesk_admin', true)->exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userId = DB::table('users')->orderBy('id')->value('id');
|
||||||
|
|
||||||
|
if ($userId === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('users')->where('id', $userId)->update([
|
||||||
|
'helpdesk_admin' => true,
|
||||||
|
'helpdesk_agent' => true,
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Never silently remove administrator access.
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -14,14 +14,15 @@ final class EnsureUserManagementAdmin
|
|||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
$allowed = $user !== null && (
|
abort_unless(
|
||||||
(method_exists($user, 'isHelpdeskAdmin') && $user->isHelpdeskAdmin())
|
$user !== null
|
||||||
|| (method_exists($user, 'isAdmin') && $user->isAdmin())
|
&& (
|
||||||
|| (bool) ($user->helpdesk_admin ?? false)
|
(bool) ($user->helpdesk_admin ?? false)
|
||||||
|
|| (method_exists($user, 'isHelpdeskAdmin') && $user->isHelpdeskAdmin())
|
||||||
|
),
|
||||||
|
403
|
||||||
);
|
);
|
||||||
|
|
||||||
abort_unless($allowed, 403);
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Modules\UserManagement\Providers;
|
namespace Modules\UserManagement\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Modules\UserManagement\Console\EnsureAdminCommand;
|
||||||
|
|
||||||
final class UserManagementServiceProvider extends ServiceProvider
|
final class UserManagementServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -12,4 +13,15 @@ final class UserManagementServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->app->register(RouteServiceProvider::class);
|
$this->app->register(RouteServiceProvider::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
$this->loadMigrationsFrom(module_path('UserManagement', 'Database/Migrations'));
|
||||||
|
|
||||||
|
if ($this->app->runningInConsole()) {
|
||||||
|
$this->commands([
|
||||||
|
EnsureAdminCommand::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
<body class="hd-app-body">
|
<body class="hd-app-body">
|
||||||
@php
|
@php
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$isAdmin =
|
$isAdmin = $user !== null && (
|
||||||
(bool) ($user?->helpdesk_admin ?? false)
|
(bool) ($user->helpdesk_admin ?? false)
|
||||||
|| ($user && method_exists($user, 'isHelpdeskAdmin') && $user->isHelpdeskAdmin())
|
|| (method_exists($user, 'isHelpdeskAdmin') && $user->isHelpdeskAdmin())
|
||||||
|| ($user && method_exists($user, 'isAdmin') && $user->isAdmin());
|
);
|
||||||
$roleLabel = $isAdmin ? 'Administrator' : ((method_exists($user, 'isHelpdeskAgent') && $user->isHelpdeskAgent()) || (bool) ($user->helpdesk_agent ?? false) ? 'Agent' : 'User');
|
$roleLabel = $isAdmin ? 'Administrator' : ((method_exists($user, 'isHelpdeskAgent') && $user->isHelpdeskAgent()) || (bool) ($user->helpdesk_agent ?? false) ? 'Agent' : 'User');
|
||||||
@endphp
|
@endphp
|
||||||
<div class="hd-app-shell" data-hd-shell>
|
<div class="hd-app-shell" data-hd-shell>
|
||||||
|
|||||||
Reference in New Issue
Block a user