Compare commits
4 Commits
v1.2.0
...
03c6ec7cae
| Author | SHA1 | Date | |
|---|---|---|---|
| 03c6ec7cae | |||
| 7a8cf2037c | |||
| 1df697afce | |||
| 313e01ad24 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/mysql/
|
/mysql/
|
||||||
.env
|
.env
|
||||||
compose.yaml
|
compose.yaml
|
||||||
|
scripts/hesk-import/.env
|
||||||
330
ARCHITECTURE.md
330
ARCHITECTURE.md
@@ -113,6 +113,29 @@ typed against `ModelNotFoundException` itself would never match) that
|
|||||||
redirects to `operator.queue`/`client.dashboard` instead, for any
|
redirects to `operator.queue`/`client.dashboard` instead, for any
|
||||||
authenticated request under `operator/*`/`client/*`.
|
authenticated request under `operator/*`/`client/*`.
|
||||||
|
|
||||||
|
That global handler only ever sees a full HTTP request (a page load/reload),
|
||||||
|
not Livewire's own AJAX update endpoint (`/livewire/update`, which doesn't
|
||||||
|
match the `operator/*`/`client/*` path check) — so it doesn't cover an
|
||||||
|
operator who already has a ticket open when it's deleted, or whose team gets
|
||||||
|
reassigned (by anyone, including via their own action — see "Teams" in
|
||||||
|
[README.md](README.md)) to one outside their visible scope
|
||||||
|
(`Ticket::isVisibleToOperator()`) mid-session. `Operator\TicketShow` handles
|
||||||
|
that case itself: a Livewire component's typed public model property
|
||||||
|
(`public Ticket $ticket`) is re-fetched by id on every subsequent request via
|
||||||
|
`firstOrFail()` (`Livewire\Features\SupportModels\ModelSynth::hydrate()`),
|
||||||
|
which throws `ModelNotFoundException` *before* any of the component's own
|
||||||
|
method code runs if the row is gone — too early for an ordinary try/catch
|
||||||
|
inside an action method to ever catch. The component instead defines
|
||||||
|
Livewire's `exception($e, $stopPropagation)` lifecycle hook (called for any
|
||||||
|
exception raised anywhere in the component's request lifecycle, hydration
|
||||||
|
included) to catch that case and redirect. The narrower case — ticket still
|
||||||
|
exists but is no longer visible, e.g. after a team reassignment — doesn't
|
||||||
|
throw at all, so it's caught separately: `refreshOrRedirectAway()` re-checks
|
||||||
|
`isVisibleToOperator()` after every live-update refresh
|
||||||
|
(`onQueueChanged()`/`refreshTicketData()`) and after the operator's own
|
||||||
|
`setTeam()` call, redirecting immediately rather than leaving them on a
|
||||||
|
ticket they can no longer legitimately keep viewing.
|
||||||
|
|
||||||
## Roles & permissions
|
## Roles & permissions
|
||||||
|
|
||||||
`$user->roles` reads/writes as a plain array (`['client', 'operator']`), but
|
`$user->roles` reads/writes as a plain array (`['client', 'operator']`), but
|
||||||
@@ -144,6 +167,16 @@ the account used for first login after a fresh install (see
|
|||||||
`SyncUserFieldsFromLdap` keeps `UserFieldValue` rows in sync with directory
|
`SyncUserFieldsFromLdap` keeps `UserFieldValue` rows in sync with directory
|
||||||
attributes.
|
attributes.
|
||||||
|
|
||||||
|
`app/Ldap/` has two directory-schema models — `LldapUser` (LLDAP/OpenLDAP,
|
||||||
|
the default) and `AdUser` (Active Directory, `LdapRecord\Models\ActiveDirectory\User`
|
||||||
|
under the hood). `Settings::ldapUserModelClass()` picks between them based on
|
||||||
|
the `ldap_directory_type` setting, and `AppServiceProvider::applyLdapSettingsOverride()`
|
||||||
|
wires the chosen class into `config('auth.providers.users.model')` on every
|
||||||
|
request — same live-override mechanism as the connection host/base DN below.
|
||||||
|
`LdapUserProvisioner` (used for sync + guest auto-provisioning) resolves the
|
||||||
|
same setting at call time rather than caching the class, so switching
|
||||||
|
directory type takes effect without a redeploy.
|
||||||
|
|
||||||
## Settings override ("live config")
|
## Settings override ("live config")
|
||||||
|
|
||||||
`App\Support\Settings` (`app/Support/Settings.php`) is a cached key/value reader
|
`App\Support\Settings` (`app/Support/Settings.php`) is a cached key/value reader
|
||||||
@@ -252,9 +285,19 @@ if "nothing updates live" ever comes back:
|
|||||||
|
|
||||||
As a defense against a dropped websocket connection (backgrounded tab,
|
As a defense against a dropped websocket connection (backgrounded tab,
|
||||||
network blip), the operator queue and both ticket-detail views also poll
|
network blip), the operator queue and both ticket-detail views also poll
|
||||||
themselves every 30–60 seconds via a small Alpine countdown calling
|
themselves via a small Alpine countdown calling `$wire.refreshQueue()` /
|
||||||
`$wire.refreshQueue()` / `$wire.refreshTicketData()` — broadcasting is
|
`$wire.refreshTicketData()` — broadcasting is best-effort, not the only way
|
||||||
best-effort, not the only way these views ever update.
|
these views ever update. The countdown badge is also clickable
|
||||||
|
(`x-on:click="remaining = total; $wire.refresh...()"` on the same element
|
||||||
|
the `x-init="setInterval(...)"` already lives on) to fetch immediately and
|
||||||
|
reset the countdown, rather than only ever firing on its own schedule. Its
|
||||||
|
interval — like the notification bell's `wire:poll` and the 4 scheduled
|
||||||
|
commands below — reads from `Settings` (`refresh_queue_seconds`/
|
||||||
|
`refresh_ticket_view_seconds`/`refresh_notifications_seconds`, admin-editable
|
||||||
|
in Konfiguracja) rather than a hardcoded number: `wire:poll.{{ $seconds }}s`
|
||||||
|
and Alpine's `x-data="{ remaining: {{ $seconds }}, ... }"` both just
|
||||||
|
interpolate to plain text in the rendered HTML, so a `Settings`-sourced value
|
||||||
|
works exactly like a literal one would.
|
||||||
|
|
||||||
A third private channel, **`App.Models.User.{id}`** (Laravel's default
|
A third private channel, **`App.Models.User.{id}`** (Laravel's default
|
||||||
per-notifiable convention, kept verbatim rather than a shorter alias),
|
per-notifiable convention, kept verbatim rather than a shorter alias),
|
||||||
@@ -274,8 +317,9 @@ fires while the tab is open, same limitation as the other Echo listeners here.
|
|||||||
|
|
||||||
`SlaRule` holds per-priority response/resolution targets in minutes. The
|
`SlaRule` holds per-priority response/resolution targets in minutes. The
|
||||||
scheduled command `tickets:check-sla-breaches` (registered in
|
scheduled command `tickets:check-sla-breaches` (registered in
|
||||||
`routes/console.php`, run every 15 minutes via `schedule:run`) flags overdue
|
`routes/console.php`, default every 15 minutes, interval admin-configurable —
|
||||||
tickets and can notify the assigned operator — see [install.md](install.md) for
|
see "Configurable scheduled-command intervals" below) flags overdue tickets
|
||||||
|
and can notify the assigned operator — see [install.md](install.md) for
|
||||||
why this requires an external cron entry (the Docker image ships no
|
why this requires an external cron entry (the Docker image ships no
|
||||||
cron/supervisor of its own).
|
cron/supervisor of its own).
|
||||||
|
|
||||||
@@ -285,8 +329,9 @@ cron/supervisor of its own).
|
|||||||
`scope_subcategory_id`/`scope_team_id`, `action_type` + `action_value`) lets an
|
`scope_subcategory_id`/`scope_team_id`, `action_type` + `action_value`) lets an
|
||||||
admin configure "if a ticket has been silent for N minutes, change its
|
admin configure "if a ticket has been silent for N minutes, change its
|
||||||
priority/status/team/assignee" without code — Admin > Automatyzacja SLA. The
|
priority/status/team/assignee" without code — Admin > Automatyzacja SLA. The
|
||||||
scheduled command `automation:run-rules` (also every 15 minutes) evaluates
|
scheduled command `automation:run-rules` (default also every 15 minutes,
|
||||||
every enabled rule against `Ticket.last_customer_activity_at` (falling back to
|
independently configurable) evaluates every enabled rule against
|
||||||
|
`Ticket.last_customer_activity_at` (falling back to
|
||||||
`created_at` if never set — mirrors how `resolutionDeadline()` treats a
|
`created_at` if never set — mirrors how `resolutionDeadline()` treats a
|
||||||
missing `SlaRule` as "no SLA" rather than backfilling one), and applies a
|
missing `SlaRule` as "no SLA" rather than backfilling one), and applies a
|
||||||
match through the same `TicketService` setters a manual operator action would
|
match through the same `TicketService` setters a manual operator action would
|
||||||
@@ -301,6 +346,29 @@ that closes the ticket doesn't block earlier-ordered rules already applied
|
|||||||
this run, but a later rule's own query naturally excludes an already-closed
|
this run, but a later rule's own query naturally excludes an already-closed
|
||||||
ticket.
|
ticket.
|
||||||
|
|
||||||
|
## Configurable scheduled-command intervals
|
||||||
|
|
||||||
|
All 4 scheduled commands (`tickets:check-sla-breaches`, `automation:run-rules`,
|
||||||
|
`emails:fetch-imap`, `ai:run-ticket-automation`) have an admin-configurable
|
||||||
|
interval (Admin > Konfiguracja — `schedule_sla_check_minutes`/
|
||||||
|
`schedule_automation_rules_minutes`/`schedule_imap_fetch_minutes`/
|
||||||
|
`schedule_ai_automation_minutes`), defaulting to their previous hardcoded
|
||||||
|
values (15/15/5/5 minutes). `routes/console.php` registers all 4 as
|
||||||
|
`->everyMinute()->when(fn () => Settings::dueEveryMinutes($key, $default))`
|
||||||
|
rather than an eagerly-built `->cron('*/N * * * *')` string — this is a
|
||||||
|
deliberate choice, not just a style preference: `routes/console.php` is
|
||||||
|
`require`'d on **every** artisan boot (`migrate`, `tinker`, `php artisan
|
||||||
|
test`, not just `schedule:run`, since it's wired in via `bootstrap/app.php`'s
|
||||||
|
`commands:` key), so anything at its *top level* that queries the database
|
||||||
|
would run before a fresh/test database necessarily has the `settings` table
|
||||||
|
yet — an early version of this feature that built the cron string eagerly at
|
||||||
|
the top level broke exactly this way. A closure passed to `->when()` is only
|
||||||
|
ever evaluated later, when `schedule:run` actually processes due events, so
|
||||||
|
`Settings::dueEveryMinutes()` never runs at boot. One visible side effect:
|
||||||
|
`php artisan schedule:list` shows `* * * * *` for all four regardless of
|
||||||
|
their actual configured interval, since the real interval only exists inside
|
||||||
|
the closure — expected, not a bug.
|
||||||
|
|
||||||
## IMAP e-mail intake
|
## IMAP e-mail intake
|
||||||
|
|
||||||
Optional, off by default (`ImapMailbox.enabled` per row — there is no single
|
Optional, off by default (`ImapMailbox.enabled` per row — there is no single
|
||||||
@@ -366,10 +434,10 @@ singleton). Split across three layers, mirroring the plan that shipped it:
|
|||||||
the ticket number; ticket view: per-message in the thread, plus a tag next
|
the ticket number; ticket view: per-message in the thread, plus a tag next
|
||||||
to the ticket number in the header).
|
to the ticket number in the header).
|
||||||
- **`emails:fetch-imap`** (`app/Console/Commands/FetchImapEmails.php`),
|
- **`emails:fetch-imap`** (`app/Console/Commands/FetchImapEmails.php`),
|
||||||
registered in `routes/console.php` as
|
registered in `routes/console.php` with `->withoutOverlapping()` (like
|
||||||
`Schedule::command('emails:fetch-imap')->everyFiveMinutes()->withoutOverlapping()`
|
`ai:run-ticket-automation`, unlike the SLA-check/automation-rules
|
||||||
— the one scheduled command in this app that opts into
|
commands — both make real outbound HTTP/IMAP calls per record, so a slow
|
||||||
`withoutOverlapping()` (SLA/automation don't), given IMAP I/O latency.
|
run risks overlapping the next tick in a way a pure-DB command doesn't).
|
||||||
Early-returns if no `ImapMailbox` is enabled. Also callable directly per
|
Early-returns if no `ImapMailbox` is enabled. Also callable directly per
|
||||||
mailbox from Admin > Poczta's "Pobierz teraz" button
|
mailbox from Admin > Poczta's "Pobierz teraz" button
|
||||||
(`ImapMailboxFetcher::fetchMailbox()`, bypassing the enabled-only
|
(`ImapMailboxFetcher::fetchMailbox()`, bypassing the enabled-only
|
||||||
@@ -392,26 +460,224 @@ tighter per-IP limit for unauthenticated requests
|
|||||||
generated by L5-Swagger at `/admin/api-docs`; there is no static Markdown API
|
generated by L5-Swagger at `/admin/api-docs`; there is no static Markdown API
|
||||||
reference in-repo.
|
reference in-repo.
|
||||||
|
|
||||||
|
## Generic AI integration
|
||||||
|
|
||||||
|
`App\Services\AiClient` is a small, feature-agnostic wrapper around an
|
||||||
|
OpenAI-compatible `/chat/completions` endpoint (`chat(array $messages, array
|
||||||
|
$options = []): ?string`) — works against Groq, OpenAI itself, or a
|
||||||
|
self-hosted Ollama instance, whichever `ai_base_url` points at.
|
||||||
|
`Settings`-driven like everything else here: `ai_enabled`, `ai_base_url`,
|
||||||
|
`ai_api_key` (encrypted, optional — deliberately not required by `enabled()`,
|
||||||
|
since a self-hosted Ollama instance typically has no auth at all),
|
||||||
|
`ai_model`, `ai_verify_ssl`. Every call is wrapped in `try/catch(\Throwable)`
|
||||||
|
and returns `null` on any failure (network, non-2xx, unexpected shape),
|
||||||
|
matching `BookStackClient`'s safe-default convention — callers are expected
|
||||||
|
to treat `null` as "AI unavailable" and degrade gracefully rather than throw.
|
||||||
|
Not tied to any single feature: `BookStackContentTagger`,
|
||||||
|
`TicketAiTriageService` and `TicketAiSummaryService` (below) are just its
|
||||||
|
first three consumers, each with their own prompt-building/parsing logic
|
||||||
|
layered on top rather than baked into the client itself.
|
||||||
|
|
||||||
## BookStack integration
|
## BookStack integration
|
||||||
|
|
||||||
`App\Services\BookStackClient` is the only outbound HTTP client in the
|
`App\Services\BookStackClient` is one of three outbound HTTP clients in the
|
||||||
codebase (Laravel's `Http` facade) — everything else here only ever receives
|
codebase (Laravel's `Http` facade), alongside `AiClient` above and
|
||||||
requests. It's entirely `Settings`-driven, no `.env`/`config()` involved:
|
`SnipeItClient` below — everything else here only ever receives requests.
|
||||||
`bookstack_enabled`, `bookstack_base_url`, `bookstack_token_id`/
|
It's entirely `Settings`-driven, no
|
||||||
`bookstack_token_secret` (encrypted, same as the LDAP/SMTP passwords),
|
`.env`/`config()` involved: `bookstack_enabled`, `bookstack_base_url`,
|
||||||
`bookstack_verify_ssl`, `bookstack_search_types` ('both'|'page'|'book'), and
|
`bookstack_token_id`/`bookstack_token_secret` (encrypted, same as the
|
||||||
**two independent** allow-lists of BookStack shelf IDs —
|
LDAP/SMTP passwords), `bookstack_verify_ssl`, and **two independent**
|
||||||
`bookstack_allowed_shelf_ids_creation` (ticket-wizard suggestions) and
|
allow-lists of BookStack shelf IDs — `bookstack_allowed_shelf_ids_creation`
|
||||||
`bookstack_allowed_shelf_ids_ticket_view` (the operator's sidebar on an
|
(ticket-wizard suggestions) and `bookstack_allowed_shelf_ids_ticket_view`
|
||||||
existing ticket) — `search()` takes a `$context` (`CONTEXT_CREATION` /
|
(the operator's sidebar on an existing ticket) — `search()` takes a
|
||||||
`CONTEXT_TICKET_VIEW`) that selects which one applies. **An empty allow-list
|
`$context` (`CONTEXT_CREATION` / `CONTEXT_TICKET_VIEW`) that selects which
|
||||||
means "search nothing"**, not "search everything" — nothing is ever
|
one applies. **An empty allow-list means "search nothing"**, not "search
|
||||||
suggested until an admin explicitly opts shelves in, independently per
|
everything" — nothing is ever suggested until an admin explicitly opts
|
||||||
context. BookStack has no "which shelf is this book on" field in its own
|
shelves in, independently per context. BookStack has no "which shelf is this
|
||||||
search response, so `BookStackClient` fetches `/api/shelves` +
|
book on" field in its own search response, so `BookStackClient` fetches
|
||||||
`/api/shelves/{id}` once (cached 30 min) into a shelf→book-ids map, used both
|
`/api/shelves` + `/api/shelves/{id}` once (cached 30 min) into a
|
||||||
to resolve the allow-list to book IDs and to build the "Shelf > Book"
|
shelf→book-ids map, used both to resolve the allow-list to book IDs and to
|
||||||
breadcrumb shown next to each suggestion. Per-query search results are cached
|
build the "Shelf > Book" breadcrumb shown next to each suggestion. Per-query
|
||||||
10 minutes, keyed on the query text **and** the active allow-list, so toggling
|
search results are cached 10 minutes, keyed on the query text **and** the
|
||||||
which shelves are allowed is reflected immediately instead of serving a
|
active allow-list, so toggling which shelves are allowed is reflected
|
||||||
pre-change result for up to 10 minutes.
|
immediately instead of serving a pre-change result for up to 10 minutes.
|
||||||
|
|
||||||
|
**Content-type filter and "search by" mode**: `bookstack_search_types` is a
|
||||||
|
comma-separated subset of `BookStackClient::SEARCH_TYPES` (`book`, `page`,
|
||||||
|
`chapter` — checkboxes in the admin UI, no more single-select "both/page/book"
|
||||||
|
dropdown), combined into BookStack's own `{type:a|b}` query syntax.
|
||||||
|
`bookstack_search_by` (`'name'`/`'tags'`/`'both'`) picks between matching the
|
||||||
|
title (`{in_name:...}`) and matching a tag whose name equals the query
|
||||||
|
(`[...]` — see BookStack content auto-tagging below for what actually writes
|
||||||
|
those tags); `'both'` runs one request per mode and merges/dedupes the
|
||||||
|
results, since BookStack's own query syntax ANDs filters together rather than
|
||||||
|
OR-ing them, so there's no single-request way to ask for "name OR tag".
|
||||||
|
`search()` takes both a `$query` (full "Category Subcategory" text, used for
|
||||||
|
the name-match variant) and an optional `$tagQuery` (bare subcategory name,
|
||||||
|
used for the tag-match variant) — the two differ because a tag is expected to
|
||||||
|
hold just the subcategory name, not the combined category+subcategory text.
|
||||||
|
|
||||||
|
## BookStack content auto-tagging
|
||||||
|
|
||||||
|
`App\Services\BookStackContentTagger` (used by the "Otaguj nową
|
||||||
|
treść"/"Otaguj wszystko ponownie" buttons on the BookStack admin card and by
|
||||||
|
`php artisan bookstack:tag-content`) is the reason the tag-based search mode
|
||||||
|
above has anything to match: it walks every book/chapter/page via
|
||||||
|
`BookStackClient::listAll()`/`detail()`, builds a Polish prompt naming the
|
||||||
|
current, live `Subcategory` list as the only allowed vocabulary, and asks
|
||||||
|
`AiClient` (above) to return which subcategory name(s) fit each item — a
|
||||||
|
single response per batch of 20 items, to keep prompt size/cost down.
|
||||||
|
Defensive JSON parsing (`parseAssignments()`) regex-extracts the first
|
||||||
|
`{...}` block before decoding, so a chatty or malformed response fails just
|
||||||
|
that one batch (`failed_batches` in the run summary) instead of crashing the
|
||||||
|
whole pass; every returned label is matched case-insensitively against the
|
||||||
|
real subcategory list before being trusted, so a hallucinated name is
|
||||||
|
silently dropped rather than written as a tag. Idempotent by default — an
|
||||||
|
item already carrying a tag matching a current subcategory name is skipped
|
||||||
|
unless `--force`/the "wszystko ponownie" button is used — and new tags are
|
||||||
|
merged into an item's existing tags (`updateTags()` PUTs the whole array;
|
||||||
|
BookStack has no "append a tag" endpoint), never overwriting unrelated ones.
|
||||||
|
|
||||||
|
## Snipe-IT asset inventory integration
|
||||||
|
|
||||||
|
`App\Services\SnipeItClient` talks to a Snipe-IT instance's REST API
|
||||||
|
(`/api/v1/...`, bearer token auth), entirely `Settings`-driven like
|
||||||
|
`BookStackClient`: `snipeit_enabled`, `snipeit_base_url`,
|
||||||
|
`snipeit_api_token` (encrypted), `snipeit_verify_ssl`. Every call is wrapped
|
||||||
|
in `try/catch(\Throwable)` returning `[]`/`null` on failure, same
|
||||||
|
safe-default convention as `AiClient`/`BookStackClient`. Three independently
|
||||||
|
toggleable settings gate what a client/operator can actually do with it —
|
||||||
|
none of them affect `SnipeItClient` itself, only which Livewire methods are
|
||||||
|
willing to call it:
|
||||||
|
|
||||||
|
- `snipeit_client_can_select_asset` (+ `snipeit_client_asset_subcategory_ids`,
|
||||||
|
a comma-separated allow-list) — gates `Client\NewTicket`'s asset picker.
|
||||||
|
Mirrors BookStack's shelf allow-lists: an **empty** subcategory list means
|
||||||
|
the picker never shows for any subcategory, not "every subcategory" —
|
||||||
|
`NewTicket::snipeitAssets()` checks both the toggle and that the currently
|
||||||
|
selected `subcategoryId` is in the list before calling
|
||||||
|
`assetsForEmail()`. `selectCategory()`/`selectSubcategory()` reset any
|
||||||
|
already-picked asset, so switching to an out-of-scope subcategory can't
|
||||||
|
silently carry a stale selection through to `submit()`.
|
||||||
|
- `snipeit_operator_view_requester_assets` — gates the same
|
||||||
|
`assetsForEmail()` lookup (by the ticket's own `email`, not the viewing
|
||||||
|
operator's) in `Operator\TicketShow`'s sidebar.
|
||||||
|
- `snipeit_operator_search_inventory` — gates `searchAssets()`, a free-text
|
||||||
|
`/hardware?search=` lookup across the *whole* inventory, for linking
|
||||||
|
equipment the requester doesn't personally own (e.g. a shared printer).
|
||||||
|
Rendered inline in the same sidebar card as the requester-assets list, not
|
||||||
|
a separate route/page.
|
||||||
|
|
||||||
|
`Operator\TicketShow::linkSnipeitAsset(int $id)` deliberately does **not**
|
||||||
|
fall back to a direct `SnipeItClient::asset($id)` lookup by id — it only
|
||||||
|
accepts an id present in `snipeitRequesterAssets`/`snipeitSearchResults`,
|
||||||
|
and each of those is itself empty unless its own setting above is on. This
|
||||||
|
means an operator can't link an arbitrary asset through a source the admin
|
||||||
|
has switched off for them, even by tampering with the Livewire request
|
||||||
|
payload. `unlinkSnipeitAsset()` has no such gate — clearing an existing link
|
||||||
|
is a correction, not a new way to browse Snipe-IT, so it stays available
|
||||||
|
even with both toggles off.
|
||||||
|
|
||||||
|
`SnipeItClient::assetsForEmail()` has to resolve an e-mail to a Snipe-IT user
|
||||||
|
first (`GET /users?search=`, no "assets by e-mail" endpoint exists), then
|
||||||
|
lists what's checked out to them (`GET /users/{id}/assets`) — cached 5
|
||||||
|
minutes per e-mail. `normalizeAsset()` is the single place that turns a raw
|
||||||
|
Snipe-IT hardware row into the shape every caller/view uses (`id`, `label`,
|
||||||
|
`serial`, `manufacturer`, `model`, `category`, `status`, `url`); `label`
|
||||||
|
joins whichever of asset tag / serial / "manufacturer model" are actually
|
||||||
|
present with `" - "`, falling back to `Zasób #{id}` if all three are blank —
|
||||||
|
Snipe-IT doesn't guarantee any of them are filled in. The `x-snipeit-assets`
|
||||||
|
Blade component renders that shape everywhere an asset list shows up
|
||||||
|
(client picker, requester sidebar, search results), with a `card` prop that
|
||||||
|
skips its own wrapping `<div class="card">` when embedded inside a
|
||||||
|
caller-provided one (the inventory-search box + its results share one card).
|
||||||
|
|
||||||
|
A linked ticket only stores `tickets.snipeit_asset_id` + a cached
|
||||||
|
`snipeit_asset_name` label (`TicketService::setSnipeitAsset()`, which also
|
||||||
|
writes a ticket-history line) — no other Snipe-IT fields are persisted.
|
||||||
|
Anywhere a linked asset's live detail is shown (the "Powiązany sprzęt" card),
|
||||||
|
it's re-fetched fresh via `SnipeItClient::asset($id)` rather than trusted
|
||||||
|
from the cache, so a status/reassignment change made directly in Snipe-IT is
|
||||||
|
reflected immediately; the cached label is only ever the fallback shown when
|
||||||
|
that live fetch fails (instance unreachable, or the asset was deleted
|
||||||
|
there).
|
||||||
|
|
||||||
|
## AI ticket triage & summary
|
||||||
|
|
||||||
|
Two independent services, both consuming `AiClient` above, both run from a
|
||||||
|
single scheduled command (`ai:run-ticket-automation`) — **never
|
||||||
|
synchronously at ticket creation**, so an LLM call never adds latency to a
|
||||||
|
live customer submitting a ticket:
|
||||||
|
|
||||||
|
- **`App\Services\TicketAiTriageService`** — a one-shot classification pass
|
||||||
|
per ticket, gated by 5 independent toggles
|
||||||
|
(`ai_triage_category_when_missing`/`subcategory_when_category_only`/
|
||||||
|
`recheck_categorized`/`fix_subject`/`set_priority`). `buildPrompt()` picks
|
||||||
|
one of 3 mutually-exclusive category scenarios from the ticket's *current*
|
||||||
|
state (no category/subcategory at all → assign both; category but no
|
||||||
|
subcategory → pick one within it; already has a subcategory → recheck and
|
||||||
|
possibly correct), independently of the subject/priority toggles. Every
|
||||||
|
scanned ticket gets `tickets.ai_triaged_at` stamped exactly once — this is
|
||||||
|
a one-shot pass, not a continuous recheck, and there's deliberately no
|
||||||
|
manual per-ticket re-trigger. Resolution is fail-closed the same way as the
|
||||||
|
BookStack tagger: every value the model returns is matched against the
|
||||||
|
real category/subcategory/priority vocabulary before being trusted: a
|
||||||
|
hallucinated or out-of-scope value (e.g. a subcategory claimed under the
|
||||||
|
wrong category) is silently dropped. Applying changes goes through a new
|
||||||
|
`TicketService::applyAiTriage(Ticket $ticket, array $changes, array
|
||||||
|
$historyLines)` — a single `$ticket->update()` for whichever
|
||||||
|
category/subcategory/subject/priority fields actually changed, one
|
||||||
|
specific history line per changed field plus a final "Automatyzacja:
|
||||||
|
klasyfikacja AI" attribution line (mirrors how `RunAutomationRules` logs
|
||||||
|
its own SLA-automation changes), and `notify()`/`TriggerEngine::handle()`
|
||||||
|
fired only for the fields that actually changed — deliberately not
|
||||||
|
composed from the existing `setPriority()`/`updateDetails()` setters, since
|
||||||
|
one AI pass can touch several fields at once and those would each write
|
||||||
|
their own generic line and fire notifications per-field instead of once
|
||||||
|
per pass.
|
||||||
|
- **`App\Services\TicketAiSummaryService`** — a summary + suggested next
|
||||||
|
action for **every** ticket (gated by a single `ai_summary_enabled`
|
||||||
|
toggle), cached on `tickets.ai_summary`/`ai_suggested_action`/
|
||||||
|
`ai_summary_generated_at` and shown only in the operator ticket view (a
|
||||||
|
"Podsumowanie AI" sidebar card, lazy-loaded via `wire:init` like the
|
||||||
|
BookStack suggestions card next to it). `run()` (the scheduled sweep)
|
||||||
|
regenerates whenever a ticket's latest message postdates its last summary
|
||||||
|
— deliberately compared against `ticket_messages.created_at`, not
|
||||||
|
`tickets.updated_at` (which also changes on unrelated actions like a
|
||||||
|
status/priority edit, which would otherwise trigger spurious
|
||||||
|
re-summarization on every tick for an active ticket). `buildTranscript()`
|
||||||
|
includes the ticket's own `body` (the opening description, outside
|
||||||
|
`ticket_messages`) ahead of the message transcript — needed because that
|
||||||
|
row would otherwise fall outside `TRANSCRIPT_MESSAGE_LIMIT` (30) on any
|
||||||
|
thread longer than that, silently dropping the original request from the
|
||||||
|
prompt. Unlike the triage service, a malformed AI response here leaves the
|
||||||
|
previous summary untouched rather than stamping "done" — the ticket stays
|
||||||
|
in the "stale" set and gets retried next run, since this feature is meant
|
||||||
|
to keep refreshing indefinitely, not run once. The system prompt is
|
||||||
|
admin-editable (`ai_summary_prompt` setting, plain textarea with a
|
||||||
|
"Resetuj" button restoring `Settings::default('ai_summary_prompt')` —
|
||||||
|
same pattern as the e-mail footer editor) and asks the model for a small
|
||||||
|
JSON object (`{"summary": "...", "suggested_action": "..."}`), parsed with
|
||||||
|
the same defensive regex-extract-then-decode approach used throughout
|
||||||
|
these AI services.
|
||||||
|
|
||||||
|
Besides `run()`'s scheduled sweep, two paths call `generateFor(Ticket
|
||||||
|
$ticket): bool` directly, bypassing the staleness check entirely:
|
||||||
|
`Operator\TicketShow::regenerateAiSummary()` (the sidebar's "Wygeneruj
|
||||||
|
teraz" button, a synchronous Livewire call — its `wire:loading` state covers
|
||||||
|
the wait, no need to dispatch anything in the background) and a
|
||||||
|
`TicketMessagePosted` listener registered in
|
||||||
|
`AppServiceProvider::regenerateAiSummaryOnNewMessage()`, active only when
|
||||||
|
both `ai_summary_enabled` and `ai_summary_regenerate_on_message` (off by
|
||||||
|
default) are on. That listener dispatches `App\Jobs\GenerateTicketAiSummaryJob`
|
||||||
|
via `::dispatchAfterResponse()` rather than the normal queue — deliberately
|
||||||
|
**not** `ShouldQueue`, since this deployment's queue worker is optional
|
||||||
|
infrastructure (see install.md) and anything pushed onto the `jobs` table
|
||||||
|
has no guarantee of ever being picked up; `dispatchAfterResponse()` instead
|
||||||
|
runs the job in-process right after the triggering HTTP/console response is
|
||||||
|
sent, needing no worker at all.
|
||||||
|
|
||||||
|
Its own interval (`ai:run-ticket-automation`) is admin-configurable the same
|
||||||
|
way the other 3 scheduled commands are — see "Configurable scheduled-command
|
||||||
|
intervals" above for the mechanism and a boot-time trap worth knowing about
|
||||||
|
before touching `routes/console.php` again.
|
||||||
|
|||||||
177
CHANGELOG.md
177
CHANGELOG.md
@@ -3,6 +3,183 @@
|
|||||||
All notable changes to this project are documented in this file. Format loosely
|
All notable changes to this project are documented in this file. Format loosely
|
||||||
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||||
|
|
||||||
|
## [1.4.0] - 2026-08-05
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Active Directory support for LDAP auth** (Admin > Integracje > "LDAP /
|
||||||
|
Active Directory") — a "Typ katalogu" dropdown switches between LLDAP/
|
||||||
|
OpenLDAP (the original, still the default) and Active Directory. AD uses a
|
||||||
|
different schema (no inetOrgPerson/posixAccount, a binary `objectGUID`
|
||||||
|
instead of `entryUUID`) and login attribute (`sAMAccountName`, not `uid`);
|
||||||
|
both are now auto-detected from the directory type instead of requiring
|
||||||
|
LLDAP's schema everywhere.
|
||||||
|
- **Operator client search** (Operator > Klienci) — a dedicated search page
|
||||||
|
(name or e-mail, any account, not just role=client) showing each match's
|
||||||
|
role badges and ticket count, linking straight into the queue pre-filtered
|
||||||
|
to that customer.
|
||||||
|
- **Paginated ticket lists** — the operator queue (50/page) and client
|
||||||
|
dashboard (20/page, current/archive tracked as separate pages so switching
|
||||||
|
tabs doesn't lose your place) no longer render every matching ticket at
|
||||||
|
once; sorting still happens over the full filtered result first.
|
||||||
|
- **Command-palette global search (Ctrl+K / Cmd+K)** — searches tickets from
|
||||||
|
anywhere in the app, scoped to what the searching user can actually see
|
||||||
|
(operators/admins search everything visible to them, clients only their
|
||||||
|
own). Supports Gmail-style operators — `od:` (reporter), `temat:`
|
||||||
|
(subject only), `treść:`/`tresc:` (message content only), `numer:`/`nr:`
|
||||||
|
(ticket number), combinable and AND'd together (`od:kacper
|
||||||
|
temat:drukarka`) — plain text with no operator still searches everything
|
||||||
|
as before. A "Szukaj" button in the operator/admin sidebars opens the same
|
||||||
|
dialog for anyone who doesn't know the shortcut.
|
||||||
|
- **Recently viewed tickets** (operator sidebar) — the last 6 tickets an
|
||||||
|
operator actually opened, most-recent first, re-bumped (not duplicated) on
|
||||||
|
a repeat visit.
|
||||||
|
- **Navbar redesign: panel switcher.** The old dropdown-only role switcher
|
||||||
|
(in the profile menu) and the plain "Panel Klienta/Operatora/Administratora"
|
||||||
|
text label are replaced by a single segmented control centered in the top
|
||||||
|
bar — Klient / Operator / Administrator — showing only the areas the
|
||||||
|
logged-in user actually holds, highlighting the current one, and sliding a
|
||||||
|
preview to whichever option is hovered before you click. Adapts to a
|
||||||
|
full-width row below the icons on narrow screens instead of overlapping
|
||||||
|
them.
|
||||||
|
- **Richer profile dropdown** — now shows the account's name, e-mail, and
|
||||||
|
role badges above the existing Powiadomienia/Wyloguj się links.
|
||||||
|
- **Per-page browser tab titles** — every page sets its own `<title>`
|
||||||
|
(e.g. the ticket subject, the selected queue, the active admin tab)
|
||||||
|
instead of every tab just showing the company name, always anchored with
|
||||||
|
the company name as a suffix so it's still identifiable once the browser
|
||||||
|
truncates a long tab title.
|
||||||
|
- **Hesk 3.x historical import** (`scripts/hesk-import/`) — a one-time,
|
||||||
|
read-only migration of tickets (with full reply/note history) from an old
|
||||||
|
Hesk helpdesk database, filtered by e-mail domain. Dry-run by default,
|
||||||
|
resumable, auto-maps categories (exact name match) and teams (when
|
||||||
|
unambiguous). See `scripts/hesk-import/README.md`.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Pagination controls ("« Poprzednia" / "Następna »") were showing the raw
|
||||||
|
translation keys `pagination.previous`/`pagination.next` instead of
|
||||||
|
actual text — the app's `APP_LOCALE=pl` had no matching `lang/pl/`
|
||||||
|
translation file and no English fallback (`APP_FALLBACK_LOCALE` is also
|
||||||
|
`pl`), so Laravel had nothing to resolve those strings to.
|
||||||
|
|
||||||
|
## [1.3.0] - 2026-07-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Snipe-IT asset inventory integration** (Admin > Integracje), optional and
|
||||||
|
off by default — connects to a Snipe-IT instance by API address + personal
|
||||||
|
API token (plus a "Nie sprawdzaj SSL" toggle for self-signed instances) and
|
||||||
|
surfaces three independently switchable capabilities:
|
||||||
|
- **Klient może wybrać sprzęt, którego dotyczy zgłoszenie** — while
|
||||||
|
creating a ticket, a client sees the devices checked out to them in
|
||||||
|
Snipe-IT (matched by e-mail) and can pick the one the ticket is about.
|
||||||
|
Scoped to admin-selected subcategories via a multi-select picker that
|
||||||
|
only appears once this is turned on — same "nothing shows until
|
||||||
|
explicitly opted in" convention as BookStack's shelf allow-lists.
|
||||||
|
- **Operator może zobaczyć sprzęt zgłaszającego w widoku zgłoszenia** — the
|
||||||
|
same per-requester asset list, shown in a sidebar card on the ticket
|
||||||
|
view, with a "Powiąż" button per item.
|
||||||
|
- **Zezwól operatorowi na przeszukiwanie całego inwentarza** — a search
|
||||||
|
box + button in the same sidebar (not a separate page) letting an
|
||||||
|
operator link any asset in Snipe-IT, not just the requester's own — for
|
||||||
|
shared equipment like printers.
|
||||||
|
- A linked asset shows live status/category/current assignment (fetched
|
||||||
|
fresh from Snipe-IT, not just the cached label) with an "Odepnij" button
|
||||||
|
that stays available to the operator regardless of the two toggles above
|
||||||
|
— clearing an existing link is a correction, not new Snipe-IT access.
|
||||||
|
Every asset is displayed as "numer środka - numer seryjny - producent
|
||||||
|
model" plus its Snipe-IT category, joining whichever of those pieces are
|
||||||
|
actually present.
|
||||||
|
- **AI summary: manual regenerate + regenerate on new message.** A
|
||||||
|
"Wygeneruj teraz" button now sits on the operator's "Podsumowanie AI" card
|
||||||
|
for an immediate, on-demand refresh. Separately, a new admin toggle
|
||||||
|
("Regeneruj podsumowanie od razu po każdej nowej wiadomości", off by
|
||||||
|
default) re-runs the summary right after any reply/note lands on a ticket,
|
||||||
|
instead of only ever picking it up on the next scheduled
|
||||||
|
`ai:run-ticket-automation` sweep. The transcript sent to the model now also
|
||||||
|
includes the ticket's own opening body text (previously only the reply
|
||||||
|
thread), fixing summaries silently missing the original request on long
|
||||||
|
tickets whose first message had scrolled out of the transcript window.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- The status dropdown in the operator ticket view could keep showing the
|
||||||
|
pre-change status after sending a reply via a status-changing quick action
|
||||||
|
(e.g. "Wyślij i oznacz jako rozwiązane") until the next full page load — a
|
||||||
|
Livewire/Alpine-morph quirk for `<select>` elements bound via `wire:change`
|
||||||
|
rather than `wire:model`. Fixed by keying the element to the status value
|
||||||
|
so the DOM node is force-replaced instead of morphed.
|
||||||
|
|
||||||
|
## [1.2.2] - 2026-07-24
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Subcategories can now be reordered within their category — up/down arrow
|
||||||
|
buttons next to "Edytuj" in Admin > Kategorie, right beside each
|
||||||
|
subcategory's edit/delete buttons. The order set there is used everywhere a
|
||||||
|
subcategory list is shown (subcategory pickers, admin listings, etc.), not
|
||||||
|
just the admin panel itself.
|
||||||
|
|
||||||
|
## [1.2.1] - 2026-07-24
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Generic AI integration** (Admin > Integracje > "Integracja AI"), optional
|
||||||
|
and off by default — an OpenAI-compatible `/chat/completions` client (works
|
||||||
|
against Groq, OpenAI itself, or a self-hosted Ollama instance) configured by
|
||||||
|
base URL, optional API key, model name, and an SSL-verification toggle for
|
||||||
|
self-signed local endpoints. Not tied to any one feature — it's the shared
|
||||||
|
foundation for the two AI-driven features below, and for anything else that
|
||||||
|
wants an LLM call in the future.
|
||||||
|
- **BookStack automatic content tagging (AI)** — a "Otaguj nową treść"/"Otaguj
|
||||||
|
wszystko ponownie (force)" button pair in the BookStack card, plus
|
||||||
|
`php artisan bookstack:tag-content` (`--dry-run`/`--force`/`--limit=N`) for
|
||||||
|
the command line. Uses the AI integration above to classify every
|
||||||
|
book/chapter/page's title+content against the current list of helpdesk
|
||||||
|
subcategories and tags matching ones by name — idempotent by default
|
||||||
|
(skips already-tagged content), so re-running after adding a few pages is
|
||||||
|
cheap. This is what gives the BookStack "search by tags" option below
|
||||||
|
something to actually match against.
|
||||||
|
- **BookStack search refinement** — "Przeszukuj" is now three independent
|
||||||
|
checkboxes (Książki / Strony / Rozdziały) instead of a single dropdown with
|
||||||
|
no chapter option, plus a new "Szukaj po" setting: słowa kluczowe w nazwie /
|
||||||
|
tagi / oba. Tag matching uses the bare subcategory name (e.g. "Drukarki i
|
||||||
|
skanery"), matching what the auto-tagging feature above writes.
|
||||||
|
- **AI-driven ticket triage + summary** (Admin > Integracje >
|
||||||
|
"Automatyzacja AI dla zgłoszeń", runs via a new scheduled
|
||||||
|
`ai:run-ticket-automation`) — five independent toggles: assign a
|
||||||
|
category/subcategory when a ticket has neither, pick a subcategory when it
|
||||||
|
only has a category, recheck and possibly correct an already-categorized
|
||||||
|
ticket, rewrite an unclear subject, and set a priority based on content.
|
||||||
|
Runs once per ticket in the background (never synchronously at submission,
|
||||||
|
so it adds no latency for a client), and every applied change leaves a
|
||||||
|
specific line plus a "Automatyzacja: klasyfikacja AI" entry in the ticket's
|
||||||
|
history, same convention as the existing SLA automation rules. Separately,
|
||||||
|
an AI-generated summary + suggested next action for **every** ticket, shown
|
||||||
|
only to operators in a new "Podsumowanie AI" sidebar card, refreshed
|
||||||
|
whenever the thread gets a new message — its system prompt is admin-editable
|
||||||
|
as a plain-text field with a "Resetuj" button back to the shipped default.
|
||||||
|
- Operators can now reassign a ticket to **any** team, not just one they
|
||||||
|
belong to (previously the dropdown only ever offered the operator's own
|
||||||
|
teams).
|
||||||
|
- The auto-refresh countdown badges (ticket view, operator queue) are now
|
||||||
|
**clickable** — fetch immediately and reset the countdown, instead of only
|
||||||
|
ever refreshing on their own fixed schedule.
|
||||||
|
- **All 7 "cyclical" intervals** in the app are now configurable from
|
||||||
|
Admin > Konfiguracja instead of fixed in code: the 3 browser auto-refresh
|
||||||
|
countdowns (ticket view, operator queue), the notification bell's poll,
|
||||||
|
and the 4 background scheduled commands (SLA breach check, SLA automation
|
||||||
|
rules, IMAP fetch, AI ticket automation). Defaults match the previous
|
||||||
|
hardcoded values, so nothing changes until an admin edits them.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- An operator viewing a ticket that gets deleted by someone else, or whose
|
||||||
|
team changes to one outside the operator's own scope (including via their
|
||||||
|
own reassignment above), is now redirected back to the operator queue
|
||||||
|
instead of hitting an error mid-session.
|
||||||
|
|
||||||
## [1.2.0] - 2026-07-23
|
## [1.2.0] - 2026-07-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
57
CLAUDE.md
57
CLAUDE.md
@@ -21,7 +21,12 @@ roles). Treat the running database as production, not a sandbox:
|
|||||||
## Container operations: use `sudo`, never build the image locally
|
## Container operations: use `sudo`, never build the image locally
|
||||||
|
|
||||||
All Docker commands against this stack need `sudo` (e.g.
|
All Docker commands against this stack need `sudo` (e.g.
|
||||||
`sudo docker compose exec servicedesk ...`, `sudo docker exec servicedesk-servicedesk-1 ...`).
|
`sudo docker compose exec app ...`, `sudo docker exec servicedesk-app-1 ...`).
|
||||||
|
|
||||||
|
The stack is four services sharing the one `servicedesk` image — `app` (Apache,
|
||||||
|
what actually serves HTTP), `reverb` (websocket server, `php artisan
|
||||||
|
reverb:start`), `cron` (scheduler loop, `php artisan schedule:work` — see
|
||||||
|
below), and `mariadb`. Only `app` and `reverb` are reachable from Traefik.
|
||||||
|
|
||||||
**Never run `docker build`, `docker compose build`, or `--build`.** The
|
**Never run `docker build`, `docker compose build`, or `--build`.** The
|
||||||
`servicedesk` image is built by CI (`.gitea/workflows/build.yml`, triggered on
|
`servicedesk` image is built by CI (`.gitea/workflows/build.yml`, triggered on
|
||||||
@@ -29,7 +34,7 @@ All Docker commands against this stack need `sudo` (e.g.
|
|||||||
`compose.yaml` only ever `pull`s a tag (`sudo docker compose pull && sudo docker
|
`compose.yaml` only ever `pull`s a tag (`sudo docker compose pull && sudo docker
|
||||||
compose up -d`, see [install.md](install.md) 1.3/1.3a) — building locally would
|
compose up -d`, see [install.md](install.md) 1.3/1.3a) — building locally would
|
||||||
just diverge from what CI produces. The app container
|
just diverge from what CI produces. The app container
|
||||||
(`servicedesk-servicedesk-1`) mounts `./src` from the host over NFS
|
(`servicedesk-app-1`) mounts `./src` from the host over NFS
|
||||||
(`/mnt/rabbit-containers` → NFS export), so plain file edits already take effect
|
(`/mnt/rabbit-containers` → NFS export), so plain file edits already take effect
|
||||||
with no rebuild or restart:
|
with no rebuild or restart:
|
||||||
|
|
||||||
@@ -56,34 +61,50 @@ with no rebuild or restart:
|
|||||||
surfaces in production as a 500 with `touch(): Utime failed: Operation not
|
surfaces in production as a 500 with `touch(): Utime failed: Operation not
|
||||||
permitted`. If you ran `php artisan test`/`tinker`/any artisan command via
|
permitted`. If you ran `php artisan test`/`tinker`/any artisan command via
|
||||||
`docker exec` in a session where you also edited Blade files afterward,
|
`docker exec` in a session where you also edited Blade files afterward,
|
||||||
finish with `sudo docker exec servicedesk-servicedesk-1 php artisan
|
finish with `sudo docker exec servicedesk-app-1 php artisan
|
||||||
view:clear` to flush any root-owned compiled views before ending the
|
view:clear` to flush any root-owned compiled views before ending the
|
||||||
session — don't wait for a report of a broken page to catch it.
|
session — don't wait for a report of a broken page to catch it.
|
||||||
|
|
||||||
## Scheduled commands need a host crontab entry
|
## Scheduled commands run in the dedicated `cron` container
|
||||||
|
|
||||||
The Docker image ships no cron/supervisor of its own (see [install.md](install.md)),
|
The Docker image ships no cron/supervisor of its own (see [install.md](install.md)),
|
||||||
so `tickets:check-sla-breaches`, `automation:run-rules`, and `emails:fetch-imap`
|
so `tickets:check-sla-breaches`, `automation:run-rules`, `emails:fetch-imap`,
|
||||||
(all registered in `routes/console.php` via `Schedule::command(...)`) only ever
|
and `ai:run-ticket-automation` (all registered in `routes/console.php` via
|
||||||
run if something outside the container calls `php artisan schedule:run` on a
|
`Schedule::command(...)`) only ever run if something calls `php artisan
|
||||||
timer. **As of 2026-07-23 this is configured** — root's crontab on the host
|
schedule:run` on a timer. **As of 2026-08-04 this is the `cron` service** in
|
||||||
runs, every minute:
|
`compose.yaml` — same `servicedesk` image, running `php artisan schedule:work`
|
||||||
|
(Laravel's own foreground scheduler loop, ticks every minute internally, no
|
||||||
|
external trigger needed). Before this it was a root crontab entry on the host
|
||||||
|
calling `docker compose exec -T servicedesk schedule:run`; that entry has been
|
||||||
|
removed from `sudo crontab -l -u root` now that the container replaces it —
|
||||||
|
don't re-add it, the two would double-run every scheduled command.
|
||||||
|
|
||||||
```cron
|
If the `cron` container isn't running (`sudo docker compose ps cron`), none of
|
||||||
* * * * * cd /mnt/rabbit-containers/servicedesk && docker compose exec -T servicedesk php artisan schedule:run >> /dev/null 2>&1
|
the four scheduled commands fire — same failure mode as the old missing-crontab
|
||||||
```
|
case, just check the container instead of the crontab. IMAP-specific activity
|
||||||
|
|
||||||
(`sudo crontab -l -u root` to inspect/edit — it previously did not exist at all,
|
|
||||||
which meant none of the three scheduled commands above had ever run
|
|
||||||
automatically; ask before changing this again, since removing it silently
|
|
||||||
breaks SLA checks, automation rules and IMAP fetching, and confusingly not the
|
|
||||||
IMAP feature alone if you're only debugging that one.) IMAP-specific activity
|
|
||||||
(connect attempts, per-message accept/reject decisions, created/replied ticket
|
(connect attempts, per-message accept/reject decisions, created/replied ticket
|
||||||
ids) is logged separately from the app's normal `LOG_LEVEL` to
|
ids) is logged separately from the app's normal `LOG_LEVEL` to
|
||||||
`storage/logs/imap-*.log` (see the `imap` channel in `config/logging.php`) —
|
`storage/logs/imap-*.log` (see the `imap` channel in `config/logging.php`) —
|
||||||
check there first when a mailbox isn't behaving as expected, before assuming
|
check there first when a mailbox isn't behaving as expected, before assuming
|
||||||
the scheduler itself isn't firing.
|
the scheduler itself isn't firing.
|
||||||
|
|
||||||
|
All four commands' intervals are admin-configurable (Admin > Konfiguracja —
|
||||||
|
`schedule_sla_check_minutes`/`schedule_automation_rules_minutes`/
|
||||||
|
`schedule_imap_fetch_minutes`/`schedule_ai_automation_minutes`), which is why
|
||||||
|
`routes/console.php` registers them as `->everyMinute()->when(fn () =>
|
||||||
|
Settings::dueEveryMinutes(...))` instead of a plain `->everyFifteenMinutes()`/
|
||||||
|
`->cron(...)` call — **never build a cron expression (or otherwise read
|
||||||
|
`Settings`) at that file's top level**. `routes/console.php` is `require`'d on
|
||||||
|
every artisan boot (`migrate`, `tinker`, `php artisan test`, not just
|
||||||
|
`schedule:run` — it's wired in via `bootstrap/app.php`'s `commands:` key), so
|
||||||
|
a top-level `Settings::get(...)` call runs before a fresh/test database
|
||||||
|
necessarily has the `settings` table, and crashes every single artisan
|
||||||
|
invocation, not just the scheduler. A `->when($closure)` guard is the fix —
|
||||||
|
the closure is only ever evaluated later, when `schedule:run` processes due
|
||||||
|
events. One visible side effect: `php artisan schedule:list` shows
|
||||||
|
`* * * * *` for all four regardless of the actual configured interval, since
|
||||||
|
that only exists inside the closure — expected, not a bug worth chasing.
|
||||||
|
|
||||||
## Apache `/icons/` alias trap
|
## Apache `/icons/` alias trap
|
||||||
|
|
||||||
The stock `php:apache` image enables `mods-enabled/alias.conf`, which defines
|
The stock `php:apache` image enables `mods-enabled/alias.conf`, which defines
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ build through a throwaway `node:22` container as documented there.
|
|||||||
|
|
||||||
1. **Run the test suite** — see [TESTING.md](TESTING.md) for details:
|
1. **Run the test suite** — see [TESTING.md](TESTING.md) for details:
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk php artisan test
|
docker compose exec app php artisan test
|
||||||
```
|
```
|
||||||
2. **Run Pint** (Laravel's code-style fixer, default preset, no project overrides):
|
2. **Run Pint** (Laravel's code-style fixer, default preset, no project overrides):
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk ./vendor/bin/pint
|
docker compose exec app ./vendor/bin/pint
|
||||||
```
|
```
|
||||||
3. If you changed anything under `resources/`, rebuild the frontend bundle and
|
3. If you changed anything under `resources/`, rebuild the frontend bundle and
|
||||||
commit the result if `public/build/` is tracked, or confirm the deploy step
|
commit the result if `public/build/` is tracked, or confirm the deploy step
|
||||||
|
|||||||
115
README.md
115
README.md
@@ -23,9 +23,22 @@ and **[wiki/admin](wiki/admin/README.md)** for role-specific how-to guides.
|
|||||||
|
|
||||||
## Feature overview
|
## Feature overview
|
||||||
|
|
||||||
|
- **Navigation** — a segmented Klient/Operator/Administrator switcher in the
|
||||||
|
top bar (only the areas a user actually holds, current one highlighted,
|
||||||
|
hover-previews the destination before you click) replaces the old dropdown
|
||||||
|
role switcher; the profile menu shows name/e-mail/role badges above
|
||||||
|
Powiadomienia/Wyloguj się; every page sets its own browser-tab title
|
||||||
|
(ticket subject, selected queue, active admin tab, ...) anchored with the
|
||||||
|
company name; and a command-palette global search (Ctrl+K/Cmd+K, or a
|
||||||
|
"Szukaj" sidebar button) finds tickets from anywhere, scoped to what the
|
||||||
|
searching user can see, with Gmail-style `od:`/`temat:`/`treść:`/`numer:`
|
||||||
|
operators. The operator sidebar also lists the last 6 tickets they
|
||||||
|
actually opened ("Ostatnio przeglądane").
|
||||||
- **Tickets** — number, subject, body, category/subcategory, status, priority, team,
|
- **Tickets** — number, subject, body, category/subcategory, status, priority, team,
|
||||||
assignee, custom fields (per subcategory), attachments, full message thread
|
assignee, custom fields (per subcategory), attachments, full message thread
|
||||||
(public replies + internal notes), history log, merge, delete.
|
(public replies + internal notes), history log, merge, delete. The operator
|
||||||
|
queue (50/page) and client dashboard (20/page, current/archive tracked
|
||||||
|
separately) paginate rather than rendering every matching ticket at once.
|
||||||
- **SLA** — per-priority response/resolution time targets; a scheduled command
|
- **SLA** — per-priority response/resolution time targets; a scheduled command
|
||||||
(`tickets:check-sla-breaches`, every 15 min) flags overdue tickets and can notify
|
(`tickets:check-sla-breaches`, every 15 min) flags overdue tickets and can notify
|
||||||
the assigned operator.
|
the assigned operator.
|
||||||
@@ -40,13 +53,23 @@ and **[wiki/admin](wiki/admin/README.md)** for role-specific how-to guides.
|
|||||||
(operator and client) update live over WebSockets (Laravel Reverb): new
|
(operator and client) update live over WebSockets (Laravel Reverb): new
|
||||||
tickets, status/priority/team/assignee changes, and new replies ("live chat")
|
tickets, status/priority/team/assignee changes, and new replies ("live chat")
|
||||||
all show up without a manual refresh. A periodic fallback refresh (with a
|
all show up without a manual refresh. A periodic fallback refresh (with a
|
||||||
visible countdown) covers a dropped websocket connection.
|
visible, clickable countdown badge — click it to fetch immediately and reset
|
||||||
|
the countdown) covers a dropped websocket connection. All of the refresh/poll
|
||||||
|
intervals in the app, browser-side and the background scheduled commands
|
||||||
|
alike, are configurable from Admin > Konfiguracja (see below).
|
||||||
- **Categories & custom fields** — admin-defined categories/subcategories, each with
|
- **Categories & custom fields** — admin-defined categories/subcategories, each with
|
||||||
its own set of custom fields (text/textarea/select/checkbox/date/number) and an
|
its own set of custom fields (text/textarea/select/checkbox/date/number) and an
|
||||||
optional default priority.
|
optional default priority. Subcategories within a category can be reordered with
|
||||||
|
up/down arrows in Admin > Kategorie; the order set there is what clients/operators
|
||||||
|
see everywhere a subcategory picker is shown.
|
||||||
- **Teams** — subcategories auto-route to a team; operators only see their own
|
- **Teams** — subcategories auto-route to a team; operators only see their own
|
||||||
team's queue (plus unrouted tickets and anything assigned to them) unless they're
|
team's queue (plus unrouted tickets and anything assigned to them) unless they're
|
||||||
an admin.
|
an admin. Reassigning a ticket to a team, though, is unrestricted — an operator
|
||||||
|
can route a ticket to any team, not just one they belong to.
|
||||||
|
- **Client search** (Operator > Klienci) — find any account by name or e-mail
|
||||||
|
(not just role=client — a ticket's customer can be any user), see its role
|
||||||
|
badges and ticket count, and jump straight into the queue pre-filtered to
|
||||||
|
that customer.
|
||||||
- **Templates** — canned response snippets for the reply box, admin-configurable
|
- **Templates** — canned response snippets for the reply box, admin-configurable
|
||||||
"quick actions" (send + transition status in one click), and HTML e-mail
|
"quick actions" (send + transition status in one click), and HTML e-mail
|
||||||
templates for every ticket lifecycle event (created, status/priority/category/
|
templates for every ticket lifecycle event (created, status/priority/category/
|
||||||
@@ -63,9 +86,12 @@ and **[wiki/admin](wiki/admin/README.md)** for role-specific how-to guides.
|
|||||||
e-mail layout/footer, SMTP connection (Admin > E-MAIL), attachment limits,
|
e-mail layout/footer, SMTP connection (Admin > E-MAIL), attachment limits,
|
||||||
session lifetime, timezone (Admin > Konfiguracja), and LDAP connection + user
|
session lifetime, timezone (Admin > Konfiguracja), and LDAP connection + user
|
||||||
sync + BookStack (Admin > Integracje).
|
sync + BookStack (Admin > Integracje).
|
||||||
- **LDAP auth** — logins bind against an LDAP/LLDAP directory (`config/auth.php`,
|
- **LDAP auth** — logins bind against a directory (`config/auth.php`,
|
||||||
`config/ldap.php`); local accounts (e.g. the emergency `admin` account) fall back
|
`config/ldap.php`); local accounts (e.g. the emergency `admin` account) fall back
|
||||||
to e-mail + local password when the LDAP bind doesn't match.
|
to e-mail + local password when the LDAP bind doesn't match. A "Typ katalogu"
|
||||||
|
toggle (Admin > Integracje) switches between LLDAP/OpenLDAP (default) and
|
||||||
|
Active Directory, which auto-selects the right schema/login attribute
|
||||||
|
(`sAMAccountName` + `objectGUID` for AD, vs. `uid` + `entryUUID`).
|
||||||
- **Triggers** (Admin > Wyzwalacze) — event-driven business rules that fire
|
- **Triggers** (Admin > Wyzwalacze) — event-driven business rules that fire
|
||||||
immediately on a ticket lifecycle event (created, any field updated, status/
|
immediately on a ticket lifecycle event (created, any field updated, status/
|
||||||
priority/assignee/team/category changed, new public reply): AND-combined
|
priority/assignee/team/category changed, new public reply): AND-combined
|
||||||
@@ -133,10 +159,54 @@ and **[wiki/admin](wiki/admin/README.md)** for role-specific how-to guides.
|
|||||||
both operators and clients (with a copy-link button for operators). Loads in
|
both operators and clients (with a copy-link button for operators). Loads in
|
||||||
after the page's first paint rather than blocking it. Configured entirely
|
after the page's first paint rather than blocking it. Configured entirely
|
||||||
from Admin > Integracje: connection + API token, optional SSL-verification
|
from Admin > Integracje: connection + API token, optional SSL-verification
|
||||||
bypass for self-signed instances, page/book search-type filter, and two
|
bypass for self-signed instances, a content-type filter (books/pages/
|
||||||
independent per-shelf allow-lists (nothing is searched until an admin opts
|
chapters, independently toggleable) and a "search by" mode (name / tags /
|
||||||
specific shelves in, separately for ticket-creation suggestions vs. the
|
both), and two independent per-shelf allow-lists (nothing is searched until
|
||||||
operator/client ticket-view sidebar).
|
an admin opts specific shelves in, separately for ticket-creation
|
||||||
|
suggestions vs. the operator/client ticket-view sidebar). A pair of
|
||||||
|
"Otaguj nową treść"/"Otaguj wszystko ponownie" buttons (also available as
|
||||||
|
`php artisan bookstack:tag-content`) use the AI integration below to
|
||||||
|
auto-tag every book/chapter/page with matching subcategory names, so the
|
||||||
|
tag-based search mode has something to find.
|
||||||
|
- **Generic AI integration** (Admin > Integracje > "Integracja AI") *(optional,
|
||||||
|
off by default)* — an OpenAI-compatible chat-completions client (Groq,
|
||||||
|
OpenAI, or a self-hosted Ollama instance) configured by base URL, optional
|
||||||
|
API key, model, and an SSL-verification toggle. Not tied to a single
|
||||||
|
feature — it backs the BookStack auto-tagging above and the AI ticket
|
||||||
|
triage/summary below, and is meant to be reused by anything that needs an
|
||||||
|
LLM call in the future.
|
||||||
|
- **AI-driven ticket triage + summary** (Admin > Integracje >
|
||||||
|
"Automatyzacja AI dla zgłoszeń") *(optional, off by default, requires the AI
|
||||||
|
integration above)* — five independent toggles run once per new ticket, in
|
||||||
|
the background (`ai:run-ticket-automation`, never synchronously at
|
||||||
|
submission): assign a category/subcategory when missing, pick a
|
||||||
|
subcategory when only a category is set, recheck/correct an
|
||||||
|
already-categorized ticket, rewrite an unclear subject, and set a priority
|
||||||
|
from the ticket's content. Every applied change is logged in the ticket's
|
||||||
|
history. Separately, an AI-generated summary + suggested next action for
|
||||||
|
every ticket, shown to operators only in a "Podsumowanie AI" sidebar card
|
||||||
|
with a manual "Wygeneruj teraz" button, an admin-editable prompt
|
||||||
|
(reset-to-default button included), and a per-transcript excerpt of the
|
||||||
|
ticket's own opening body alongside the reply thread (so long tickets
|
||||||
|
don't lose the original request once it scrolls out of the message
|
||||||
|
window). Refreshed by the same periodic sweep by default; an optional
|
||||||
|
admin toggle regenerates it immediately after every new reply/note
|
||||||
|
instead of waiting for the next scheduled run.
|
||||||
|
- **Snipe-IT asset inventory integration** *(optional, off by default)* —
|
||||||
|
connects to a Snipe-IT instance (API address + personal API token, plus an
|
||||||
|
SSL-verification bypass for self-signed instances) and adds three
|
||||||
|
independently toggleable capabilities from Admin > Integracje: a client
|
||||||
|
can pick which of their own Snipe-IT assets a ticket concerns while
|
||||||
|
creating it (scoped to admin-selected subcategories, empty selection means
|
||||||
|
it never shows — same convention as BookStack's shelf allow-lists), an
|
||||||
|
operator sees the requester's own assets in a ticket-view sidebar card,
|
||||||
|
and an operator can search the entire Snipe-IT inventory from that same
|
||||||
|
sidebar (not a separate page) to link shared equipment the requester isn't
|
||||||
|
the current owner of. Every asset is shown as "numer środka - numer
|
||||||
|
seryjny - producent model" plus its Snipe-IT category; a linked asset's
|
||||||
|
live status/assignment is fetched fresh on the ticket page, and unlinking
|
||||||
|
stays available to an operator even if both view/search toggles are later
|
||||||
|
turned off.
|
||||||
|
|
||||||
## Tech stack
|
## Tech stack
|
||||||
|
|
||||||
@@ -151,11 +221,13 @@ and **[wiki/admin](wiki/admin/README.md)** for role-specific how-to guides.
|
|||||||
dashboard is hand-rolled inline-styled bar/column charts, so it needs no client
|
dashboard is hand-rolled inline-styled bar/column charts, so it needs no client
|
||||||
build step beyond the CSS bundle.
|
build step beyond the CSS bundle.
|
||||||
- **Database**: MariaDB.
|
- **Database**: MariaDB.
|
||||||
- **Deployment**: `compose.yaml` — `servicedesk` (source bind-mounted from `./src`,
|
- **Deployment**: `compose.yaml` — `app` (source bind-mounted from `./src`,
|
||||||
no image rebuild needed for PHP/Blade/route changes) + `mariadb` + `reverb`
|
no image rebuild needed for PHP/Blade/route changes) + `mariadb` + `reverb`
|
||||||
(same image, `php artisan reverb:start`), fronted by Traefik with a private-CA
|
(same image, `php artisan reverb:start`) + `cron` (same image, `php artisan
|
||||||
TLS cert (the websocket path is routed to `reverb` by a higher-priority
|
schedule:work` — runs the scheduled commands below without needing a host
|
||||||
Traefik rule; everything else goes to `servicedesk`). The `servicedesk` image
|
crontab), fronted by Traefik with a private-CA TLS cert (the websocket path
|
||||||
|
is routed to `reverb` by a higher-priority Traefik rule; everything else
|
||||||
|
goes to `app`). The `servicedesk` image
|
||||||
itself is built and pushed by Gitea Actions (`.gitea/workflows/build.yml`) to
|
itself is built and pushed by Gitea Actions (`.gitea/workflows/build.yml`) to
|
||||||
the Gitea container registry whenever `Dockerfile` changes — `compose.yaml`
|
the Gitea container registry whenever `Dockerfile` changes — `compose.yaml`
|
||||||
just pulls a tag, it never builds locally.
|
just pulls a tag, it never builds locally.
|
||||||
@@ -177,7 +249,7 @@ Compose-level and Laravel-level) and the LDAP/SMTP gotcha after a fresh seed.
|
|||||||
```
|
```
|
||||||
- Fresh install / reset:
|
- Fresh install / reset:
|
||||||
```bash
|
```bash
|
||||||
sudo docker exec servicedesk-servicedesk-1 php artisan migrate:fresh --seed
|
sudo docker exec servicedesk-app-1 php artisan migrate:fresh --seed
|
||||||
```
|
```
|
||||||
Seeds real reference data (categories, custom fields, statuses/priorities/SLA,
|
Seeds real reference data (categories, custom fields, statuses/priorities/SLA,
|
||||||
teams, quick actions, response/e-mail templates, branding/config with example
|
teams, quick actions, response/e-mail templates, branding/config with example
|
||||||
@@ -192,10 +264,15 @@ src/ Laravel application
|
|||||||
app/Livewire/ Client/Operator/Admin Livewire components
|
app/Livewire/ Client/Operator/Admin Livewire components
|
||||||
app/Models/ Eloquent models
|
app/Models/ Eloquent models
|
||||||
app/Events/ Broadcast events (TicketQueueChanged, TicketMessagePosted)
|
app/Events/ Broadcast events (TicketQueueChanged, TicketMessagePosted)
|
||||||
app/Console/Commands/ Scheduled commands (SLA breach check, automation rules, IMAP fetch)
|
app/Console/Commands/ Scheduled commands (SLA breach check, automation rules, IMAP fetch,
|
||||||
|
AI ticket triage/summary) + bookstack:tag-content + hesk:import
|
||||||
|
(one-time historical migration, see scripts/hesk-import/)
|
||||||
app/Services/ TicketService (ticket lifecycle + notifications), BookStackClient,
|
app/Services/ TicketService (ticket lifecycle + notifications), BookStackClient,
|
||||||
ImapMailboxFetcher (I/O) + ImapMessageClassifier (pure logic)
|
ImapMailboxFetcher (I/O) + ImapMessageClassifier (pure logic),
|
||||||
app/Ldap/ LDAP user model + sync handlers
|
AiClient (generic LLM client), BookStackContentTagger,
|
||||||
|
TicketAiTriageService, TicketAiSummaryService, SnipeItClient
|
||||||
|
app/Ldap/ LDAP user models — LldapUser (LLDAP/OpenLDAP, default) and
|
||||||
|
AdUser (Active Directory) — plus sync handlers
|
||||||
database/migrations/ Schema (one file per table group, final shape)
|
database/migrations/ Schema (one file per table group, final shape)
|
||||||
database/seeders/ DatabaseSeeder — reference data, no ticket data
|
database/seeders/ DatabaseSeeder — reference data, no ticket data
|
||||||
resources/css/ Tailwind entrypoint (needs `npm run build` after edits)
|
resources/css/ Tailwind entrypoint (needs `npm run build` after edits)
|
||||||
@@ -208,4 +285,6 @@ wiki/
|
|||||||
client/ How-to guide for the Client role
|
client/ How-to guide for the Client role
|
||||||
operator/ How-to guide for the Operator role
|
operator/ How-to guide for the Operator role
|
||||||
admin/ How-to guide for the Admin role
|
admin/ How-to guide for the Admin role
|
||||||
|
scripts/
|
||||||
|
hesk-import/ One-time Hesk 3.x ticket history import — see its own README.md
|
||||||
```
|
```
|
||||||
|
|||||||
10
TESTING.md
10
TESTING.md
@@ -13,20 +13,20 @@ fast in-process fakes (`array`/`sync`) for the same reason.
|
|||||||
From inside the app container (or on a bare-metal install, from `src/`):
|
From inside the app container (or on a bare-metal install, from `src/`):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk php artisan test
|
docker compose exec app php artisan test
|
||||||
```
|
```
|
||||||
|
|
||||||
or directly with Pest:
|
or directly with Pest:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk ./vendor/bin/pest
|
docker compose exec app ./vendor/bin/pest
|
||||||
```
|
```
|
||||||
|
|
||||||
Run a single file or filter by name:
|
Run a single file or filter by name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk php artisan test --filter=SlaBreachNotificationTest
|
docker compose exec app php artisan test --filter=SlaBreachNotificationTest
|
||||||
docker compose exec servicedesk ./vendor/bin/pest tests/Feature/TicketApiTest.php
|
docker compose exec app ./vendor/bin/pest tests/Feature/TicketApiTest.php
|
||||||
```
|
```
|
||||||
|
|
||||||
There is no CI pipeline configured for this repository — running the suite
|
There is no CI pipeline configured for this repository — running the suite
|
||||||
@@ -60,5 +60,5 @@ automatically without extra boilerplate.
|
|||||||
on Laravel's default preset). Run it before committing:
|
on Laravel's default preset). Run it before committing:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk ./vendor/bin/pint
|
docker compose exec app ./vendor/bin/pint
|
||||||
```
|
```
|
||||||
|
|||||||
121
install.md
121
install.md
@@ -24,7 +24,7 @@ osobne pliki, w dwóch różnych miejscach.
|
|||||||
- Docker + wtyczka `docker compose`.
|
- Docker + wtyczka `docker compose`.
|
||||||
- Zewnętrzna sieć Docker `traefik_public`, jeśli używasz Traefika tak jak w
|
- Zewnętrzna sieć Docker `traefik_public`, jeśli używasz Traefika tak jak w
|
||||||
`compose.yaml` (`docker network create traefik_public`, jeśli jeszcze nie
|
`compose.yaml` (`docker network create traefik_public`, jeśli jeszcze nie
|
||||||
istnieje). Bez Traefika trzeba samodzielnie zmapować porty serwisu `servicedesk`
|
istnieje). Bez Traefika trzeba samodzielnie zmapować porty serwisu `app`
|
||||||
na hosta (`ports: ["8080:80"]`) i obsłużyć TLS inaczej (patrz sekcja 2 niżej, w
|
na hosta (`ports: ["8080:80"]`) i obsłużyć TLS inaczej (patrz sekcja 2 niżej, w
|
||||||
razie potrzeby reverse-proxy przed kontenerem).
|
razie potrzeby reverse-proxy przed kontenerem).
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ APP_LOCALE=pl
|
|||||||
APP_FALLBACK_LOCALE=pl
|
APP_FALLBACK_LOCALE=pl
|
||||||
|
|
||||||
AUTHOR_CONTACT=helpdesk@twoja-domena.pl # widoczne w Admin > O aplikacji
|
AUTHOR_CONTACT=helpdesk@twoja-domena.pl # widoczne w Admin > O aplikacji
|
||||||
VERSION=1.1.3 # widoczne w Admin > O aplikacji
|
VERSION=1.3.0 # widoczne w Admin > O aplikacji
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=mariadb # nazwa serwisu z compose.yaml, NIE 127.0.0.1
|
DB_HOST=mariadb # nazwa serwisu z compose.yaml, NIE 127.0.0.1
|
||||||
@@ -90,8 +90,8 @@ QUEUE_CONNECTION=database
|
|||||||
`APP_KEY` wygenerujesz komendą artisan (krok 1.4) — zostaw puste w pliku.
|
`APP_KEY` wygenerujesz komendą artisan (krok 1.4) — zostaw puste w pliku.
|
||||||
|
|
||||||
`LDAP_*` i `MAIL_*` w `src/.env` są tylko **wartościami startowymi/awaryjnymi**.
|
`LDAP_*` i `MAIL_*` w `src/.env` są tylko **wartościami startowymi/awaryjnymi**.
|
||||||
Docelowo LDAP i SMTP konfiguruje się wygodniej z poziomu **Admin > Konfiguracja**
|
Docelowo LDAP konfiguruje się wygodniej z poziomu **Admin > Integracje**, a SMTP
|
||||||
w samej aplikacji (patrz ramka ostrzegawcza w kroku 1.6) — ale jeśli chcesz mieć
|
z **Admin > Poczta** (patrz ramka ostrzegawcza w kroku 1.6) — ale jeśli chcesz mieć
|
||||||
sensowny fallback zanim ktokolwiek się zaloguje do panelu admina, warto je od razu
|
sensowny fallback zanim ktokolwiek się zaloguje do panelu admina, warto je od razu
|
||||||
uzupełnić:
|
uzupełnić:
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ w restartach z błędem `Undefined constant "...SIGINT"`; dodaj `pcntl posix` do
|
|||||||
listy w `docker-php-ext-install` i poczekaj na przebudowanie obrazu przez CI.
|
listy w `docker-php-ext-install` i poczekaj na przebudowanie obrazu przez CI.
|
||||||
|
|
||||||
Traefik musi kierować ścieżkę websocketu (`/app*`) do `reverb`, a resztę do
|
Traefik musi kierować ścieżkę websocketu (`/app*`) do `reverb`, a resztę do
|
||||||
`servicedesk` — na tej samej domenie, więc bez dodatkowego wpisu DNS/certyfikatu:
|
`app` — na tej samej domenie, więc bez dodatkowego wpisu DNS/certyfikatu:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
reverb:
|
reverb:
|
||||||
@@ -240,10 +240,10 @@ te wartości są wypiekane w zbudowany bundle JS, nie czytane w runtime.
|
|||||||
### 1.4. Instalacja aplikacji wewnątrz kontenera
|
### 1.4. Instalacja aplikacji wewnątrz kontenera
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose exec servicedesk composer install --no-dev --optimize-autoloader
|
docker compose exec app composer install --no-dev --optimize-autoloader
|
||||||
docker compose exec servicedesk php artisan key:generate
|
docker compose exec app php artisan key:generate
|
||||||
docker compose exec servicedesk php artisan migrate --seed
|
docker compose exec app php artisan migrate --seed
|
||||||
docker compose exec servicedesk php artisan storage:link
|
docker compose exec app php artisan storage:link
|
||||||
```
|
```
|
||||||
|
|
||||||
`migrate --seed` (bez `--fresh`) na pustej bazie utworzy wszystkie tabele i
|
`migrate --seed` (bez `--fresh`) na pustej bazie utworzy wszystkie tabele i
|
||||||
@@ -254,7 +254,7 @@ po pierwszym zalogowaniu (Admin > Użytkownicy).
|
|||||||
|
|
||||||
### 1.5. Zbudowanie zasobów front-endowych (CSS/Tailwind)
|
### 1.5. Zbudowanie zasobów front-endowych (CSS/Tailwind)
|
||||||
|
|
||||||
Ani host, ani kontener `servicedesk` nie mają zainstalowanego Node.js — buduj
|
Ani host, ani kontener `app` nie mają zainstalowanego Node.js — buduj
|
||||||
przez jednorazowy kontener `node:22` zamiast dorzucać Node do obrazu aplikacji:
|
przez jednorazowy kontener `node:22` zamiast dorzucać Node do obrazu aplikacji:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -265,19 +265,43 @@ docker run --rm -v "$(pwd)/src":/app -w /app node:22 npm run build
|
|||||||
|
|
||||||
Powtarzaj drugi krok po każdej zmianie w `resources/css/` lub `resources/js/`.
|
Powtarzaj drugi krok po każdej zmianie w `resources/css/` lub `resources/js/`.
|
||||||
|
|
||||||
### 1.6. Zadanie cykliczne (SLA, automatyzacje, poczta IMAP) i kolejka
|
### 1.6. Zadanie cykliczne (SLA, automatyzacje, poczta IMAP, AI) i kolejka
|
||||||
|
|
||||||
`routes/console.php` planuje `tickets:check-sla-breaches` i `automation:run-rules`
|
`routes/console.php` planuje `tickets:check-sla-breaches` i `automation:run-rules`
|
||||||
co 15 minut oraz `emails:fetch-imap` (odbieranie zgłoszeń/odpowiedzi e-mailem —
|
co 15 minut, oraz `emails:fetch-imap` (odbieranie zgłoszeń/odpowiedzi e-mailem —
|
||||||
patrz Admin > Poczta) co 5 minut, ale **obraz Dockera nie ma wbudowanego
|
patrz Admin > Poczta) i `ai:run-ticket-automation` (opcjonalna automatyczna
|
||||||
cron/supervisora** — bez dodatkowego kroku żadne z tych zadań nigdy się nie
|
kategoryzacja/podsumowania AI zgłoszeń — patrz Admin > Integracje) co 5 minut,
|
||||||
uruchomi (poczta IMAP nadal da się sprawdzić ręcznie przyciskiem „Pobierz teraz”,
|
ale **obraz Dockera nie ma wbudowanego cron/supervisora** — bez dodatkowego
|
||||||
ale bez crona nic nie dzieje się samo). Najprościej dodać wpis crona **na hoście**:
|
kroku żadne z tych zadań nigdy się nie uruchomi (poczta IMAP nadal da się
|
||||||
|
sprawdzić ręcznie przyciskiem „Pobierz teraz”, ale bez tego nic nie dzieje się
|
||||||
|
samo). Wszystkie cztery interwały są też konfigurowalne z poziomu **Admin >
|
||||||
|
Konfiguracja** (bez potrzeby edycji kodu czy restartu — nowa wartość obowiązuje
|
||||||
|
od najbliższego tyknięcia harmonogramu).
|
||||||
|
|
||||||
```cron
|
`compose.yaml` rozwiązuje to czwartą usługą, `cron` — tego samego obrazu
|
||||||
* * * * * cd /ścieżka/do/repo && docker compose exec -T servicedesk php artisan schedule:run >> /dev/null 2>&1
|
`servicedesk`, tylko z innym poleceniem:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
cron:
|
||||||
|
image: gitea.kzbikowski.pl/kzbkowski/servicedesk:${IMAGE_TAG:-latest}
|
||||||
|
command: php artisan schedule:work
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
mariadb:
|
||||||
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`schedule:work` to własna, pierwszoplanowa pętla harmonogramu Laravela —
|
||||||
|
odpowiednik odpalania `schedule:run` co minutę, ale bez potrzeby zewnętrznego
|
||||||
|
triggera. Ten kontener nie musi być widoczny w Traefiku (nie obsługuje ruchu
|
||||||
|
HTTP), stąd tylko sieć `internal`. Sprawdź, że działa: `docker compose ps cron`
|
||||||
|
oraz `docker compose logs -f cron` (loguje każde odpalenie zaplanowanego
|
||||||
|
zadania).
|
||||||
|
|
||||||
Powiadomienia e-mail wysyłają się synchronicznie (nie trafiają do kolejki), więc
|
Powiadomienia e-mail wysyłają się synchronicznie (nie trafiają do kolejki), więc
|
||||||
`php artisan queue:work` nie jest obowiązkowy — `QUEUE_CONNECTION=database` w
|
`php artisan queue:work` nie jest obowiązkowy — `QUEUE_CONNECTION=database` w
|
||||||
`.env` wystarcza jako bezpieczny domyślny driver, gdyby coś w przyszłości zaczęło
|
`.env` wystarcza jako bezpieczny domyślny driver, gdyby coś w przyszłości zaczęło
|
||||||
@@ -286,8 +310,9 @@ kolejkować zadania.
|
|||||||
### ⚠️ Ważne: LDAP/SMTP z panelu Admina nadpisują `.env` w locie
|
### ⚠️ Ważne: LDAP/SMTP z panelu Admina nadpisują `.env` w locie
|
||||||
|
|
||||||
`AppServiceProvider` na starcie żądania sprawdza tabelę `settings` — jeśli w
|
`AppServiceProvider` na starcie żądania sprawdza tabelę `settings` — jeśli w
|
||||||
Admin > Konfiguracja pole **host LDAP** albo **SMTP włączony + host** jest
|
Admin > Integracje pole **host LDAP** albo w Admin > Poczta **SMTP włączony +
|
||||||
ustawione, **te wartości wygrywają z `.env`**, bez potrzeby restartu czy redeployu.
|
host** jest ustawione, **te wartości wygrywają z `.env`**, bez potrzeby
|
||||||
|
restartu czy redeployu.
|
||||||
|
|
||||||
Po świeżym `migrate --seed` te pola zawierają **przykładowe placeholdery**
|
Po świeżym `migrate --seed` te pola zawierają **przykładowe placeholdery**
|
||||||
(`ldap.example.com`, `smtp.example.com`, `changeme-*-password`) — to znaczy, że
|
(`ldap.example.com`, `smtp.example.com`, `changeme-*-password`) — to znaczy, że
|
||||||
@@ -296,20 +321,43 @@ adresami**, nawet jeśli w `.env` wpisałeś prawdziwe dane! Zanim oddasz system
|
|||||||
użytku:
|
użytku:
|
||||||
|
|
||||||
1. Zaloguj się lokalnym kontem `admin@example.com` / `admin`.
|
1. Zaloguj się lokalnym kontem `admin@example.com` / `admin`.
|
||||||
2. Wejdź w **Admin > Konfiguracja** i wpisz prawdziwe dane LDAP/SMTP (albo wyczyść
|
2. Wejdź w **Admin > Integracje** i wpisz prawdziwe dane LDAP (wybierz też
|
||||||
pole hosta LDAP, żeby wrócić do wartości z `.env`).
|
właściwy **Typ katalogu** — LLDAP/OpenLDAP albo Active Directory — jeśli
|
||||||
3. Użyj przycisków **„Testuj połączenie”** przy obu sekcjach, zanim zaczniesz
|
katalog to nie LLDAP; albo wyczyść pole hosta LDAP, żeby wrócić do
|
||||||
polegać na logowaniu przez katalog.
|
wartości z `.env`), a w **Admin > Poczta** dane SMTP.
|
||||||
|
3. Użyj przycisku **„Testuj połączenie”** w Integracje i **„Wyślij testową
|
||||||
|
wiadomość”** w Poczta, zanim zaczniesz polegać na logowaniu przez katalog
|
||||||
|
albo na powiadomieniach e-mail.
|
||||||
|
|
||||||
### Integracje opcjonalne (BookStack)
|
### Integracje opcjonalne (BookStack, AI)
|
||||||
|
|
||||||
Podpowiedzi artykułów z bazy wiedzy BookStack (przy tworzeniu zgłoszenia i w
|
Podpowiedzi artykułów z bazy wiedzy BookStack (przy tworzeniu zgłoszenia i w
|
||||||
panelu operatora) są **domyślnie wyłączone** i nie wymagają żadnej zmiennej w
|
panelu operatora) są **domyślnie wyłączone** i nie wymagają żadnej zmiennej w
|
||||||
`.env` — całość konfiguruje się w **Admin > Konfiguracja**: adres instancji,
|
`.env` — całość konfiguruje się w **Admin > Integracje**: adres instancji,
|
||||||
Token ID/Secret (rola/użytkownik właściciela tokenu musi mieć w BookStacku
|
Token ID/Secret (rola/użytkownik właściciela tokenu musi mieć w BookStacku
|
||||||
uprawnienie „Access System API”), oraz osobne listy dozwolonych półek dla
|
uprawnienie „Access System API”), filtr typu treści (książki/strony/rozdziały,
|
||||||
podpowiedzi przy tworzeniu zgłoszenia i dla panelu operatora — dopóki żadna
|
niezależne checkboxy), tryb wyszukiwania (po nazwie / po tagach / oba), oraz
|
||||||
półka nie jest zaznaczona, wyszukiwanie nic nie zwraca.
|
osobne listy dozwolonych półek dla podpowiedzi przy tworzeniu zgłoszenia i dla
|
||||||
|
panelu operatora — dopóki żadna półka nie jest zaznaczona, wyszukiwanie nic
|
||||||
|
nie zwraca.
|
||||||
|
|
||||||
|
Integracja AI (Admin > Integracje > „Integracja AI”) jest **domyślnie
|
||||||
|
wyłączona** i tak samo nie wymaga żadnej zmiennej w `.env` — adres API
|
||||||
|
(dowolny dostawca kompatybilny z OpenAI: Groq, OpenAI, lokalny Ollama),
|
||||||
|
opcjonalny klucz API, nazwa modelu i przełącznik weryfikacji SSL. Sama w
|
||||||
|
sobie nic nie robi — dopiero po jej włączeniu można włączyć automatyczne
|
||||||
|
tagowanie treści BookStack (przyciski przy integracji BookStack) oraz
|
||||||
|
automatyczną kategoryzację/podsumowania AI zgłoszeń (Admin > Integracje >
|
||||||
|
„Automatyzacja AI dla zgłoszeń”, wymaga też wpisu crona z kroku 1.6/2.6
|
||||||
|
powyżej — to ten sam harmonogram co SLA/automatyzacje/IMAP).
|
||||||
|
|
||||||
|
### Import historycznych zgłoszeń z Heska (opcjonalnie)
|
||||||
|
|
||||||
|
Jeśli migrujesz z helpdesku Hesk 3.x, `scripts/hesk-import/` zawiera
|
||||||
|
jednorazowe (nie ciągłe) narzędzie migracyjne — importuje zgłoszenia wraz z
|
||||||
|
pełną historią odpowiedzi/notatek, ograniczone do jednej domeny e-mail, w
|
||||||
|
trybie dry-run domyślnie. Nie dotyka bazy Heska poza odczytem. Zobacz
|
||||||
|
`scripts/hesk-import/README.md` po pełną instrukcję.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -352,7 +400,7 @@ APP_LOCALE=pl
|
|||||||
APP_FALLBACK_LOCALE=pl
|
APP_FALLBACK_LOCALE=pl
|
||||||
|
|
||||||
AUTHOR_CONTACT=helpdesk@twoja-domena.pl
|
AUTHOR_CONTACT=helpdesk@twoja-domena.pl
|
||||||
VERSION=1.1.3
|
VERSION=1.3.0
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=127.0.0.1 # albo adres IP/hostname prawdziwego serwera DB
|
DB_HOST=127.0.0.1 # albo adres IP/hostname prawdziwego serwera DB
|
||||||
@@ -366,7 +414,7 @@ QUEUE_CONNECTION=database
|
|||||||
```
|
```
|
||||||
|
|
||||||
Uzupełnij też `LDAP_*`/`MAIL_*` jak w sekcji 1.2 (to samo ostrzeżenie o
|
Uzupełnij też `LDAP_*`/`MAIL_*` jak w sekcji 1.2 (to samo ostrzeżenie o
|
||||||
Admin > Konfiguracja nadpisującym te wartości w locie dotyczy tu identycznie).
|
Admin > Integracje/Poczta nadpisującym te wartości w locie dotyczy tu identycznie).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php artisan key:generate
|
php artisan key:generate
|
||||||
@@ -460,10 +508,11 @@ server {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2.6. Zadanie cykliczne (SLA, automatyzacje, poczta IMAP) i kolejka
|
### 2.6. Zadanie cykliczne (SLA, automatyzacje, poczta IMAP, AI) i kolejka
|
||||||
|
|
||||||
Crontab użytkownika, pod którym stoi aplikacja (np. `www-data`) — obsługuje też
|
Crontab użytkownika, pod którym stoi aplikacja (np. `www-data`) — obsługuje też
|
||||||
`automation:run-rules` i `emails:fetch-imap` (patrz 1.6 wyżej):
|
`automation:run-rules`, `emails:fetch-imap` i `ai:run-ticket-automation`
|
||||||
|
(patrz 1.6 wyżej, w tym konfigurowalne interwały w Admin > Konfiguracja):
|
||||||
|
|
||||||
```cron
|
```cron
|
||||||
* * * * * cd /var/www/servicedesk/src && php artisan schedule:run >> /dev/null 2>&1
|
* * * * * cd /var/www/servicedesk/src && php artisan schedule:run >> /dev/null 2>&1
|
||||||
@@ -506,9 +555,9 @@ jednej ścieżki, analogicznie do reguły Traefika w 1.3b).
|
|||||||
### 2.7. Pierwsze logowanie i dalsza konfiguracja
|
### 2.7. Pierwsze logowanie i dalsza konfiguracja
|
||||||
|
|
||||||
Identycznie jak w kroku 1.6 — zaloguj się `admin@example.com` / `admin`, zmień
|
Identycznie jak w kroku 1.6 — zaloguj się `admin@example.com` / `admin`, zmień
|
||||||
hasło, uzupełnij prawdziwe LDAP/SMTP w Admin > Konfiguracja (placeholdery z seeda
|
hasło, uzupełnij prawdziwe LDAP w Admin > Integracje i SMTP w Admin > Poczta
|
||||||
inaczej realnie próbują łączyć się z fałszywymi adresami), przetestuj oba
|
(placeholdery z seeda inaczej realnie próbują łączyć się z fałszywymi
|
||||||
połączenia przyciskiem „Testuj połączenie”.
|
adresami), przetestuj oba połączenia.
|
||||||
|
|
||||||
### 2.8. Aktualizacje (bez przestoju)
|
### 2.8. Aktualizacje (bez przestoju)
|
||||||
|
|
||||||
|
|||||||
5
scripts/hesk-import/.env.example
Normal file
5
scripts/hesk-import/.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
HESK_DB_HOST=
|
||||||
|
HESK_DB_PORT=3306
|
||||||
|
HESK_DB_DATABASE=
|
||||||
|
HESK_DB_USERNAME=
|
||||||
|
HESK_DB_PASSWORD=
|
||||||
83
scripts/hesk-import/README.md
Normal file
83
scripts/hesk-import/README.md
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# Hesk 3.x import
|
||||||
|
|
||||||
|
One-time historical migration of tickets (with full reply/note history) from a
|
||||||
|
Hesk 3.x helpdesk database into this app, restricted to a single e-mail
|
||||||
|
domain. Read-only against the Hesk database — never writes there.
|
||||||
|
|
||||||
|
This is **not** an ongoing sync. Run it once to backfill history from an
|
||||||
|
old Hesk install; it doesn't pick up edits made in Hesk afterward.
|
||||||
|
|
||||||
|
## What it does
|
||||||
|
|
||||||
|
- Matches Hesk tickets by requester e-mail domain (`--domain=firma.pl`).
|
||||||
|
- Imports each ticket's subject/body, status, priority, and full reply +
|
||||||
|
internal-note history, converting Hesk's `<br />`-laden "plain" text into
|
||||||
|
real line breaks.
|
||||||
|
- Maps Hesk categories to this app's categories by exact (case/whitespace-
|
||||||
|
insensitive) name match. A Hesk category with no match is skipped by
|
||||||
|
default — pass `--include-unmapped-categories` to import those tickets
|
||||||
|
anyway, uncategorized.
|
||||||
|
- Auto-assigns a team when every subcategory under the matched category
|
||||||
|
routes to the same single team (same rule `TicketService::autoAssignTeam()`
|
||||||
|
uses for normal ticket creation); ambiguous categories are left unrouted.
|
||||||
|
- Finds or creates a client account per requester e-mail, reusing an existing
|
||||||
|
account (adding the `client` role if it doesn't have it yet) rather than
|
||||||
|
duplicating.
|
||||||
|
- Hesk staff replies are **not** linked to a real operator account (this
|
||||||
|
script never creates operator accounts) — the reply still shows the
|
||||||
|
correct staff name and "operator" badge via `author_name`, just without a
|
||||||
|
clickable user behind it.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp scripts/hesk-import/.env.example scripts/hesk-import/.env
|
||||||
|
```
|
||||||
|
|
||||||
|
Fill in `scripts/hesk-import/.env` with the Hesk database's
|
||||||
|
host/port/database/username/password. That file is gitignored — it holds
|
||||||
|
real credentials for a database this app otherwise has no access to.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Always dry-run first — it reports what *would* happen without writing
|
||||||
|
anything:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/hesk-import/hesk-import.sh --domain=firma.pl
|
||||||
|
```
|
||||||
|
|
||||||
|
Try a small batch for real before committing to the whole thing:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/hesk-import/hesk-import.sh --domain=firma.pl --limit=10 --commit
|
||||||
|
```
|
||||||
|
|
||||||
|
Then the full import:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/hesk-import/hesk-import.sh --domain=firma.pl --commit
|
||||||
|
```
|
||||||
|
|
||||||
|
Safe to re-run (including after an interrupted/crashed run): already-imported
|
||||||
|
Hesk ticket ids are tracked in `storage/app/hesk-import-state.json` inside the
|
||||||
|
app container and skipped on subsequent runs.
|
||||||
|
|
||||||
|
### Backfilling team assignment
|
||||||
|
|
||||||
|
If tickets were already imported before team-by-category mapping existed (or
|
||||||
|
teams/subcategories changed since), backfill `team_id` on existing imported
|
||||||
|
tickets without importing anything new:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/hesk-import/hesk-import.sh --assign-teams --commit
|
||||||
|
```
|
||||||
|
|
||||||
|
## How it's wired up
|
||||||
|
|
||||||
|
`hesk-import.sh` is a thin wrapper: it loads `.env` in this folder, then runs
|
||||||
|
`php artisan hesk:import` inside the `app` container via `docker compose
|
||||||
|
exec`, passing the Hesk DB credentials as one-off environment variables (they
|
||||||
|
never touch the app's own `.env` or get persisted anywhere but the state
|
||||||
|
file). The actual import logic lives in
|
||||||
|
[`../../src/app/Console/Commands/ImportHeskTickets.php`](../../src/app/Console/Commands/ImportHeskTickets.php).
|
||||||
49
scripts/hesk-import/hesk-import.sh
Normal file
49
scripts/hesk-import/hesk-import.sh
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Imports tickets from a Hesk 3.x helpdesk database into this app, filtered
|
||||||
|
# to one e-mail domain. Thin wrapper around `php artisan hesk:import` (see
|
||||||
|
# ../../src/app/Console/Commands/ImportHeskTickets.php for the actual logic)
|
||||||
|
# — this script only wires up the Hesk DB credentials and runs it inside the
|
||||||
|
# app container. See README.md in this folder for full setup/usage docs.
|
||||||
|
#
|
||||||
|
# Setup: copy .env.example (this folder) to .env (gitignored) and fill in
|
||||||
|
# your Hesk database's host/port/database/username/password.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# scripts/hesk-import/hesk-import.sh --domain=firma.pl # dry run (default, writes nothing)
|
||||||
|
# scripts/hesk-import/hesk-import.sh --domain=firma.pl --limit=10 --commit # real run, first 10 tickets only
|
||||||
|
# scripts/hesk-import/hesk-import.sh --domain=firma.pl --commit # real run, everything
|
||||||
|
#
|
||||||
|
# Safe to re-run: already-imported Hesk tickets are tracked in
|
||||||
|
# storage/app/hesk-import-state.json inside the app container and skipped.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||||
|
ENV_FILE="$SCRIPT_DIR/.env"
|
||||||
|
|
||||||
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
echo "Brak $ENV_FILE — skopiuj scripts/hesk-import/.env.example i uzupełnij dane dostępowe do bazy Heska." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -a
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$ENV_FILE"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
: "${HESK_DB_HOST:?ustaw HESK_DB_HOST w $ENV_FILE}"
|
||||||
|
: "${HESK_DB_DATABASE:?ustaw HESK_DB_DATABASE w $ENV_FILE}"
|
||||||
|
: "${HESK_DB_USERNAME:?ustaw HESK_DB_USERNAME w $ENV_FILE}"
|
||||||
|
HESK_DB_PORT="${HESK_DB_PORT:-3306}"
|
||||||
|
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
exec sudo docker compose exec \
|
||||||
|
-e HESK_DB_HOST="$HESK_DB_HOST" \
|
||||||
|
-e HESK_DB_PORT="$HESK_DB_PORT" \
|
||||||
|
-e HESK_DB_DATABASE="$HESK_DB_DATABASE" \
|
||||||
|
-e HESK_DB_USERNAME="$HESK_DB_USERNAME" \
|
||||||
|
-e HESK_DB_PASSWORD="$HESK_DB_PASSWORD" \
|
||||||
|
app php artisan hesk:import "$@"
|
||||||
@@ -5,7 +5,7 @@ APP_DEBUG=false
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
AUTHOR_CONTACT=helpdesk@kzbikowski.pl
|
AUTHOR_CONTACT=helpdesk@kzbikowski.pl
|
||||||
VERSION=1.1.4
|
VERSION=1.4.0
|
||||||
|
|
||||||
APP_LOCALE=en
|
APP_LOCALE=en
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
|
|||||||
35
src/app/Console/Commands/BookstackTagContent.php
Normal file
35
src/app/Console/Commands/BookstackTagContent.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\BookStackContentTagger;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class BookstackTagContent extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'bookstack:tag-content
|
||||||
|
{--dry-run : Klasyfikuj i pokaż wynik bez zapisu tagów do BookStack}
|
||||||
|
{--force : Klasyfikuj ponownie elementy, które już mają tag podkategorii}
|
||||||
|
{--limit= : Zatrzymaj się po przetworzeniu N elementów}';
|
||||||
|
|
||||||
|
protected $description = 'Otaguj każdą książkę/rozdział/stronę w BookStack pasującymi nazwami podkategorii helpdesku, z pomocą skonfigurowanego dostawcy AI';
|
||||||
|
|
||||||
|
public function handle(BookStackContentTagger $tagger): int
|
||||||
|
{
|
||||||
|
$totals = $tagger->run(
|
||||||
|
dryRun: (bool) $this->option('dry-run'),
|
||||||
|
force: (bool) $this->option('force'),
|
||||||
|
limit: $this->option('limit') !== null ? (int) $this->option('limit') : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->info(sprintf(
|
||||||
|
'BookStack tagging: przeskanowano %d, otagowano %d, pominięto %d, nieudanych paczek %d.',
|
||||||
|
$totals['scanned'],
|
||||||
|
$totals['tagged'],
|
||||||
|
$totals['skipped'],
|
||||||
|
$totals['failed_batches'],
|
||||||
|
));
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
504
src/app/Console/Commands/ImportHeskTickets.php
Normal file
504
src/app/Console/Commands/ImportHeskTickets.php
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Role;
|
||||||
|
use App\Models\Team;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One-off migration from a Hesk 3.x helpdesk database into this app's own
|
||||||
|
* tickets/users. Never writes to the Hesk database — read-only there.
|
||||||
|
*
|
||||||
|
* Runs in dry-run mode by default (reports what it would do); pass --commit
|
||||||
|
* to actually write. Resumable: every successfully imported Hesk ticket id
|
||||||
|
* is recorded in a local state file (--state, defaults to
|
||||||
|
* storage/app/hesk-import-state.json), so a re-run (interrupted connection,
|
||||||
|
* crashed midway, etc.) skips tickets already imported instead of
|
||||||
|
* duplicating them. Not idempotent across *edits* on the Hesk side — this is
|
||||||
|
* a one-time historical import, not an ongoing sync.
|
||||||
|
*/
|
||||||
|
class ImportHeskTickets extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'hesk:import
|
||||||
|
{--domain= : Only import tickets whose requester e-mail ends in @this-domain}
|
||||||
|
{--commit : Actually write to the database (default is a dry run)}
|
||||||
|
{--limit= : Only process this many Hesk tickets (after the domain filter), useful for a test run}
|
||||||
|
{--state= : Path to the resume-state JSON file (default storage/app/hesk-import-state.json)}
|
||||||
|
{--include-unmapped-categories : Also import tickets whose Hesk category has no matching servicedesk category (default: skip them)}
|
||||||
|
{--assign-teams : Backfill team_id (by category) on already-imported tickets that don\'t have one yet, then exit — does not import anything}';
|
||||||
|
|
||||||
|
protected $description = 'Import tickets (with full reply/note history) from a Hesk 3.x database, restricted to one e-mail domain';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hesk ticket.status -> our status_key. Hesk's built-in codes are
|
||||||
|
* 0=New, 1=Waiting reply (for staff), 2=Replied (waiting on customer),
|
||||||
|
* 3=Resolved. Any other value (seen: a handful of "5" rows, presumably
|
||||||
|
* a since-deleted custom status) falls back to 'open'.
|
||||||
|
*/
|
||||||
|
private const STATUS_MAP = [
|
||||||
|
0 => 'new',
|
||||||
|
1 => 'waiting_operator',
|
||||||
|
2 => 'waiting_customer',
|
||||||
|
3 => 'closed',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hesk ticket.priority -> our priority_key. Hesk's enum is 1=Critical,
|
||||||
|
* 2=High, 3=Medium (the near-universal default — every Hesk category
|
||||||
|
* here defaults new tickets to priority 3); 0 is an unused/rare edge
|
||||||
|
* value, treated as the closest thing Hesk has to "Low".
|
||||||
|
*/
|
||||||
|
private const PRIORITY_MAP = [
|
||||||
|
0 => 'low',
|
||||||
|
1 => 'critical',
|
||||||
|
2 => 'high',
|
||||||
|
3 => 'medium',
|
||||||
|
];
|
||||||
|
|
||||||
|
private array $categoryMap = [];
|
||||||
|
|
||||||
|
/** @var array<int, int> servicedesk category id => servicedesk team id, only when unambiguous */
|
||||||
|
private array $teamByCategory = [];
|
||||||
|
|
||||||
|
/** @var array<int, string> Hesk help_users.id => name, loaded once */
|
||||||
|
private array $heskStaffNames = [];
|
||||||
|
|
||||||
|
private array $state = ['imported' => []];
|
||||||
|
|
||||||
|
private string $statePath;
|
||||||
|
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
if ($this->option('assign-teams')) {
|
||||||
|
return $this->runAssignTeams((bool) $this->option('commit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$domain = trim((string) $this->option('domain'), " \t\n\r\0\x0B@");
|
||||||
|
|
||||||
|
if ($domain === '') {
|
||||||
|
$this->error('Podaj --domain=twoja-domena.pl (bez @).');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$commit = (bool) $this->option('commit');
|
||||||
|
$limit = $this->option('limit') !== null ? (int) $this->option('limit') : null;
|
||||||
|
$includeUnmapped = (bool) $this->option('include-unmapped-categories');
|
||||||
|
$this->statePath = $this->option('state') ?: storage_path('app/hesk-import-state.json');
|
||||||
|
|
||||||
|
if (! $this->configureHeskConnection()) {
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->loadState();
|
||||||
|
$this->buildCategoryMap();
|
||||||
|
$this->buildTeamMap();
|
||||||
|
$this->loadHeskStaffNames();
|
||||||
|
|
||||||
|
$tickets = DB::connection('hesk')->table('help_tickets')
|
||||||
|
->where('email', 'like', '%@'.$domain)
|
||||||
|
->orderBy('id')
|
||||||
|
->when($limit, fn ($q) => $q->limit($limit))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->info(sprintf(
|
||||||
|
'%s tryb: %d zgłoszeń z Heska pasuje do domeny @%s (%d już zaimportowanych wcześniej, zostaną pominięte).',
|
||||||
|
$commit ? 'KOMMIT' : 'DRY-RUN',
|
||||||
|
$tickets->count(),
|
||||||
|
$domain,
|
||||||
|
$tickets->whereIn('id', $this->state['imported'])->count(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$stats = ['created' => 0, 'skipped' => 0, 'skipped_unmapped_category' => 0, 'failed' => 0, 'messages' => 0, 'customers_created' => 0];
|
||||||
|
$unmappedCategories = [];
|
||||||
|
|
||||||
|
$bar = $this->output->createProgressBar($tickets->count());
|
||||||
|
$bar->start();
|
||||||
|
|
||||||
|
foreach ($tickets as $heskTicket) {
|
||||||
|
$bar->advance();
|
||||||
|
|
||||||
|
if (in_array($heskTicket->id, $this->state['imported'], true)) {
|
||||||
|
$stats['skipped']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$categoryMapped = array_key_exists($heskTicket->category, $this->categoryMap);
|
||||||
|
|
||||||
|
if (! $categoryMapped && ! in_array($heskTicket->category, $unmappedCategories, true)) {
|
||||||
|
$unmappedCategories[] = $heskTicket->category;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: a Hesk category with no servicedesk equivalent means
|
||||||
|
// this ticket is skipped entirely rather than imported without
|
||||||
|
// a category — --include-unmapped-categories opts back in.
|
||||||
|
if (! $categoryMapped && ! $includeUnmapped) {
|
||||||
|
$stats['skipped_unmapped_category']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $commit) {
|
||||||
|
$stats['created']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::transaction(function () use ($heskTicket, &$stats) {
|
||||||
|
$this->importOneTicket($heskTicket, $stats);
|
||||||
|
});
|
||||||
|
$this->state['imported'][] = $heskTicket->id;
|
||||||
|
$this->saveState();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$stats['failed']++;
|
||||||
|
$this->newLine();
|
||||||
|
$this->error("Zgłoszenie Hesk #{$heskTicket->id} ({$heskTicket->trackid}) nie zostało zaimportowane: ".$e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bar->finish();
|
||||||
|
$this->newLine(2);
|
||||||
|
|
||||||
|
$this->table(['Miara', 'Wartość'], [
|
||||||
|
['Zgłoszenia utworzone', $stats['created']],
|
||||||
|
['Wiadomości/notatki utworzone', $stats['messages']],
|
||||||
|
['Nowe konta klientów', $stats['customers_created']],
|
||||||
|
['Pominięte (już zaimportowane)', $stats['skipped']],
|
||||||
|
['Pominięte (kategoria bez odpowiednika)', $stats['skipped_unmapped_category']],
|
||||||
|
['Błędy', $stats['failed']],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($unmappedCategories) {
|
||||||
|
$names = collect($unmappedCategories)
|
||||||
|
->map(fn ($id) => DB::connection('hesk')->table('help_categories')->where('id', $id)->value('name') ?? "id={$id}")
|
||||||
|
->implode(', ');
|
||||||
|
$action = $includeUnmapped ? 'zgłoszenia zaimportowane bez kategorii' : 'zgłoszenia POMINIĘTE — użyj --include-unmapped-categories, żeby jednak je zaimportować bez kategorii';
|
||||||
|
$this->warn("Kategorie Heska bez odpowiednika w servicedesk ({$action}): {$names}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $commit) {
|
||||||
|
$this->newLine();
|
||||||
|
$this->comment('To był dry-run — nic nie zostało zapisane. Uruchom ponownie z --commit, żeby faktycznie zaimportować.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function configureHeskConnection(): bool
|
||||||
|
{
|
||||||
|
$host = env('HESK_DB_HOST');
|
||||||
|
$port = env('HESK_DB_PORT', 3306);
|
||||||
|
$database = env('HESK_DB_DATABASE');
|
||||||
|
$username = env('HESK_DB_USERNAME');
|
||||||
|
$password = env('HESK_DB_PASSWORD');
|
||||||
|
|
||||||
|
if (! $host || ! $database || ! $username) {
|
||||||
|
$this->error('Brakuje HESK_DB_HOST / HESK_DB_DATABASE / HESK_DB_USERNAME w środowisku (patrz scripts/hesk-import/hesk-import.sh).');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Config::set('database.connections.hesk', [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => $host,
|
||||||
|
'port' => $port,
|
||||||
|
'database' => $database,
|
||||||
|
'username' => $username,
|
||||||
|
'password' => $password,
|
||||||
|
'charset' => 'utf8mb4',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
'options' => [PDO::ATTR_TIMEOUT => 10],
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::connection('hesk')->getPdo();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->error('Nie udało się połączyć z bazą Heska: '.$e->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hesk category name (normalized) -> servicedesk category id. Only
|
||||||
|
* exact (case/whitespace-insensitive) name matches are mapped; anything
|
||||||
|
* else is left uncategorized and reported at the end instead of guessed at.
|
||||||
|
*/
|
||||||
|
private function buildCategoryMap(): void
|
||||||
|
{
|
||||||
|
$ours = Category::query()->get()->keyBy(fn (Category $c) => $this->normalizeCategoryName($c->name));
|
||||||
|
|
||||||
|
foreach (DB::connection('hesk')->table('help_categories')->get() as $heskCategory) {
|
||||||
|
$match = $ours->get($this->normalizeCategoryName($heskCategory->name));
|
||||||
|
|
||||||
|
if ($match) {
|
||||||
|
$this->categoryMap[$heskCategory->id] = $match->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function normalizeCategoryName(string $name): string
|
||||||
|
{
|
||||||
|
return mb_strtolower(trim($name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* servicedesk category id -> servicedesk team id, only when every
|
||||||
|
* subcategory under that category belongs to the same single team (the
|
||||||
|
* existing team_subcategory routing — see TicketService::autoAssignTeam()
|
||||||
|
* for the same rule applied to normal in-app ticket creation, there scoped
|
||||||
|
* to a specific subcategory rather than a whole category). A category
|
||||||
|
* whose subcategories are split across more than one team is left
|
||||||
|
* unmapped rather than guessed at.
|
||||||
|
*/
|
||||||
|
private function buildTeamMap(): void
|
||||||
|
{
|
||||||
|
foreach (Category::query()->pluck('id') as $categoryId) {
|
||||||
|
$teamIds = Team::query()
|
||||||
|
->whereHas('subcategories', fn ($q) => $q->where('subcategories.category_id', $categoryId))
|
||||||
|
->pluck('id')
|
||||||
|
->unique();
|
||||||
|
|
||||||
|
if ($teamIds->count() === 1) {
|
||||||
|
$this->teamByCategory[$categoryId] = $teamIds->first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backfill mode (--assign-teams): sets team_id on tickets that already
|
||||||
|
* exist (from an earlier --commit run, before team assignment was added)
|
||||||
|
* and don't have one yet — doesn't import anything, doesn't touch the
|
||||||
|
* Hesk database at all.
|
||||||
|
*/
|
||||||
|
private function runAssignTeams(bool $commit): int
|
||||||
|
{
|
||||||
|
$this->buildTeamMap();
|
||||||
|
|
||||||
|
if (! $this->teamByCategory) {
|
||||||
|
$this->warn('Żadna kategoria nie ma jednoznacznie przypisanego zespołu (na podstawie podkategorii) — nie ma czego przypisać.');
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalUpdated = 0;
|
||||||
|
|
||||||
|
foreach ($this->teamByCategory as $categoryId => $teamId) {
|
||||||
|
$query = Ticket::query()->where('category_id', $categoryId)->whereNull('team_id');
|
||||||
|
$count = $query->count();
|
||||||
|
|
||||||
|
if ($count === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->line(sprintf(
|
||||||
|
'Kategoria "%s" -> zespół "%s": %d zgłoszeń%s',
|
||||||
|
Category::query()->find($categoryId)?->name ?? "id={$categoryId}",
|
||||||
|
Team::query()->find($teamId)?->name ?? "id={$teamId}",
|
||||||
|
$count,
|
||||||
|
$commit ? '' : ' (dry-run)',
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($commit) {
|
||||||
|
$query->update(['team_id' => $teamId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalUpdated += $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->newLine();
|
||||||
|
$this->info(($commit ? 'Zaktualizowano' : 'Do zaktualizowania').': '.$totalUpdated.' zgłoszeń.');
|
||||||
|
|
||||||
|
if (! $commit) {
|
||||||
|
$this->comment('To był dry-run — uruchom ponownie z --assign-teams --commit, żeby faktycznie zapisać.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadHeskStaffNames(): void
|
||||||
|
{
|
||||||
|
$this->heskStaffNames = DB::connection('hesk')->table('help_users')->pluck('name', 'id')->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function importOneTicket(object $heskTicket, array &$stats): void
|
||||||
|
{
|
||||||
|
$customer = $this->resolveCustomer($heskTicket->email, $heskTicket->name, $stats);
|
||||||
|
$categoryId = $this->categoryMap[$heskTicket->category] ?? null;
|
||||||
|
|
||||||
|
$ticket = Ticket::query()->create([
|
||||||
|
'number' => Ticket::nextNumber(),
|
||||||
|
'customer_id' => $customer->id,
|
||||||
|
'email' => $heskTicket->email,
|
||||||
|
'name' => $heskTicket->name ?: $heskTicket->email,
|
||||||
|
'category_id' => $categoryId,
|
||||||
|
'team_id' => $categoryId ? ($this->teamByCategory[$categoryId] ?? null) : null,
|
||||||
|
'subject' => $this->cleanText($heskTicket->subject) ?: '(bez tematu)',
|
||||||
|
'body' => $this->cleanText($heskTicket->message),
|
||||||
|
'status_key' => self::STATUS_MAP[(int) $heskTicket->status] ?? 'open',
|
||||||
|
'priority_key' => self::PRIORITY_MAP[(int) $heskTicket->priority] ?? 'medium',
|
||||||
|
'source' => 'hesk_import',
|
||||||
|
'last_customer_activity_at' => $heskTicket->lastchange,
|
||||||
|
'created_at' => $heskTicket->dt,
|
||||||
|
'updated_at' => $heskTicket->lastchange,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Ticket::booted() re-saves the row right after create() to stamp a
|
||||||
|
// checksum, which — being a normal Eloquent save() — stomps
|
||||||
|
// updated_at back to "now". Restore the historical value via the
|
||||||
|
// query builder so it bypasses Eloquent's timestamp handling.
|
||||||
|
DB::table('tickets')->where('id', $ticket->id)->update(['updated_at' => $heskTicket->lastchange]);
|
||||||
|
|
||||||
|
$opening = $ticket->messages()->create([
|
||||||
|
'author_name' => $heskTicket->name ?: $heskTicket->email,
|
||||||
|
'body' => $this->cleanText($heskTicket->message),
|
||||||
|
'created_at' => $heskTicket->dt,
|
||||||
|
'updated_at' => $heskTicket->dt,
|
||||||
|
]);
|
||||||
|
$opening->attachAuthor($customer->id, 'client');
|
||||||
|
$stats['messages']++;
|
||||||
|
|
||||||
|
foreach ($this->heskReplies($heskTicket->id) as $reply) {
|
||||||
|
$this->importReply($ticket, $reply, $customer, $stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->heskNotes($heskTicket->id) as $note) {
|
||||||
|
$this->importNote($ticket, $note, $stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stats['created']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function heskReplies(int $heskTicketId): Collection
|
||||||
|
{
|
||||||
|
return DB::connection('hesk')->table('help_replies')
|
||||||
|
->where('replyto', $heskTicketId)
|
||||||
|
->orderBy('dt')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function heskNotes(int $heskTicketId): Collection
|
||||||
|
{
|
||||||
|
return DB::connection('hesk')->table('help_notes')
|
||||||
|
->where('ticket', $heskTicketId)
|
||||||
|
->orderBy('dt')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function importReply(Ticket $ticket, object $reply, User $customer, array &$stats): void
|
||||||
|
{
|
||||||
|
$isStaff = (int) $reply->staffid > 0;
|
||||||
|
$authorName = $isStaff
|
||||||
|
? ($this->heskStaffNames[$reply->staffid] ?? 'Personel')
|
||||||
|
: ($reply->name ?: $customer->name);
|
||||||
|
|
||||||
|
$message = $ticket->messages()->create([
|
||||||
|
'author_name' => $authorName,
|
||||||
|
'body' => $this->cleanText($reply->message),
|
||||||
|
'created_at' => $reply->dt,
|
||||||
|
'updated_at' => $reply->dt,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Staff replies aren't linked to a real User (we deliberately don't
|
||||||
|
// create operator accounts for imported Hesk staff — see the
|
||||||
|
// migration script's design questions) — attachAuthor(null,
|
||||||
|
// 'operator') still tags the role/badge correctly via author_name.
|
||||||
|
$message->attachAuthor($isStaff ? null : $customer->id, $isStaff ? 'operator' : 'client');
|
||||||
|
$stats['messages']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function importNote(Ticket $ticket, object $note, array &$stats): void
|
||||||
|
{
|
||||||
|
$message = $ticket->messages()->create([
|
||||||
|
'author_name' => $this->heskStaffNames[$note->who] ?? 'Personel',
|
||||||
|
'internal' => true,
|
||||||
|
'body' => $this->cleanText($note->message),
|
||||||
|
'created_at' => $note->dt,
|
||||||
|
'updated_at' => $note->dt,
|
||||||
|
]);
|
||||||
|
$message->attachAuthor(null, 'operator');
|
||||||
|
$stats['messages']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds or creates the local client account for a Hesk requester e-mail.
|
||||||
|
* Reuses an existing account (e.g. the one real admin account, or one
|
||||||
|
* already created by an earlier ticket from the same person) rather than
|
||||||
|
* duplicating, and only ever adds the 'client' role — never removes
|
||||||
|
* whatever roles the account already had.
|
||||||
|
*/
|
||||||
|
private function resolveCustomer(string $email, ?string $name, array &$stats): User
|
||||||
|
{
|
||||||
|
$email = trim($email);
|
||||||
|
$user = User::query()->where('email', $email)->first();
|
||||||
|
|
||||||
|
if (! $user) {
|
||||||
|
$user = User::query()->create([
|
||||||
|
'name' => $name ?: $email,
|
||||||
|
'email' => $email,
|
||||||
|
'roles' => ['client'],
|
||||||
|
]);
|
||||||
|
$stats['customers_created']++;
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! in_array('client', $user->roles, true)) {
|
||||||
|
$user->roles = [...$user->roles, 'client'];
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hesk's "plain" message/subject columns still carry <br /> tags (and
|
||||||
|
* occasionally other inline HTML) from HTML-formatted source e-mails —
|
||||||
|
* this app renders ticket/message bodies as escaped plain text
|
||||||
|
* (white-space:pre-wrap), so raw tags would show up literally instead
|
||||||
|
* of as line breaks.
|
||||||
|
*/
|
||||||
|
private function cleanText(?string $value): string
|
||||||
|
{
|
||||||
|
if ($value === null || $value === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = preg_replace('/<br\s*\/?>/i', "\n", $value);
|
||||||
|
$text = strip_tags($text);
|
||||||
|
$text = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||||
|
|
||||||
|
return trim($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadState(): void
|
||||||
|
{
|
||||||
|
if (is_file($this->statePath)) {
|
||||||
|
$decoded = json_decode(file_get_contents($this->statePath), true);
|
||||||
|
$this->state = is_array($decoded) ? $decoded : $this->state;
|
||||||
|
$this->state['imported'] ??= [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function saveState(): void
|
||||||
|
{
|
||||||
|
$dir = dirname($this->statePath);
|
||||||
|
if (! is_dir($dir)) {
|
||||||
|
mkdir($dir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($this->statePath, json_encode($this->state));
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/app/Console/Commands/RunAiTicketAutomation.php
Normal file
35
src/app/Console/Commands/RunAiTicketAutomation.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\TicketAiSummaryService;
|
||||||
|
use App\Services\TicketAiTriageService;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class RunAiTicketAutomation extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'ai:run-ticket-automation';
|
||||||
|
|
||||||
|
protected $description = 'Run AI-driven ticket triage (categorize/prioritize new tickets) and refresh AI ticket summaries for the operator view';
|
||||||
|
|
||||||
|
public function handle(TicketAiTriageService $triage, TicketAiSummaryService $summary): int
|
||||||
|
{
|
||||||
|
$triageTotals = $triage->run();
|
||||||
|
$summaryTotals = $summary->run();
|
||||||
|
|
||||||
|
$this->info(sprintf(
|
||||||
|
'AI triage: scanned %d, changed %d, failed %d.',
|
||||||
|
$triageTotals['scanned'],
|
||||||
|
$triageTotals['changed'],
|
||||||
|
$triageTotals['failed'],
|
||||||
|
));
|
||||||
|
$this->info(sprintf(
|
||||||
|
'AI summaries: scanned %d, updated %d, failed %d.',
|
||||||
|
$summaryTotals['scanned'],
|
||||||
|
$summaryTotals['updated'],
|
||||||
|
$summaryTotals['failed'],
|
||||||
|
));
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/app/Jobs/GenerateTicketAiSummaryJob.php
Normal file
30
src/app/Jobs/GenerateTicketAiSummaryJob.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Services\TicketAiSummaryService;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deliberately NOT a queued job (no ShouldQueue) — this app's queue worker
|
||||||
|
* is optional infrastructure (see install.md), so anything pushed onto the
|
||||||
|
* `jobs` table has no guarantee of ever being picked up. Dispatched with
|
||||||
|
* ::dispatchAfterResponse() instead, which runs it in-process right after
|
||||||
|
* the triggering HTTP/console response is sent, needing no worker at all.
|
||||||
|
*/
|
||||||
|
class GenerateTicketAiSummaryJob
|
||||||
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
|
||||||
|
public function __construct(protected int $ticketId) {}
|
||||||
|
|
||||||
|
public function handle(TicketAiSummaryService $summary): void
|
||||||
|
{
|
||||||
|
$ticket = Ticket::find($this->ticketId);
|
||||||
|
|
||||||
|
if ($ticket) {
|
||||||
|
$summary->generateFor($ticket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/app/Ldap/AdUser.php
Normal file
18
src/app/Ldap/AdUser.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ldap;
|
||||||
|
|
||||||
|
use LdapRecord\Models\ActiveDirectory\User as ActiveDirectoryUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active Directory counterpart to LldapUser — same role (the LdapRecord
|
||||||
|
* model backing the 'users' auth provider), but for AD's schema instead of
|
||||||
|
* LLDAP/OpenLDAP's. AD user objects carry objectClass top/person/
|
||||||
|
* organizationalPerson/user (no inetOrgPerson/posixAccount/mailAccount, so
|
||||||
|
* LldapUser's object-class scope matches zero AD entries) and expose a
|
||||||
|
* binary objectGUID rather than entryUUID — both already handled correctly
|
||||||
|
* by LdapRecord's stock ActiveDirectory\User, so no overrides are needed
|
||||||
|
* here, only the swap in AppServiceProvider::applyLdapSettingsOverride()
|
||||||
|
* (driven by the ldap_directory_type setting).
|
||||||
|
*/
|
||||||
|
class AdUser extends ActiveDirectoryUser {}
|
||||||
@@ -17,8 +17,11 @@ use App\Models\Team;
|
|||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserField;
|
use App\Models\UserField;
|
||||||
|
use App\Services\AiClient;
|
||||||
use App\Services\BookStackClient;
|
use App\Services\BookStackClient;
|
||||||
|
use App\Services\BookStackContentTagger;
|
||||||
use App\Services\LdapUserProvisioner;
|
use App\Services\LdapUserProvisioner;
|
||||||
|
use App\Services\SnipeItClient;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -152,6 +155,32 @@ class Panel extends Component
|
|||||||
|
|
||||||
public ?string $bookstackTestMessage = null;
|
public ?string $bookstackTestMessage = null;
|
||||||
|
|
||||||
|
public ?array $bookstackTagResult = null;
|
||||||
|
|
||||||
|
public ?string $bookstackTagError = null;
|
||||||
|
|
||||||
|
public array $snipeitConfig = [];
|
||||||
|
|
||||||
|
public ?string $snipeitTestResult = null;
|
||||||
|
|
||||||
|
public ?string $snipeitTestMessage = null;
|
||||||
|
|
||||||
|
public array $aiConfig = [];
|
||||||
|
|
||||||
|
public ?string $aiTestResult = null;
|
||||||
|
|
||||||
|
public ?string $aiTestMessage = null;
|
||||||
|
|
||||||
|
public array $aiTriageConfig = [];
|
||||||
|
|
||||||
|
public bool $aiSummaryEnabled = false;
|
||||||
|
|
||||||
|
public bool $aiSummaryRegenerateOnMessage = false;
|
||||||
|
|
||||||
|
public string $aiSummaryPrompt = '';
|
||||||
|
|
||||||
|
public int $aiSummaryPromptVersion = 0;
|
||||||
|
|
||||||
// ---- generic pending-delete confirm ----
|
// ---- generic pending-delete confirm ----
|
||||||
public ?string $pendingDeleteType = null;
|
public ?string $pendingDeleteType = null;
|
||||||
|
|
||||||
@@ -179,10 +208,18 @@ class Panel extends Component
|
|||||||
'ticketNumberPrefix' => Settings::get('ticket_number_prefix'),
|
'ticketNumberPrefix' => Settings::get('ticket_number_prefix'),
|
||||||
'ticketNumberObfuscate' => Settings::bool('ticket_number_obfuscate'),
|
'ticketNumberObfuscate' => Settings::bool('ticket_number_obfuscate'),
|
||||||
'ticketNumberMinLength' => Settings::get('ticket_number_min_length'),
|
'ticketNumberMinLength' => Settings::get('ticket_number_min_length'),
|
||||||
|
'refreshTicketViewSeconds' => Settings::get('refresh_ticket_view_seconds'),
|
||||||
|
'refreshQueueSeconds' => Settings::get('refresh_queue_seconds'),
|
||||||
|
'refreshNotificationsSeconds' => Settings::get('refresh_notifications_seconds'),
|
||||||
|
'scheduleSlaCheckMinutes' => Settings::get('schedule_sla_check_minutes'),
|
||||||
|
'scheduleAutomationRulesMinutes' => Settings::get('schedule_automation_rules_minutes'),
|
||||||
|
'scheduleImapFetchMinutes' => Settings::get('schedule_imap_fetch_minutes'),
|
||||||
|
'scheduleAiAutomationMinutes' => Settings::get('schedule_ai_automation_minutes'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->ldapConfig = [
|
$this->ldapConfig = [
|
||||||
'enabled' => Settings::bool('ldap_enabled'),
|
'enabled' => Settings::bool('ldap_enabled'),
|
||||||
|
'directoryType' => Settings::get('ldap_directory_type', 'lldap'),
|
||||||
'host' => Settings::get('ldap_host'),
|
'host' => Settings::get('ldap_host'),
|
||||||
'port' => Settings::get('ldap_port'),
|
'port' => Settings::get('ldap_port'),
|
||||||
'baseDn' => Settings::get('ldap_base_dn'),
|
'baseDn' => Settings::get('ldap_base_dn'),
|
||||||
@@ -202,10 +239,41 @@ class Panel extends Component
|
|||||||
'tokenSecret' => Settings::get('bookstack_token_secret'),
|
'tokenSecret' => Settings::get('bookstack_token_secret'),
|
||||||
'verifySsl' => Settings::bool('bookstack_verify_ssl'),
|
'verifySsl' => Settings::bool('bookstack_verify_ssl'),
|
||||||
'showToGuests' => Settings::bool('bookstack_show_to_guests'),
|
'showToGuests' => Settings::bool('bookstack_show_to_guests'),
|
||||||
'searchTypes' => Settings::get('bookstack_search_types', 'both'),
|
'searchTypes' => BookStackClient::normalizeSearchTypes(Settings::get('bookstack_search_types', '')),
|
||||||
|
'searchBy' => in_array($searchBy = Settings::get('bookstack_search_by', 'both'), BookStackClient::SEARCH_BY_OPTIONS, true) ? $searchBy : 'both',
|
||||||
'allowedShelfIdsCreation' => $this->parseShelfIds(Settings::get('bookstack_allowed_shelf_ids_creation', '')),
|
'allowedShelfIdsCreation' => $this->parseShelfIds(Settings::get('bookstack_allowed_shelf_ids_creation', '')),
|
||||||
'allowedShelfIdsTicketView' => $this->parseShelfIds(Settings::get('bookstack_allowed_shelf_ids_ticket_view', '')),
|
'allowedShelfIdsTicketView' => $this->parseShelfIds(Settings::get('bookstack_allowed_shelf_ids_ticket_view', '')),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$this->snipeitConfig = [
|
||||||
|
'enabled' => Settings::bool('snipeit_enabled'),
|
||||||
|
'baseUrl' => Settings::get('snipeit_base_url'),
|
||||||
|
'apiToken' => Settings::get('snipeit_api_token'),
|
||||||
|
'skipSslVerification' => ! Settings::bool('snipeit_verify_ssl'),
|
||||||
|
'clientCanSelectAsset' => Settings::bool('snipeit_client_can_select_asset'),
|
||||||
|
'clientAssetSubcategoryIds' => $this->parseShelfIds(Settings::get('snipeit_client_asset_subcategory_ids', '')),
|
||||||
|
'operatorViewRequesterAssets' => Settings::bool('snipeit_operator_view_requester_assets'),
|
||||||
|
'operatorSearchInventory' => Settings::bool('snipeit_operator_search_inventory'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->aiConfig = [
|
||||||
|
'enabled' => Settings::bool('ai_enabled'),
|
||||||
|
'baseUrl' => Settings::get('ai_base_url'),
|
||||||
|
'apiKey' => Settings::get('ai_api_key'),
|
||||||
|
'model' => Settings::get('ai_model'),
|
||||||
|
'verifySsl' => Settings::bool('ai_verify_ssl'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->aiTriageConfig = [
|
||||||
|
'categoryWhenMissing' => Settings::bool('ai_triage_category_when_missing'),
|
||||||
|
'subcategoryWhenCategoryOnly' => Settings::bool('ai_triage_subcategory_when_category_only'),
|
||||||
|
'recheckCategorized' => Settings::bool('ai_triage_recheck_categorized'),
|
||||||
|
'fixSubject' => Settings::bool('ai_triage_fix_subject'),
|
||||||
|
'setPriority' => Settings::bool('ai_triage_set_priority'),
|
||||||
|
];
|
||||||
|
$this->aiSummaryEnabled = Settings::bool('ai_summary_enabled');
|
||||||
|
$this->aiSummaryRegenerateOnMessage = Settings::bool('ai_summary_regenerate_on_message');
|
||||||
|
$this->aiSummaryPrompt = Settings::get('ai_summary_prompt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTab(string $tab): void
|
public function setTab(string $tab): void
|
||||||
@@ -270,10 +338,55 @@ class Panel extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Category::query()->find($categoryId)?->subcategories()->create(['name' => $name]);
|
$category = Category::query()->find($categoryId);
|
||||||
|
|
||||||
|
if (! $category) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextPosition = ((int) $category->subcategories()->max('sort_order')) + 1;
|
||||||
|
$category->subcategories()->create(['name' => $name, 'sort_order' => $nextPosition]);
|
||||||
$this->newSubNames[$categoryId] = '';
|
$this->newSubNames[$categoryId] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function moveSubcategoryUp(int $subcategoryId): void
|
||||||
|
{
|
||||||
|
$this->swapSubcategoryOrder($subcategoryId, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function moveSubcategoryDown(int $subcategoryId): void
|
||||||
|
{
|
||||||
|
$this->swapSubcategoryOrder($subcategoryId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function swapSubcategoryOrder(int $subcategoryId, int $direction): void
|
||||||
|
{
|
||||||
|
$sub = Subcategory::query()->find($subcategoryId);
|
||||||
|
|
||||||
|
if (! $sub) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$siblings = Subcategory::query()
|
||||||
|
->where('category_id', $sub->category_id)
|
||||||
|
->orderBy('sort_order')
|
||||||
|
->orderBy('id')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$idx = $siblings->search(fn (Subcategory $s) => $s->id === $sub->id);
|
||||||
|
$swapIdx = $idx + $direction;
|
||||||
|
|
||||||
|
if ($idx === false || $swapIdx < 0 || $swapIdx >= $siblings->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$other = $siblings[$swapIdx];
|
||||||
|
[$order, $otherOrder] = [$sub->sort_order, $other->sort_order];
|
||||||
|
|
||||||
|
$sub->update(['sort_order' => $otherOrder]);
|
||||||
|
$other->update(['sort_order' => $order]);
|
||||||
|
}
|
||||||
|
|
||||||
public function openSubcategoryEditForm(int $subcategoryId): void
|
public function openSubcategoryEditForm(int $subcategoryId): void
|
||||||
{
|
{
|
||||||
$sub = Subcategory::query()->with('customFields')->findOrFail($subcategoryId);
|
$sub = Subcategory::query()->with('customFields')->findOrFail($subcategoryId);
|
||||||
@@ -1348,6 +1461,14 @@ class Panel extends Component
|
|||||||
Settings::set('ticket_number_prefix', trim((string) $this->systemConfig['ticketNumberPrefix']));
|
Settings::set('ticket_number_prefix', trim((string) $this->systemConfig['ticketNumberPrefix']));
|
||||||
Settings::set('ticket_number_obfuscate', $this->systemConfig['ticketNumberObfuscate'] ? '1' : '0');
|
Settings::set('ticket_number_obfuscate', $this->systemConfig['ticketNumberObfuscate'] ? '1' : '0');
|
||||||
Settings::set('ticket_number_min_length', (string) max(1, (int) $this->systemConfig['ticketNumberMinLength']));
|
Settings::set('ticket_number_min_length', (string) max(1, (int) $this->systemConfig['ticketNumberMinLength']));
|
||||||
|
|
||||||
|
Settings::set('refresh_ticket_view_seconds', (string) max(1, (int) $this->systemConfig['refreshTicketViewSeconds']));
|
||||||
|
Settings::set('refresh_queue_seconds', (string) max(1, (int) $this->systemConfig['refreshQueueSeconds']));
|
||||||
|
Settings::set('refresh_notifications_seconds', (string) max(1, (int) $this->systemConfig['refreshNotificationsSeconds']));
|
||||||
|
Settings::set('schedule_sla_check_minutes', (string) max(1, (int) $this->systemConfig['scheduleSlaCheckMinutes']));
|
||||||
|
Settings::set('schedule_automation_rules_minutes', (string) max(1, (int) $this->systemConfig['scheduleAutomationRulesMinutes']));
|
||||||
|
Settings::set('schedule_imap_fetch_minutes', (string) max(1, (int) $this->systemConfig['scheduleImapFetchMinutes']));
|
||||||
|
Settings::set('schedule_ai_automation_minutes', (string) max(1, (int) $this->systemConfig['scheduleAiAutomationMinutes']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1378,6 +1499,7 @@ class Panel extends Component
|
|||||||
public function saveLdapConfig(): void
|
public function saveLdapConfig(): void
|
||||||
{
|
{
|
||||||
Settings::set('ldap_enabled', $this->ldapConfig['enabled'] ? '1' : '0');
|
Settings::set('ldap_enabled', $this->ldapConfig['enabled'] ? '1' : '0');
|
||||||
|
Settings::set('ldap_directory_type', $this->ldapConfig['directoryType'] === 'ad' ? 'ad' : 'lldap');
|
||||||
Settings::set('ldap_host', $this->ldapConfig['host']);
|
Settings::set('ldap_host', $this->ldapConfig['host']);
|
||||||
Settings::set('ldap_port', (string) $this->ldapConfig['port']);
|
Settings::set('ldap_port', (string) $this->ldapConfig['port']);
|
||||||
Settings::set('ldap_base_dn', $this->ldapConfig['baseDn']);
|
Settings::set('ldap_base_dn', $this->ldapConfig['baseDn']);
|
||||||
@@ -1439,8 +1561,10 @@ class Panel extends Component
|
|||||||
Settings::set('bookstack_verify_ssl', $this->bookstackConfig['verifySsl'] ? '1' : '0');
|
Settings::set('bookstack_verify_ssl', $this->bookstackConfig['verifySsl'] ? '1' : '0');
|
||||||
Settings::set('bookstack_show_to_guests', $this->bookstackConfig['showToGuests'] ? '1' : '0');
|
Settings::set('bookstack_show_to_guests', $this->bookstackConfig['showToGuests'] ? '1' : '0');
|
||||||
|
|
||||||
if (in_array($this->bookstackConfig['searchTypes'], ['both', 'page', 'book'], true)) {
|
Settings::set('bookstack_search_types', implode(',', BookStackClient::normalizeSearchTypes($this->bookstackConfig['searchTypes'])));
|
||||||
Settings::set('bookstack_search_types', $this->bookstackConfig['searchTypes']);
|
|
||||||
|
if (in_array($this->bookstackConfig['searchBy'], BookStackClient::SEARCH_BY_OPTIONS, true)) {
|
||||||
|
Settings::set('bookstack_search_by', $this->bookstackConfig['searchBy']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::set('bookstack_allowed_shelf_ids_creation', implode(',', $this->bookstackConfig['allowedShelfIdsCreation']));
|
Settings::set('bookstack_allowed_shelf_ids_creation', implode(',', $this->bookstackConfig['allowedShelfIdsCreation']));
|
||||||
@@ -1490,6 +1614,15 @@ class Panel extends Component
|
|||||||
: [...$ids, $id];
|
: [...$ids, $id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toggleBookstackSearchType(string $type): void
|
||||||
|
{
|
||||||
|
$types = $this->bookstackConfig['searchTypes'];
|
||||||
|
|
||||||
|
$this->bookstackConfig['searchTypes'] = in_array($type, $types, true)
|
||||||
|
? array_values(array_diff($types, [$type]))
|
||||||
|
: [...$types, $type];
|
||||||
|
}
|
||||||
|
|
||||||
public function testBookstackConnection(): void
|
public function testBookstackConnection(): void
|
||||||
{
|
{
|
||||||
$cfg = $this->bookstackConfig;
|
$cfg = $this->bookstackConfig;
|
||||||
@@ -1508,6 +1641,142 @@ class Panel extends Component
|
|||||||
$this->bookstackTestMessage = $result['message'];
|
$this->bookstackTestMessage = $result['message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs synchronously in the request (no queue worker runs in this
|
||||||
|
* deployment — see CLAUDE.md — so a dispatched job would just sit in the
|
||||||
|
* `jobs` table). Safe to click again if it times out on a large wiki:
|
||||||
|
* every write is idempotent, so a re-run just skips whatever already got
|
||||||
|
* tagged (or, for the --force variant, re-classifies from scratch).
|
||||||
|
*/
|
||||||
|
public function runBookstackTagging(bool $force = false): void
|
||||||
|
{
|
||||||
|
if (! app(BookStackClient::class)->enabled() || ! app(AiClient::class)->enabled()) {
|
||||||
|
$this->bookstackTagResult = null;
|
||||||
|
$this->bookstackTagError = 'Włącz i skonfiguruj obie integracje — BookStack oraz AI — przed uruchomieniem tagowania.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->bookstackTagError = null;
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
|
$this->bookstackTagResult = app(BookStackContentTagger::class)->run(force: $force);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function runBookstackTaggingForce(): void
|
||||||
|
{
|
||||||
|
$this->runBookstackTagging(force: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== SNIPE-IT CONFIG =====================
|
||||||
|
|
||||||
|
public function saveSnipeitConfig(): void
|
||||||
|
{
|
||||||
|
Settings::set('snipeit_enabled', $this->snipeitConfig['enabled'] ? '1' : '0');
|
||||||
|
Settings::set('snipeit_base_url', $this->snipeitConfig['baseUrl']);
|
||||||
|
|
||||||
|
if ($this->snipeitConfig['apiToken']) {
|
||||||
|
Settings::set('snipeit_api_token', $this->snipeitConfig['apiToken']);
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::set('snipeit_verify_ssl', $this->snipeitConfig['skipSslVerification'] ? '0' : '1');
|
||||||
|
Settings::set('snipeit_client_can_select_asset', $this->snipeitConfig['clientCanSelectAsset'] ? '1' : '0');
|
||||||
|
Settings::set('snipeit_client_asset_subcategory_ids', implode(',', $this->snipeitConfig['clientAssetSubcategoryIds']));
|
||||||
|
Settings::set('snipeit_operator_view_requester_assets', $this->snipeitConfig['operatorViewRequesterAssets'] ? '1' : '0');
|
||||||
|
Settings::set('snipeit_operator_search_inventory', $this->snipeitConfig['operatorSearchInventory'] ? '1' : '0');
|
||||||
|
|
||||||
|
$this->snipeitTestResult = null;
|
||||||
|
$this->snipeitTestMessage = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleSnipeitClientSubcategory(int $id): void
|
||||||
|
{
|
||||||
|
$ids = $this->snipeitConfig['clientAssetSubcategoryIds'];
|
||||||
|
|
||||||
|
$this->snipeitConfig['clientAssetSubcategoryIds'] = in_array($id, $ids, true)
|
||||||
|
? array_values(array_diff($ids, [$id]))
|
||||||
|
: [...$ids, $id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSnipeitConnection(): void
|
||||||
|
{
|
||||||
|
$cfg = $this->snipeitConfig;
|
||||||
|
|
||||||
|
if (empty($cfg['baseUrl'])) {
|
||||||
|
$this->snipeitTestResult = 'error';
|
||||||
|
$this->snipeitTestMessage = 'Uzupełnij adres API.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = $cfg['apiToken'] ?: Settings::get('snipeit_api_token');
|
||||||
|
$result = app(SnipeItClient::class)->testConnection($cfg['baseUrl'], $token ?? '', ! $cfg['skipSslVerification']);
|
||||||
|
|
||||||
|
$this->snipeitTestResult = $result['ok'] ? 'ok' : 'error';
|
||||||
|
$this->snipeitTestMessage = $result['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== AI CONFIG =====================
|
||||||
|
|
||||||
|
public function saveAiConfig(): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_enabled', $this->aiConfig['enabled'] ? '1' : '0');
|
||||||
|
Settings::set('ai_base_url', $this->aiConfig['baseUrl']);
|
||||||
|
|
||||||
|
if ($this->aiConfig['apiKey']) {
|
||||||
|
Settings::set('ai_api_key', $this->aiConfig['apiKey']);
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::set('ai_model', $this->aiConfig['model']);
|
||||||
|
Settings::set('ai_verify_ssl', $this->aiConfig['verifySsl'] ? '1' : '0');
|
||||||
|
|
||||||
|
$this->aiTestResult = null;
|
||||||
|
$this->aiTestMessage = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAiConnection(): void
|
||||||
|
{
|
||||||
|
$cfg = $this->aiConfig;
|
||||||
|
|
||||||
|
if (empty($cfg['baseUrl']) || empty($cfg['model'])) {
|
||||||
|
$this->aiTestResult = 'error';
|
||||||
|
$this->aiTestMessage = 'Uzupełnij adres API i nazwę modelu.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiKey = $cfg['apiKey'] ?: Settings::get('ai_api_key');
|
||||||
|
$result = app(AiClient::class)->testConnection($cfg['baseUrl'], $apiKey ?? '', $cfg['model'], (bool) $cfg['verifySsl']);
|
||||||
|
|
||||||
|
$this->aiTestResult = $result['ok'] ? 'ok' : 'error';
|
||||||
|
$this->aiTestMessage = $result['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveAiTriageConfig(): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_triage_category_when_missing', $this->aiTriageConfig['categoryWhenMissing'] ? '1' : '0');
|
||||||
|
Settings::set('ai_triage_subcategory_when_category_only', $this->aiTriageConfig['subcategoryWhenCategoryOnly'] ? '1' : '0');
|
||||||
|
Settings::set('ai_triage_recheck_categorized', $this->aiTriageConfig['recheckCategorized'] ? '1' : '0');
|
||||||
|
Settings::set('ai_triage_fix_subject', $this->aiTriageConfig['fixSubject'] ? '1' : '0');
|
||||||
|
Settings::set('ai_triage_set_priority', $this->aiTriageConfig['setPriority'] ? '1' : '0');
|
||||||
|
Settings::set('ai_summary_enabled', $this->aiSummaryEnabled ? '1' : '0');
|
||||||
|
Settings::set('ai_summary_regenerate_on_message', $this->aiSummaryRegenerateOnMessage ? '1' : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveAiSummaryPrompt(string $value): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_summary_prompt', $value);
|
||||||
|
$this->aiSummaryPrompt = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetAiSummaryPrompt(): void
|
||||||
|
{
|
||||||
|
$default = Settings::default('ai_summary_prompt');
|
||||||
|
Settings::set('ai_summary_prompt', $default);
|
||||||
|
$this->aiSummaryPrompt = $default;
|
||||||
|
$this->aiSummaryPromptVersion++;
|
||||||
|
}
|
||||||
|
|
||||||
// ===================== GENERIC DELETE CONFIRM =====================
|
// ===================== GENERIC DELETE CONFIRM =====================
|
||||||
|
|
||||||
public function requestDelete(string $type, mixed $id, string $message): void
|
public function requestDelete(string $type, mixed $id, string $message): void
|
||||||
@@ -1547,8 +1816,37 @@ class Panel extends Component
|
|||||||
$this->cancelPendingDelete();
|
$this->cancelPendingDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrors the labels in the $tabGroups array built inline in
|
||||||
|
* admin/panel.blade.php (icons/grouping live only there — this is just
|
||||||
|
* the page-title-sized subset, not worth threading the whole structure
|
||||||
|
* through the PHP side for).
|
||||||
|
*/
|
||||||
|
private const TAB_LABELS = [
|
||||||
|
'categories' => 'Kategorie',
|
||||||
|
'fields' => 'Pola dodatkowe',
|
||||||
|
'statuses' => 'Statusy',
|
||||||
|
'priorities' => 'Priorytety i SLA',
|
||||||
|
'reply-quick-actions' => 'Szybkie akcje odpowiedzi',
|
||||||
|
'response-templates' => 'Szablony odpowiedzi',
|
||||||
|
'automation-rules' => 'Automatyzacja SLA',
|
||||||
|
'triggers' => 'Wyzwalacze',
|
||||||
|
'users' => 'Użytkownicy',
|
||||||
|
'teams' => 'Zespoły',
|
||||||
|
'user-fields' => 'Pola dodatkowe',
|
||||||
|
'templates' => 'Szablony e-mail',
|
||||||
|
'email' => 'Poczta',
|
||||||
|
'branding' => 'Wygląd i branding',
|
||||||
|
'config' => 'Konfiguracja',
|
||||||
|
'integrations' => 'Integracje',
|
||||||
|
'api-keys' => 'Klucze API',
|
||||||
|
'about' => 'O aplikacji',
|
||||||
|
];
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.admin.panel');
|
$tabLabel = self::TAB_LABELS[$this->tab] ?? 'Panel administratora';
|
||||||
|
|
||||||
|
return view('livewire.admin.panel')->title(Settings::pageTitle($tabLabel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,6 @@ class Login extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.auth.login');
|
return view('livewire.auth.login')->title(Settings::pageTitle('Logowanie'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,36 +3,52 @@
|
|||||||
namespace App\Livewire\Client;
|
namespace App\Livewire\Client;
|
||||||
|
|
||||||
use App\Models\Status;
|
use App\Models\Status;
|
||||||
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
class Dashboard extends Component
|
class Dashboard extends Component
|
||||||
{
|
{
|
||||||
|
use WithPagination;
|
||||||
|
|
||||||
|
private const PER_PAGE = 20;
|
||||||
|
|
||||||
public string $tab = 'current';
|
public string $tab = 'current';
|
||||||
|
|
||||||
public string $search = '';
|
public string $search = '';
|
||||||
|
|
||||||
#[Computed]
|
protected function baseQuery()
|
||||||
public function tickets()
|
|
||||||
{
|
{
|
||||||
return Auth::user()->ticketsAsCustomer()
|
return Auth::user()->ticketsAsCustomer()
|
||||||
->search($this->search)
|
->search($this->search)
|
||||||
->with('subcategory.category')
|
->with('subcategory.category')
|
||||||
->orderByDesc('updated_at')
|
->orderByDesc('updated_at');
|
||||||
->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separate named paginators (see pageName below) so switching tabs
|
||||||
|
* doesn't reset whichever page the other tab was on.
|
||||||
|
*/
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function currentTickets()
|
public function currentTickets()
|
||||||
{
|
{
|
||||||
return $this->tickets->whereNotIn('status_key', Status::closedKeys());
|
return $this->baseQuery()->whereNotIn('status_key', Status::closedKeys())
|
||||||
|
->paginate(self::PER_PAGE, pageName: 'currentPage');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function archiveTickets()
|
public function archiveTickets()
|
||||||
{
|
{
|
||||||
return $this->tickets->whereIn('status_key', Status::closedKeys());
|
return $this->baseQuery()->whereIn('status_key', Status::closedKeys())
|
||||||
|
->paginate(self::PER_PAGE, pageName: 'archivePage');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedSearch(): void
|
||||||
|
{
|
||||||
|
$this->resetPage('currentPage');
|
||||||
|
$this->resetPage('archivePage');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTab(string $tab): void
|
public function setTab(string $tab): void
|
||||||
@@ -42,6 +58,6 @@ class Dashboard extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.client.dashboard');
|
return view('livewire.client.dashboard')->title(Settings::pageTitle('Moje zgłoszenia'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Livewire\Client;
|
|||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\Subcategory;
|
use App\Models\Subcategory;
|
||||||
use App\Services\BookStackClient;
|
use App\Services\BookStackClient;
|
||||||
|
use App\Services\SnipeItClient;
|
||||||
use App\Services\TicketService;
|
use App\Services\TicketService;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -40,6 +41,61 @@ class NewTicket extends Component
|
|||||||
$this->suggestedArticlesLoaded = true;
|
$this->suggestedArticlesLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same wire:init-deferred pattern as suggestedArticlesLoaded above,
|
||||||
|
// for the Snipe-IT "Twój sprzęt" picker.
|
||||||
|
public bool $snipeitAssetsLoaded = false;
|
||||||
|
|
||||||
|
public ?int $selectedSnipeitAssetId = null;
|
||||||
|
|
||||||
|
public function loadSnipeitAssets(): void
|
||||||
|
{
|
||||||
|
$this->snipeitAssetsLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty unless the admin turned the picker on AND allow-listed the
|
||||||
|
* currently selected subcategory for it (see
|
||||||
|
* snipeit_client_asset_subcategory_ids) — an empty allow-list means
|
||||||
|
* "no subcategory", not "every subcategory", mirroring how BookStack's
|
||||||
|
* shelf allow-lists work.
|
||||||
|
*
|
||||||
|
* @return array<int, array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, url: string}>
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function snipeitAssets(): array
|
||||||
|
{
|
||||||
|
if (! $this->snipeitAssetsLoaded || ! Settings::bool('snipeit_client_can_select_asset') || ! $this->subcategoryId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! in_array($this->subcategoryId, $this->snipeitAllowedSubcategoryIds(), true)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return app(SnipeItClient::class)->assetsForEmail(Auth::user()->email);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int[]
|
||||||
|
*/
|
||||||
|
protected function snipeitAllowedSubcategoryIds(): array
|
||||||
|
{
|
||||||
|
return collect(explode(',', Settings::get('snipeit_client_asset_subcategory_ids', '')))
|
||||||
|
->map(fn ($v) => (int) trim($v))
|
||||||
|
->filter()
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectSnipeitAsset(int $id): void
|
||||||
|
{
|
||||||
|
if (! Settings::bool('snipeit_client_can_select_asset')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->selectedSnipeitAssetId = $this->selectedSnipeitAssetId === $id ? null : $id;
|
||||||
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function categories()
|
public function categories()
|
||||||
{
|
{
|
||||||
@@ -62,12 +118,14 @@ class NewTicket extends Component
|
|||||||
{
|
{
|
||||||
$this->categoryId = $id;
|
$this->categoryId = $id;
|
||||||
$this->subcategoryId = null;
|
$this->subcategoryId = null;
|
||||||
|
$this->selectedSnipeitAssetId = null;
|
||||||
$this->step = 2;
|
$this->step = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectSubcategory(int $id): void
|
public function selectSubcategory(int $id): void
|
||||||
{
|
{
|
||||||
$this->subcategoryId = $id;
|
$this->subcategoryId = $id;
|
||||||
|
$this->selectedSnipeitAssetId = null;
|
||||||
$this->step = 3;
|
$this->step = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +140,9 @@ class NewTicket extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
||||||
|
$tagQuery = trim($this->selectedSubcategory?->name ?? '');
|
||||||
|
|
||||||
return app(BookStackClient::class)->search($query);
|
return app(BookStackClient::class)->search($query, tagQuery: $tagQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backToCategory(): void
|
public function backToCategory(): void
|
||||||
@@ -129,12 +188,18 @@ class NewTicket extends Component
|
|||||||
|
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$selectedAsset = $this->selectedSnipeitAssetId
|
||||||
|
? collect($this->snipeitAssets)->firstWhere('id', $this->selectedSnipeitAssetId)
|
||||||
|
: null;
|
||||||
|
|
||||||
$ticket = app(TicketService::class)->create([
|
$ticket = app(TicketService::class)->create([
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
'subcategory_id' => $this->subcategoryId,
|
'subcategory_id' => $this->subcategoryId,
|
||||||
'subject' => $this->subject,
|
'subject' => $this->subject,
|
||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
'custom_values' => $this->customValues,
|
'custom_values' => $this->customValues,
|
||||||
|
'snipeit_asset_id' => $selectedAsset['id'] ?? null,
|
||||||
|
'snipeit_asset_name' => $selectedAsset['label'] ?? null,
|
||||||
], $user);
|
], $user);
|
||||||
|
|
||||||
app(TicketService::class)->attachFiles($ticket, $ticket->messages()->first(), $this->attachments);
|
app(TicketService::class)->attachFiles($ticket, $ticket->messages()->first(), $this->attachments);
|
||||||
@@ -144,6 +209,6 @@ class NewTicket extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.client.new-ticket');
|
return view('livewire.client.new-ticket')->title(Settings::pageTitle('Nowe zgłoszenie'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class TicketShow extends Component
|
|||||||
|
|
||||||
public string $csatComment = '';
|
public string $csatComment = '';
|
||||||
|
|
||||||
|
public bool $showAllOtherTickets = false;
|
||||||
|
|
||||||
|
private const OTHER_TICKETS_PREVIEW_COUNT = 5;
|
||||||
|
|
||||||
// Set via wire:init (see the blade view) rather than on the initial
|
// Set via wire:init (see the blade view) rather than on the initial
|
||||||
// render, so the BookStack HTTP call in suggestedArticles() never
|
// render, so the BookStack HTTP call in suggestedArticles() never
|
||||||
// delays the ticket page's first paint — it loads in a beat later instead.
|
// delays the ticket page's first paint — it loads in a beat later instead.
|
||||||
@@ -103,7 +107,21 @@ class TicketShow extends Component
|
|||||||
#[Computed]
|
#[Computed]
|
||||||
public function otherTickets()
|
public function otherTickets()
|
||||||
{
|
{
|
||||||
return Auth::user()->ticketsAsCustomer()->where('id', '!=', $this->ticket->id)->get();
|
$query = Auth::user()->ticketsAsCustomer()->where('id', '!=', $this->ticket->id)->latest();
|
||||||
|
|
||||||
|
return $this->showAllOtherTickets ? $query->get() : $query->take(self::OTHER_TICKETS_PREVIEW_COUNT)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function otherTicketsCount(): int
|
||||||
|
{
|
||||||
|
return Auth::user()->ticketsAsCustomer()->where('id', '!=', $this->ticket->id)->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revealAllOtherTickets(): void
|
||||||
|
{
|
||||||
|
$this->showAllOtherTickets = true;
|
||||||
|
unset($this->otherTickets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,8 +140,9 @@ class TicketShow extends Component
|
|||||||
|
|
||||||
$subcategory = $this->ticket->subcategory;
|
$subcategory = $this->ticket->subcategory;
|
||||||
$query = trim(($subcategory?->category?->name ?? '').' '.($subcategory?->name ?? ''));
|
$query = trim(($subcategory?->category?->name ?? '').' '.($subcategory?->name ?? ''));
|
||||||
|
$tagQuery = trim($subcategory?->name ?? '');
|
||||||
|
|
||||||
return app(BookStackClient::class)->search($query);
|
return app(BookStackClient::class)->search($query, tagQuery: $tagQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatedAttachments(): void
|
public function updatedAttachments(): void
|
||||||
@@ -221,6 +240,6 @@ class TicketShow extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.client.ticket-show');
|
return view('livewire.client.ticket-show')->title(Settings::pageTitle($this->ticket->displayNumber().' — '.$this->ticket->subject));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
141
src/app/Livewire/GlobalSearch.php
Normal file
141
src/app/Livewire/GlobalSearch.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class GlobalSearch extends Component
|
||||||
|
{
|
||||||
|
public string $search = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gmail-style "field:value" operators — recognized keys (accent-
|
||||||
|
* insensitive, a couple of Polish synonyms each) narrow the match to
|
||||||
|
* that one field; anything left over after stripping them still runs
|
||||||
|
* through the broad Ticket::scopeSearch() default. Multiple operators
|
||||||
|
* combine with AND, same as Gmail's "from:x subject:y".
|
||||||
|
*/
|
||||||
|
private const FIELD_PREFIXES = [
|
||||||
|
'od' => 'from',
|
||||||
|
'nadawca' => 'from',
|
||||||
|
'temat' => 'subject',
|
||||||
|
'tytul' => 'subject',
|
||||||
|
'tytuł' => 'subject',
|
||||||
|
'tresc' => 'body',
|
||||||
|
'treść' => 'body',
|
||||||
|
'numer' => 'number',
|
||||||
|
'nr' => 'number',
|
||||||
|
];
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function results()
|
||||||
|
{
|
||||||
|
$term = trim($this->search);
|
||||||
|
|
||||||
|
if ($term === '' || ! ($user = Auth::user())) {
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->baseQuery($user);
|
||||||
|
|
||||||
|
if (! $query) {
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
[$fields, $free] = $this->parseQuery($term);
|
||||||
|
|
||||||
|
foreach ($fields as $field => $values) {
|
||||||
|
foreach ($values as $value) {
|
||||||
|
$this->applyFieldFilter($query, $field, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// search() itself no-ops on an empty term, so this is safe to call
|
||||||
|
// unconditionally — it only matters when there was no operator at
|
||||||
|
// all, or an operator left some free text behind.
|
||||||
|
$query->search($free);
|
||||||
|
|
||||||
|
return $query->orderByDesc('updated_at')->limit(8)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits "od:kacper temat:drukarka reszta" into recognized field
|
||||||
|
* operators plus whatever free text is left over. An unrecognized
|
||||||
|
* "key:value" (e.g. a pasted URL) is left untouched in the free text
|
||||||
|
* rather than silently dropped.
|
||||||
|
*/
|
||||||
|
private function parseQuery(string $term): array
|
||||||
|
{
|
||||||
|
$fields = [];
|
||||||
|
|
||||||
|
$free = preg_replace_callback(
|
||||||
|
'/(\pL+):(\S+)/u',
|
||||||
|
function ($m) use (&$fields) {
|
||||||
|
$key = mb_strtolower($m[1]);
|
||||||
|
|
||||||
|
if (! isset(self::FIELD_PREFIXES[$key])) {
|
||||||
|
return $m[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields[self::FIELD_PREFIXES[$key]][] = $m[2];
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
$term
|
||||||
|
);
|
||||||
|
|
||||||
|
return [$fields, trim(preg_replace('/\s+/', ' ', $free))];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function applyFieldFilter($query, string $field, string $value): void
|
||||||
|
{
|
||||||
|
$like = '%'.$value.'%';
|
||||||
|
|
||||||
|
match ($field) {
|
||||||
|
'from' => $query->where(fn ($q) => $q->where('name', 'like', $like)->orWhere('email', 'like', $like)),
|
||||||
|
'subject' => $query->where('subject', 'like', $like),
|
||||||
|
'number' => $query->where('number', 'like', $like),
|
||||||
|
'body' => $query->where(fn ($q) => $q->where('body', 'like', $like)
|
||||||
|
->orWhereIn('id', DB::table('ticket_messages')->where('body', 'like', $like)->pluck('ticket_id'))),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function urlFor(Ticket $ticket): string
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
return $user->isOperator()
|
||||||
|
? route('operator.ticket', $ticket)
|
||||||
|
: route('client.ticket', $ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scoped (and routed, see urlFor()) by the operator role specifically
|
||||||
|
* rather than isAdmin() — admin alone doesn't grant the operator.*
|
||||||
|
* routes (see routes/web.php's role:operator middleware), so a result
|
||||||
|
* pointing there would 404 for an admin-only account.
|
||||||
|
*/
|
||||||
|
protected function baseQuery(User $user)
|
||||||
|
{
|
||||||
|
if ($user->isOperator()) {
|
||||||
|
return Ticket::query()->visibleToOperator($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->isClient()) {
|
||||||
|
return $user->ticketsAsCustomer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire.global-search');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ use App\Services\BookStackClient;
|
|||||||
use App\Services\LdapUserProvisioner;
|
use App\Services\LdapUserProvisioner;
|
||||||
use App\Services\TicketService;
|
use App\Services\TicketService;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithFileUploads;
|
use Livewire\WithFileUploads;
|
||||||
@@ -41,6 +42,13 @@ class Landing extends Component
|
|||||||
// delays the page's first paint — it loads in a beat later instead.
|
// delays the page's first paint — it loads in a beat later instead.
|
||||||
public bool $suggestedArticlesLoaded = false;
|
public bool $suggestedArticlesLoaded = false;
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
$this->redirect(route('client.dashboard'), navigate: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function loadSuggestedArticles(): void
|
public function loadSuggestedArticles(): void
|
||||||
{
|
{
|
||||||
$this->suggestedArticlesLoaded = true;
|
$this->suggestedArticlesLoaded = true;
|
||||||
@@ -100,8 +108,9 @@ class Landing extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
||||||
|
$tagQuery = trim($this->selectedSubcategory?->name ?? '');
|
||||||
|
|
||||||
return app(BookStackClient::class)->search($query);
|
return app(BookStackClient::class)->search($query, tagQuery: $tagQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backToCategory(): void
|
public function backToCategory(): void
|
||||||
@@ -186,6 +195,8 @@ class Landing extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.landing');
|
$context = $this->submittedTicketId ? 'Zgłoszenie utworzone' : 'Zgłoś problem';
|
||||||
|
|
||||||
|
return view('livewire.landing')->title(Settings::pageTitle($context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/app/Livewire/Operator/ClientSearch.php
Normal file
51
src/app/Livewire/Operator/ClientSearch.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire\Operator;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Attributes\Url;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class ClientSearch extends Component
|
||||||
|
{
|
||||||
|
#[Url]
|
||||||
|
public string $search = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A search box, not a browse-everything list — capped rather than
|
||||||
|
* paginated, same reasoning as the debounced search inputs elsewhere
|
||||||
|
* (queue/dashboard): once there's a match count this large, the fix is a
|
||||||
|
* narrower search term, not another page to click through.
|
||||||
|
*/
|
||||||
|
private const MAX_RESULTS = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matches by name or e-mail across every account, not just role=client —
|
||||||
|
* a ticket's customer_id can point at any user (e.g. an operator who
|
||||||
|
* also filed a ticket), so narrowing to clients only would hide valid
|
||||||
|
* results. Role badges in the view make it clear who's who.
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function results()
|
||||||
|
{
|
||||||
|
$term = trim($this->search);
|
||||||
|
|
||||||
|
if ($term === '') {
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
return User::query()
|
||||||
|
->where(fn ($q) => $q->where('name', 'like', "%{$term}%")->orWhere('email', 'like', "%{$term}%"))
|
||||||
|
->withCount('ticketsAsCustomer')
|
||||||
|
->orderBy('name')
|
||||||
|
->limit(self::MAX_RESULTS)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire.operator.client-search')->title(Settings::pageTitle('Klienci'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,8 +91,9 @@ class NewTicket extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
|
||||||
|
$tagQuery = trim($this->selectedSubcategory?->name ?? '');
|
||||||
|
|
||||||
return app(BookStackClient::class)->search($query);
|
return app(BookStackClient::class)->search($query, tagQuery: $tagQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backToCategory(): void
|
public function backToCategory(): void
|
||||||
@@ -159,6 +160,6 @@ class NewTicket extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.operator.new-ticket');
|
return view('livewire.operator.new-ticket')->title(Settings::pageTitle('Nowe zgłoszenie'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,30 @@ use App\Models\Team;
|
|||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\TicketService;
|
use App\Services\TicketService;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
use Livewire\Attributes\Url;
|
use Livewire\Attributes\Url;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
class Queue extends Component
|
class Queue extends Component
|
||||||
{
|
{
|
||||||
|
use WithPagination;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rows per page for the ticket table below. Sorting (see sortTickets())
|
||||||
|
* still happens in PHP over the full filtered result — several sortable
|
||||||
|
* columns (kategoria, przypisany, zespół...) are derived labels with no
|
||||||
|
* single backing SQL column — so this slices the already-sorted
|
||||||
|
* collection rather than using a query-level ->paginate(). That still
|
||||||
|
* bounds how many rows ever hit the DOM at once, which is what actually
|
||||||
|
* mattered once the ticket count grew into the thousands.
|
||||||
|
*/
|
||||||
|
private const PER_PAGE = 50;
|
||||||
|
|
||||||
#[Url]
|
#[Url]
|
||||||
public string $queue = 'all';
|
public string $queue = 'all';
|
||||||
|
|
||||||
@@ -129,6 +145,32 @@ class Queue extends Component
|
|||||||
$this->sortDir = $filters['sortDir'] ?? $this->sortDir;
|
$this->sortDir = $filters['sortDir'] ?? $this->sortDir;
|
||||||
$this->visibleColumns = $filters['visibleColumns'] ?? $this->visibleColumns;
|
$this->visibleColumns = $filters['visibleColumns'] ?? $this->visibleColumns;
|
||||||
$this->selectedIds = [];
|
$this->selectedIds = [];
|
||||||
|
$this->resetPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any change to a filter/search/queue-tab input can shrink the result
|
||||||
|
* set out from under whatever page the operator was on — snap back to
|
||||||
|
* page 1 rather than showing an empty table.
|
||||||
|
*/
|
||||||
|
public function updatedSearch(): void
|
||||||
|
{
|
||||||
|
$this->resetPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedFilterStatus(): void
|
||||||
|
{
|
||||||
|
$this->resetPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedFilterPriority(): void
|
||||||
|
{
|
||||||
|
$this->resetPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedFilterCategory(): void
|
||||||
|
{
|
||||||
|
$this->resetPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCurrentView(): void
|
public function saveCurrentView(): void
|
||||||
@@ -285,6 +327,21 @@ class Queue extends Component
|
|||||||
return $groups;
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last few tickets this operator actually opened (see
|
||||||
|
* Ticket::recordViewBy(), called from TicketShow::mount()) — re-scoped
|
||||||
|
* through visibleToOperator() in case a team reassignment since the
|
||||||
|
* view happened would now hide it from them.
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function recentlyViewed()
|
||||||
|
{
|
||||||
|
return Auth::user()->recentlyViewedTickets()
|
||||||
|
->visibleToOperator(Auth::user())
|
||||||
|
->take(6)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function filteredTickets()
|
public function filteredTickets()
|
||||||
{
|
{
|
||||||
@@ -314,8 +371,15 @@ class Queue extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tickets = $query->with(['subcategory.category', 'category', 'assignee', 'priority', 'status', 'team'])->get();
|
$tickets = $query->with(['subcategory.category', 'category', 'assignee', 'priority', 'status', 'team'])->get();
|
||||||
|
$sorted = $this->sortTickets($tickets);
|
||||||
|
|
||||||
return $this->sortTickets($tickets);
|
return new LengthAwarePaginator(
|
||||||
|
$sorted->forPage($this->getPage(), self::PER_PAGE)->values(),
|
||||||
|
$sorted->count(),
|
||||||
|
self::PER_PAGE,
|
||||||
|
$this->getPage(),
|
||||||
|
['path' => request()->url()],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,11 +479,14 @@ class Queue extends Component
|
|||||||
if ($key !== 'closed' && $this->filterStatus !== 'all' && Status::stageFor($this->filterStatus) === 'closed') {
|
if ($key !== 'closed' && $this->filterStatus !== 'all' && Status::stageFor($this->filterStatus) === 'closed') {
|
||||||
$this->filterStatus = 'all';
|
$this->filterStatus = 'all';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->resetPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearCustomerFilter(): void
|
public function clearCustomerFilter(): void
|
||||||
{
|
{
|
||||||
$this->filterCustomerId = null;
|
$this->filterCustomerId = null;
|
||||||
|
$this->resetPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleSelect(int $id): void
|
public function toggleSelect(int $id): void
|
||||||
@@ -496,6 +563,8 @@ class Queue extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.operator.queue');
|
$queueLabel = $this->queueDefs()[$this->queue]['label'] ?? 'Kolejka';
|
||||||
|
|
||||||
|
return view('livewire.operator.queue')->title(Settings::pageTitle($queueLabel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Models\Status;
|
|||||||
use App\Models\Team;
|
use App\Models\Team;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -624,6 +625,6 @@ class Stats extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.operator.stats');
|
return view('livewire.operator.stats')->title(Settings::pageTitle('Statystyki'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,11 @@ use App\Models\Ticket;
|
|||||||
use App\Models\TicketMessage;
|
use App\Models\TicketMessage;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\BookStackClient;
|
use App\Services\BookStackClient;
|
||||||
|
use App\Services\SnipeItClient;
|
||||||
|
use App\Services\TicketAiSummaryService;
|
||||||
use App\Services\TicketService;
|
use App\Services\TicketService;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
@@ -78,6 +81,38 @@ class TicketShow extends Component
|
|||||||
$this->suggestedArticlesLoaded = true;
|
$this->suggestedArticlesLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same wire:init-deferred pattern — the AI summary card just displays
|
||||||
|
// whatever the scheduled ai:run-ticket-automation command last computed
|
||||||
|
// (no live AI call from the ticket page), but refreshing the ticket here
|
||||||
|
// picks up a summary the command generated after this page's initial load.
|
||||||
|
public bool $aiSummaryLoaded = false;
|
||||||
|
|
||||||
|
public function loadAiSummary(): void
|
||||||
|
{
|
||||||
|
$this->aiSummaryLoaded = true;
|
||||||
|
$this->ticket->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ?string $aiSummaryRegenerateError = null;
|
||||||
|
|
||||||
|
// Manual regeneration is an explicit operator action (unlike the
|
||||||
|
// wire:init-deferred load above), so it's fine to block on the AI call
|
||||||
|
// here rather than deferring it — the button's wire:loading state covers
|
||||||
|
// the wait.
|
||||||
|
public function regenerateAiSummary(): void
|
||||||
|
{
|
||||||
|
$this->aiSummaryRegenerateError = null;
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
if (! app(TicketAiSummaryService::class)->generateFor($this->ticket)) {
|
||||||
|
$this->aiSummaryRegenerateError = 'Nie udało się wygenerować podsumowania. Sprawdź konfigurację integracji AI.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->ticket->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
public function mount(Ticket $ticket): void
|
public function mount(Ticket $ticket): void
|
||||||
{
|
{
|
||||||
abort_unless($ticket->isVisibleToOperator(Auth::user()), 403);
|
abort_unless($ticket->isVisibleToOperator(Auth::user()), 403);
|
||||||
@@ -89,6 +124,26 @@ class TicketShow extends Component
|
|||||||
// ticket-show.blade.php) — so every open resumes it, not just the
|
// ticket-show.blade.php) — so every open resumes it, not just the
|
||||||
// very first one.
|
// very first one.
|
||||||
$this->ticket->resumeTimer();
|
$this->ticket->resumeTimer();
|
||||||
|
|
||||||
|
$this->ticket->recordViewBy(Auth::user());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Livewire lifecycle hook, called for any exception raised while
|
||||||
|
* handling a request for this component — including one thrown while
|
||||||
|
* re-hydrating the typed $ticket property itself (Livewire re-fetches
|
||||||
|
* it by id on every request), which happens before any of this
|
||||||
|
* component's own methods run and so can't be caught locally the way
|
||||||
|
* refreshOrRedirectAway() catches it during an explicit refresh().
|
||||||
|
* Covers a ticket deleted by someone else while an operator still has
|
||||||
|
* it open — sends them back to their queue instead of a hard error.
|
||||||
|
*/
|
||||||
|
public function exception(\Throwable $e, $stopPropagation): void
|
||||||
|
{
|
||||||
|
if ($e instanceof ModelNotFoundException) {
|
||||||
|
$this->redirect(route('operator.queue'), navigate: true);
|
||||||
|
$stopPropagation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
@@ -209,6 +264,36 @@ class TicketShow extends Component
|
|||||||
unset($this->publicMessages, $this->internalMessages);
|
unset($this->publicMessages, $this->internalMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-fetches the ticket and, for a non-admin operator, sends them back
|
||||||
|
* to their queue instead of leaving them stuck on a page that can no
|
||||||
|
* longer legitimately show anything — either because the ticket was
|
||||||
|
* deleted (refresh() throws ModelNotFoundException, same as
|
||||||
|
* Model::findOrFail() internally) or because a team/assignee change
|
||||||
|
* (by this operator or anyone else) moved it out of their visible
|
||||||
|
* scope. Returns false when it redirected, so callers can bail out of
|
||||||
|
* whatever they were doing instead of continuing to operate on a
|
||||||
|
* ticket that's about to disappear from under them.
|
||||||
|
*/
|
||||||
|
protected function refreshOrRedirectAway(): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->ticket->refresh();
|
||||||
|
} catch (ModelNotFoundException) {
|
||||||
|
$this->redirect(route('operator.queue'), navigate: true);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->ticket->isVisibleToOperator(Auth::user())) {
|
||||||
|
$this->redirect(route('operator.queue'), navigate: true);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bridged from a TicketQueueChanged broadcast (see resources/js/echo.js
|
* Bridged from a TicketQueueChanged broadcast (see resources/js/echo.js
|
||||||
* and Queue::onQueueChanged()) — lets a status/priority/team/assignee
|
* and Queue::onQueueChanged()) — lets a status/priority/team/assignee
|
||||||
@@ -222,7 +307,7 @@ class TicketShow extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ticket->refresh();
|
$this->refreshOrRedirectAway();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -232,8 +317,11 @@ class TicketShow extends Component
|
|||||||
*/
|
*/
|
||||||
public function refreshTicketData(): void
|
public function refreshTicketData(): void
|
||||||
{
|
{
|
||||||
|
if (! $this->refreshOrRedirectAway()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->publicMessages, $this->internalMessages);
|
unset($this->publicMessages, $this->internalMessages);
|
||||||
$this->ticket->refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
@@ -266,24 +354,121 @@ class TicketShow extends Component
|
|||||||
|
|
||||||
$subcategory = $this->ticket->subcategory;
|
$subcategory = $this->ticket->subcategory;
|
||||||
$query = trim(($subcategory?->category?->name ?? '').' '.($subcategory?->name ?? ''));
|
$query = trim(($subcategory?->category?->name ?? '').' '.($subcategory?->name ?? ''));
|
||||||
|
$tagQuery = trim($subcategory?->name ?? '');
|
||||||
|
|
||||||
return app(BookStackClient::class)->search($query, 5, BookStackClient::CONTEXT_TICKET_VIEW);
|
return app(BookStackClient::class)->search($query, 5, BookStackClient::CONTEXT_TICKET_VIEW, $tagQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------- Snipe-IT --------
|
||||||
|
|
||||||
|
// Same wire:init-deferred pattern as suggestedArticlesLoaded above — the
|
||||||
|
// requester's asset list is a Snipe-IT HTTP call, deferred so it never
|
||||||
|
// delays the ticket page's first paint.
|
||||||
|
public bool $snipeitAssetsLoaded = false;
|
||||||
|
|
||||||
|
public function loadSnipeitAssets(): void
|
||||||
|
{
|
||||||
|
$this->snipeitAssetsLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string $snipeitSearchQuery = '';
|
||||||
|
|
||||||
|
public array $snipeitSearchResults = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, url: string}>
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function snipeitRequesterAssets(): array
|
||||||
|
{
|
||||||
|
if (! $this->snipeitAssetsLoaded || ! Settings::bool('snipeit_operator_view_requester_assets') || ! $this->ticket->email) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return app(SnipeItClient::class)->assetsForEmail($this->ticket->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A non-admin operator can only reassign a ticket to one of their own
|
* Live detail for the ticket's linked asset (if any) — always fetched
|
||||||
* teams (mirrors the visibility scoping in Operator\Queue).
|
* fresh so a status/assignment change made directly in Snipe-IT shows up
|
||||||
|
* without an operator having to re-link anything. Not gated behind
|
||||||
|
* snipeit_operator_view_requester_assets/snipeit_operator_search_inventory:
|
||||||
|
* showing what's already on the ticket isn't the same permission as
|
||||||
|
* browsing the rest of Snipe-IT. Falls back to the ticket's own cached
|
||||||
|
* snipeit_asset_name in the view when this comes back null (unreachable
|
||||||
|
* instance or the asset was deleted there).
|
||||||
|
*
|
||||||
|
* @return array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, assignedTo: ?string, url: string}|null
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function snipeitLinkedAsset(): ?array
|
||||||
|
{
|
||||||
|
return $this->ticket->snipeit_asset_id
|
||||||
|
? app(SnipeItClient::class)->asset($this->ticket->snipeit_asset_id)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchSnipeitAssets(): void
|
||||||
|
{
|
||||||
|
if (! Settings::bool('snipeit_operator_search_inventory')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->snipeitSearchResults = app(SnipeItClient::class)->searchAssets($this->snipeitSearchQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $id must come from whichever list it was clicked from — the requester's
|
||||||
|
* assets (gated on snipeit_operator_view_requester_assets) or an
|
||||||
|
* inventory search result (gated on snipeit_operator_search_inventory) —
|
||||||
|
* rather than a direct Snipe-IT lookup by id, so an operator can't link
|
||||||
|
* an arbitrary asset via a source that's admin-disabled for them.
|
||||||
|
*/
|
||||||
|
public function linkSnipeitAsset(int $id): void
|
||||||
|
{
|
||||||
|
$fromRequesterAssets = Settings::bool('snipeit_operator_view_requester_assets')
|
||||||
|
? collect($this->snipeitRequesterAssets)->firstWhere('id', $id)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$fromSearchResults = Settings::bool('snipeit_operator_search_inventory')
|
||||||
|
? collect($this->snipeitSearchResults)->firstWhere('id', $id)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$asset = $fromRequesterAssets ?? $fromSearchResults;
|
||||||
|
|
||||||
|
if (! $asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app(TicketService::class)->setSnipeitAsset($this->ticket, ['id' => $asset['id'], 'label' => $asset['label']]);
|
||||||
|
$this->ticket->refresh();
|
||||||
|
unset($this->snipeitLinkedAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlike linkSnipeitAsset(), not gated behind either visibility setting
|
||||||
|
* — clearing a link a ticket already has is a correction, not a new way
|
||||||
|
* to browse Snipe-IT, so it stays available even if an admin later turns
|
||||||
|
* both of those off.
|
||||||
|
*/
|
||||||
|
public function unlinkSnipeitAsset(): void
|
||||||
|
{
|
||||||
|
app(TicketService::class)->setSnipeitAsset($this->ticket, null);
|
||||||
|
$this->ticket->refresh();
|
||||||
|
unset($this->snipeitLinkedAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every team, regardless of the viewing operator's own membership —
|
||||||
|
* unlike ticket *visibility* (Operator\Queue, scoped to an operator's
|
||||||
|
* own teams), reassignment isn't restricted: an operator working a
|
||||||
|
* ticket needs to be able to route it to whichever team actually owns
|
||||||
|
* the problem, even one they don't personally belong to.
|
||||||
*/
|
*/
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function teams()
|
public function teams()
|
||||||
{
|
{
|
||||||
$query = Team::query();
|
return Team::query()->get();
|
||||||
|
|
||||||
if (! Auth::user()->isAdmin()) {
|
|
||||||
$query->whereHas('members', fn ($q) => $q->where('users.id', Auth::id()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
@@ -357,7 +542,12 @@ class TicketShow extends Component
|
|||||||
public function setTeam(string $id): void
|
public function setTeam(string $id): void
|
||||||
{
|
{
|
||||||
app(TicketService::class)->setTeam($this->ticket, $id ? Team::query()->find($id) : null);
|
app(TicketService::class)->setTeam($this->ticket, $id ? Team::query()->find($id) : null);
|
||||||
$this->ticket->refresh();
|
|
||||||
|
// Reassigning to a team the operator doesn't belong to can move the
|
||||||
|
// ticket out of their own visible scope (see Ticket::isVisibleToOperator())
|
||||||
|
// — send them back to their queue rather than leaving them on a
|
||||||
|
// ticket they can no longer legitimately keep viewing.
|
||||||
|
$this->refreshOrRedirectAway();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- reporter --------
|
// -------- reporter --------
|
||||||
@@ -585,6 +775,6 @@ class TicketShow extends Component
|
|||||||
// progress is saved incrementally rather than only on explicit stop.
|
// progress is saved incrementally rather than only on explicit stop.
|
||||||
$this->ticket->flushTimer();
|
$this->ticket->flushTimer();
|
||||||
|
|
||||||
return view('livewire.operator.ticket-show');
|
return view('livewire.operator.ticket-show')->title(Settings::pageTitle($this->ticket->displayNumber().' — '.$this->ticket->subject));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Livewire\Settings;
|
namespace App\Livewire\Settings;
|
||||||
|
|
||||||
use App\Models\NotificationPreference;
|
use App\Models\NotificationPreference;
|
||||||
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ class NotificationPreferences extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.settings.notification-preferences', ['rows' => $this->rows()]);
|
return view('livewire.settings.notification-preferences', ['rows' => $this->rows()])
|
||||||
|
->title(Settings::pageTitle('Powiadomienia'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ class Category extends Model
|
|||||||
{
|
{
|
||||||
public function subcategories(): HasMany
|
public function subcategories(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Subcategory::class);
|
return $this->hasMany(Subcategory::class)->orderBy('sort_order');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
#[Fillable(['category_id', 'name', 'description', 'default_priority_key'])]
|
#[Fillable(['category_id', 'name', 'description', 'default_priority_key', 'sort_order'])]
|
||||||
class Subcategory extends Model
|
class Subcategory extends Model
|
||||||
{
|
{
|
||||||
public function category(): BelongsTo
|
public function category(): BelongsTo
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use Illuminate\Support\Facades\DB;
|
|||||||
'status_key', 'priority_key', 'team_id', 'assignee_id', 'custom_fields', 'api_client_id', 'source',
|
'status_key', 'priority_key', 'team_id', 'assignee_id', 'custom_fields', 'api_client_id', 'source',
|
||||||
'sla_notified_at', 'last_customer_activity_at', 'time_spent_seconds', 'timer_started_at',
|
'sla_notified_at', 'last_customer_activity_at', 'time_spent_seconds', 'timer_started_at',
|
||||||
'created_at', 'updated_at', 'csat_rating', 'csat_comment', 'csat_rated_at',
|
'created_at', 'updated_at', 'csat_rating', 'csat_comment', 'csat_rated_at',
|
||||||
|
'ai_triaged_at', 'ai_summary', 'ai_suggested_action', 'ai_summary_generated_at',
|
||||||
|
'snipeit_asset_id', 'snipeit_asset_name',
|
||||||
])]
|
])]
|
||||||
class Ticket extends Model
|
class Ticket extends Model
|
||||||
{
|
{
|
||||||
@@ -44,6 +46,9 @@ class Ticket extends Model
|
|||||||
'timer_started_at' => 'datetime',
|
'timer_started_at' => 'datetime',
|
||||||
'csat_rating' => 'integer',
|
'csat_rating' => 'integer',
|
||||||
'csat_rated_at' => 'datetime',
|
'csat_rated_at' => 'datetime',
|
||||||
|
'ai_triaged_at' => 'datetime',
|
||||||
|
'ai_summary_generated_at' => 'datetime',
|
||||||
|
'snipeit_asset_id' => 'integer',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +97,26 @@ class Ticket extends Model
|
|||||||
return $this->watchers()->where('users.id', $user->id)->exists();
|
return $this->watchers()->where('users.id', $user->id)->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function viewers(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(User::class, 'ticket_views')->withPivot('viewed_at');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bumps viewed_at for an existing view rather than duplicating it — sync()
|
||||||
|
* updates pivot columns on already-attached rows, not just new ones.
|
||||||
|
*
|
||||||
|
* Formatted explicitly with microseconds: a plain Carbon instance gets
|
||||||
|
* bound through the connection's default date format (whole seconds,
|
||||||
|
* regardless of the column's own declared precision), so two views in
|
||||||
|
* the same second would otherwise tie and silently fall back to sorting
|
||||||
|
* by row id instead of actual recency.
|
||||||
|
*/
|
||||||
|
public function recordViewBy(User $user): void
|
||||||
|
{
|
||||||
|
$this->viewers()->syncWithoutDetaching([$user->id => ['viewed_at' => now()->format('Y-m-d H:i:s.u')]]);
|
||||||
|
}
|
||||||
|
|
||||||
public function status(): BelongsTo
|
public function status(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Status::class, 'status_key');
|
return $this->belongsTo(Status::class, 'status_key');
|
||||||
|
|||||||
@@ -189,6 +189,13 @@ class User extends Authenticatable implements LdapAuthenticatable
|
|||||||
return $this->belongsToMany(Ticket::class, 'ticket_watchers');
|
return $this->belongsToMany(Ticket::class, 'ticket_watchers');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recentlyViewedTickets(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Ticket::class, 'ticket_views')
|
||||||
|
->withPivot('viewed_at')
|
||||||
|
->orderByPivot('viewed_at', 'desc');
|
||||||
|
}
|
||||||
|
|
||||||
public function ticketsAssigned(): HasMany
|
public function ticketsAssigned(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Ticket::class, 'assignee_id');
|
return $this->hasMany(Ticket::class, 'assignee_id');
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Events\NotificationCreated;
|
use App\Events\NotificationCreated;
|
||||||
|
use App\Events\TicketMessagePosted;
|
||||||
|
use App\Jobs\GenerateTicketAiSummaryJob;
|
||||||
use App\Models\ApiClient;
|
use App\Models\ApiClient;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\TicketNotification;
|
use App\Notifications\TicketNotification;
|
||||||
@@ -40,6 +42,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->applyTimezoneSettingsOverride();
|
$this->applyTimezoneSettingsOverride();
|
||||||
$this->configureApiRateLimiting();
|
$this->configureApiRateLimiting();
|
||||||
$this->broadcastBellNotifications();
|
$this->broadcastBellNotifications();
|
||||||
|
$this->regenerateAiSummaryOnNewMessage();
|
||||||
|
|
||||||
// 'user' backs the polymorphic notifiable_type column on the
|
// 'user' backs the polymorphic notifiable_type column on the
|
||||||
// database-notifications table (in-app notification bell).
|
// database-notifications table (in-app notification bell).
|
||||||
@@ -68,6 +71,25 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin-optional: when enabled, every reply/note/API message re-runs the
|
||||||
|
* AI summary for its ticket right away instead of waiting for the next
|
||||||
|
* ai:run-ticket-automation sweep (up to schedule_ai_automation_minutes
|
||||||
|
* stale). dispatchAfterResponse() runs in-process after the triggering
|
||||||
|
* request finishes rather than going through the queue table — see
|
||||||
|
* GenerateTicketAiSummaryJob's docblock for why.
|
||||||
|
*/
|
||||||
|
protected function regenerateAiSummaryOnNewMessage(): void
|
||||||
|
{
|
||||||
|
Event::listen(TicketMessagePosted::class, function (TicketMessagePosted $event) {
|
||||||
|
if (! Settings::bool('ai_summary_enabled') || ! Settings::bool('ai_summary_regenerate_on_message')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateTicketAiSummaryJob::dispatchAfterResponse($event->ticketId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API keys get a generous per-key budget; unauthenticated requests (which
|
* API keys get a generous per-key budget; unauthenticated requests (which
|
||||||
* only ever hit the guard before rejecting with 401) get a much smaller
|
* only ever hit the guard before rejecting with 401) get a much smaller
|
||||||
@@ -136,6 +158,12 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Config::set('ldap.connections.default', $config);
|
Config::set('ldap.connections.default', $config);
|
||||||
Container::addConnection(new Connection($config), 'default');
|
Container::addConnection(new Connection($config), 'default');
|
||||||
|
|
||||||
|
// Active Directory's objectClass chain (top/person/organizationalPerson/
|
||||||
|
// user) and login attribute (sAMAccountName) differ from the
|
||||||
|
// LLDAP/OpenLDAP schema LldapUser is scoped to — swap in AdUser so a
|
||||||
|
// directory switch doesn't leave every login matching zero entries.
|
||||||
|
Config::set('auth.providers.users.model', Settings::ldapUserModelClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
95
src/app/Services/AiClient.php
Normal file
95
src/app/Services/AiClient.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic OpenAI-compatible chat-completions client — works against Groq,
|
||||||
|
* OpenAI itself, or a self-hosted Ollama instance's OpenAI-compat endpoint,
|
||||||
|
* whichever the admin points ai_base_url at. Not BookStack-specific; the
|
||||||
|
* BookStack content tagger is just the first consumer.
|
||||||
|
*/
|
||||||
|
class AiClient
|
||||||
|
{
|
||||||
|
public function enabled(): bool
|
||||||
|
{
|
||||||
|
// Deliberately no api-key requirement here — a self-hosted Ollama
|
||||||
|
// instance typically has no auth at all.
|
||||||
|
return Settings::bool('ai_enabled')
|
||||||
|
&& Settings::get('ai_base_url')
|
||||||
|
&& Settings::get('ai_model');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{role: string, content: string}> $messages
|
||||||
|
* @return string|null the assistant message content, or null on any failure
|
||||||
|
*/
|
||||||
|
public function chat(array $messages, array $options = []): ?string
|
||||||
|
{
|
||||||
|
if (! $this->enabled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->client()->post('/chat/completions', [
|
||||||
|
'model' => Settings::get('ai_model'),
|
||||||
|
'messages' => $messages,
|
||||||
|
...$options,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->json('choices.0.message.content');
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests unsaved admin-form values directly, rather than whatever's
|
||||||
|
* currently stored — mirrors BookStackClient::testConnection().
|
||||||
|
*
|
||||||
|
* @return array{ok: bool, message: ?string}
|
||||||
|
*/
|
||||||
|
public function testConnection(string $baseUrl, string $apiKey, string $model, bool $verifySsl = true): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$http = Http::withOptions(['verify' => $verifySsl])
|
||||||
|
->timeout(10)
|
||||||
|
->baseUrl(rtrim($baseUrl, '/'));
|
||||||
|
|
||||||
|
if ($apiKey !== '') {
|
||||||
|
$http = $http->withToken($apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $http->post('/chat/completions', [
|
||||||
|
'model' => $model,
|
||||||
|
'messages' => [['role' => 'user', 'content' => 'ping']],
|
||||||
|
'max_tokens' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
return ['ok' => true, 'message' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['ok' => false, 'message' => $response->json('error.message') ?? ('HTTP '.$response->status())];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return ['ok' => false, 'message' => $e->getMessage()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function client()
|
||||||
|
{
|
||||||
|
$http = Http::withOptions(['verify' => Settings::bool('ai_verify_ssl')])
|
||||||
|
->timeout(60)
|
||||||
|
->baseUrl(rtrim(Settings::get('ai_base_url'), '/'));
|
||||||
|
|
||||||
|
$apiKey = Settings::get('ai_api_key');
|
||||||
|
|
||||||
|
return $apiKey ? $http->withToken($apiKey) : $http;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,31 @@ class BookStackClient
|
|||||||
self::CONTEXT_TICKET_VIEW => 'bookstack_allowed_shelf_ids_ticket_view',
|
self::CONTEXT_TICKET_VIEW => 'bookstack_allowed_shelf_ids_ticket_view',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content types selectable via the admin's "Przeszukuj" checkboxes.
|
||||||
|
* Deliberately excludes 'bookshelf' — shelves are only ever a filter
|
||||||
|
* (dozwolone półki), never a suggestion result in their own right.
|
||||||
|
*/
|
||||||
|
public const SEARCH_TYPES = ['book', 'page', 'chapter'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How the query text is matched, via the admin's "Szukaj po" option —
|
||||||
|
* 'name' restricts to the title ({in_name:...}), 'tags' matches a tag
|
||||||
|
* whose name equals the query (expected to hold the helpdesk
|
||||||
|
* category/subcategory name, e.g. a "Drukarki" tag on the relevant
|
||||||
|
* BookStack pages), 'both' runs both and merges the results (BookStack's
|
||||||
|
* query syntax ANDs filters together, so there's no single-query way to
|
||||||
|
* express "name OR tag").
|
||||||
|
*/
|
||||||
|
public const SEARCH_BY_OPTIONS = ['name', 'tags', 'both'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content types the bulk-tagging command operates over — same set as
|
||||||
|
* SEARCH_TYPES (book/page/chapter, no bookshelf), named separately since
|
||||||
|
* the two consts serve different features that happen to share a domain.
|
||||||
|
*/
|
||||||
|
public const CONTENT_TYPES = self::SEARCH_TYPES;
|
||||||
|
|
||||||
public function enabled(): bool
|
public function enabled(): bool
|
||||||
{
|
{
|
||||||
return Settings::bool('bookstack_enabled')
|
return Settings::bool('bookstack_enabled')
|
||||||
@@ -39,44 +64,56 @@ class BookStackClient
|
|||||||
* before any content is ever suggested, independently per context).
|
* before any content is ever suggested, independently per context).
|
||||||
* Cached briefly since the same category/subcategory query repeats
|
* Cached briefly since the same category/subcategory query repeats
|
||||||
* across every ticket created/viewed with that combination. Respects the
|
* across every ticket created/viewed with that combination. Respects the
|
||||||
* admin-configured bookstack_search_types setting ('both'|'page'|'book')
|
* admin-configured bookstack_search_types (subset of SEARCH_TYPES, via
|
||||||
* via BookStack's own `{type:x}` query syntax. The cache key folds in the
|
* BookStack's `{type:a|b}` syntax) and bookstack_search_by ('name'|
|
||||||
* allowed-shelf list so changing it in Admin > Konfiguracja is reflected
|
* 'tags'|'both', via `{in_name:...}`/`[...]`) settings. The cache key
|
||||||
* immediately, instead of possibly serving a pre-change result for up to
|
* folds in the allowed-shelf list so changing it in Admin > Konfiguracja
|
||||||
* 10 minutes.
|
* is reflected immediately, instead of possibly serving a pre-change
|
||||||
|
* result for up to 10 minutes.
|
||||||
|
*
|
||||||
|
* $tagQuery is the text matched by the 'tags' variant, separate from
|
||||||
|
* $query (matched by the 'name' variant) — callers pass the bare
|
||||||
|
* subcategory name here (what bookstack:tag-content actually writes as
|
||||||
|
* a tag), while $query stays the fuller "Category Subcategory" text
|
||||||
|
* that's more useful for a plain title/body search. Defaults to $query
|
||||||
|
* so existing call sites that don't pass it keep working.
|
||||||
*
|
*
|
||||||
* @return array<int, array{name: string, url: ?string, type: string, book: ?string, shelf: ?string}>
|
* @return array<int, array{name: string, url: ?string, type: string, book: ?string, shelf: ?string}>
|
||||||
*/
|
*/
|
||||||
public function search(string $query, int $limit = 5, string $context = self::CONTEXT_CREATION): array
|
public function search(string $query, int $limit = 5, string $context = self::CONTEXT_CREATION, ?string $tagQuery = null): array
|
||||||
{
|
{
|
||||||
$query = trim($query);
|
$query = trim($query);
|
||||||
|
$tagQuery = trim($tagQuery ?? $query);
|
||||||
$allowedShelfIds = $this->allowedShelfIds($context);
|
$allowedShelfIds = $this->allowedShelfIds($context);
|
||||||
|
|
||||||
if (! $this->enabled() || $query === '' || ! $allowedShelfIds) {
|
if (! $this->enabled() || $query === '' || ! $allowedShelfIds) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$typeFilter = Settings::get('bookstack_search_types', 'both');
|
$searchBy = $this->searchBy();
|
||||||
|
$bookstackQueries = $searchBy === 'both'
|
||||||
|
? [$this->buildQuery($query, 'name'), $this->buildQuery($tagQuery, 'tags')]
|
||||||
|
: [$this->buildQuery($searchBy === 'tags' ? $tagQuery : $query, $searchBy)];
|
||||||
|
|
||||||
if (in_array($typeFilter, ['page', 'book'], true)) {
|
$cacheKey = 'bookstack:search:'.md5(implode('||', $bookstackQueries).'|'.$limit.'|'.implode(',', $allowedShelfIds));
|
||||||
$query .= " {type:{$typeFilter}}";
|
|
||||||
}
|
|
||||||
|
|
||||||
$cacheKey = 'bookstack:search:'.md5($query.'|'.$limit.'|'.implode(',', $allowedShelfIds));
|
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($bookstackQueries, $limit, $allowedShelfIds) {
|
||||||
|
|
||||||
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($query, $limit, $allowedShelfIds) {
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client()->get('/api/search', ['query' => $query, 'count' => $limit]);
|
|
||||||
|
|
||||||
if (! $response->successful()) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$shelfMap = $this->shelfBookMap();
|
$shelfMap = $this->shelfBookMap();
|
||||||
$allowedBookIds = $this->bookIdsForShelves($shelfMap, $allowedShelfIds);
|
$allowedBookIds = $this->bookIdsForShelves($shelfMap, $allowedShelfIds);
|
||||||
$bookShelfNames = $this->bookShelfNames($shelfMap);
|
$bookShelfNames = $this->bookShelfNames($shelfMap);
|
||||||
|
|
||||||
return collect($response->json('data', []))
|
$items = collect();
|
||||||
|
|
||||||
|
foreach ($bookstackQueries as $bookstackQuery) {
|
||||||
|
$response = $this->client()->get('/api/search', ['query' => $bookstackQuery, 'count' => $limit]);
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
$items = $items->concat($response->json('data', []));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items
|
||||||
->filter(function (array $item) use ($allowedShelfIds, $allowedBookIds) {
|
->filter(function (array $item) use ($allowedShelfIds, $allowedBookIds) {
|
||||||
$type = $item['type'] ?? null;
|
$type = $item['type'] ?? null;
|
||||||
|
|
||||||
@@ -103,6 +140,8 @@ class BookStackClient
|
|||||||
];
|
];
|
||||||
})
|
})
|
||||||
->filter(fn (array $item) => $item['name'] !== '')
|
->filter(fn (array $item) => $item['name'] !== '')
|
||||||
|
->unique(fn (array $item) => $item['url'] ?? $item['name'])
|
||||||
|
->take($limit)
|
||||||
->values()
|
->values()
|
||||||
->all();
|
->all();
|
||||||
} catch (\Throwable) {
|
} catch (\Throwable) {
|
||||||
@@ -111,6 +150,68 @@ class BookStackClient
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds one BookStack search-syntax query string for $query, restricted
|
||||||
|
* to $by ('name' -> `{in_name:...}`, 'tags' -> `[...]`) and to the
|
||||||
|
* configured content types (`{type:a|b}`, omitted if all types are
|
||||||
|
* allowed since that's equivalent to no filter).
|
||||||
|
*/
|
||||||
|
protected function buildQuery(string $query, string $by): string
|
||||||
|
{
|
||||||
|
$parts = [$by === 'tags' ? "[{$query}]" : "{in_name:{$query}}"];
|
||||||
|
|
||||||
|
$types = $this->searchTypes();
|
||||||
|
|
||||||
|
if (array_diff(self::SEARCH_TYPES, $types)) {
|
||||||
|
$parts[] = '{type:'.implode('|', $types).'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[] non-empty subset of SEARCH_TYPES
|
||||||
|
*/
|
||||||
|
protected function searchTypes(): array
|
||||||
|
{
|
||||||
|
return self::normalizeSearchTypes(Settings::get('bookstack_search_types', ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes bookstack_search_types storage into a non-empty subset of
|
||||||
|
* SEARCH_TYPES — shared with Admin\Panel so the checkbox UI and the
|
||||||
|
* actual search agree on the same format. Also understands the legacy
|
||||||
|
* single-value 'both'/'page'/'book' storage from before the setting
|
||||||
|
* became a checkbox list, so existing configuration keeps working.
|
||||||
|
*
|
||||||
|
* @param string[]|string $raw
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public static function normalizeSearchTypes(array|string $raw): array
|
||||||
|
{
|
||||||
|
$legacy = ['both' => self::SEARCH_TYPES, 'page' => ['page'], 'book' => ['book']];
|
||||||
|
|
||||||
|
if (is_string($raw) && isset($legacy[$raw])) {
|
||||||
|
return $legacy[$raw];
|
||||||
|
}
|
||||||
|
|
||||||
|
$types = collect(is_array($raw) ? $raw : explode(',', $raw))
|
||||||
|
->map(fn ($v) => trim((string) $v))
|
||||||
|
->filter(fn ($v) => in_array($v, self::SEARCH_TYPES, true))
|
||||||
|
->unique()
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
|
||||||
|
return $types ?: self::SEARCH_TYPES;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function searchBy(): string
|
||||||
|
{
|
||||||
|
$raw = Settings::get('bookstack_search_by', 'both');
|
||||||
|
|
||||||
|
return in_array($raw, self::SEARCH_BY_OPTIONS, true) ? $raw : 'both';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drops the cached shelf list and shelf>book membership map — used by
|
* Drops the cached shelf list and shelf>book membership map — used by
|
||||||
* the admin's "Odśwież listę półek" button so a shelf renamed/added/
|
* the admin's "Odśwież listę półek" button so a shelf renamed/added/
|
||||||
@@ -155,6 +256,103 @@ class BookStackClient
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every book/chapter/page of $type across the whole BookStack instance —
|
||||||
|
* NOT filtered by the allowed-shelf settings, unlike search(). Those only
|
||||||
|
* gate which suggestions are ever shown to a client/operator; the bulk
|
||||||
|
* tagger is meant to cover every piece of content regardless. Paginates
|
||||||
|
* through BookStack's count/offset list endpoints (count capped at 500,
|
||||||
|
* the API's own per-page maximum). Uncached — this is a one-shot batch
|
||||||
|
* read, not a repeated request-path lookup.
|
||||||
|
*
|
||||||
|
* @return array<int, array{id: int, name: string}>
|
||||||
|
*/
|
||||||
|
public function listAll(string $type): array
|
||||||
|
{
|
||||||
|
if (! $this->enabled() || ! in_array($type, self::CONTENT_TYPES, true)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
$offset = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
$response = $this->client()->get("/api/{$type}s", ['count' => 500, 'offset' => $offset]);
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = $response->json('data', []);
|
||||||
|
$items = [...$items, ...$page];
|
||||||
|
$offset += 500;
|
||||||
|
$total = $response->json('total', 0);
|
||||||
|
} while (count($page) > 0 && count($items) < $total);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full detail for a single book/chapter/page — its current tags (needed
|
||||||
|
* to merge rather than clobber when the tagger writes new ones) and the
|
||||||
|
* text used to classify it (a page's markdown source, or a book/
|
||||||
|
* chapter's description). Null if $type is invalid or the item can't be
|
||||||
|
* fetched.
|
||||||
|
*
|
||||||
|
* @return array{id: int, name: string, tags: array<int, array{name: string, value: string}>, content: string}|null
|
||||||
|
*/
|
||||||
|
public function detail(string $type, int $id): ?array
|
||||||
|
{
|
||||||
|
if (! $this->enabled() || ! in_array($type, self::CONTENT_TYPES, true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->client()->get("/api/{$type}s/{$id}");
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $data['id'],
|
||||||
|
'name' => $data['name'] ?? '',
|
||||||
|
'tags' => $data['tags'] ?? [],
|
||||||
|
'content' => $data['markdown'] ?? $data['description'] ?? '',
|
||||||
|
];
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites just the tags field on a book/chapter/page — BookStack
|
||||||
|
* treats every field on its update endpoints as optional, so this never
|
||||||
|
* touches the item's name/content/other attributes. Callers are
|
||||||
|
* responsible for merging in any tags they want to keep (this replaces
|
||||||
|
* the whole array, it doesn't append).
|
||||||
|
*
|
||||||
|
* @param array<int, array{name: string, value: string}> $tags
|
||||||
|
*/
|
||||||
|
public function updateTags(string $type, int $id, array $tags): bool
|
||||||
|
{
|
||||||
|
if (! $this->enabled() || ! in_array($type, self::CONTENT_TYPES, true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return $this->client()->put("/api/{$type}s/{$id}", ['tags' => $tags])->successful();
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int[]
|
* @return int[]
|
||||||
*/
|
*/
|
||||||
|
|||||||
260
src/app/Services/BookStackContentTagger.php
Normal file
260
src/app/Services/BookStackContentTagger.php
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\Subcategory;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk-assigns BookStack tags to every book/chapter/page, using the
|
||||||
|
* configured AiClient to classify each item's title+content against the
|
||||||
|
* helpdesk's current subcategory vocabulary — so BookStackClient::search()'s
|
||||||
|
* 'tags'/'both' mode has something to actually match against. Idempotent by
|
||||||
|
* default: an item already carrying a tag matching a current subcategory
|
||||||
|
* name is skipped, so re-running after adding a handful of new pages is
|
||||||
|
* cheap; $force re-classifies everything.
|
||||||
|
*/
|
||||||
|
class BookStackContentTagger
|
||||||
|
{
|
||||||
|
protected const BATCH_SIZE = 20;
|
||||||
|
|
||||||
|
protected const CONTENT_EXCERPT_CHARS = 2000;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected BookStackClient $bookstack,
|
||||||
|
protected AiClient $ai,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{scanned: int, tagged: int, skipped: int, failed_batches: int}
|
||||||
|
*/
|
||||||
|
public function run(bool $dryRun = false, bool $force = false, ?int $limit = null): array
|
||||||
|
{
|
||||||
|
$totals = ['scanned' => 0, 'tagged' => 0, 'skipped' => 0, 'failed_batches' => 0];
|
||||||
|
|
||||||
|
if (! $this->bookstack->enabled() || ! $this->ai->enabled()) {
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vocabulary = $this->subcategoryVocabulary();
|
||||||
|
|
||||||
|
if (! $vocabulary) {
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (BookStackClient::CONTENT_TYPES as $type) {
|
||||||
|
foreach ($this->itemsToProcess($type, $vocabulary, $force, $limit, $totals) as $batch) {
|
||||||
|
$this->processBatch($type, $batch, $vocabulary, $dryRun, $totals);
|
||||||
|
|
||||||
|
if ($limit !== null && $totals['scanned'] >= $limit) {
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[] current subcategory names, deduped case-insensitively
|
||||||
|
*/
|
||||||
|
protected function subcategoryVocabulary(): array
|
||||||
|
{
|
||||||
|
return Subcategory::query()
|
||||||
|
->pluck('name')
|
||||||
|
->filter()
|
||||||
|
->unique(fn (string $name) => Str::lower($name))
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yields item detail records (id, name, tags, content) in chunks of
|
||||||
|
* BATCH_SIZE, skipping already-tagged items unless $force. Detail is
|
||||||
|
* fetched per item since BookStack's list endpoints don't include
|
||||||
|
* tags/content — acceptable here since this is an offline batch job, not
|
||||||
|
* a request-path call.
|
||||||
|
*
|
||||||
|
* @param string[] $vocabulary
|
||||||
|
* @param array{scanned: int, tagged: int, skipped: int, failed_batches: int} $totals
|
||||||
|
* @return \Generator<int, array<int, array{id: int, name: string, tags: array, content: string}>>
|
||||||
|
*/
|
||||||
|
protected function itemsToProcess(string $type, array $vocabulary, bool $force, ?int $limit, array &$totals): \Generator
|
||||||
|
{
|
||||||
|
$batch = [];
|
||||||
|
|
||||||
|
foreach ($this->bookstack->listAll($type) as $summary) {
|
||||||
|
if ($limit !== null && $totals['scanned'] >= $limit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$detail = $this->bookstack->detail($type, $summary['id']);
|
||||||
|
|
||||||
|
if (! $detail) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totals['scanned']++;
|
||||||
|
|
||||||
|
if (! $force && $this->alreadyTagged($detail['tags'], $vocabulary)) {
|
||||||
|
$totals['skipped']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$batch[] = $detail;
|
||||||
|
|
||||||
|
if (count($batch) >= self::BATCH_SIZE) {
|
||||||
|
yield $batch;
|
||||||
|
$batch = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($batch) {
|
||||||
|
yield $batch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{name: string, value: string}> $tags
|
||||||
|
* @param string[] $vocabulary
|
||||||
|
*/
|
||||||
|
protected function alreadyTagged(array $tags, array $vocabulary): bool
|
||||||
|
{
|
||||||
|
$existing = collect($tags)->map(fn (array $t) => Str::lower($t['name'] ?? ''));
|
||||||
|
$vocabLower = collect($vocabulary)->map(fn (string $v) => Str::lower($v));
|
||||||
|
|
||||||
|
return $existing->intersect($vocabLower)->isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{id: int, name: string, tags: array, content: string}> $batch
|
||||||
|
* @param string[] $vocabulary
|
||||||
|
* @param array{scanned: int, tagged: int, skipped: int, failed_batches: int} $totals
|
||||||
|
*/
|
||||||
|
protected function processBatch(string $type, array $batch, array $vocabulary, bool $dryRun, array &$totals): void
|
||||||
|
{
|
||||||
|
$prompt = $this->buildPrompt($batch, $vocabulary);
|
||||||
|
|
||||||
|
$raw = $this->ai->chat([
|
||||||
|
['role' => 'system', 'content' => $prompt['system']],
|
||||||
|
['role' => 'user', 'content' => $prompt['user']],
|
||||||
|
], ['temperature' => 0]);
|
||||||
|
|
||||||
|
$assignments = $this->parseAssignments($raw, $vocabulary);
|
||||||
|
|
||||||
|
if ($assignments === null) {
|
||||||
|
$totals['failed_batches']++;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($batch as $item) {
|
||||||
|
$labels = $assignments[(string) $item['id']] ?? [];
|
||||||
|
|
||||||
|
if (! $labels) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dryRun) {
|
||||||
|
$totals['tagged']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mergedTags = $this->mergeTags($item['tags'], $labels);
|
||||||
|
|
||||||
|
if ($this->bookstack->updateTags($type, $item['id'], $mergedTags)) {
|
||||||
|
$totals['tagged']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{id: int, name: string, tags: array, content: string}> $batch
|
||||||
|
* @param string[] $vocabulary
|
||||||
|
* @return array{system: string, user: string}
|
||||||
|
*/
|
||||||
|
protected function buildPrompt(array $batch, array $vocabulary): array
|
||||||
|
{
|
||||||
|
$system = 'Klasyfikujesz artykuły bazy wiedzy do kategorii zgłoszeń helpdesk. '
|
||||||
|
.'Dostępne kategorie (użyj DOKŁADNIE tej pisowni): '.implode(', ', $vocabulary).'. '
|
||||||
|
.'Dla każdego elementu przypisz 0, 1 lub więcej pasujących kategorii — nie zgaduj '
|
||||||
|
.'kategorii, jeśli żadna sensownie nie pasuje, zwróć pustą tablicę. '
|
||||||
|
.'Odpowiedz WYŁĄCZNIE obiektem JSON, bez żadnego innego tekstu ani formatowania, '
|
||||||
|
.'gdzie klucz to id elementu (jako string), a wartość to tablica dopasowanych nazw '
|
||||||
|
.'kategorii. Przykład: {"12": ["Drukarki i skanery"], "13": []}';
|
||||||
|
|
||||||
|
$user = collect($batch)->map(function (array $item) {
|
||||||
|
$excerpt = Str::limit(strip_tags($item['content']), self::CONTENT_EXCERPT_CHARS, '');
|
||||||
|
|
||||||
|
return "id={$item['id']} nazwa=\"{$item['name']}\"\n{$excerpt}";
|
||||||
|
})->implode("\n---\n");
|
||||||
|
|
||||||
|
return ['system' => $system, 'user' => $user];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defensively parses the LLM's JSON response — not every OpenAI-
|
||||||
|
* compatible provider (esp. self-hosted Ollama models) reliably honors a
|
||||||
|
* "respond with only JSON" instruction, so this first tries to pull out
|
||||||
|
* the first {...} block (in case the model wrapped it in prose or a
|
||||||
|
* markdown code fence) before decoding. A malformed/non-JSON response
|
||||||
|
* fails just this one batch (caller counts it in failed_batches) rather
|
||||||
|
* than aborting the whole run. Only vocabulary-matching labels survive
|
||||||
|
* (case-insensitive); anything else the model returns is discarded.
|
||||||
|
*
|
||||||
|
* @param string[] $vocabulary
|
||||||
|
* @return array<string, string[]>|null
|
||||||
|
*/
|
||||||
|
protected function parseAssignments(?string $raw, array $vocabulary): ?array
|
||||||
|
{
|
||||||
|
if (! $raw) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! preg_match('/\{.*\}/s', $raw, $matches)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode($matches[0], true);
|
||||||
|
|
||||||
|
if (! is_array($decoded)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vocabByLower = collect($vocabulary)->mapWithKeys(fn (string $v) => [Str::lower($v) => $v]);
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($decoded as $id => $labels) {
|
||||||
|
if (! is_array($labels)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[(string) $id] = collect($labels)
|
||||||
|
->map(fn ($l) => $vocabByLower[Str::lower((string) $l)] ?? null)
|
||||||
|
->filter()
|
||||||
|
->unique()
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{name: string, value: string}> $existing
|
||||||
|
* @param string[] $newLabels
|
||||||
|
* @return array<int, array{name: string, value: string}>
|
||||||
|
*/
|
||||||
|
protected function mergeTags(array $existing, array $newLabels): array
|
||||||
|
{
|
||||||
|
$existingLower = collect($existing)->map(fn (array $t) => Str::lower($t['name'] ?? ''));
|
||||||
|
|
||||||
|
$additions = collect($newLabels)
|
||||||
|
->reject(fn (string $label) => $existingLower->contains(Str::lower($label)))
|
||||||
|
->map(fn (string $label) => ['name' => $label, 'value' => '']);
|
||||||
|
|
||||||
|
return [...$existing, ...$additions->values()->all()];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Ldap\LldapUser;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserField;
|
use App\Models\UserField;
|
||||||
|
use App\Support\Settings;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use LdapRecord\Models\Model as LdapModel;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,11 +81,26 @@ class LdapUserProvisioner
|
|||||||
return $matched;
|
return $matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findLdapEntryForUser(User $user): ?LldapUser
|
/**
|
||||||
|
* The LdapRecord model class for whichever directory is currently
|
||||||
|
* configured (LLDAP vs Active Directory — see
|
||||||
|
* Settings::ldapUserModelClass()) — resolved fresh on every call rather
|
||||||
|
* than cached, since an admin can flip the directory type mid-session.
|
||||||
|
*/
|
||||||
|
protected function ldapUserModel(): string
|
||||||
|
{
|
||||||
|
return Settings::ldapUserModelClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findLdapEntryForUser(User $user): ?LdapModel
|
||||||
{
|
{
|
||||||
if ($user->guid) {
|
if ($user->guid) {
|
||||||
try {
|
try {
|
||||||
$byGuid = LldapUser::query()->where('entryuuid', '=', $user->guid)->first();
|
// findByGuid() builds the right raw filter for either a
|
||||||
|
// binary objectGUID (AD) or a plain entryUUID string
|
||||||
|
// (LLDAP/OpenLDAP) — unlike a plain ->where(), it doesn't
|
||||||
|
// need to know which attribute that is.
|
||||||
|
$byGuid = $this->ldapUserModel()::query()->findByGuid($user->guid);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::warning('LDAP lookup by guid failed: '.$e->getMessage());
|
Log::warning('LDAP lookup by guid failed: '.$e->getMessage());
|
||||||
$byGuid = null;
|
$byGuid = null;
|
||||||
@@ -98,10 +114,10 @@ class LdapUserProvisioner
|
|||||||
return $this->findLdapEntryByEmail($user->email);
|
return $this->findLdapEntryByEmail($user->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findLdapEntryByEmail(string $email): ?LldapUser
|
protected function findLdapEntryByEmail(string $email): ?LdapModel
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return LldapUser::query()->where('mail', '=', $email)->first();
|
return $this->ldapUserModel()::query()->where('mail', '=', $email)->first();
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::warning('LDAP lookup by email failed: '.$e->getMessage());
|
Log::warning('LDAP lookup by email failed: '.$e->getMessage());
|
||||||
|
|
||||||
@@ -109,7 +125,7 @@ class LdapUserProvisioner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyFieldsFromLdap(User $user, LldapUser $ldapEntry): void
|
public function applyFieldsFromLdap(User $user, LdapModel $ldapEntry): void
|
||||||
{
|
{
|
||||||
$values = $user->custom_field_values ?? [];
|
$values = $user->custom_field_values ?? [];
|
||||||
|
|
||||||
|
|||||||
212
src/app/Services/SnipeItClient.php
Normal file
212
src/app/Services/SnipeItClient.php
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class SnipeItClient
|
||||||
|
{
|
||||||
|
public function enabled(): bool
|
||||||
|
{
|
||||||
|
return Settings::bool('snipeit_enabled')
|
||||||
|
&& Settings::get('snipeit_base_url')
|
||||||
|
&& Settings::get('snipeit_api_token');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assets Snipe-IT has checked out to $email — feeds the "Sprzęt
|
||||||
|
* zgłaszającego" sidebar shown to a client creating a ticket and to an
|
||||||
|
* operator viewing one. Snipe-IT has no "assets by e-mail" endpoint, so
|
||||||
|
* this looks the requester up as a Snipe-IT user first, then lists what's
|
||||||
|
* assigned to them. Cached briefly per e-mail since the ticket-creation
|
||||||
|
* form and ticket-view page both re-render this on every interaction.
|
||||||
|
*
|
||||||
|
* @return array<int, array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, url: string}>
|
||||||
|
*/
|
||||||
|
public function assetsForEmail(string $email): array
|
||||||
|
{
|
||||||
|
$email = trim($email);
|
||||||
|
|
||||||
|
if (! $this->enabled() || $email === '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cache::remember('snipeit:user-assets:'.md5(strtolower($email)), now()->addMinutes(5), function () use ($email) {
|
||||||
|
try {
|
||||||
|
$user = $this->findUserByEmail($email);
|
||||||
|
|
||||||
|
if (! $user) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->client()->get("/users/{$user['id']}/assets");
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect($response->json('rows', []))
|
||||||
|
->map(fn (array $a) => $this->normalizeAsset($a))
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full-inventory search behind the operator's "przeszukaj cały
|
||||||
|
* inwentarz" picker — unlike assetsForEmail() this isn't scoped to any
|
||||||
|
* one requester. Uncached: it's a live, as-you-type lookup.
|
||||||
|
*
|
||||||
|
* @return array<int, array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, url: string}>
|
||||||
|
*/
|
||||||
|
public function searchAssets(string $query, int $limit = 10): array
|
||||||
|
{
|
||||||
|
$query = trim($query);
|
||||||
|
|
||||||
|
if (! $this->enabled() || $query === '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->client()->get('/hardware', ['search' => $query, 'limit' => $limit]);
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect($response->json('rows', []))
|
||||||
|
->map(fn (array $a) => $this->normalizeAsset($a))
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Live detail for a ticket's linked asset — fetched fresh rather than
|
||||||
|
* trusting the ticket's cached snipeit_asset_name, so a status/
|
||||||
|
* reassignment change in Snipe-IT is reflected immediately. Null if
|
||||||
|
* unreachable or the asset was deleted there; callers fall back to the
|
||||||
|
* cached label in that case.
|
||||||
|
*
|
||||||
|
* @return array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, assignedTo: ?string, url: string}|null
|
||||||
|
*/
|
||||||
|
public function asset(int $id): ?array
|
||||||
|
{
|
||||||
|
if (! $this->enabled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->client()->get("/hardware/{$id}");
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
return [
|
||||||
|
...$this->normalizeAsset($data),
|
||||||
|
'assignedTo' => $data['assigned_to']['name'] ?? null,
|
||||||
|
];
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests unsaved admin-form values directly, rather than whatever's
|
||||||
|
* currently stored — mirrors BookStackClient::testConnection(). Hits a
|
||||||
|
* plain list endpoint (rather than e.g. /users/me, which isn't present
|
||||||
|
* on every Snipe-IT version) so this works as a version-agnostic
|
||||||
|
* auth+reachability check.
|
||||||
|
*
|
||||||
|
* @return array{ok: bool, message: ?string}
|
||||||
|
*/
|
||||||
|
public function testConnection(string $baseUrl, string $token, bool $verifySsl = true): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = Http::withToken($token)
|
||||||
|
->acceptJson()
|
||||||
|
->withOptions(['verify' => $verifySsl])
|
||||||
|
->timeout(6)
|
||||||
|
->get(rtrim($baseUrl, '/').'/api/v1/hardware', ['limit' => 1]);
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
return ['ok' => true, 'message' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = $response->json('messages') ?? $response->json('message');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ok' => false,
|
||||||
|
'message' => is_string($message) ? $message : ($message ? json_encode($message) : ('HTTP '.$response->status())),
|
||||||
|
];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return ['ok' => false, 'message' => $e->getMessage()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findUserByEmail(string $email): ?array
|
||||||
|
{
|
||||||
|
$response = $this->client()->get('/users', ['search' => $email, 'limit' => 5]);
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect($response->json('rows', []))
|
||||||
|
->first(fn (array $u) => isset($u['email']) && strcasecmp($u['email'], $email) === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* label is "numer środka - numer seryjny - producent model" — joining
|
||||||
|
* whichever of those three pieces is actually present (Snipe-IT doesn't
|
||||||
|
* guarantee any of them), falling back to the bare asset id if all three
|
||||||
|
* are blank. The display format requested for the "Sprzęt zgłaszającego"
|
||||||
|
* picker and sidebar, everywhere an asset is listed.
|
||||||
|
*
|
||||||
|
* @return array{id: int, label: string, serial: ?string, manufacturer: ?string, model: ?string, category: ?string, status: ?string, url: string}
|
||||||
|
*/
|
||||||
|
protected function normalizeAsset(array $a): array
|
||||||
|
{
|
||||||
|
$assetTag = $a['asset_tag'] ?? null;
|
||||||
|
$serial = $a['serial'] ?? null;
|
||||||
|
$manufacturer = $a['manufacturer']['name'] ?? null;
|
||||||
|
$model = $a['model']['name'] ?? null;
|
||||||
|
$modelDisplay = trim(($manufacturer ? "{$manufacturer} " : '').($model ?? ''));
|
||||||
|
|
||||||
|
$labelParts = collect([$assetTag, $serial, $modelDisplay])
|
||||||
|
->map(fn ($v) => trim((string) $v))
|
||||||
|
->filter(fn ($v) => $v !== '');
|
||||||
|
|
||||||
|
$label = $labelParts->isNotEmpty() ? $labelParts->implode(' - ') : 'Zasób #'.$a['id'];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $a['id'],
|
||||||
|
'label' => $label,
|
||||||
|
'serial' => $serial,
|
||||||
|
'manufacturer' => $manufacturer,
|
||||||
|
'model' => $model,
|
||||||
|
'category' => $a['category']['name'] ?? null,
|
||||||
|
'status' => $a['status_label']['name'] ?? null,
|
||||||
|
'url' => rtrim(Settings::get('snipeit_base_url'), '/').'/hardware/'.$a['id'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function client()
|
||||||
|
{
|
||||||
|
return Http::withToken(Settings::get('snipeit_api_token'))
|
||||||
|
->acceptJson()
|
||||||
|
->withOptions(['verify' => Settings::bool('snipeit_verify_ssl')])
|
||||||
|
->timeout(6)
|
||||||
|
->baseUrl(rtrim(Settings::get('snipeit_base_url'), '/').'/api/v1');
|
||||||
|
}
|
||||||
|
}
|
||||||
166
src/app/Services/TicketAiSummaryService.php
Normal file
166
src/app/Services/TicketAiSummaryService.php
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates an AI summary + suggested next action for every ticket, cached
|
||||||
|
* on the ticket row and shown only in the operator view (see
|
||||||
|
* TicketAiTriageService's docblock for why this runs from the scheduled
|
||||||
|
* ai:run-ticket-automation command rather than live on page load). Stays
|
||||||
|
* reasonably fresh by regenerating whenever a ticket's latest message
|
||||||
|
* postdates its last summary, not on every scheduler tick for every ticket.
|
||||||
|
*/
|
||||||
|
class TicketAiSummaryService
|
||||||
|
{
|
||||||
|
protected const BATCH_LIMIT = 25;
|
||||||
|
|
||||||
|
protected const MESSAGE_EXCERPT_CHARS = 1500;
|
||||||
|
|
||||||
|
protected const BODY_EXCERPT_CHARS = 4000;
|
||||||
|
|
||||||
|
protected const TRANSCRIPT_MESSAGE_LIMIT = 30;
|
||||||
|
|
||||||
|
public function __construct(protected AiClient $ai) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{scanned: int, updated: int, failed: int}
|
||||||
|
*/
|
||||||
|
public function run(?int $limit = null): array
|
||||||
|
{
|
||||||
|
$totals = ['scanned' => 0, 'updated' => 0, 'failed' => 0];
|
||||||
|
|
||||||
|
if (! $this->ai->enabled() || ! Settings::bool('ai_summary_enabled')) {
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->staleQuery()
|
||||||
|
->limit($limit ?? self::BATCH_LIMIT)
|
||||||
|
->get()
|
||||||
|
->each(function (Ticket $ticket) use (&$totals) {
|
||||||
|
$totals['scanned']++;
|
||||||
|
|
||||||
|
$this->summarizeOne($ticket) ? $totals['updated']++ : $totals['failed']++;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tickets with no summary yet, or whose latest message postdates the
|
||||||
|
* last summary generation. Deliberately compares against
|
||||||
|
* ticket_messages.created_at rather than tickets.updated_at — the
|
||||||
|
* latter also changes on unrelated actions (status/priority/timer
|
||||||
|
* edits), which would otherwise trigger spurious re-summarization on
|
||||||
|
* every scheduler tick for an active ticket.
|
||||||
|
*/
|
||||||
|
protected function staleQuery(): Builder
|
||||||
|
{
|
||||||
|
return Ticket::query()->where(function (Builder $q) {
|
||||||
|
$q->whereNull('ai_summary_generated_at')
|
||||||
|
->orWhere(function (Builder $q2) {
|
||||||
|
$q2->whereNotNull('ai_summary_generated_at')
|
||||||
|
->whereColumn('ai_summary_generated_at', '<', DB::raw(
|
||||||
|
'(select max(ticket_messages.created_at) from ticket_messages where ticket_messages.ticket_id = tickets.id)'
|
||||||
|
));
|
||||||
|
});
|
||||||
|
})->orderBy('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regenerates the summary for a single ticket right now, bypassing the
|
||||||
|
* staleness check — used by the manual "regenerate" button and the
|
||||||
|
* on-new-message hook, as opposed to run()'s scheduled batch sweep.
|
||||||
|
*/
|
||||||
|
public function generateFor(Ticket $ticket): bool
|
||||||
|
{
|
||||||
|
if (! $this->ai->enabled() || ! Settings::bool('ai_summary_enabled')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->summarizeOne($ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function summarizeOne(Ticket $ticket): bool
|
||||||
|
{
|
||||||
|
$raw = $this->ai->chat([
|
||||||
|
['role' => 'system', 'content' => Settings::get('ai_summary_prompt')],
|
||||||
|
['role' => 'user', 'content' => $this->buildTranscript($ticket)],
|
||||||
|
], ['temperature' => 0.2]);
|
||||||
|
|
||||||
|
$parsed = $this->parseResponse($raw);
|
||||||
|
|
||||||
|
if ($parsed === null) {
|
||||||
|
// Leaves any prior summary untouched and generated_at unchanged,
|
||||||
|
// so the ticket stays in the stale set and gets retried next run
|
||||||
|
// rather than silently losing a working summary.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket->update([
|
||||||
|
'ai_summary' => $parsed['summary'],
|
||||||
|
'ai_suggested_action' => $parsed['suggested_action'],
|
||||||
|
'ai_summary_generated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Includes tickets.body explicitly (the opening description, separate
|
||||||
|
* from ticket_messages) rather than relying on it showing up as the
|
||||||
|
* thread's first message — that row falls outside the last-N transcript
|
||||||
|
* window on any ticket with more than TRANSCRIPT_MESSAGE_LIMIT messages,
|
||||||
|
* which would otherwise silently drop the original request from long
|
||||||
|
* threads. Mirrors TicketAiTriageService's own subject+body framing.
|
||||||
|
*/
|
||||||
|
protected function buildTranscript(Ticket $ticket): string
|
||||||
|
{
|
||||||
|
$lines = [
|
||||||
|
"Temat: {$ticket->subject}",
|
||||||
|
"Treść:\n".Str::limit(strip_tags($ticket->body), self::BODY_EXCERPT_CHARS),
|
||||||
|
];
|
||||||
|
|
||||||
|
$ticket->messages()->latest('created_at')->limit(self::TRANSCRIPT_MESSAGE_LIMIT)->get()
|
||||||
|
->sortBy('created_at')
|
||||||
|
->each(function ($message) use (&$lines) {
|
||||||
|
$role = $message->internal ? 'notatka wewnętrzna' : ($message->role === 'client' ? 'klient' : 'operator');
|
||||||
|
$body = Str::limit(strip_tags($message->body), self::MESSAGE_EXCERPT_CHARS, '');
|
||||||
|
$lines[] = "[{$role}] {$message->author_name}: {$body}";
|
||||||
|
});
|
||||||
|
|
||||||
|
return implode("\n\n", $lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same defensive-parsing shape used elsewhere in this app's AI services
|
||||||
|
* (BookStackContentTagger, TicketAiTriageService) — extracts the first
|
||||||
|
* {...} block before decoding.
|
||||||
|
*
|
||||||
|
* @return array{summary: string, suggested_action: ?string}|null
|
||||||
|
*/
|
||||||
|
protected function parseResponse(?string $raw): ?array
|
||||||
|
{
|
||||||
|
if (! $raw || ! preg_match('/\{.*\}/s', $raw, $matches)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode($matches[0], true);
|
||||||
|
|
||||||
|
if (! is_array($decoded) || empty($decoded['summary']) || ! is_string($decoded['summary'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'summary' => trim($decoded['summary']),
|
||||||
|
'suggested_action' => ! empty($decoded['suggested_action']) && is_string($decoded['suggested_action'])
|
||||||
|
? trim($decoded['suggested_action'])
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
311
src/app/Services/TicketAiTriageService.php
Normal file
311
src/app/Services/TicketAiTriageService.php
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Priority;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One-shot AI classification of new tickets, gated by 5 independent
|
||||||
|
* settings toggles (ai_triage_category_when_missing/
|
||||||
|
* subcategory_when_category_only/recheck_categorized/fix_subject/
|
||||||
|
* set_priority). Runs from the scheduled ai:run-ticket-automation command,
|
||||||
|
* never synchronously at ticket creation, so it never adds LLM latency to a
|
||||||
|
* live customer submitting a ticket. Every scanned ticket gets
|
||||||
|
* ai_triaged_at stamped exactly once — this is a one-shot pass per ticket,
|
||||||
|
* not a continuous recheck, and there's no manual re-trigger by design.
|
||||||
|
*/
|
||||||
|
class TicketAiTriageService
|
||||||
|
{
|
||||||
|
protected const BATCH_LIMIT = 25;
|
||||||
|
|
||||||
|
protected const BODY_EXCERPT_CHARS = 4000;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected AiClient $ai,
|
||||||
|
protected TicketService $tickets,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{scanned: int, changed: int, failed: int}
|
||||||
|
*/
|
||||||
|
public function run(?int $limit = null): array
|
||||||
|
{
|
||||||
|
$totals = ['scanned' => 0, 'changed' => 0, 'failed' => 0];
|
||||||
|
|
||||||
|
if (! $this->ai->enabled() || ! $this->anyToggleEnabled()) {
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vocabulary = $this->buildVocabulary();
|
||||||
|
$priorities = Priority::query()->orderBy('sort_order')->pluck('label', 'key')->all();
|
||||||
|
|
||||||
|
Ticket::query()->whereNull('ai_triaged_at')
|
||||||
|
->orderBy('id')
|
||||||
|
->limit($limit ?? self::BATCH_LIMIT)
|
||||||
|
->get()
|
||||||
|
->each(function (Ticket $ticket) use ($vocabulary, $priorities, &$totals) {
|
||||||
|
$totals['scanned']++;
|
||||||
|
$this->triageOne($ticket, $vocabulary, $priorities, $totals);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function anyToggleEnabled(): bool
|
||||||
|
{
|
||||||
|
return Settings::bool('ai_triage_category_when_missing')
|
||||||
|
|| Settings::bool('ai_triage_subcategory_when_category_only')
|
||||||
|
|| Settings::bool('ai_triage_recheck_categorized')
|
||||||
|
|| Settings::bool('ai_triage_fix_subject')
|
||||||
|
|| Settings::bool('ai_triage_set_priority');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{id: int, name: string, subcategories: array<int, array{id: int, name: string}>}> $vocabulary
|
||||||
|
* @param array<string, string> $priorities
|
||||||
|
* @param array{scanned: int, changed: int, failed: int} $totals
|
||||||
|
*/
|
||||||
|
protected function triageOne(Ticket $ticket, array $vocabulary, array $priorities, array &$totals): void
|
||||||
|
{
|
||||||
|
$prompt = $this->buildPrompt($ticket, $vocabulary, $priorities);
|
||||||
|
|
||||||
|
if ($prompt === null) {
|
||||||
|
$ticket->update(['ai_triaged_at' => now()]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw = $this->ai->chat([
|
||||||
|
['role' => 'system', 'content' => $prompt['system']],
|
||||||
|
['role' => 'user', 'content' => $prompt['user']],
|
||||||
|
], ['temperature' => 0]);
|
||||||
|
|
||||||
|
$parsed = $this->parseResponse($raw);
|
||||||
|
|
||||||
|
// A response came back but couldn't be parsed — not fatal to the
|
||||||
|
// run, just means this ticket wasn't classified this time.
|
||||||
|
// ai_triaged_at is still stamped below so a persistently-bad
|
||||||
|
// response doesn't get retried forever.
|
||||||
|
if ($raw !== null && $parsed === null) {
|
||||||
|
$totals['failed']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[$changes, $historyLines] = $parsed
|
||||||
|
? $this->resolveChanges($ticket, $parsed, $vocabulary, $priorities, $prompt['scope'])
|
||||||
|
: [[], []];
|
||||||
|
|
||||||
|
if ($changes) {
|
||||||
|
$this->tickets->applyAiTriage($ticket, $changes, $historyLines);
|
||||||
|
$totals['changed']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket->update(['ai_triaged_at' => now()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array{id: int, name: string, subcategories: array<int, array{id: int, name: string}>}>
|
||||||
|
*/
|
||||||
|
protected function buildVocabulary(): array
|
||||||
|
{
|
||||||
|
return Category::query()->with('subcategories')->get()
|
||||||
|
->map(fn (Category $c) => [
|
||||||
|
'id' => $c->id,
|
||||||
|
'name' => $c->name,
|
||||||
|
'subcategories' => $c->subcategories->map(fn ($s) => ['id' => $s->id, 'name' => $s->name])->all(),
|
||||||
|
])
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which of the 3 mutually-exclusive category scenarios (if
|
||||||
|
* any) applies to $ticket's current state, and whether subject/priority
|
||||||
|
* are also in scope, then builds the prompt around exactly that. Returns
|
||||||
|
* null when nothing is applicable/enabled for this ticket, so the caller
|
||||||
|
* can skip straight to stamping ai_triaged_at without an AI call.
|
||||||
|
*
|
||||||
|
* @param array<int, array{id: int, name: string, subcategories: array}> $vocabulary
|
||||||
|
* @param array<string, string> $priorities
|
||||||
|
* @return array{system: string, user: string, scope: ?string}|null
|
||||||
|
*/
|
||||||
|
protected function buildPrompt(Ticket $ticket, array $vocabulary, array $priorities): ?array
|
||||||
|
{
|
||||||
|
$scope = null;
|
||||||
|
|
||||||
|
if (! $ticket->category_id && ! $ticket->subcategory_id && Settings::bool('ai_triage_category_when_missing')) {
|
||||||
|
$scope = 'missing';
|
||||||
|
} elseif ($ticket->category_id && ! $ticket->subcategory_id && Settings::bool('ai_triage_subcategory_when_category_only')) {
|
||||||
|
$scope = 'category_only';
|
||||||
|
} elseif ($ticket->subcategory_id && Settings::bool('ai_triage_recheck_categorized')) {
|
||||||
|
$scope = 'recheck';
|
||||||
|
}
|
||||||
|
|
||||||
|
$wantSubject = Settings::bool('ai_triage_fix_subject');
|
||||||
|
$wantPriority = Settings::bool('ai_triage_set_priority');
|
||||||
|
|
||||||
|
if ($scope === null && ! $wantSubject && ! $wantPriority) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = ['Klasyfikujesz zgłoszenia helpdesku na podstawie tematu i treści.'];
|
||||||
|
|
||||||
|
if ($scope === 'missing') {
|
||||||
|
$parts[] = 'To zgłoszenie nie ma jeszcze przypisanej kategorii ani podkategorii. Wybierz najlepiej '
|
||||||
|
.'pasującą kategorię z listy poniżej (użyj DOKŁADNIE tej pisowni) i, jeśli to możliwe, także '
|
||||||
|
.'konkretną podkategorię w jej ramach. Jeśli żadna kategoria sensownie nie pasuje, zwróć null dla obu pól.';
|
||||||
|
} elseif ($scope === 'category_only') {
|
||||||
|
$parts[] = "To zgłoszenie ma już przypisaną kategorię \"{$ticket->category->name}\", ale brak konkretnej "
|
||||||
|
.'podkategorii. Wybierz najlepiej pasującą podkategorię z listy poniżej (należącą do tej kategorii, '
|
||||||
|
.'użyj DOKŁADNIE tej pisowni). Jeśli żadna nie pasuje dobrze, zwróć null.';
|
||||||
|
} elseif ($scope === 'recheck') {
|
||||||
|
$parts[] = "To zgłoszenie ma już przypisaną podkategorię \"{$ticket->subcategory->label()}\". Sprawdź, "
|
||||||
|
.'czy to nadal najlepsze dopasowanie na podstawie treści. Jeśli tak — zwróć null (nic nie zmieniaj). '
|
||||||
|
.'Jeśli lepiej pasuje inna kategoria/podkategoria z listy poniżej, zwróć ją.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($scope !== null) {
|
||||||
|
$parts[] = "Dostępne kategorie i podkategorie:\n".$this->vocabularyText($vocabulary, $scope, $ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($wantSubject) {
|
||||||
|
$parts[] = 'Jeśli obecny temat zgłoszenia jest niejasny lub mylący, zaproponuj lepszy, zwięzły temat po '
|
||||||
|
.'polsku w polu "subject" (w przeciwnym razie null).';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($wantPriority) {
|
||||||
|
$priorityList = collect($priorities)->map(fn ($label, $key) => "{$key} ({$label})")->implode(', ');
|
||||||
|
$parts[] = 'Na podstawie treści oceń priorytet zgłoszenia i zwróć jego klucz w polu "priority" — '
|
||||||
|
."dostępne klucze: {$priorityList}.";
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts[] = 'Odpowiedz WYŁĄCZNIE obiektem JSON, bez żadnego innego tekstu ani formatowania: '
|
||||||
|
.'{"category": "...", "subcategory": "...", "subject": "...", "priority": "..."} — pola, o które nie '
|
||||||
|
.'proszono powyżej, ustaw na null.';
|
||||||
|
|
||||||
|
$user = "Temat: {$ticket->subject}\n\nTreść:\n".Str::limit(strip_tags($ticket->body), self::BODY_EXCERPT_CHARS);
|
||||||
|
|
||||||
|
return ['system' => implode("\n\n", $parts), 'user' => $user, 'scope' => $scope];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{id: int, name: string, subcategories: array<int, array{id: int, name: string}>}> $vocabulary
|
||||||
|
*/
|
||||||
|
protected function vocabularyText(array $vocabulary, string $scope, Ticket $ticket): string
|
||||||
|
{
|
||||||
|
$categories = $scope === 'category_only'
|
||||||
|
? collect($vocabulary)->filter(fn (array $c) => $c['id'] === $ticket->category_id)
|
||||||
|
: collect($vocabulary);
|
||||||
|
|
||||||
|
return $categories
|
||||||
|
->map(fn (array $c) => "- {$c['name']}: ".collect($c['subcategories'])->pluck('name')->implode(', '))
|
||||||
|
->implode("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same defensive-parsing shape as BookStackContentTagger::parseAssignments()
|
||||||
|
* — extracts the first {...} block before decoding, so prose-wrapped or
|
||||||
|
* malformed responses fail gracefully instead of crashing the run.
|
||||||
|
*/
|
||||||
|
protected function parseResponse(?string $raw): ?array
|
||||||
|
{
|
||||||
|
if (! $raw || ! preg_match('/\{.*\}/s', $raw, $matches)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode($matches[0], true);
|
||||||
|
|
||||||
|
return is_array($decoded) ? $decoded : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fail-closed resolution: every value from the model is matched against
|
||||||
|
* the real vocabulary/priority list before being trusted — an
|
||||||
|
* unmatched/hallucinated category, a subcategory outside its claimed
|
||||||
|
* category, or an unknown priority key is silently dropped rather than
|
||||||
|
* written to the ticket. Only fields whose resolved value actually
|
||||||
|
* differs from the ticket's current value produce a change + history
|
||||||
|
* line, so e.g. a "recheck" that confirms the existing subcategory
|
||||||
|
* leaves no trace.
|
||||||
|
*
|
||||||
|
* @param array<int, array{id: int, name: string, subcategories: array<int, array{id: int, name: string}>}> $vocabulary
|
||||||
|
* @param array<string, string> $priorities
|
||||||
|
* @return array{0: array<string, mixed>, 1: string[]}
|
||||||
|
*/
|
||||||
|
protected function resolveChanges(Ticket $ticket, array $parsed, array $vocabulary, array $priorities, ?string $scope): array
|
||||||
|
{
|
||||||
|
$changes = [];
|
||||||
|
$historyLines = [];
|
||||||
|
|
||||||
|
if ($scope !== null) {
|
||||||
|
$resolved = $this->resolveCategory($parsed, $vocabulary, $scope, $ticket);
|
||||||
|
|
||||||
|
if ($resolved) {
|
||||||
|
[$categoryId, $subcategoryId, $label] = $resolved;
|
||||||
|
|
||||||
|
if ($categoryId !== $ticket->category_id || $subcategoryId !== $ticket->subcategory_id) {
|
||||||
|
$changes['category_id'] = $categoryId;
|
||||||
|
$changes['subcategory_id'] = $subcategoryId;
|
||||||
|
$historyLines[] = "Kategoria zmieniona na: {$label}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings::bool('ai_triage_fix_subject') && ! empty($parsed['subject']) && is_string($parsed['subject'])) {
|
||||||
|
$newSubject = Str::limit(trim($parsed['subject']), 255, '');
|
||||||
|
|
||||||
|
if ($newSubject !== '' && $newSubject !== $ticket->subject) {
|
||||||
|
$changes['subject'] = $newSubject;
|
||||||
|
$historyLines[] = "Temat zmieniony na: „{$newSubject}”";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings::bool('ai_triage_set_priority') && ! empty($parsed['priority']) && is_string($parsed['priority'])) {
|
||||||
|
$key = collect($priorities)->keys()->first(fn ($k) => Str::lower($k) === Str::lower($parsed['priority']));
|
||||||
|
|
||||||
|
if ($key !== null && $key !== $ticket->priority_key) {
|
||||||
|
$changes['priority_key'] = $key;
|
||||||
|
$historyLines[] = 'Priorytet zmieniony na: '.Priority::labelFor($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$changes, $historyLines];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{id: int, name: string, subcategories: array<int, array{id: int, name: string}>}> $vocabulary
|
||||||
|
* @return array{0: ?int, 1: ?int, 2: string}|null [category_id, subcategory_id, display label]
|
||||||
|
*/
|
||||||
|
protected function resolveCategory(array $parsed, array $vocabulary, string $scope, Ticket $ticket): ?array
|
||||||
|
{
|
||||||
|
$categories = $scope === 'category_only'
|
||||||
|
? collect($vocabulary)->filter(fn (array $c) => $c['id'] === $ticket->category_id)
|
||||||
|
: collect($vocabulary);
|
||||||
|
|
||||||
|
$subName = $parsed['subcategory'] ?? null;
|
||||||
|
|
||||||
|
if (is_string($subName) && $subName !== '') {
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
foreach ($category['subcategories'] as $sub) {
|
||||||
|
if (Str::lower($sub['name']) === Str::lower($subName)) {
|
||||||
|
return [null, $sub['id'], "{$category['name']} / {$sub['name']}"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$catName = $parsed['category'] ?? null;
|
||||||
|
|
||||||
|
if (is_string($catName) && $catName !== '') {
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
if (Str::lower($category['name']) === Str::lower($catName)) {
|
||||||
|
return [$category['id'], null, $category['name']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,8 @@ class TicketService
|
|||||||
'custom_fields' => $data['custom_values'] ?? [],
|
'custom_fields' => $data['custom_values'] ?? [],
|
||||||
'last_customer_activity_at' => now(),
|
'last_customer_activity_at' => now(),
|
||||||
'source' => $data['source'] ?? 'web',
|
'source' => $data['source'] ?? 'web',
|
||||||
|
'snipeit_asset_id' => $data['snipeit_asset_id'] ?? null,
|
||||||
|
'snipeit_asset_name' => $data['snipeit_asset_name'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$message = $ticket->messages()->create([
|
$message = $ticket->messages()->create([
|
||||||
@@ -161,12 +163,79 @@ class TicketService
|
|||||||
TicketQueueChanged::dispatch($ticket->id, 'team_changed', Auth::id());
|
TicketQueueChanged::dispatch($ticket->id, 'team_changed', Auth::id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies one AI-triage pass's changes (see TicketAiTriageService) in a
|
||||||
|
* single update, rather than composing setPriority()/updateDetails() —
|
||||||
|
* a pass can touch category, subcategory, subject and priority
|
||||||
|
* together, and those would each write their own generic history line
|
||||||
|
* and fire notify()/TriggerEngine::handle() per field instead of once
|
||||||
|
* per pass, fragmenting one semantic AI decision into several
|
||||||
|
* unrelated-looking edits. $historyLines carries one mechanical
|
||||||
|
* "X changed to: Y" line per changed field (built by the caller, since
|
||||||
|
* it already knows the human-readable labels); this always appends one
|
||||||
|
* more attribution line on top, mirroring how RunAutomationRules logs
|
||||||
|
* "Automatyzacja: {label}" after its own field-change lines.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $changes column => value, only the fields that actually changed
|
||||||
|
* @param string[] $historyLines
|
||||||
|
*/
|
||||||
|
public function applyAiTriage(Ticket $ticket, array $changes, array $historyLines): void
|
||||||
|
{
|
||||||
|
if (! $changes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$categoryChanged = array_key_exists('category_id', $changes) || array_key_exists('subcategory_id', $changes);
|
||||||
|
$priorityChanged = array_key_exists('priority_key', $changes);
|
||||||
|
|
||||||
|
$ticket->update($changes);
|
||||||
|
|
||||||
|
foreach ($historyLines as $line) {
|
||||||
|
$ticket->addHistory($line);
|
||||||
|
}
|
||||||
|
$ticket->addHistory('Automatyzacja: klasyfikacja AI');
|
||||||
|
|
||||||
|
if ($categoryChanged) {
|
||||||
|
$this->notify($ticket, 'category_changed');
|
||||||
|
app(TriggerEngine::class)->handle($ticket, 'category_changed');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priorityChanged) {
|
||||||
|
$this->notify($ticket, 'priority_changed');
|
||||||
|
app(TriggerEngine::class)->handle($ticket, 'priority_changed');
|
||||||
|
}
|
||||||
|
|
||||||
|
app(TriggerEngine::class)->handle($ticket, 'ticket_updated');
|
||||||
|
TicketQueueChanged::dispatch($ticket->id, 'ai_triage', Auth::id());
|
||||||
|
}
|
||||||
|
|
||||||
public function setReporter(Ticket $ticket, User $customer): void
|
public function setReporter(Ticket $ticket, User $customer): void
|
||||||
{
|
{
|
||||||
$ticket->update(['customer_id' => $customer->id, 'email' => $customer->email, 'name' => $customer->name]);
|
$ticket->update(['customer_id' => $customer->id, 'email' => $customer->email, 'name' => $customer->name]);
|
||||||
$ticket->addHistory('Zgłaszający zmieniony na: '.$customer->name);
|
$ticket->addHistory('Zgłaszający zmieniony na: '.$customer->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links/unlinks the Snipe-IT asset attached to a ticket — $asset null
|
||||||
|
* unlinks. Only the label (not live status/assignment) is cached on the
|
||||||
|
* ticket row, so it still shows something if Snipe-IT later becomes
|
||||||
|
* unreachable or the asset is deleted there, without a live API call on
|
||||||
|
* every ticket list render (see SnipeItClient::asset() for the live
|
||||||
|
* fetch used on the ticket-detail page itself).
|
||||||
|
*
|
||||||
|
* @param array{id: int, label: string}|null $asset
|
||||||
|
*/
|
||||||
|
public function setSnipeitAsset(Ticket $ticket, ?array $asset): void
|
||||||
|
{
|
||||||
|
$ticket->update([
|
||||||
|
'snipeit_asset_id' => $asset['id'] ?? null,
|
||||||
|
'snipeit_asset_name' => $asset['label'] ?? null,
|
||||||
|
]);
|
||||||
|
$ticket->addHistory($asset
|
||||||
|
? 'Powiązano sprzęt (inwentarz): '.$asset['label']
|
||||||
|
: 'Odpięto powiązany sprzęt (inwentarz)');
|
||||||
|
}
|
||||||
|
|
||||||
public function updateDetails(Ticket $ticket, array $data): void
|
public function updateDetails(Ticket $ticket, array $data): void
|
||||||
{
|
{
|
||||||
$categoryChanged = ($data['subcategory_id'] ?? null) !== $ticket->subcategory_id;
|
$categoryChanged = ($data['subcategory_id'] ?? null) !== $ticket->subcategory_id;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Support;
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Ldap\AdUser;
|
||||||
|
use App\Ldap\LldapUser;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
@@ -25,6 +27,13 @@ class Settings
|
|||||||
'ticket_number_prefix' => '#',
|
'ticket_number_prefix' => '#',
|
||||||
'ticket_number_obfuscate' => '0',
|
'ticket_number_obfuscate' => '0',
|
||||||
'ticket_number_min_length' => '4',
|
'ticket_number_min_length' => '4',
|
||||||
|
'refresh_ticket_view_seconds' => '30',
|
||||||
|
'refresh_queue_seconds' => '60',
|
||||||
|
'refresh_notifications_seconds' => '30',
|
||||||
|
'schedule_sla_check_minutes' => '15',
|
||||||
|
'schedule_automation_rules_minutes' => '15',
|
||||||
|
'schedule_imap_fetch_minutes' => '5',
|
||||||
|
'schedule_ai_automation_minutes' => '5',
|
||||||
'ldap_enabled' => '1',
|
'ldap_enabled' => '1',
|
||||||
'ldap_host' => '',
|
'ldap_host' => '',
|
||||||
'ldap_port' => '389',
|
'ldap_port' => '389',
|
||||||
@@ -48,9 +57,37 @@ class Settings
|
|||||||
'bookstack_token_secret' => '',
|
'bookstack_token_secret' => '',
|
||||||
'bookstack_verify_ssl' => '1',
|
'bookstack_verify_ssl' => '1',
|
||||||
'bookstack_show_to_guests' => '0',
|
'bookstack_show_to_guests' => '0',
|
||||||
'bookstack_search_types' => 'both',
|
'bookstack_search_types' => 'book,page,chapter',
|
||||||
|
'bookstack_search_by' => 'both',
|
||||||
'bookstack_allowed_shelf_ids_creation' => '',
|
'bookstack_allowed_shelf_ids_creation' => '',
|
||||||
'bookstack_allowed_shelf_ids_ticket_view' => '',
|
'bookstack_allowed_shelf_ids_ticket_view' => '',
|
||||||
|
'snipeit_enabled' => '0',
|
||||||
|
'snipeit_base_url' => '',
|
||||||
|
'snipeit_api_token' => '',
|
||||||
|
'snipeit_verify_ssl' => '1',
|
||||||
|
'snipeit_client_can_select_asset' => '0',
|
||||||
|
'snipeit_client_asset_subcategory_ids' => '',
|
||||||
|
'snipeit_operator_view_requester_assets' => '1',
|
||||||
|
'snipeit_operator_search_inventory' => '1',
|
||||||
|
'ai_enabled' => '0',
|
||||||
|
'ai_base_url' => '',
|
||||||
|
'ai_api_key' => '',
|
||||||
|
'ai_model' => '',
|
||||||
|
'ai_verify_ssl' => '1',
|
||||||
|
'ai_triage_category_when_missing' => '0',
|
||||||
|
'ai_triage_subcategory_when_category_only' => '0',
|
||||||
|
'ai_triage_recheck_categorized' => '0',
|
||||||
|
'ai_triage_fix_subject' => '0',
|
||||||
|
'ai_triage_set_priority' => '0',
|
||||||
|
'ai_summary_enabled' => '0',
|
||||||
|
'ai_summary_regenerate_on_message' => '0',
|
||||||
|
'ai_summary_prompt' => 'Jesteś asystentem operatora helpdesku. Otrzymujesz temat, treść oraz historię '
|
||||||
|
.'wiadomości zgłoszenia. Podsumuj sprawę rzeczowo po polsku (2-3 zdania, czego dotyczy problem i na '
|
||||||
|
.'jakim jest etapie — np. czeka na odpowiedź klienta czy na działanie operatora) i zaproponuj krótką, '
|
||||||
|
.'konkretną kolejną akcję (jedno zdanie), np. "Poproś klienta o zrzut ekranu błędu" albo "Zamknij '
|
||||||
|
.'zgłoszenie — klient potwierdził rozwiązanie". Odpowiedz WYŁĄCZNIE obiektem JSON, bez innego tekstu: '
|
||||||
|
.'{"summary": "...", "suggested_action": "..."}. Jeśli nie da się ocenić kolejnego kroku, ustaw '
|
||||||
|
.'"suggested_action" na pusty string.',
|
||||||
'email_footer' => '<p>Ta wiadomość została wygenerowana automatycznie przez system {firma} — prosimy na nią nie odpowiadać.</p>',
|
'email_footer' => '<p>Ta wiadomość została wygenerowana automatycznie przez system {firma} — prosimy na nią nie odpowiadać.</p>',
|
||||||
'accent_color' => '#7c6fd6',
|
'accent_color' => '#7c6fd6',
|
||||||
'login_notice_type' => 'info',
|
'login_notice_type' => 'info',
|
||||||
@@ -63,7 +100,7 @@ class Settings
|
|||||||
.'</div>',
|
.'</div>',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static array $encrypted = ['ldap_bind_password', 'mail_smtp_password', 'bookstack_token_secret'];
|
protected static array $encrypted = ['ldap_bind_password', 'mail_smtp_password', 'bookstack_token_secret', 'ai_api_key', 'snipeit_api_token'];
|
||||||
|
|
||||||
public static function get(string $key, ?string $default = null): ?string
|
public static function get(string $key, ?string $default = null): ?string
|
||||||
{
|
{
|
||||||
@@ -194,6 +231,20 @@ class Settings
|
|||||||
return $path ? Storage::disk('public')->url($path) : asset('branding/default-mark.svg');
|
return $path ? Storage::disk('public')->url($path) : asset('branding/default-mark.svg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-page <title>: the context first (so it's still visible once the
|
||||||
|
* browser truncates a long tab title, and so tabs are distinguishable
|
||||||
|
* at a glance) with the company name as a trailing, always-present
|
||||||
|
* anchor. Falls back to just the company name for pages with no more
|
||||||
|
* specific context (landing, login).
|
||||||
|
*/
|
||||||
|
public static function pageTitle(?string $context = null): string
|
||||||
|
{
|
||||||
|
$company = static::get('company_name');
|
||||||
|
|
||||||
|
return $context ? "{$context} — {$company}" : $company;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The admin-configured timezone (IANA identifier, e.g. "Europe/Warsaw"),
|
* The admin-configured timezone (IANA identifier, e.g. "Europe/Warsaw"),
|
||||||
* applied at runtime by AppServiceProvider so every date/time displayed
|
* applied at runtime by AppServiceProvider so every date/time displayed
|
||||||
@@ -209,6 +260,24 @@ class Settings
|
|||||||
: static::$defaults['timezone'];
|
: static::$defaults['timezone'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether an admin-configurable "every N minutes" scheduled command
|
||||||
|
* (schedule_*_minutes, routes/console.php) is due to run this minute.
|
||||||
|
* Used inside a Schedule::command(...)->when(...) closure rather than
|
||||||
|
* building a cron string up front — a closure is only evaluated when
|
||||||
|
* schedule:run actually processes due events, whereas eagerly reading
|
||||||
|
* Settings (which queries the DB) at routes/console.php's top level
|
||||||
|
* would run on every artisan boot (migrate, tinker, tests, ...), before
|
||||||
|
* the settings table necessarily even exists. Clamped to a minimum of 1
|
||||||
|
* so a blank/zero/negative stored value can never busy-loop.
|
||||||
|
*/
|
||||||
|
public static function dueEveryMinutes(string $key, int $default): bool
|
||||||
|
{
|
||||||
|
$minutes = max(1, (int) static::get($key, (string) $default));
|
||||||
|
|
||||||
|
return now()->minute % $minutes === 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a single e-mail template's rendered HTML body in the fixed
|
* Wraps a single e-mail template's rendered HTML body in the fixed
|
||||||
* "box" layout — company name, ticket content and footer — so every
|
* "box" layout — company name, ticket content and footer — so every
|
||||||
@@ -233,19 +302,46 @@ class Settings
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the admin has pointed LDAP auth at Active Directory rather
|
||||||
|
* than an LLDAP/OpenLDAP-schema directory — changes which LdapRecord
|
||||||
|
* model class backs logins (see ldapUserModelClass()) and which
|
||||||
|
* attribute a bare username search defaults to (see
|
||||||
|
* ldapUsernameAttribute()), since AD's objectClass chain and login
|
||||||
|
* attribute (sAMAccountName, not uid) differ from LLDAP's.
|
||||||
|
*/
|
||||||
|
public static function isActiveDirectory(): bool
|
||||||
|
{
|
||||||
|
return static::get('ldap_directory_type') === 'ad';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The LdapRecord model class the 'users' auth provider should use —
|
||||||
|
* wired into config('auth.providers.users.model') at runtime by
|
||||||
|
* AppServiceProvider::applyLdapSettingsOverride(), same as the
|
||||||
|
* connection host/base DN below.
|
||||||
|
*/
|
||||||
|
public static function ldapUserModelClass(): string
|
||||||
|
{
|
||||||
|
return static::isActiveDirectory() ? AdUser::class : LldapUser::class;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the admin-configurable LDAP user filter (e.g. "(uid={0})") to
|
* Parses the admin-configurable LDAP user filter (e.g. "(uid={0})") to
|
||||||
* find which LDAP attribute logins are matched against.
|
* find which LDAP attribute logins are matched against. Defaults to
|
||||||
|
* Active Directory's sAMAccountName when no filter is set and the
|
||||||
|
* directory type is AD — uid is never populated on a stock AD user.
|
||||||
*/
|
*/
|
||||||
public static function ldapUsernameAttribute(): string
|
public static function ldapUsernameAttribute(): string
|
||||||
{
|
{
|
||||||
$filter = static::get('ldap_user_filter', '(uid={0})');
|
$default = static::isActiveDirectory() ? '(sAMAccountName={0})' : '(uid={0})';
|
||||||
|
$filter = static::get('ldap_user_filter') ?: $default;
|
||||||
|
|
||||||
if (preg_match('/\(([a-zA-Z0-9-]+)=\{0\}\)/', (string) $filter, $matches)) {
|
if (preg_match('/\(([a-zA-Z0-9-]+)=\{0\}\)/', (string) $filter, $matches)) {
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'uid';
|
return static::isActiveDirectory() ? 'sAMAccountName' : 'uid';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* ai_triaged_at marks that the AI auto-triage pass has run for this
|
||||||
|
* ticket (regardless of whether it changed anything) — never reset, so
|
||||||
|
* the scheduled command's query is just "tickets where this is null".
|
||||||
|
*
|
||||||
|
* ai_summary/ai_suggested_action/ai_summary_generated_at cache the AI
|
||||||
|
* ticket summary shown to operators; generated_at lets the summary
|
||||||
|
* command cheaply tell whether a ticket's summary is stale relative to
|
||||||
|
* its latest message, without re-summarizing every ticket every run.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table) {
|
||||||
|
$table->timestamp('ai_triaged_at')->nullable()->after('source');
|
||||||
|
$table->text('ai_summary')->nullable()->after('ai_triaged_at');
|
||||||
|
$table->text('ai_suggested_action')->nullable()->after('ai_summary');
|
||||||
|
$table->timestamp('ai_summary_generated_at')->nullable()->after('ai_suggested_action');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['ai_triaged_at', 'ai_summary', 'ai_suggested_action', 'ai_summary_generated_at']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('subcategories', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('sort_order')->default(0)->after('default_priority_key');
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (DB::table('subcategories')->orderBy('category_id')->orderBy('id')->get() as $position => $sub) {
|
||||||
|
DB::table('subcategories')->where('id', $sub->id)->update(['sort_order' => $position]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('subcategories', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('sort_order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* snipeit_asset_name is a cached label (asset tag + name/model) captured
|
||||||
|
* at link time — kept alongside the id so the ticket list/header still
|
||||||
|
* shows something meaningful if Snipe-IT is unreachable or the asset was
|
||||||
|
* later deleted there, without depending on a live API call.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('snipeit_asset_id')->nullable()->after('ai_summary_generated_at');
|
||||||
|
$table->string('snipeit_asset_name')->nullable()->after('snipeit_asset_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['snipeit_asset_id', 'snipeit_asset_name']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('ticket_views', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('ticket_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
|
// Microsecond precision (not the plain-timestamp default) so two
|
||||||
|
// views landing in the same second — plausible with fast repeat
|
||||||
|
// clicks, not just test speed — still order correctly instead of
|
||||||
|
// tying and falling back to row id.
|
||||||
|
$table->timestamp('viewed_at', 6);
|
||||||
|
|
||||||
|
$table->unique(['ticket_id', 'user_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('ticket_views');
|
||||||
|
}
|
||||||
|
};
|
||||||
8
src/lang/pl/pagination.php
Normal file
8
src/lang/pl/pagination.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'previous' => '« Poprzednia',
|
||||||
|
'next' => 'Następna »',
|
||||||
|
|
||||||
|
];
|
||||||
@@ -211,6 +211,63 @@ body {
|
|||||||
.seg-opt:has(input:checked) { background: color-mix(in srgb, var(--color-accent) 16%, transparent); color: var(--color-accent); }
|
.seg-opt:has(input:checked) { background: color-mix(in srgb, var(--color-accent) 16%, transparent); color: var(--color-accent); }
|
||||||
.seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
|
.seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
|
||||||
|
|
||||||
|
.panel-switch {
|
||||||
|
display: inline-flex;
|
||||||
|
padding: 3px;
|
||||||
|
border: 1px solid var(--color-divider);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: color-mix(in srgb, var(--color-text) 4%, transparent);
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
.panel-switch::-webkit-scrollbar { display: none; }
|
||||||
|
.panel-switch-indicator {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-accent);
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
.nav .panel-switch-option {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
flex: 1 1 0;
|
||||||
|
min-width: 128px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 6px 16px;
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--color-text);
|
||||||
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
.nav .panel-switch-option:hover { color: #fff; text-decoration: none; }
|
||||||
|
.nav .panel-switch-option-active, .nav .panel-switch-option-active:hover { color: #fff; }
|
||||||
|
|
||||||
|
/* Preview the destination before the click actually navigates there:
|
||||||
|
the indicator follows whichever option is under the cursor (falling
|
||||||
|
back to the real active position, set inline per-request by
|
||||||
|
panel-switcher.blade.php, the moment the pointer leaves). Position is
|
||||||
|
purely by hovered index — independent of how many roles/options
|
||||||
|
exist — so these three rules cover the max of three areas regardless
|
||||||
|
of which subset a given user has. */
|
||||||
|
.panel-switch:has(> .panel-switch-option:nth-of-type(1):hover) .panel-switch-indicator { transform: translateX(0%) !important; }
|
||||||
|
.panel-switch:has(> .panel-switch-option:nth-of-type(2):hover) .panel-switch-indicator { transform: translateX(100%) !important; }
|
||||||
|
.panel-switch:has(> .panel-switch-option:nth-of-type(3):hover) .panel-switch-indicator { transform: translateX(200%) !important; }
|
||||||
|
|
||||||
|
/* The real active option's white text is only correct while the
|
||||||
|
indicator sits under it — once hover has pulled the indicator away to
|
||||||
|
a neighboring option, drop it back to normal text color so it doesn't
|
||||||
|
read as near-invisible white-on-track. */
|
||||||
|
.panel-switch:hover .panel-switch-option-active:not(:hover) { color: var(--color-text); }
|
||||||
|
|
||||||
.theme-toggle-option {
|
.theme-toggle-option {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -341,8 +398,26 @@ body {
|
|||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.page-pad { padding: 16px !important; }
|
.page-pad { padding: 16px !important; }
|
||||||
.nav { padding-left: 14px !important; padding-right: 14px !important; gap: 10px; }
|
.nav { padding-left: 14px !important; padding-right: 14px !important; gap: 10px; flex-wrap: wrap; }
|
||||||
.nav-panel-label { display: none; }
|
|
||||||
|
/* At this width the switcher's own centered slot collides with the
|
||||||
|
brand text and the icon buttons sharing the row (nothing left to
|
||||||
|
shrink once labels are already at their minimum width) — same
|
||||||
|
"restructure instead of cram" fix as the mobile table pattern above:
|
||||||
|
drop it to its own full-width row below instead of fighting for
|
||||||
|
space with everything else in the bar. */
|
||||||
|
.panel-switch {
|
||||||
|
position: relative !important;
|
||||||
|
left: auto !important;
|
||||||
|
top: auto !important;
|
||||||
|
transform: none !important;
|
||||||
|
order: 10;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.nav .panel-switch-option { padding: 10px; font-size: 11.5px; min-width: 92px; }
|
||||||
|
|
||||||
/* Theme/notifications/profile dropdowns are anchored (position:absolute)
|
/* Theme/notifications/profile dropdowns are anchored (position:absolute)
|
||||||
to their own small trigger button by default, which overflows off the
|
to their own small trigger button by default, which overflows off the
|
||||||
|
|||||||
50
src/resources/views/components/panel-switcher.blade.php
Normal file
50
src/resources/views/components/panel-switcher.blade.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
@props(['area' => null])
|
||||||
|
|
||||||
|
@php
|
||||||
|
// $area is passed explicitly by each page (e.g. <x-topbar area="operator" />)
|
||||||
|
// rather than inferred from request()->routeIs() here: this component is
|
||||||
|
// rendered as part of each top-level Livewire page's own template, so it
|
||||||
|
// re-renders on every wire:click/wire:model round-trip on that page (tab
|
||||||
|
// switches, pagination, search, ...) — and during that AJAX request,
|
||||||
|
// request()->route() is Livewire's own update route, not client./operator./
|
||||||
|
// admin.*, which silently broke the highlight on every in-page interaction
|
||||||
|
// when this used to key off the ambient request instead of an explicit prop.
|
||||||
|
$user = auth()->user();
|
||||||
|
$areas = [];
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
if ($user->isClient()) {
|
||||||
|
$areas[] = ['label' => 'Klient', 'url' => route('client.dashboard'), 'active' => $area === 'client'];
|
||||||
|
}
|
||||||
|
if ($user->isOperator()) {
|
||||||
|
$areas[] = ['label' => 'Operator', 'url' => route('operator.queue'), 'active' => $area === 'operator'];
|
||||||
|
}
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
$areas[] = ['label' => 'Administrator', 'url' => route('admin.panel'), 'active' => $area === 'admin'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$activeIndex = collect($areas)->search(fn ($area) => $area['active']);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@if (count($areas))
|
||||||
|
<div
|
||||||
|
class="panel-switch"
|
||||||
|
style="position:absolute;left:50%;top:50%;transform:translate(-50%, -50%)"
|
||||||
|
>
|
||||||
|
@if ($activeIndex !== false)
|
||||||
|
<span
|
||||||
|
class="panel-switch-indicator"
|
||||||
|
style="width:calc(100% / {{ count($areas) }});transform:translateX({{ $activeIndex * 100 }}%)"
|
||||||
|
></span>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@foreach ($areas as $item)
|
||||||
|
<a
|
||||||
|
href="{{ $item['url'] }}"
|
||||||
|
wire:navigate
|
||||||
|
class="panel-switch-option {{ $item['active'] ? 'panel-switch-option-active' : '' }}"
|
||||||
|
>{{ $item['label'] }}</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
@php
|
@php
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$areas = [];
|
|
||||||
|
|
||||||
if ($user) {
|
|
||||||
if ($user->isClient()) {
|
|
||||||
$areas[] = ['label' => 'Panel Klienta', 'url' => route('client.dashboard'), 'active' => request()->routeIs('client.*')];
|
|
||||||
}
|
|
||||||
if ($user->isOperator()) {
|
|
||||||
$areas[] = ['label' => 'Panel Operatora', 'url' => route('operator.queue'), 'active' => request()->routeIs('operator.*')];
|
|
||||||
}
|
|
||||||
if ($user->isAdmin()) {
|
|
||||||
$areas[] = ['label' => 'Panel Administratora', 'url' => route('admin.panel'), 'active' => request()->routeIs('admin.*')];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@if ($user)
|
@if ($user)
|
||||||
@@ -26,23 +13,27 @@
|
|||||||
x-show="open"
|
x-show="open"
|
||||||
x-cloak
|
x-cloak
|
||||||
class="nav-dropdown"
|
class="nav-dropdown"
|
||||||
style="position:absolute;top:100%;right:0;margin-top:6px;background:var(--color-surface);border:1px solid var(--color-divider);border-radius:8px;box-shadow:var(--shadow-md);min-width:200px;overflow:hidden;z-index:30"
|
style="position:absolute;top:100%;right:0;margin-top:6px;background:var(--color-surface);border:1px solid var(--color-divider);border-radius:8px;box-shadow:var(--shadow-md);min-width:220px;overflow:hidden;z-index:30"
|
||||||
>
|
>
|
||||||
@foreach ($areas as $area)
|
<div style="display:flex;flex-direction:column;gap:6px;padding:12px">
|
||||||
<a
|
<span style="font-weight:600;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{ $user->name }}</span>
|
||||||
href="{{ $area['url'] }}"
|
<span style="font-size:11.5px;color:color-mix(in srgb, var(--color-text) 60%, transparent);overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{ $user->email }}</span>
|
||||||
wire:navigate
|
<div style="display:flex;flex-wrap:wrap;gap:4px;margin-top:2px">
|
||||||
@click="open = false"
|
@if ($user->isClient())
|
||||||
class="theme-toggle-option"
|
<span class="tag tag-neutral">Klient</span>
|
||||||
style="text-decoration:none;color:{{ $area['active'] ? 'var(--color-accent)' : 'var(--color-text)' }};font-size:12.5px"
|
@endif
|
||||||
>{{ $area['label'] }}</a>
|
@if ($user->isOperator())
|
||||||
@endforeach
|
<span class="tag tag-accent-2">Operator</span>
|
||||||
|
@endif
|
||||||
|
@if ($user->isAdmin())
|
||||||
|
<span class="tag tag-accent">Administrator</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@if (count($areas))
|
<div style="border-top:1px solid var(--color-divider)"></div>
|
||||||
<div style="border-top:1px solid var(--color-divider)"></div>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
@if ($user && ($user->isOperator() || $user->isAdmin()))
|
@if ($user->isOperator() || $user->isAdmin())
|
||||||
<a
|
<a
|
||||||
href="{{ route('settings.notifications') }}"
|
href="{{ route('settings.notifications') }}"
|
||||||
wire:navigate
|
wire:navigate
|
||||||
|
|||||||
64
src/resources/views/components/snipeit-assets.blade.php
Normal file
64
src/resources/views/components/snipeit-assets.blade.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
@props([
|
||||||
|
'assets',
|
||||||
|
'variant' => 'banner',
|
||||||
|
'title' => 'Twój sprzęt (inwentarz)',
|
||||||
|
'selectable' => false,
|
||||||
|
'selectAction' => 'selectSnipeitAsset',
|
||||||
|
'selectedId' => null,
|
||||||
|
// false when embedded inside a caller-provided card (e.g. the operator's
|
||||||
|
// "Przeszukaj inwentarz" search box + results in one container) — skips
|
||||||
|
// this component's own wrapping card/title so the two don't nest.
|
||||||
|
'card' => true,
|
||||||
|
])
|
||||||
|
|
||||||
|
@php
|
||||||
|
$isSidebar = $variant === 'sidebar';
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@if (count($assets))
|
||||||
|
@if ($card)
|
||||||
|
<div class="card" style="{{ $isSidebar ? 'padding:16px;gap:8px' : 'padding:14px;gap:10px;background:color-mix(in srgb, var(--color-accent) 6%, transparent);border-color:color-mix(in srgb, var(--color-accent) 25%, var(--color-divider))' }}">
|
||||||
|
@if ($isSidebar)
|
||||||
|
<div class="card-kicker">{{ $title }}</div>
|
||||||
|
@else
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;font-size:12.5px;font-weight:600">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:16px">devices</span>
|
||||||
|
{{ $title }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
<div style="display:flex;flex-direction:column;gap:2px">
|
||||||
|
@foreach ($assets as $a)
|
||||||
|
@php $isSelected = $selectedId === $a['id']; @endphp
|
||||||
|
<div style="display:flex;gap:8px;align-items:center;padding:8px;border-radius:6px;{{ $isSelected ? 'background:color-mix(in srgb, var(--color-accent) 10%, transparent)' : '' }}">
|
||||||
|
<a
|
||||||
|
href="{{ $a['url'] }}"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
style="display:flex;gap:10px;align-items:flex-start;flex:1;min-width:0;text-decoration:none;color:inherit"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px;flex:none;margin-top:1px;color:var(--color-accent)">devices</span>
|
||||||
|
<span style="min-width:0;flex:1">
|
||||||
|
<span style="display:block;font-size:13px;font-weight:500;{{ $isSelected ? 'color:var(--color-accent)' : '' }}">{{ $a['label'] }}</span>
|
||||||
|
@if (! empty($a['category']))
|
||||||
|
<span style="display:block;font-size:11px;color:color-mix(in srgb, var(--color-text) 55%, transparent);margin-top:1px">{{ $a['category'] }}</span>
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
@if ($selectable)
|
||||||
|
@if ($isSelected)
|
||||||
|
<span style="flex:none;display:flex;align-items:center;gap:4px;font-size:11px;color:var(--color-accent);white-space:nowrap">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:16px">check_circle</span>
|
||||||
|
Powiązano
|
||||||
|
</span>
|
||||||
|
@else
|
||||||
|
<button type="button" class="btn btn-secondary" style="flex:none;font-size:11px;padding:4px 8px;white-space:nowrap" wire:click="{{ $selectAction }}({{ $a['id'] }})">Powiąż</button>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@if ($card)
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
@@ -1,18 +1,9 @@
|
|||||||
@php
|
@props(['area' => null])
|
||||||
$panelLabel = match (true) {
|
|
||||||
request()->routeIs('client.*') => 'Panel Klienta',
|
|
||||||
request()->routeIs('operator.*') => 'Panel Operatora',
|
|
||||||
request()->routeIs('admin.*') => 'Panel Administratora',
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
@endphp
|
|
||||||
|
|
||||||
<div class="nav" style="position:relative;padding:16px 28px;border-bottom:1px solid var(--color-divider)">
|
<div class="nav" style="position:relative;padding:16px 28px;border-bottom:1px solid var(--color-divider)">
|
||||||
<span class="nav-brand">{{ \App\Support\Settings::get('company_name') }}</span>
|
<span class="nav-brand">{{ \App\Support\Settings::get('company_name') }}</span>
|
||||||
|
|
||||||
@if ($panelLabel)
|
<x-panel-switcher :area="$area" />
|
||||||
<span class="nav-panel-label" style="position:absolute;left:50%;top:50%;transform:translate(-50%, -50%);font-weight:500;font-size:13.5px;white-space:nowrap">{{ $panelLabel }}</span>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<x-theme-toggle />
|
<x-theme-toggle />
|
||||||
|
|
||||||
@@ -20,6 +11,7 @@
|
|||||||
|
|
||||||
@auth
|
@auth
|
||||||
<livewire:notification-bell />
|
<livewire:notification-bell />
|
||||||
|
<livewire:global-search />
|
||||||
@endauth
|
@endauth
|
||||||
|
|
||||||
<x-profile-menu />
|
<x-profile-menu />
|
||||||
|
|||||||
@@ -27,10 +27,15 @@ $tabGroups = [
|
|||||||
];
|
];
|
||||||
@endphp
|
@endphp
|
||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="admin" />
|
||||||
|
|
||||||
<div class="app-split" style="flex:1;display:flex;min-height:0">
|
<div class="app-split" style="flex:1;display:flex;min-height:0">
|
||||||
<div class="side-rail" style="padding:16px 10px;gap:16px;overflow:auto;background:color-mix(in srgb, var(--color-text) 5%, var(--color-bg))">
|
<div class="side-rail" style="padding:16px 10px;gap:16px;overflow:auto;background:color-mix(in srgb, var(--color-text) 5%, var(--color-bg))">
|
||||||
|
<button type="button" @click="window.dispatchEvent(new CustomEvent('open-global-search'))" style="display:flex;align-items:center;gap:10px;width:100%;padding:8px 12px;border-radius:6px;border:none;cursor:pointer;font-size:13.5px;text-align:left;white-space:nowrap;background:transparent;color:var(--color-text)">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px">search</span>
|
||||||
|
<span>Szukaj</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
@foreach ($tabGroups as $groupLabel => $items)
|
@foreach ($tabGroups as $groupLabel => $items)
|
||||||
<div style="display:flex;flex-direction:column;gap:1px">
|
<div style="display:flex;flex-direction:column;gap:1px">
|
||||||
<div style="font-size:10px;letter-spacing:0.09em;text-transform:uppercase;color:color-mix(in srgb, var(--color-text) 45%, transparent);padding:4px 12px 6px;white-space:nowrap">{{ $groupLabel }}</div>
|
<div style="font-size:10px;letter-spacing:0.09em;text-transform:uppercase;color:color-mix(in srgb, var(--color-text) 45%, transparent);padding:4px 12px 6px;white-space:nowrap">{{ $groupLabel }}</div>
|
||||||
@@ -85,7 +90,7 @@ $tabGroups = [
|
|||||||
<table class="table" style="margin:0;border-top:none">
|
<table class="table" style="margin:0;border-top:none">
|
||||||
<thead><tr><th>Podkategoria</th><th></th></tr></thead>
|
<thead><tr><th>Podkategoria</th><th></th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($cat->subcategories as $sub)
|
@foreach ($cat->subcategories as $i => $sub)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div style="display:flex;flex-direction:column;gap:2px">
|
<div style="display:flex;flex-direction:column;gap:2px">
|
||||||
@@ -97,7 +102,9 @@ $tabGroups = [
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div style="display:flex;gap:6px;justify-content:flex-end">
|
<div style="display:flex;gap:6px;justify-content:flex-end;align-items:center">
|
||||||
|
<button class="btn btn-icon" type="button" wire:click="moveSubcategoryUp({{ $sub->id }})" @disabled($i === 0) style="padding:2px;width:24px;height:24px" title="Przesuń wyżej"><span class="material-symbols-outlined" style="font-size:16px">arrow_upward</span></button>
|
||||||
|
<button class="btn btn-icon" type="button" wire:click="moveSubcategoryDown({{ $sub->id }})" @disabled($i === $cat->subcategories->count() - 1) style="padding:2px;width:24px;height:24px" title="Przesuń niżej"><span class="material-symbols-outlined" style="font-size:16px">arrow_downward</span></button>
|
||||||
<button class="btn btn-ghost" type="button" wire:click="openSubcategoryEditForm({{ $sub->id }})">Edytuj</button>
|
<button class="btn btn-ghost" type="button" wire:click="openSubcategoryEditForm({{ $sub->id }})">Edytuj</button>
|
||||||
<button class="btn btn-ghost" type="button" wire:click="removeSubcategory({{ $sub->id }})">Usuń</button>
|
<button class="btn btn-ghost" type="button" wire:click="removeSubcategory({{ $sub->id }})">Usuń</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -638,6 +645,31 @@ $tabGroups = [
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card" style="padding:20px;gap:14px">
|
||||||
|
<h4 style="margin:0">Częstotliwość odświeżania i harmonogramu</h4>
|
||||||
|
|
||||||
|
<div class="card-kicker">Odświeżanie w przeglądarce</div>
|
||||||
|
<div style="display:flex;gap:10px">
|
||||||
|
<div class="field" style="flex:1"><label>Widok zgłoszenia (klient i operator)</label><input class="input" type="number" min="1" wire:model="systemConfig.refreshTicketViewSeconds"></div>
|
||||||
|
<div class="field" style="flex:1"><label>Lista zgłoszeń operatora</label><input class="input" type="number" min="1" wire:model="systemConfig.refreshQueueSeconds"></div>
|
||||||
|
</div>
|
||||||
|
<div class="field"><label>Dzwonek powiadomień</label><input class="input" type="number" min="1" wire:model="systemConfig.refreshNotificationsSeconds"></div>
|
||||||
|
<p class="text-muted" style="font-size:12px;margin:0">Sekundy między automatycznymi odświeżeniami w przeglądarce (niezależnie od odświeżenia na żądanie po kliknięciu w licznik).</p>
|
||||||
|
|
||||||
|
<div class="hr"></div>
|
||||||
|
|
||||||
|
<div class="card-kicker">Zadania w tle</div>
|
||||||
|
<div style="display:flex;gap:10px">
|
||||||
|
<div class="field" style="flex:1"><label>Sprawdzanie naruszeń SLA</label><input class="input" type="number" min="1" wire:model="systemConfig.scheduleSlaCheckMinutes"></div>
|
||||||
|
<div class="field" style="flex:1"><label>Reguły automatyzacji</label><input class="input" type="number" min="1" wire:model="systemConfig.scheduleAutomationRulesMinutes"></div>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;gap:10px">
|
||||||
|
<div class="field" style="flex:1"><label>Pobieranie e-maili (IMAP)</label><input class="input" type="number" min="1" wire:model="systemConfig.scheduleImapFetchMinutes"></div>
|
||||||
|
<div class="field" style="flex:1"><label>Automatyczna kategoryzacja i podsumowania AI</label><input class="input" type="number" min="1" wire:model="systemConfig.scheduleAiAutomationMinutes"></div>
|
||||||
|
</div>
|
||||||
|
<p class="text-muted" style="font-size:12px;margin:0">Minuty między uruchomieniami zadań w tle. Zmiana obowiązuje od najbliższego uruchomienia harmonogramu (co minutę), bez potrzeby restartu.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="grid-column:1/-1;display:flex">
|
<div style="grid-column:1/-1;display:flex">
|
||||||
<button type="submit" class="btn btn-primary">Zapisz</button>
|
<button type="submit" class="btn btn-primary">Zapisz</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -657,6 +689,13 @@ $tabGroups = [
|
|||||||
<label class="radio"><input type="checkbox" wire:model="ldapConfig.enabled" style="position:static;opacity:1;width:auto;height:auto"><strong>Włącz autentykację LDAP/AD</strong></label>
|
<label class="radio"><input type="checkbox" wire:model="ldapConfig.enabled" style="position:static;opacity:1;width:auto;height:auto"><strong>Włącz autentykację LDAP/AD</strong></label>
|
||||||
|
|
||||||
@if ($ldapConfig['enabled'])
|
@if ($ldapConfig['enabled'])
|
||||||
|
<div class="field">
|
||||||
|
<label>Typ katalogu</label>
|
||||||
|
<select class="input" wire:model="ldapConfig.directoryType">
|
||||||
|
<option value="lldap">LLDAP / OpenLDAP</option>
|
||||||
|
<option value="ad">Active Directory</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="field"><label>Host serwera LDAP</label><input class="input" placeholder="ldap.example.com" wire:model="ldapConfig.host"></div>
|
<div class="field"><label>Host serwera LDAP</label><input class="input" placeholder="ldap.example.com" wire:model="ldapConfig.host"></div>
|
||||||
<div style="display:flex;gap:10px">
|
<div style="display:flex;gap:10px">
|
||||||
<div class="field" style="flex:1"><label>Port</label><input class="input" type="number" placeholder="389" wire:model="ldapConfig.port"></div>
|
<div class="field" style="flex:1"><label>Port</label><input class="input" type="number" placeholder="389" wire:model="ldapConfig.port"></div>
|
||||||
@@ -665,7 +704,13 @@ $tabGroups = [
|
|||||||
<div class="field"><label>Base DN</label><input class="input" placeholder="dc=example,dc=com" wire:model="ldapConfig.baseDn"></div>
|
<div class="field"><label>Base DN</label><input class="input" placeholder="dc=example,dc=com" wire:model="ldapConfig.baseDn"></div>
|
||||||
<div class="field"><label>Bind DN</label><input class="input" placeholder="cn=admin,dc=example,dc=com" wire:model="ldapConfig.bindDn"></div>
|
<div class="field"><label>Bind DN</label><input class="input" placeholder="cn=admin,dc=example,dc=com" wire:model="ldapConfig.bindDn"></div>
|
||||||
<div class="field"><label>Hasło Bind</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="ldapConfig.bindPassword"></div>
|
<div class="field"><label>Hasło Bind</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="ldapConfig.bindPassword"></div>
|
||||||
<div class="field"><label>User Filter</label><input class="input" placeholder="(uid={0})" wire:model="ldapConfig.userFilter"></div>
|
<div class="field">
|
||||||
|
<label>User Filter</label>
|
||||||
|
<input class="input" placeholder="{{ $ldapConfig['directoryType'] === 'ad' ? '(sAMAccountName={0})' : '(uid={0})' }}" wire:model="ldapConfig.userFilter">
|
||||||
|
@if ($ldapConfig['directoryType'] === 'ad')
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Active Directory nie ma atrybutu "uid" — puste pole domyślnie użyje sAMAccountName.</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
<label class="radio"><input type="checkbox" wire:model="ldapConfig.autoProvisionGuests" style="position:static;opacity:1;width:auto;height:auto">Automatycznie zakładaj konto dla gościa zgłaszającego, jeśli jego e-mail istnieje w LDAP</label>
|
<label class="radio"><input type="checkbox" wire:model="ldapConfig.autoProvisionGuests" style="position:static;opacity:1;width:auto;height:auto">Automatycznie zakładaj konto dla gościa zgłaszającego, jeśli jego e-mail istnieje w LDAP</label>
|
||||||
<label class="radio"><input type="checkbox" wire:model="ldapConfig.restrictUserCreationToLdap" style="position:static;opacity:1;width:auto;height:auto">Zezwalaj na ręczne zapraszanie użytkowników tylko, jeśli ich e-mail istnieje w LDAP</label>
|
<label class="radio"><input type="checkbox" wire:model="ldapConfig.restrictUserCreationToLdap" style="position:static;opacity:1;width:auto;height:auto">Zezwalaj na ręczne zapraszanie użytkowników tylko, jeśli ich e-mail istnieje w LDAP</label>
|
||||||
<label class="radio"><input type="checkbox" wire:model="ldapConfig.restrictTicketsToLdap" style="position:static;opacity:1;width:auto;height:auto">Zezwalaj na tworzenie zgłoszeń bez logowania tylko dla adresów e-mail istniejących w LDAP</label>
|
<label class="radio"><input type="checkbox" wire:model="ldapConfig.restrictTicketsToLdap" style="position:static;opacity:1;width:auto;height:auto">Zezwalaj na tworzenie zgłoszeń bez logowania tylko dla adresów e-mail istniejących w LDAP</label>
|
||||||
@@ -695,12 +740,35 @@ $tabGroups = [
|
|||||||
<div class="field"><label>Token Secret</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="bookstackConfig.tokenSecret"></div>
|
<div class="field"><label>Token Secret</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="bookstackConfig.tokenSecret"></div>
|
||||||
<p class="text-muted" style="font-size:11.5px;margin:-4px 0 0">Token API generuje się w BookStack: Profil → Ustawienia API. Użytkownik/rola właściciela tokenu musi mieć uprawnienie „Access System API”.</p>
|
<p class="text-muted" style="font-size:11.5px;margin:-4px 0 0">Token API generuje się w BookStack: Profil → Ustawienia API. Użytkownik/rola właściciela tokenu musi mieć uprawnienie „Access System API”.</p>
|
||||||
|
|
||||||
<div class="field"><label>Przeszukuj</label>
|
<div class="field">
|
||||||
<select class="input" style="width:auto" wire:model="bookstackConfig.searchTypes">
|
<label>Przeszukuj</label>
|
||||||
<option value="both">Strony i książki</option>
|
<div style="display:flex;gap:16px;flex-wrap:wrap">
|
||||||
<option value="page">Tylko strony</option>
|
<label style="display:flex;align-items:center;gap:6px;font-size:13px;font-weight:400">
|
||||||
<option value="book">Tylko książki</option>
|
<input type="checkbox" style="position:static;opacity:1;width:auto;height:auto" @checked(in_array('book', $bookstackConfig['searchTypes'])) wire:click="toggleBookstackSearchType('book')">
|
||||||
|
Książki
|
||||||
|
</label>
|
||||||
|
<label style="display:flex;align-items:center;gap:6px;font-size:13px;font-weight:400">
|
||||||
|
<input type="checkbox" style="position:static;opacity:1;width:auto;height:auto" @checked(in_array('page', $bookstackConfig['searchTypes'])) wire:click="toggleBookstackSearchType('page')">
|
||||||
|
Strony
|
||||||
|
</label>
|
||||||
|
<label style="display:flex;align-items:center;gap:6px;font-size:13px;font-weight:400">
|
||||||
|
<input type="checkbox" style="position:static;opacity:1;width:auto;height:auto" @checked(in_array('chapter', $bookstackConfig['searchTypes'])) wire:click="toggleBookstackSearchType('chapter')">
|
||||||
|
Rozdziały
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
@if (empty($bookstackConfig['searchTypes']))
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Nic nie zaznaczono — przy zapisie zostaną użyte wszystkie typy.</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Szukaj po</label>
|
||||||
|
<select class="input" style="width:auto" wire:model="bookstackConfig.searchBy">
|
||||||
|
<option value="both">Słowa kluczowe w nazwie lub tagi</option>
|
||||||
|
<option value="name">Tylko słowa kluczowe w nazwie</option>
|
||||||
|
<option value="tags">Tylko tagi</option>
|
||||||
</select>
|
</select>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">„Tagi” dopasowują artykuły oznaczone w BookStack tagiem o nazwie zgodnej z kategorią/podkategorią zgłoszenia (np. tag „Drukarki” dla podkategorii „Drukarki”).</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display:flex;justify-content:flex-end">
|
<div style="display:flex;justify-content:flex-end">
|
||||||
@@ -750,6 +818,26 @@ $tabGroups = [
|
|||||||
<label class="radio"><input type="checkbox" wire:model="bookstackConfig.verifySsl" style="position:static;opacity:1;width:auto;height:auto">Weryfikuj certyfikat SSL instancji BookStack</label>
|
<label class="radio"><input type="checkbox" wire:model="bookstackConfig.verifySsl" style="position:static;opacity:1;width:auto;height:auto">Weryfikuj certyfikat SSL instancji BookStack</label>
|
||||||
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Wyłącz tylko jeśli instancja BookStack korzysta z certyfikatu self-signed / z prywatnego CA.</span>
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Wyłącz tylko jeśli instancja BookStack korzysta z certyfikatu self-signed / z prywatnego CA.</span>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Automatyczne tagowanie treści (AI)</label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Używa integracji AI (skonfigurowanej w karcie „Integracja AI” obok) do otagowania książek/stron/rozdziałów nazwami pasujących podkategorii helpdesku — bez tego wyszukiwanie „po tagach” nic nie znajdzie. „Otaguj nową treść” pomija już otagowane pozycje; „Otaguj wszystko ponownie” klasyfikuje od nowa całą wiki (dłużej, więcej zapytań do AI).</p>
|
||||||
|
<div style="display:flex;gap:10px;margin-top:6px;align-items:center;flex-wrap:wrap">
|
||||||
|
<button type="button" class="btn btn-secondary" wire:click="runBookstackTagging" wire:loading.attr="disabled" wire:target="runBookstackTagging,runBookstackTaggingForce">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:16px;vertical-align:middle" wire:loading.class="spin" wire:target="runBookstackTagging">sell</span>
|
||||||
|
Otaguj nową treść
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary" wire:click="runBookstackTaggingForce" wire:loading.attr="disabled" wire:target="runBookstackTagging,runBookstackTaggingForce">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:16px;vertical-align:middle" wire:loading.class="spin" wire:target="runBookstackTaggingForce">refresh</span>
|
||||||
|
Otaguj wszystko ponownie (force)
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if ($bookstackTagResult !== null)
|
||||||
|
<div class="text-muted" style="font-size:11.5px;margin-top:6px">Przeskanowano {{ $bookstackTagResult['scanned'] }}, otagowano {{ $bookstackTagResult['tagged'] }}, pominięto {{ $bookstackTagResult['skipped'] }}, nieudanych paczek {{ $bookstackTagResult['failed_batches'] }}.</div>
|
||||||
|
@elseif ($bookstackTagError)
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;color:var(--color-danger);font-size:11.5px;margin-top:6px"><span class="material-symbols-outlined" style="font-size:16px">error</span>{{ $bookstackTagError }}</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="display:flex;gap:10px;margin-top:8px;align-items:center;flex-wrap:wrap">
|
<div style="display:flex;gap:10px;margin-top:8px;align-items:center;flex-wrap:wrap">
|
||||||
<button type="button" class="btn btn-secondary" wire:click="testBookstackConnection">Testuj połączenie</button>
|
<button type="button" class="btn btn-secondary" wire:click="testBookstackConnection">Testuj połączenie</button>
|
||||||
<button type="submit" class="btn btn-primary">Zapisz</button>
|
<button type="submit" class="btn btn-primary">Zapisz</button>
|
||||||
@@ -764,6 +852,128 @@ $tabGroups = [
|
|||||||
@endif
|
@endif
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form wire:submit="saveSnipeitConfig" class="card" style="padding:20px;gap:14px">
|
||||||
|
<h4 style="margin:0">Snipe-IT (ewidencja sprzętu)</h4>
|
||||||
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Pokazuje sprzęt przypisany do zgłaszającego przy tworzeniu i przeglądaniu zgłoszenia oraz pozwala powiązać zgłoszenie z konkretnym urządzeniem z ewidencji Snipe-IT.</span>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="snipeitConfig.enabled" style="position:static;opacity:1;width:auto;height:auto"><strong>Włącz integrację z Snipe-IT</strong></label>
|
||||||
|
|
||||||
|
@if ($snipeitConfig['enabled'])
|
||||||
|
<div class="field"><label>Adres API</label><input class="input" placeholder="https://assets.firma.pl" wire:model="snipeitConfig.baseUrl"></div>
|
||||||
|
<div class="field"><label>Klucz API</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="snipeitConfig.apiToken"></div>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:-4px 0 0">Osobisty token API generuje się w Snipe-IT: profil użytkownika → „Create New Token”.</p>
|
||||||
|
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="snipeitConfig.skipSslVerification" style="position:static;opacity:1;width:auto;height:auto">Nie sprawdzaj SSL</label>
|
||||||
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Zaznacz tylko, jeśli instancja Snipe-IT korzysta z certyfikatu self-signed / z prywatnego CA.</span>
|
||||||
|
|
||||||
|
<div style="border-top:1px solid var(--color-divider);margin:4px 0"></div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Klient</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="snipeitConfig.clientCanSelectAsset" style="position:static;opacity:1;width:auto;height:auto">Klient może wybrać sprzęt, którego dotyczy zgłoszenie</label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Przy tworzeniu zgłoszenia klient zobaczy listę swojego sprzętu z Snipe-IT (dopasowanego po adresie e-mail) i będzie mógł je powiązać ze zgłoszeniem.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if ($snipeitConfig['clientCanSelectAsset'])
|
||||||
|
<div class="field">
|
||||||
|
<label>Ogranicz do podkategorii</label>
|
||||||
|
<x-multiselect
|
||||||
|
:options="$this->subcategoriesForTeamForm"
|
||||||
|
:selected-ids="$snipeitConfig['clientAssetSubcategoryIds']"
|
||||||
|
toggle-action="toggleSnipeitClientSubcategory"
|
||||||
|
placeholder="Brak wybranych podkategorii"
|
||||||
|
/>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Wybór sprzętu pojawi się klientowi tylko przy tworzeniu zgłoszenia w zaznaczonych tu podkategoriach. Jeśli nic nie jest zaznaczone, opcja nie pojawi się w żadnej podkategorii.</p>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div style="border-top:1px solid var(--color-divider);margin:4px 0"></div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Operator</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="snipeitConfig.operatorViewRequesterAssets" style="position:static;opacity:1;width:auto;height:auto">Operator może zobaczyć sprzęt zgłaszającego w widoku zgłoszenia</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="snipeitConfig.operatorSearchInventory" style="position:static;opacity:1;width:auto;height:auto">Zezwól operatorowi na przeszukiwanie całego inwentarza (nie tylko sprzętu zgłaszającego)</label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Obie funkcje pojawiają się w bocznym panelu widoku zgłoszenia operatora — przeszukiwanie inwentarza jako pole wyszukiwania z przyciskiem „Szukaj”, nie osobna podstrona. Odpięcie już powiązanego urządzenia jest zawsze dostępne dla operatora, niezależnie od tych dwóch ustawień.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;gap:10px;margin-top:8px;align-items:center;flex-wrap:wrap">
|
||||||
|
<button type="button" class="btn btn-secondary" wire:click="testSnipeitConnection">Testuj połączenie</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Zapisz</button>
|
||||||
|
@if ($snipeitTestResult === 'ok')
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;color:var(--color-success)"><span class="material-symbols-outlined" style="font-size:18px">check_circle</span>Połączenie OK</div>
|
||||||
|
@elseif ($snipeitTestResult === 'error')
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;color:var(--color-danger)"><span class="material-symbols-outlined" style="font-size:18px">error</span>Błąd połączenia{{ $snipeitTestMessage ? ': '.$snipeitTestMessage : '' }}</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<button type="submit" class="btn btn-primary" style="align-self:flex-start">Zapisz</button>
|
||||||
|
@endif
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form wire:submit="saveAiConfig" class="card" style="padding:20px;gap:14px">
|
||||||
|
<h4 style="margin:0">Integracja AI</h4>
|
||||||
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Ogólne połączenie z dostawcą modelu językowego (API kompatybilne z OpenAI — Groq, OpenAI, lokalny Ollama itp.), wykorzystywane m.in. do automatycznego tagowania treści w BookStack.</span>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiConfig.enabled" style="position:static;opacity:1;width:auto;height:auto"><strong>Włącz integrację AI</strong></label>
|
||||||
|
|
||||||
|
@if ($aiConfig['enabled'])
|
||||||
|
<div class="field"><label>Adres API (Base URL)</label><input class="input" placeholder="https://api.groq.com/openai/v1" wire:model="aiConfig.baseUrl"></div>
|
||||||
|
<div class="field"><label>Klucz API</label><input class="input" type="password" placeholder="(bez zmian jeśli puste)" wire:model="aiConfig.apiKey"></div>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:-4px 0 0">Zostaw puste dla lokalnych instancji bez autoryzacji (np. Ollama).</p>
|
||||||
|
<div class="field"><label>Model</label><input class="input" placeholder="np. llama-3.3-70b-versatile" wire:model="aiConfig.model"></div>
|
||||||
|
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiConfig.verifySsl" style="position:static;opacity:1;width:auto;height:auto">Weryfikuj certyfikat SSL</label>
|
||||||
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Wyłącz tylko jeśli instancja (np. lokalny Ollama) korzysta z certyfikatu self-signed / z prywatnego CA.</span>
|
||||||
|
|
||||||
|
<div style="display:flex;gap:10px;margin-top:8px;align-items:center;flex-wrap:wrap">
|
||||||
|
<button type="button" class="btn btn-secondary" wire:click="testAiConnection">Testuj połączenie</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Zapisz</button>
|
||||||
|
@if ($aiTestResult === 'ok')
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;color:var(--color-success)"><span class="material-symbols-outlined" style="font-size:18px">check_circle</span>Połączenie OK</div>
|
||||||
|
@elseif ($aiTestResult === 'error')
|
||||||
|
<div style="display:flex;align-items:center;gap:6px;color:var(--color-danger)"><span class="material-symbols-outlined" style="font-size:18px">error</span>Błąd połączenia{{ $aiTestMessage ? ': '.$aiTestMessage : '' }}</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<button type="submit" class="btn btn-primary" style="align-self:flex-start">Zapisz</button>
|
||||||
|
@endif
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form wire:submit="saveAiTriageConfig" class="card" style="padding:20px;gap:14px">
|
||||||
|
<h4 style="margin:0">Automatyzacja AI dla zgłoszeń</h4>
|
||||||
|
<span class="text-muted" style="font-size:11.5px;margin-top:-8px">Wymaga włączonej integracji AI (karta obok). Zgłoszenia są przetwarzane w tle, cyklicznie co kilka minut — nie spowalnia to tworzenia zgłoszenia przez klienta.</span>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Automatyczna kategoryzacja nowych zgłoszeń</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiTriageConfig.categoryWhenMissing" style="position:static;opacity:1;width:auto;height:auto">Przypisz kategorię/podkategorię, gdy zgłoszenie nie ma żadnej</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiTriageConfig.subcategoryWhenCategoryOnly" style="position:static;opacity:1;width:auto;height:auto">Dobierz podkategorię, gdy zgłoszenie ma tylko kategorię</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiTriageConfig.recheckCategorized" style="position:static;opacity:1;width:auto;height:auto">Zweryfikuj i ewentualnie popraw już przypisaną podkategorię</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiTriageConfig.fixSubject" style="position:static;opacity:1;width:auto;height:auto">Popraw temat zgłoszenia, jeśli jest niejasny</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiTriageConfig.setPriority" style="position:static;opacity:1;width:auto;height:auto">Ustaw priorytet na podstawie treści</label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Każde zgłoszenie jest sprawdzane tylko raz — zastosowane zmiany trafiają do historii zgłoszenia z adnotacją „Automatyzacja: klasyfikacja AI”.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="border-top:1px solid var(--color-divider);margin:4px 0"></div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Podsumowanie AI dla operatora</label>
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiSummaryEnabled" style="position:static;opacity:1;width:auto;height:auto"><strong>Generuj podsumowanie i sugerowaną akcję dla każdego zgłoszenia</strong></label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Widoczne wyłącznie w panelu operatora, w bocznym panelu zgłoszenia. Domyślnie odświeżane cyklicznie (co kilka minut, wraz z pozostałą automatyzacją AI powyżej).</p>
|
||||||
|
|
||||||
|
<label class="radio"><input type="checkbox" wire:model="aiSummaryRegenerateOnMessage" style="position:static;opacity:1;width:auto;height:auto">Regeneruj podsumowanie od razu po każdej nowej wiadomości</label>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Zamiast czekać na najbliższy cykl automatyzacji — dotyczy odpowiedzi operatora, klienta i notatek wewnętrznych.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div style="display:flex;justify-content:space-between;align-items:center">
|
||||||
|
<label>Prompt systemowy podsumowania</label>
|
||||||
|
<button type="button" class="btn btn-ghost" style="padding:2px 8px;font-size:12px" wire:click="resetAiSummaryPrompt" wire:confirm="Przywrócić domyślny prompt? Obecna treść zostanie zastąpiona.">Resetuj</button>
|
||||||
|
</div>
|
||||||
|
<textarea wire:key="ai-summary-prompt-{{ $aiSummaryPromptVersion }}" class="input" rows="6" wire:change="saveAiSummaryPrompt($event.target.value)">{{ $aiSummaryPrompt }}</textarea>
|
||||||
|
<p class="text-muted" style="font-size:11.5px;margin:2px 0 0">Model musi zwrócić obiekt JSON z kluczami "summary" i "suggested_action" — nie zmieniaj tego wymogu, chyba że wiadomo, że nowy dostawca/model obsłuży to inaczej.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary" style="align-self:flex-start">Zapisz</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="client" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
<div class="seg">
|
<div class="seg">
|
||||||
<label class="seg-opt"><input type="radio" name="ctab" @checked($tab === 'current') wire:click="setTab('current')">Aktualne ({{ $this->currentTickets->count() }})</label>
|
<label class="seg-opt"><input type="radio" name="ctab" @checked($tab === 'current') wire:click="setTab('current')">Aktualne ({{ $this->currentTickets->total() }})</label>
|
||||||
<label class="seg-opt"><input type="radio" name="ctab" @checked($tab === 'archive') wire:click="setTab('archive')">Archiwalne ({{ $this->archiveTickets->count() }})</label>
|
<label class="seg-opt"><input type="radio" name="ctab" @checked($tab === 'archive') wire:click="setTab('archive')">Archiwalne ({{ $this->archiveTickets->total() }})</label>
|
||||||
</div>
|
</div>
|
||||||
<input class="input" type="search" placeholder="Szukaj po numerze, temacie, treści…" wire:model.live.debounce.400ms="search" style="max-width:280px">
|
<input class="input" type="search" placeholder="Szukaj po numerze, temacie, treści…" wire:model.live.debounce.400ms="search" style="max-width:280px">
|
||||||
</div>
|
</div>
|
||||||
@@ -32,6 +32,10 @@
|
|||||||
@if (($tab === 'current' ? $this->currentTickets : $this->archiveTickets)->isEmpty())
|
@if (($tab === 'current' ? $this->currentTickets : $this->archiveTickets)->isEmpty())
|
||||||
<p class="text-muted" style="font-size:13px">Brak zgłoszeń w tej zakładce.</p>
|
<p class="text-muted" style="font-size:13px">Brak zgłoszeń w tej zakładce.</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
<div style="margin-top:4px">
|
||||||
|
{{ ($tab === 'current' ? $this->currentTickets : $this->archiveTickets)->links() }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="client" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
@@ -64,6 +64,15 @@
|
|||||||
<x-bookstack-suggestions :articles="$this->suggestedArticles" />
|
<x-bookstack-suggestions :articles="$this->suggestedArticles" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div wire:init="loadSnipeitAssets">
|
||||||
|
<x-snipeit-assets
|
||||||
|
:assets="$this->snipeitAssets"
|
||||||
|
title="Twój sprzęt (inwentarz) — powiąż, jeśli zgłoszenie go dotyczy"
|
||||||
|
:selectable="\App\Support\Settings::bool('snipeit_client_can_select_asset')"
|
||||||
|
:selected-id="$selectedSnipeitAssetId"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Temat</label>
|
<label>Temat</label>
|
||||||
<input class="input" wire:model="subject">
|
<input class="input" wire:model="subject">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="client" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:1180px;width:100%;margin:0 auto;box-sizing:border-box">
|
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:1180px;width:100%;margin:0 auto;box-sizing:border-box">
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
@@ -7,13 +7,18 @@
|
|||||||
|
|
||||||
{{-- Live updates arrive via broadcasting, but websocket connections can
|
{{-- Live updates arrive via broadcasting, but websocket connections can
|
||||||
drop silently — this is a periodic fallback refresh, with a visible
|
drop silently — this is a periodic fallback refresh, with a visible
|
||||||
countdown so it's clear the thread is still refreshing on its own. --}}
|
countdown so it's clear the thread is still refreshing on its own.
|
||||||
|
Also clickable, to fetch immediately and reset the countdown. --}}
|
||||||
|
@php
|
||||||
|
$refreshTicketSeconds = max(1, (int) \App\Support\Settings::get('refresh_ticket_view_seconds'));
|
||||||
|
@endphp
|
||||||
<div
|
<div
|
||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
style="cursor:default;gap:6px"
|
style="cursor:pointer;gap:6px"
|
||||||
x-data="{ remaining: 30, total: 30 }"
|
x-data="{ remaining: {{ $refreshTicketSeconds }}, total: {{ $refreshTicketSeconds }} }"
|
||||||
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshTicketData(); }, 1000)"
|
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshTicketData(); }, 1000)"
|
||||||
title="Zgłoszenie odświeża się automatycznie"
|
x-on:click="remaining = total; $wire.refreshTicketData()"
|
||||||
|
title="Zgłoszenie odświeża się automatycznie — kliknij, aby odświeżyć teraz"
|
||||||
>
|
>
|
||||||
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
||||||
<span x-text="remaining + 's'"></span>
|
<span x-text="remaining + 's'"></span>
|
||||||
@@ -114,6 +119,16 @@
|
|||||||
<x-bookstack-suggestions :articles="$this->suggestedArticles" variant="sidebar" title="Baza wiedzy" />
|
<x-bookstack-suggestions :articles="$this->suggestedArticles" variant="sidebar" title="Baza wiedzy" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if ($ticket->snipeit_asset_name)
|
||||||
|
<div class="card" style="padding:16px;gap:6px">
|
||||||
|
<div class="card-kicker">Powiązany sprzęt</div>
|
||||||
|
<div style="display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px;color:var(--color-accent)">devices</span>
|
||||||
|
{{ $ticket->snipeit_asset_name }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="card" style="padding:16px;gap:10px">
|
<div class="card" style="padding:16px;gap:10px">
|
||||||
<div class="card-kicker">Status i priorytet</div>
|
<div class="card-kicker">Status i priorytet</div>
|
||||||
<div style="display:flex;gap:6px;flex-wrap:wrap">
|
<div style="display:flex;gap:6px;flex-wrap:wrap">
|
||||||
@@ -167,13 +182,18 @@
|
|||||||
<div class="card" style="padding:16px;gap:8px">
|
<div class="card" style="padding:16px;gap:8px">
|
||||||
<div class="card-kicker">Inne Twoje zgłoszenia</div>
|
<div class="card-kicker">Inne Twoje zgłoszenia</div>
|
||||||
@forelse ($this->otherTickets as $ot)
|
@forelse ($this->otherTickets as $ot)
|
||||||
<a href="{{ route('client.ticket', $ot) }}" wire:navigate style="display:flex;justify-content:space-between;align-items:center;gap:8px;cursor:pointer;text-decoration:none;color:inherit">
|
<a wire:key="other-ticket-{{ $ot->id }}" href="{{ route('client.ticket', $ot) }}" wire:navigate style="display:flex;justify-content:space-between;align-items:center;gap:8px;cursor:pointer;text-decoration:none;color:inherit">
|
||||||
<span style="font-size:13px">{{ $ot->displayNumber() }} — {{ $ot->subject }}</span>
|
<span style="font-size:13px">{{ $ot->displayNumber() }} — {{ $ot->subject }}</span>
|
||||||
<span style="{{ $ot->statusStyle() }};flex:none">{{ $ot->statusLabel() }}</span>
|
<span style="{{ $ot->statusStyle() }};flex:none">{{ $ot->statusLabel() }}</span>
|
||||||
</a>
|
</a>
|
||||||
@empty
|
@empty
|
||||||
<p class="text-muted" style="font-size:12px;margin:0">Brak innych zgłoszeń.</p>
|
<p wire:key="other-tickets-empty" class="text-muted" style="font-size:12px;margin:0">Brak innych zgłoszeń.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
@if (! $showAllOtherTickets && $this->otherTicketsCount > count($this->otherTickets))
|
||||||
|
<button wire:key="show-all-other-tickets" type="button" wire:click="revealAllOtherTickets" class="btn btn-secondary" style="font-size:12px;padding:6px 10px;align-self:flex-start">
|
||||||
|
Pokaż wszystkie ({{ $this->otherTicketsCount }})
|
||||||
|
</button>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
51
src/resources/views/livewire/global-search.blade.php
Normal file
51
src/resources/views/livewire/global-search.blade.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<div
|
||||||
|
x-data="{ open: false }"
|
||||||
|
x-on:open-global-search.window="open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||||
|
x-on:keydown.cmd.k.window.prevent="open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||||
|
x-on:keydown.ctrl.k.window.prevent="open = true; $nextTick(() => $refs.searchInput.focus())"
|
||||||
|
x-on:keydown.escape.window="open = false"
|
||||||
|
>
|
||||||
|
<div class="dialog-backdrop" x-show="open" x-cloak style="align-items:flex-start;padding-top:10vh">
|
||||||
|
<div class="dialog" style="max-width:720px;padding:0;gap:0;overflow:hidden" @click.outside="open = false">
|
||||||
|
<div style="display:flex;align-items:center;gap:14px;padding:18px 22px;border-bottom:1px solid var(--color-divider)">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:26px;color:color-mix(in srgb, var(--color-text) 55%, transparent)">search</span>
|
||||||
|
<input
|
||||||
|
x-ref="searchInput"
|
||||||
|
type="text"
|
||||||
|
wire:model.live.debounce.200ms="search"
|
||||||
|
placeholder="Szukaj zgłoszenia… (np. od:kacper temat:drukarka)"
|
||||||
|
class="input"
|
||||||
|
style="border:none;padding:10px 12px;box-shadow:none;font-size:18px"
|
||||||
|
x-on:keydown.enter="$refs.resultsList?.querySelector('a')?.click()"
|
||||||
|
>
|
||||||
|
<kbd style="font-size:11px;color:color-mix(in srgb, var(--color-text) 45%, transparent);border:1px solid var(--color-divider);border-radius:4px;padding:2px 7px;flex:none">Esc</kbd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div x-ref="resultsList" style="max-height:460px;overflow-y:auto">
|
||||||
|
@forelse ($this->results as $ticket)
|
||||||
|
<a
|
||||||
|
href="{{ $this->urlFor($ticket) }}"
|
||||||
|
wire:navigate
|
||||||
|
@click="open = false"
|
||||||
|
style="display:flex;align-items:center;justify-content:space-between;gap:16px;padding:14px 22px;text-decoration:none;color:inherit;border-bottom:1px solid var(--color-divider)"
|
||||||
|
>
|
||||||
|
<div style="min-width:0">
|
||||||
|
<div style="font-weight:500;font-size:14.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{ $ticket->displayNumber() }} — {{ $ticket->subject }}</div>
|
||||||
|
<div class="card-meta" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap">
|
||||||
|
{{ $ticket->categoryLabel() }} · {{ $ticket->name }} · {{ \App\Support\Rel::format($ticket->updated_at) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;gap:6px;flex:none">
|
||||||
|
<span style="{{ $ticket->priorityStyle() }}">{{ $ticket->priorityLabel() }}</span>
|
||||||
|
<span style="{{ $ticket->statusStyle() }}">{{ $ticket->statusLabel() }}</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
@empty
|
||||||
|
<div style="padding:28px 22px;text-align:center;font-size:13.5px;color:color-mix(in srgb, var(--color-text) 55%, transparent)">
|
||||||
|
{{ trim($search) === '' ? 'Zacznij pisać, aby wyszukać zgłoszenie… (obsługuje też od:, temat:, treść:, numer:)' : 'Brak wyników.' }}
|
||||||
|
</div>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<div x-data="{ open: false }" @click.outside="open = false" class="nav-dropdown-wrap" style="position:relative;display:inline-block" wire:poll.30s="$refresh">
|
<div x-data="{ open: false }" @click.outside="open = false" class="nav-dropdown-wrap" style="position:relative;display:inline-block" wire:poll.{{ max(1, (int) \App\Support\Settings::get('refresh_notifications_seconds')) }}s="$refresh">
|
||||||
<button type="button" class="btn btn-secondary" @click="open = !open" style="position:relative;display:flex;align-items:center;gap:0;padding:8px">
|
<button type="button" class="btn btn-secondary" @click="open = !open" style="position:relative;display:flex;align-items:center;gap:0;padding:8px">
|
||||||
<span class="material-symbols-outlined" style="font-size:18px">notifications</span>
|
<span class="material-symbols-outlined" style="font-size:18px">notifications</span>
|
||||||
@if ($this->unreadCount)
|
@if ($this->unreadCount)
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
|
<x-topbar area="operator" />
|
||||||
|
|
||||||
|
<div class="page-pad" style="flex:1;padding:20px 24px;overflow:auto;display:flex;flex-direction:column;gap:20px;max-width:820px;width:100%;margin:0 auto;box-sizing:border-box">
|
||||||
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
|
<h2 style="margin:0">Klienci</h2>
|
||||||
|
<a href="{{ route('operator.queue') }}" wire:navigate class="btn btn-ghost">← Wróć do listy</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="input"
|
||||||
|
type="search"
|
||||||
|
placeholder="Szukaj po imieniu, nazwisku lub adresie e-mail…"
|
||||||
|
wire:model.live.debounce.400ms="search"
|
||||||
|
autofocus
|
||||||
|
>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px">
|
||||||
|
@if (trim($search) === '')
|
||||||
|
<p class="text-muted" style="font-size:13px">Zacznij pisać, aby wyszukać klienta.</p>
|
||||||
|
@else
|
||||||
|
@forelse ($this->results as $u)
|
||||||
|
<a
|
||||||
|
wire:key="client-{{ $u->id }}"
|
||||||
|
href="{{ route('operator.queue', ['filterCustomerId' => $u->id]) }}"
|
||||||
|
wire:navigate
|
||||||
|
class="card elev-sm"
|
||||||
|
style="padding:14px 16px;cursor:pointer;flex-direction:row;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;text-decoration:none;color:inherit"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div style="font-weight:500">{{ $u->name }}</div>
|
||||||
|
<div class="card-meta">{{ $u->email }}</div>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end">
|
||||||
|
@if ($u->hasRole('client'))
|
||||||
|
<span class="tag tag-outline">Klient</span>
|
||||||
|
@endif
|
||||||
|
@if ($u->hasRole('operator'))
|
||||||
|
<span class="tag tag-outline">Operator</span>
|
||||||
|
@endif
|
||||||
|
@if ($u->hasRole('admin'))
|
||||||
|
<span class="tag tag-outline">Administrator</span>
|
||||||
|
@endif
|
||||||
|
<span class="tag tag-neutral">{{ $u->tickets_as_customer_count }} {{ $u->tickets_as_customer_count === 1 ? 'zgłoszenie' : 'zgłoszeń' }}</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
@empty
|
||||||
|
<p class="text-muted" style="font-size:13px">Brak wyników dla „{{ $search }}”.</p>
|
||||||
|
@endforelse
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="operator" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
<div class="page-pad" style="flex:1;padding:28px;display:flex;flex-direction:column;gap:20px;max-width:920px;width:100%;margin:0 auto;box-sizing:border-box">
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="operator" />
|
||||||
|
|
||||||
<div class="app-split" style="flex:1;display:flex;min-height:0">
|
<div class="app-split" style="flex:1;display:flex;min-height:0">
|
||||||
<div
|
<div
|
||||||
@@ -14,6 +14,11 @@
|
|||||||
<span class="side-rail-toggle-label" x-text="collapsed ? 'Przegląd' : 'Zwiń panel'"></span>
|
<span class="side-rail-toggle-label" x-text="collapsed ? 'Przegląd' : 'Zwiń panel'"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="button" class="side-rail-toggle" title="Szukaj" @click="window.dispatchEvent(new CustomEvent('open-global-search'))">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px">search</span>
|
||||||
|
<span class="side-rail-toggle-label">Szukaj</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<div class="side-rail-scroll">
|
<div class="side-rail-scroll">
|
||||||
@foreach ($this->queueGroups as $groupLabel => $items)
|
@foreach ($this->queueGroups as $groupLabel => $items)
|
||||||
<div style="display:flex;flex-direction:column;gap:1px">
|
<div style="display:flex;flex-direction:column;gap:1px">
|
||||||
@@ -27,6 +32,18 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
@if ($this->recentlyViewed->isNotEmpty())
|
||||||
|
<div style="display:flex;flex-direction:column;gap:1px">
|
||||||
|
<div class="side-rail-group-label" style="font-size:10px;letter-spacing:0.09em;text-transform:uppercase;color:color-mix(in srgb, var(--color-text) 45%, transparent);padding:4px 12px 6px;white-space:nowrap">Ostatnio przeglądane</div>
|
||||||
|
@foreach ($this->recentlyViewed as $ticket)
|
||||||
|
<a href="{{ route('operator.ticket', $ticket) }}" wire:navigate class="side-rail-item" title="{{ $ticket->displayNumber() }} — {{ $ticket->subject }}" style="display:flex;align-items:center;gap:10px;width:100%;padding:8px 12px;border-radius:6px;font-size:13.5px;text-align:left;white-space:nowrap;text-decoration:none;color:var(--color-text);overflow:hidden">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px;flex:none">history</span>
|
||||||
|
<span class="side-rail-label" style="overflow:hidden;text-overflow:ellipsis">{{ $ticket->displayNumber() }} — {{ $ticket->subject }}</span>
|
||||||
|
</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -40,6 +57,10 @@
|
|||||||
<button type="button" class="btn btn-secondary" @disabled(count($selectedIds) < 2) wire:click="mergeSelected">Scal zgłoszenia ({{ count($selectedIds) }})</button>
|
<button type="button" class="btn btn-secondary" @disabled(count($selectedIds) < 2) wire:click="mergeSelected">Scal zgłoszenia ({{ count($selectedIds) }})</button>
|
||||||
<button type="button" class="btn btn-secondary" @disabled(count($selectedIds) < 1) wire:click="requestDeleteSelected" style="color:var(--color-danger)">Usuń zgłoszenia ({{ count($selectedIds) }})</button>
|
<button type="button" class="btn btn-secondary" @disabled(count($selectedIds) < 1) wire:click="requestDeleteSelected" style="color:var(--color-danger)">Usuń zgłoszenia ({{ count($selectedIds) }})</button>
|
||||||
</div>
|
</div>
|
||||||
|
<a href="{{ route('operator.clients') }}" wire:navigate class="btn btn-secondary" style="display:flex;align-items:center;gap:6px">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px">person_search</span>
|
||||||
|
Klienci
|
||||||
|
</a>
|
||||||
<a href="{{ route('operator.stats') }}" wire:navigate class="btn btn-secondary" style="display:flex;align-items:center;gap:6px">
|
<a href="{{ route('operator.stats') }}" wire:navigate class="btn btn-secondary" style="display:flex;align-items:center;gap:6px">
|
||||||
<span class="material-symbols-outlined" style="font-size:18px">bar_chart</span>
|
<span class="material-symbols-outlined" style="font-size:18px">bar_chart</span>
|
||||||
Statystyki
|
Statystyki
|
||||||
@@ -120,13 +141,18 @@
|
|||||||
{{-- Live updates arrive via broadcasting, but websocket connections can
|
{{-- Live updates arrive via broadcasting, but websocket connections can
|
||||||
drop silently (backgrounded tab, network blip) — this is a periodic
|
drop silently (backgrounded tab, network blip) — this is a periodic
|
||||||
fallback refresh, with a visible countdown so it's clear the queue
|
fallback refresh, with a visible countdown so it's clear the queue
|
||||||
is still refreshing itself rather than just stuck. --}}
|
is still refreshing itself rather than just stuck. Also clickable,
|
||||||
|
to fetch immediately and reset the countdown. --}}
|
||||||
|
@php
|
||||||
|
$refreshQueueSeconds = max(1, (int) \App\Support\Settings::get('refresh_queue_seconds'));
|
||||||
|
@endphp
|
||||||
<div
|
<div
|
||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
style="cursor:default;gap:6px"
|
style="cursor:pointer;gap:6px"
|
||||||
x-data="{ remaining: 60, total: 60 }"
|
x-data="{ remaining: {{ $refreshQueueSeconds }}, total: {{ $refreshQueueSeconds }} }"
|
||||||
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshQueue(); }, 1000)"
|
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshQueue(); }, 1000)"
|
||||||
title="Kolejka odświeża się automatycznie co minutę"
|
x-on:click="remaining = total; $wire.refreshQueue()"
|
||||||
|
title="Kolejka odświeża się automatycznie — kliknij, aby odświeżyć teraz"
|
||||||
>
|
>
|
||||||
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
||||||
<span x-text="remaining + 's'"></span>
|
<span x-text="remaining + 's'"></span>
|
||||||
@@ -203,6 +229,9 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="margin-top:12px">
|
||||||
|
{{ $this->filteredTickets->links() }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="operator" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:20px 24px;overflow:auto;display:flex;flex-direction:column;gap:20px">
|
<div class="page-pad" style="flex:1;padding:20px 24px;overflow:auto;display:flex;flex-direction:column;gap:20px">
|
||||||
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div style="flex:1;display:flex;flex-direction:column">
|
<div style="flex:1;display:flex;flex-direction:column">
|
||||||
<x-topbar />
|
<x-topbar area="operator" />
|
||||||
|
|
||||||
<div class="page-pad" style="flex:1;padding:20px 24px;overflow:auto">
|
<div class="page-pad" style="flex:1;padding:20px 24px;overflow:auto">
|
||||||
<div style="display:flex;flex-direction:column;gap:16px;max-width:1180px;margin:0 auto">
|
<div style="display:flex;flex-direction:column;gap:16px;max-width:1180px;margin:0 auto">
|
||||||
@@ -19,13 +19,18 @@
|
|||||||
|
|
||||||
{{-- Live updates arrive via broadcasting, but websocket connections can
|
{{-- Live updates arrive via broadcasting, but websocket connections can
|
||||||
drop silently — this is a periodic fallback refresh, with a visible
|
drop silently — this is a periodic fallback refresh, with a visible
|
||||||
countdown so it's clear the thread is still refreshing on its own. --}}
|
countdown so it's clear the thread is still refreshing on its own.
|
||||||
|
Also clickable, to fetch immediately and reset the countdown. --}}
|
||||||
|
@php
|
||||||
|
$refreshTicketSeconds = max(1, (int) \App\Support\Settings::get('refresh_ticket_view_seconds'));
|
||||||
|
@endphp
|
||||||
<div
|
<div
|
||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
style="cursor:default;gap:6px"
|
style="cursor:pointer;gap:6px"
|
||||||
x-data="{ remaining: 30, total: 30 }"
|
x-data="{ remaining: {{ $refreshTicketSeconds }}, total: {{ $refreshTicketSeconds }} }"
|
||||||
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshTicketData(); }, 1000)"
|
x-init="setInterval(() => { remaining = remaining <= 1 ? total : remaining - 1; if (remaining === total) $wire.refreshTicketData(); }, 1000)"
|
||||||
title="Zgłoszenie odświeża się automatycznie"
|
x-on:click="remaining = total; $wire.refreshTicketData()"
|
||||||
|
title="Zgłoszenie odświeża się automatycznie — kliknij, aby odświeżyć teraz"
|
||||||
>
|
>
|
||||||
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
<span class="material-symbols-outlined" style="font-size:18px">schedule</span>
|
||||||
<span x-text="remaining + 's'"></span>
|
<span x-text="remaining + 's'"></span>
|
||||||
@@ -286,7 +291,7 @@
|
|||||||
<div class="card-kicker">Status i przypisanie</div>
|
<div class="card-kicker">Status i przypisanie</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Status</label>
|
<label>Status</label>
|
||||||
<select class="input" wire:change="setStatus($event.target.value)">
|
<select class="input" wire:key="ticket-status-select-{{ $ticket->status_key }}" wire:change="setStatus($event.target.value)">
|
||||||
@foreach ($this->statuses as $s)
|
@foreach ($this->statuses as $s)
|
||||||
<option value="{{ $s->key }}" @selected($ticket->status_key === $s->key)>{{ $s->label }}</option>
|
<option value="{{ $s->key }}" @selected($ticket->status_key === $s->key)>{{ $s->label }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
@@ -325,10 +330,93 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if (\App\Support\Settings::bool('snipeit_enabled'))
|
||||||
|
@if ($ticket->snipeit_asset_id)
|
||||||
|
@php $linkedAsset = $this->snipeitLinkedAsset; @endphp
|
||||||
|
<div class="card" style="padding:16px;gap:6px">
|
||||||
|
<div style="display:flex;justify-content:space-between;align-items:flex-start;gap:8px">
|
||||||
|
<div class="card-kicker">Powiązany sprzęt</div>
|
||||||
|
<button type="button" class="btn btn-ghost" style="font-size:11px;padding:2px 6px" wire:click="unlinkSnipeitAsset">Odepnij</button>
|
||||||
|
</div>
|
||||||
|
<a href="{{ $linkedAsset['url'] ?? '#' }}" target="_blank" rel="noopener noreferrer" style="display:flex;gap:8px;align-items:flex-start;min-width:0;text-decoration:none;color:inherit">
|
||||||
|
<span class="material-symbols-outlined" style="font-size:18px;flex:none;margin-top:1px;color:var(--color-accent)">devices</span>
|
||||||
|
<span style="min-width:0">
|
||||||
|
<span style="display:block;font-size:13px;font-weight:500;color:var(--color-accent)">{{ $linkedAsset['label'] ?? $ticket->snipeit_asset_name }}</span>
|
||||||
|
@if ($linkedAsset)
|
||||||
|
<span style="display:block;font-size:11px;color:color-mix(in srgb, var(--color-text) 55%, transparent)">{{ collect([$linkedAsset['category'] ?? null, $linkedAsset['status'] ?? null, $linkedAsset['assignedTo'] ?? null])->filter()->implode(' · ') }}</span>
|
||||||
|
@else
|
||||||
|
<span style="display:block;font-size:11px;color:color-mix(in srgb, var(--color-text) 55%, transparent)">Niedostępne w Snipe-IT (brak połączenia lub usunięto)</span>
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (\App\Support\Settings::bool('snipeit_operator_view_requester_assets'))
|
||||||
|
<div wire:init="loadSnipeitAssets">
|
||||||
|
<x-snipeit-assets
|
||||||
|
:assets="$this->snipeitRequesterAssets"
|
||||||
|
variant="sidebar"
|
||||||
|
title="Sprzęt zgłaszającego"
|
||||||
|
:selectable="true"
|
||||||
|
select-action="linkSnipeitAsset"
|
||||||
|
:selected-id="$ticket->snipeit_asset_id"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (\App\Support\Settings::bool('snipeit_operator_search_inventory'))
|
||||||
|
<div class="card" style="padding:16px;gap:8px">
|
||||||
|
<div class="card-kicker">Przeszukaj inwentarz</div>
|
||||||
|
<div style="display:flex;gap:6px">
|
||||||
|
<input class="input" style="flex:1" placeholder="Nr inwentarzowy, model, nazwa..." wire:model="snipeitSearchQuery" wire:keydown.enter.prevent="searchSnipeitAssets">
|
||||||
|
<button type="button" class="btn btn-secondary" style="flex:none" wire:click="searchSnipeitAssets">Szukaj</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<x-snipeit-assets
|
||||||
|
:assets="$snipeitSearchResults"
|
||||||
|
variant="sidebar"
|
||||||
|
:card="false"
|
||||||
|
:selectable="true"
|
||||||
|
select-action="linkSnipeitAsset"
|
||||||
|
:selected-id="$ticket->snipeit_asset_id"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
<div wire:init="loadSuggestedArticles">
|
<div wire:init="loadSuggestedArticles">
|
||||||
<x-bookstack-suggestions :articles="$this->suggestedArticles" variant="sidebar" title="Baza wiedzy" :show-copy="true" />
|
<x-bookstack-suggestions :articles="$this->suggestedArticles" variant="sidebar" title="Baza wiedzy" :show-copy="true" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if (\App\Support\Settings::bool('ai_summary_enabled'))
|
||||||
|
<div wire:init="loadAiSummary" class="card" style="padding:16px;gap:8px">
|
||||||
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:8px">
|
||||||
|
<div class="card-kicker">Podsumowanie AI</div>
|
||||||
|
<button type="button" class="btn btn-ghost" style="padding:2px 8px;font-size:12px;flex:none" wire:click="regenerateAiSummary" wire:loading.attr="disabled" wire:target="regenerateAiSummary">
|
||||||
|
<span wire:loading.remove wire:target="regenerateAiSummary">Wygeneruj teraz</span>
|
||||||
|
<span wire:loading wire:target="regenerateAiSummary">Generowanie…</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if ($aiSummaryRegenerateError)
|
||||||
|
<div style="font-size:12px;color:var(--color-danger)">{{ $aiSummaryRegenerateError }}</div>
|
||||||
|
@endif
|
||||||
|
@if ($aiSummaryLoaded)
|
||||||
|
@if ($ticket->ai_summary)
|
||||||
|
<div style="font-size:13px;line-height:1.5">{{ $ticket->ai_summary }}</div>
|
||||||
|
@if ($ticket->ai_suggested_action)
|
||||||
|
<div style="margin-top:6px;padding-top:8px;border-top:1px solid var(--color-divider);font-size:13px">
|
||||||
|
<strong>Sugerowana akcja:</strong> {{ $ticket->ai_suggested_action }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div class="text-muted" style="font-size:11px;margin-top:4px">Zaktualizowano: {{ $ticket->ai_summary_generated_at?->diffForHumans() }}</div>
|
||||||
|
@else
|
||||||
|
<p class="text-muted" style="font-size:12.5px;margin:0">Podsumowanie pojawi się po najbliższym cyklu automatyzacji AI, albo od razu po kliknięciu „Wygeneruj teraz”.</p>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="card" style="padding:16px;gap:8px">
|
<div class="card" style="padding:16px;gap:8px">
|
||||||
<div class="card-kicker">SLA</div>
|
<div class="card-kicker">SLA</div>
|
||||||
<div style="font-size:12.5px">{{ $ticket->slaInfo()['text'] }}</div>
|
<div style="font-size:12.5px">{{ $ticket->slaInfo()['text'] }}</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Support\Settings;
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Schedule;
|
use Illuminate\Support\Facades\Schedule;
|
||||||
@@ -8,6 +9,16 @@ Artisan::command('inspire', function () {
|
|||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
})->purpose('Display an inspiring quote');
|
})->purpose('Display an inspiring quote');
|
||||||
|
|
||||||
Schedule::command('tickets:check-sla-breaches')->everyFifteenMinutes();
|
// Intervals are admin-configurable (Admin > Konfiguracja). Each command is
|
||||||
Schedule::command('automation:run-rules')->everyFifteenMinutes();
|
// considered every minute but the ->when() closure (evaluated lazily by
|
||||||
Schedule::command('emails:fetch-imap')->everyFiveMinutes()->withoutOverlapping();
|
// schedule:run, never at boot) decides whether the configured interval has
|
||||||
|
// actually elapsed — see Settings::dueEveryMinutes() for why this can't be
|
||||||
|
// an eagerly-built cron string instead.
|
||||||
|
Schedule::command('tickets:check-sla-breaches')->everyMinute()
|
||||||
|
->when(fn () => Settings::dueEveryMinutes('schedule_sla_check_minutes', 15));
|
||||||
|
Schedule::command('automation:run-rules')->everyMinute()
|
||||||
|
->when(fn () => Settings::dueEveryMinutes('schedule_automation_rules_minutes', 15));
|
||||||
|
Schedule::command('emails:fetch-imap')->everyMinute()->withoutOverlapping()
|
||||||
|
->when(fn () => Settings::dueEveryMinutes('schedule_imap_fetch_minutes', 5));
|
||||||
|
Schedule::command('ai:run-ticket-automation')->everyMinute()->withoutOverlapping()
|
||||||
|
->when(fn () => Settings::dueEveryMinutes('schedule_ai_automation_minutes', 5));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Livewire\Client\Dashboard as ClientDashboard;
|
|||||||
use App\Livewire\Client\NewTicket as ClientNewTicket;
|
use App\Livewire\Client\NewTicket as ClientNewTicket;
|
||||||
use App\Livewire\Client\TicketShow as ClientTicketShow;
|
use App\Livewire\Client\TicketShow as ClientTicketShow;
|
||||||
use App\Livewire\Landing;
|
use App\Livewire\Landing;
|
||||||
|
use App\Livewire\Operator\ClientSearch as OperatorClientSearch;
|
||||||
use App\Livewire\Operator\NewTicket as OperatorNewTicket;
|
use App\Livewire\Operator\NewTicket as OperatorNewTicket;
|
||||||
use App\Livewire\Operator\Queue as OperatorQueue;
|
use App\Livewire\Operator\Queue as OperatorQueue;
|
||||||
use App\Livewire\Operator\Stats as OperatorStats;
|
use App\Livewire\Operator\Stats as OperatorStats;
|
||||||
@@ -56,6 +57,7 @@ Route::middleware(['auth', 'role:operator'])->prefix('operator')->name('operator
|
|||||||
Route::get('/', OperatorQueue::class)->name('queue');
|
Route::get('/', OperatorQueue::class)->name('queue');
|
||||||
Route::get('/new', OperatorNewTicket::class)->name('new');
|
Route::get('/new', OperatorNewTicket::class)->name('new');
|
||||||
Route::get('/stats', OperatorStats::class)->name('stats');
|
Route::get('/stats', OperatorStats::class)->name('stats');
|
||||||
|
Route::get('/clients', OperatorClientSearch::class)->name('clients');
|
||||||
Route::get('/tickets/{ticket}', OperatorTicketShow::class)->name('ticket');
|
Route::get('/tickets/{ticket}', OperatorTicketShow::class)->name('ticket');
|
||||||
|
|
||||||
// Fired via navigator.sendBeacon on tab/browser close (see the
|
// Fired via navigator.sendBeacon on tab/browser close (see the
|
||||||
|
|||||||
61
src/tests/Feature/AdminAiIntegrationConfigTest.php
Normal file
61
src/tests/Feature/AdminAiIntegrationConfigTest.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Admin\Panel;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('the Integracje tab shows the Integracja AI card', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->assertSee('Integracja AI');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saving the AI config persists settings and encrypts the api key at rest', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiConfig.enabled', true)
|
||||||
|
->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1')
|
||||||
|
->set('aiConfig.apiKey', 'super-secret-key')
|
||||||
|
->set('aiConfig.model', 'llama-3.3-70b-versatile')
|
||||||
|
->set('aiConfig.verifySsl', true)
|
||||||
|
->call('saveAiConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('ai_base_url'))->toBe('https://api.groq.test/openai/v1');
|
||||||
|
expect(Settings::get('ai_model'))->toBe('llama-3.3-70b-versatile');
|
||||||
|
expect(Settings::get('ai_api_key'))->toBe('super-secret-key');
|
||||||
|
|
||||||
|
$stored = Setting::query()->where('key', 'ai_api_key')->value('value');
|
||||||
|
expect($stored)->not->toBe('super-secret-key');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('leaving the api key field blank on save keeps the previously stored key', function () {
|
||||||
|
Settings::set('ai_api_key', 'already-stored-key');
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiConfig.enabled', true)
|
||||||
|
->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1')
|
||||||
|
->set('aiConfig.model', 'llama-3.3-70b-versatile')
|
||||||
|
->call('saveAiConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('ai_api_key'))->toBe('already-stored-key');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testAiConnection reports the result of a live probe using unsaved form values', function () {
|
||||||
|
Http::fake(['api.groq.test/*' => Http::response(['choices' => [['message' => ['content' => 'pong']]]])]);
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiConfig.enabled', true)
|
||||||
|
->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1')
|
||||||
|
->set('aiConfig.apiKey', 'key')
|
||||||
|
->set('aiConfig.model', 'llama-3.3-70b-versatile')
|
||||||
|
->call('testAiConnection')
|
||||||
|
->assertSet('aiTestResult', 'ok');
|
||||||
|
});
|
||||||
85
src/tests/Feature/AdminAiTriageConfigTest.php
Normal file
85
src/tests/Feature/AdminAiTriageConfigTest.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Admin\Panel;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('the Integracje tab shows the Automatyzacja AI dla zgłoszeń card', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->assertSee('Automatyzacja AI dla zgłoszeń');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saving the triage config persists all 5 toggles plus the summary toggle', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiTriageConfig.categoryWhenMissing', true)
|
||||||
|
->set('aiTriageConfig.subcategoryWhenCategoryOnly', true)
|
||||||
|
->set('aiTriageConfig.recheckCategorized', true)
|
||||||
|
->set('aiTriageConfig.fixSubject', true)
|
||||||
|
->set('aiTriageConfig.setPriority', true)
|
||||||
|
->set('aiSummaryEnabled', true)
|
||||||
|
->call('saveAiTriageConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::bool('ai_triage_category_when_missing'))->toBeTrue();
|
||||||
|
expect(Settings::bool('ai_triage_subcategory_when_category_only'))->toBeTrue();
|
||||||
|
expect(Settings::bool('ai_triage_recheck_categorized'))->toBeTrue();
|
||||||
|
expect(Settings::bool('ai_triage_fix_subject'))->toBeTrue();
|
||||||
|
expect(Settings::bool('ai_triage_set_priority'))->toBeTrue();
|
||||||
|
expect(Settings::bool('ai_summary_enabled'))->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unchecking every toggle and saving turns them all back off', function () {
|
||||||
|
Settings::set('ai_triage_category_when_missing', '1');
|
||||||
|
Settings::set('ai_summary_enabled', '1');
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiTriageConfig.categoryWhenMissing', false)
|
||||||
|
->set('aiSummaryEnabled', false)
|
||||||
|
->call('saveAiTriageConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::bool('ai_triage_category_when_missing'))->toBeFalse();
|
||||||
|
expect(Settings::bool('ai_summary_enabled'))->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saving the triage config also persists the regenerate-on-message toggle', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('aiSummaryRegenerateOnMessage', true)
|
||||||
|
->call('saveAiTriageConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::bool('ai_summary_regenerate_on_message'))->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saveAiSummaryPrompt persists custom prompt text', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->call('saveAiSummaryPrompt', 'Mój niestandardowy prompt.')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('ai_summary_prompt'))->toBe('Mój niestandardowy prompt.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resetAiSummaryPrompt restores the default prompt after it was customized', function () {
|
||||||
|
$default = Settings::default('ai_summary_prompt');
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->call('saveAiSummaryPrompt', 'Coś zupełnie innego.')
|
||||||
|
->assertSet('aiSummaryPrompt', 'Coś zupełnie innego.');
|
||||||
|
|
||||||
|
expect(Settings::get('ai_summary_prompt'))->toBe('Coś zupełnie innego.');
|
||||||
|
|
||||||
|
$component->call('resetAiSummaryPrompt')
|
||||||
|
->assertSet('aiSummaryPrompt', $default);
|
||||||
|
|
||||||
|
expect(Settings::get('ai_summary_prompt'))->toBe($default);
|
||||||
|
});
|
||||||
54
src/tests/Feature/AdminBookstackTaggingButtonsTest.php
Normal file
54
src/tests/Feature/AdminBookstackTaggingButtonsTest.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Admin\Panel;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('the tagging buttons are visible once BookStack is enabled', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('bookstackConfig.enabled', true)
|
||||||
|
->assertSee('Otaguj nową treść')
|
||||||
|
->assertSee('Otaguj wszystko ponownie');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking the normal button runs a non-force tagging pass and shows the summary', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [10 => [], 11 => [['name' => 'Drukarki i skanery', 'value' => '']]],
|
||||||
|
aiContent: '{"10": ["Drukarki i skanery"], "11": ["Drukarki i skanery"]}',
|
||||||
|
);
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->call('runBookstackTagging')
|
||||||
|
->assertSet('bookstackTagResult', ['scanned' => 2, 'tagged' => 1, 'skipped' => 1, 'failed_batches' => 0])
|
||||||
|
->assertSee('Przeskanowano 2, otagowano 1, pominięto 1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking the force button reclassifies already-tagged content too', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [11 => [['name' => 'Drukarki i skanery', 'value' => '']]],
|
||||||
|
aiContent: '{"11": ["Drukarki i skanery"]}',
|
||||||
|
);
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->call('runBookstackTaggingForce')
|
||||||
|
->assertSet('bookstackTagResult', ['scanned' => 1, 'tagged' => 1, 'skipped' => 0, 'failed_batches' => 0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('running tagging without a configured AI integration shows a helpful error instead of a silent no-op', function () {
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
Settings::set('ai_enabled', '0');
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->call('runBookstackTagging')
|
||||||
|
->assertSet('bookstackTagResult', null)
|
||||||
|
->assertSee('Włącz i skonfiguruj obie integracje');
|
||||||
|
});
|
||||||
@@ -45,3 +45,59 @@ test('admin can add a description to a subcategory via the edit dialog', functio
|
|||||||
|
|
||||||
expect($sub->fresh()->description)->toBe('Problemy z połączeniem VPN.');
|
expect($sub->fresh()->description)->toBe('Problemy z połączeniem VPN.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('admin can reorder subcategories with up/down arrows', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
$category = Category::query()->create(['name' => 'IT-Pomoc']);
|
||||||
|
$vpn = $category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
|
||||||
|
$wifi = $category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
|
||||||
|
$drukarki = $category->subcategories()->create(['name' => 'Drukarki', 'sort_order' => 2]);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'categories')
|
||||||
|
->call('moveSubcategoryUp', $drukarki->id)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($category->fresh()->subcategories->pluck('name')->all())
|
||||||
|
->toBe(['VPN', 'Drukarki', 'WiFi']);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'categories')
|
||||||
|
->call('moveSubcategoryDown', $vpn->id)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($category->fresh()->subcategories->pluck('name')->all())
|
||||||
|
->toBe(['Drukarki', 'VPN', 'WiFi']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('moving the top subcategory up or the bottom one down is a no-op', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
$category = Category::query()->create(['name' => 'IT-Pomoc']);
|
||||||
|
$vpn = $category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
|
||||||
|
$wifi = $category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'categories')
|
||||||
|
->call('moveSubcategoryUp', $vpn->id)
|
||||||
|
->call('moveSubcategoryDown', $wifi->id)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($category->fresh()->subcategories->pluck('name')->all())
|
||||||
|
->toBe(['VPN', 'WiFi']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a new subcategory is appended to the end of the display order', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
$category = Category::query()->create(['name' => 'IT-Pomoc']);
|
||||||
|
$category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
|
||||||
|
$category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'categories')
|
||||||
|
->set('newSubNames.'.$category->id, 'Drukarki')
|
||||||
|
->call('addSubcategory', $category->id)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($category->fresh()->subcategories->pluck('name')->all())
|
||||||
|
->toBe(['VPN', 'WiFi', 'Drukarki']);
|
||||||
|
});
|
||||||
|
|||||||
106
src/tests/Feature/AdminSnipeitIntegrationConfigTest.php
Normal file
106
src/tests/Feature/AdminSnipeitIntegrationConfigTest.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Admin\Panel;
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
function adminUserForSnipeitTest(): User
|
||||||
|
{
|
||||||
|
return User::query()->create(['name' => 'Admin', 'email' => 'admin-snipeit@example.com', 'roles' => ['admin']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('the Integracje tab shows the Snipe-IT card with the requested fields', function () {
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->assertSee('Snipe-IT')
|
||||||
|
->assertSee('Adres API')
|
||||||
|
->assertSee('Klucz API')
|
||||||
|
->assertSee('Nie sprawdzaj SSL')
|
||||||
|
->assertSee('Klient może wybrać sprzęt, którego dotyczy zgłoszenie')
|
||||||
|
->assertSee('Operator może zobaczyć sprzęt zgłaszającego w widoku zgłoszenia')
|
||||||
|
->assertSee('Zezwól operatorowi na przeszukiwanie całego inwentarza');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the subcategory scope picker only appears once "klient może wybrać sprzęt" is checked', function () {
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->assertDontSee('Ogranicz do podkategorii')
|
||||||
|
->set('snipeitConfig.clientCanSelectAsset', true)
|
||||||
|
->assertSee('Ogranicz do podkategorii')
|
||||||
|
->assertSee('Sprzęt / Laptop');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saving the Snipe-IT config persists settings, encrypts the token at rest, and inverts the SSL checkbox', function () {
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$sub = $category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->set('snipeitConfig.baseUrl', 'https://assets.firma.test')
|
||||||
|
->set('snipeitConfig.apiToken', 'super-secret-token')
|
||||||
|
->set('snipeitConfig.skipSslVerification', true)
|
||||||
|
->set('snipeitConfig.clientCanSelectAsset', true)
|
||||||
|
->call('toggleSnipeitClientSubcategory', $sub->id)
|
||||||
|
->set('snipeitConfig.operatorViewRequesterAssets', true)
|
||||||
|
->set('snipeitConfig.operatorSearchInventory', false)
|
||||||
|
->call('saveSnipeitConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('snipeit_enabled'))->toBe('1');
|
||||||
|
expect(Settings::get('snipeit_base_url'))->toBe('https://assets.firma.test');
|
||||||
|
expect(Settings::get('snipeit_api_token'))->toBe('super-secret-token');
|
||||||
|
// "Nie sprawdzaj SSL" checked means verify_ssl is stored as off.
|
||||||
|
expect(Settings::bool('snipeit_verify_ssl'))->toBeFalse();
|
||||||
|
expect(Settings::bool('snipeit_client_can_select_asset'))->toBeTrue();
|
||||||
|
expect(Settings::get('snipeit_client_asset_subcategory_ids'))->toBe((string) $sub->id);
|
||||||
|
expect(Settings::bool('snipeit_operator_view_requester_assets'))->toBeTrue();
|
||||||
|
expect(Settings::bool('snipeit_operator_search_inventory'))->toBeFalse();
|
||||||
|
|
||||||
|
$stored = Setting::query()->where('key', 'snipeit_api_token')->value('value');
|
||||||
|
expect($stored)->not->toBe('super-secret-token');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('leaving the api token field blank on save keeps the previously stored token', function () {
|
||||||
|
Settings::set('snipeit_api_token', 'already-stored-token');
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->set('snipeitConfig.baseUrl', 'https://assets.firma.test')
|
||||||
|
->call('saveSnipeitConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('snipeit_api_token'))->toBe('already-stored-token');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testSnipeitConnection reports the result of a live probe using unsaved form values', function () {
|
||||||
|
Http::fake(['assets.firma.test/*' => Http::response(['rows' => []])]);
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->set('snipeitConfig.baseUrl', 'https://assets.firma.test')
|
||||||
|
->set('snipeitConfig.apiToken', 'tok')
|
||||||
|
->call('testSnipeitConnection')
|
||||||
|
->assertSet('snipeitTestResult', 'ok');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testSnipeitConnection requires a base URL before probing', function () {
|
||||||
|
$admin = adminUserForSnipeitTest();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations'])
|
||||||
|
->set('snipeitConfig.enabled', true)
|
||||||
|
->call('testSnipeitConnection')
|
||||||
|
->assertSet('snipeitTestResult', 'error');
|
||||||
|
});
|
||||||
66
src/tests/Feature/AiClientTest.php
Normal file
66
src/tests/Feature/AiClientTest.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Services\AiClient;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
test('enabled is false unless ai_enabled, ai_base_url and ai_model are all set — api key is optional', function () {
|
||||||
|
expect(app(AiClient::class)->enabled())->toBeFalse();
|
||||||
|
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://api.groq.test/openai/v1');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
|
||||||
|
expect(app(AiClient::class)->enabled())->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chat returns the assistant message content on success', function () {
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://api.groq.test/openai/v1');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'api.groq.test/*' => Http::response(['choices' => [['message' => ['content' => 'hello']]]]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(app(AiClient::class)->chat([['role' => 'user', 'content' => 'hi']]))->toBe('hello');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chat returns null on a non-successful response instead of throwing', function () {
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://api.groq.test/openai/v1');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
|
||||||
|
Http::fake(['api.groq.test/*' => Http::response(['error' => 'nope'], 500)]);
|
||||||
|
|
||||||
|
expect(app(AiClient::class)->chat([['role' => 'user', 'content' => 'hi']]))->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chat sends no Authorization header when no api key is configured (self-hosted Ollama style)', function () {
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'http://ollama.test/v1');
|
||||||
|
Settings::set('ai_model', 'llama3');
|
||||||
|
|
||||||
|
Http::fake(['ollama.test/*' => Http::response(['choices' => [['message' => ['content' => 'ok']]]])]);
|
||||||
|
|
||||||
|
app(AiClient::class)->chat([['role' => 'user', 'content' => 'hi']]);
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => ! $request->hasHeader('Authorization'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testConnection reports ok on a successful response', function () {
|
||||||
|
Http::fake(['api.groq.test/*' => Http::response(['choices' => [['message' => ['content' => 'pong']]]])]);
|
||||||
|
|
||||||
|
$ok = app(AiClient::class)->testConnection('https://api.groq.test/openai/v1', 'key', 'llama3', true);
|
||||||
|
|
||||||
|
expect($ok)->toBe(['ok' => true, 'message' => null]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testConnection reports the provider error message on failure', function () {
|
||||||
|
Http::fake(['api.groq.test/*' => Http::response(['error' => ['message' => 'bad model']], 400)]);
|
||||||
|
|
||||||
|
$error = app(AiClient::class)->testConnection('https://api.groq.test/openai/v1', 'key', 'bad-model', true);
|
||||||
|
|
||||||
|
expect($error['ok'])->toBeFalse();
|
||||||
|
expect($error['message'])->toBe('bad model');
|
||||||
|
});
|
||||||
68
src/tests/Feature/AiSummaryRegenerateOnMessageTest.php
Normal file
68
src/tests/Feature/AiSummaryRegenerateOnMessageTest.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Jobs\GenerateTicketAiSummaryJob;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\TicketService;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Bus;
|
||||||
|
|
||||||
|
function enableAiSummaryRegenerateOnMessage(bool $enabled): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_summary_enabled', '1');
|
||||||
|
Settings::set('ai_summary_regenerate_on_message', $enabled ? '1' : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('an operator reply dispatches an immediate summary regeneration when the setting is enabled', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableAiSummaryRegenerateOnMessage(true);
|
||||||
|
Bus::fake();
|
||||||
|
|
||||||
|
$ticket = makeTicket();
|
||||||
|
$operator = operatorUser();
|
||||||
|
|
||||||
|
app(TicketService::class)->operatorReply($ticket, $operator, 'Odpowiedź operatora.');
|
||||||
|
|
||||||
|
Bus::assertDispatchedAfterResponse(GenerateTicketAiSummaryJob::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a client reply does not dispatch regeneration when the setting is disabled', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableAiSummaryRegenerateOnMessage(false);
|
||||||
|
Bus::fake();
|
||||||
|
|
||||||
|
$ticket = makeTicket();
|
||||||
|
$client = User::factory()->create();
|
||||||
|
|
||||||
|
app(TicketService::class)->clientReply($ticket, $client, 'Odpowiedź klienta.');
|
||||||
|
|
||||||
|
Bus::assertNotDispatched(GenerateTicketAiSummaryJob::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an internal operator note also triggers regeneration, matching the transcript including internal notes', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableAiSummaryRegenerateOnMessage(true);
|
||||||
|
Bus::fake();
|
||||||
|
|
||||||
|
$ticket = makeTicket();
|
||||||
|
$operator = operatorUser();
|
||||||
|
|
||||||
|
app(TicketService::class)->operatorNote($ticket, $operator, 'Notatka wewnętrzna.');
|
||||||
|
|
||||||
|
Bus::assertDispatchedAfterResponse(GenerateTicketAiSummaryJob::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('no regeneration is dispatched when the AI summary feature itself is off, even with the toggle on', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_summary_enabled', '0');
|
||||||
|
Settings::set('ai_summary_regenerate_on_message', '1');
|
||||||
|
Bus::fake();
|
||||||
|
|
||||||
|
$ticket = makeTicket();
|
||||||
|
$operator = operatorUser();
|
||||||
|
|
||||||
|
app(TicketService::class)->operatorReply($ticket, $operator, 'Odpowiedź operatora.');
|
||||||
|
|
||||||
|
Bus::assertNotDispatched(GenerateTicketAiSummaryJob::class);
|
||||||
|
});
|
||||||
154
src/tests/Feature/BookStackContentTaggerTest.php
Normal file
154
src/tests/Feature/BookStackContentTaggerTest.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Services\BookStackContentTagger;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
function seedTaggerSubcategory(): void
|
||||||
|
{
|
||||||
|
$category = Category::query()->create(['name' => 'IT-Pomoc']);
|
||||||
|
$category->subcategories()->create(['name' => 'Drukarki i skanery']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableBookstackAndAiForTagging(): void
|
||||||
|
{
|
||||||
|
Settings::set('bookstack_enabled', '1');
|
||||||
|
Settings::set('bookstack_base_url', 'https://wiki.test');
|
||||||
|
Settings::set('bookstack_token_id', 'id');
|
||||||
|
Settings::set('bookstack_token_secret', 'secret');
|
||||||
|
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array> $pageTags page id => existing tags array
|
||||||
|
*/
|
||||||
|
function fakeTaggerBookstackAndAi(array $pageTags, string $aiContent): void
|
||||||
|
{
|
||||||
|
Http::fake([
|
||||||
|
'wiki.test/api/books*' => Http::response(['data' => [], 'total' => 0]),
|
||||||
|
'wiki.test/api/chapters*' => Http::response(['data' => [], 'total' => 0]),
|
||||||
|
'wiki.test/api/pages*' => function ($request) use ($pageTags) {
|
||||||
|
$path = parse_url($request->url(), PHP_URL_PATH);
|
||||||
|
|
||||||
|
if ($request->method() === 'GET' && Str::endsWith($path, '/api/pages')) {
|
||||||
|
return Http::response([
|
||||||
|
'data' => collect($pageTags)->keys()->map(fn ($id) => ['id' => $id, 'name' => "Page {$id}"])->values()->all(),
|
||||||
|
'total' => count($pageTags),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = (int) basename($path);
|
||||||
|
|
||||||
|
if ($request->method() === 'GET') {
|
||||||
|
return Http::response([
|
||||||
|
'id' => $id,
|
||||||
|
'name' => "Page {$id}",
|
||||||
|
'tags' => $pageTags[$id] ?? [],
|
||||||
|
'markdown' => 'Treść o drukarkach i skanerach.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->method() === 'PUT') {
|
||||||
|
return Http::response(['id' => $id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Http::response([], 404);
|
||||||
|
},
|
||||||
|
'ai.test/*' => Http::response(['choices' => [['message' => ['content' => $aiContent]]]]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('normal run tags untagged content and skips already-tagged content', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [10 => [], 11 => [['name' => 'Drukarki i skanery', 'value' => '']]],
|
||||||
|
aiContent: '{"10": ["Drukarki i skanery"], "11": ["Drukarki i skanery"]}',
|
||||||
|
);
|
||||||
|
|
||||||
|
$totals = app(BookStackContentTagger::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 2, 'tagged' => 1, 'skipped' => 1, 'failed_batches' => 0]);
|
||||||
|
|
||||||
|
Http::assertSent(fn ($r) => $r->method() === 'PUT'
|
||||||
|
&& str_contains((string) $r->url(), '/api/pages/10')
|
||||||
|
&& collect($r->data()['tags'])->contains(fn ($t) => $t['name'] === 'Drukarki i skanery'));
|
||||||
|
|
||||||
|
Http::assertNotSent(fn ($r) => $r->method() === 'PUT' && str_contains((string) $r->url(), '/api/pages/11'));
|
||||||
|
|
||||||
|
// the already-tagged page never even makes it into the AI prompt
|
||||||
|
Http::assertSent(fn ($r) => str_contains((string) $r->url(), 'ai.test')
|
||||||
|
? (str_contains($r['messages'][1]['content'], 'id=10') && ! str_contains($r['messages'][1]['content'], 'id=11'))
|
||||||
|
: true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('--dry-run classifies but never calls PUT', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [10 => []],
|
||||||
|
aiContent: '{"10": ["Drukarki i skanery"]}',
|
||||||
|
);
|
||||||
|
|
||||||
|
$totals = app(BookStackContentTagger::class)->run(dryRun: true);
|
||||||
|
|
||||||
|
expect($totals['tagged'])->toBe(1);
|
||||||
|
Http::assertNotSent(fn ($r) => $r->method() === 'PUT');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('--force re-classifies and re-writes already-tagged content', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [11 => [['name' => 'Drukarki i skanery', 'value' => '']]],
|
||||||
|
aiContent: '{"11": ["Drukarki i skanery"]}',
|
||||||
|
);
|
||||||
|
|
||||||
|
$totals = app(BookStackContentTagger::class)->run(force: true);
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'tagged' => 1, 'skipped' => 0, 'failed_batches' => 0]);
|
||||||
|
Http::assertSent(fn ($r) => $r->method() === 'PUT' && str_contains((string) $r->url(), '/api/pages/11'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tag matching is case-insensitive when deciding whether content is already tagged', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [11 => [['name' => 'drukarki i skanery', 'value' => '']]],
|
||||||
|
aiContent: '{"11": []}',
|
||||||
|
);
|
||||||
|
|
||||||
|
$totals = app(BookStackContentTagger::class)->run();
|
||||||
|
|
||||||
|
expect($totals['skipped'])->toBe(1);
|
||||||
|
expect($totals['scanned'])->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a malformed AI response fails only that batch, without writing any tags', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(
|
||||||
|
pageTags: [10 => []],
|
||||||
|
aiContent: 'this is not json at all',
|
||||||
|
);
|
||||||
|
|
||||||
|
$totals = app(BookStackContentTagger::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'tagged' => 0, 'skipped' => 0, 'failed_batches' => 1]);
|
||||||
|
Http::assertNotSent(fn ($r) => $r->method() === 'PUT');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the tagger never touches bookshelves', function () {
|
||||||
|
seedTaggerSubcategory();
|
||||||
|
enableBookstackAndAiForTagging();
|
||||||
|
fakeTaggerBookstackAndAi(pageTags: [], aiContent: '{}');
|
||||||
|
|
||||||
|
app(BookStackContentTagger::class)->run();
|
||||||
|
|
||||||
|
Http::assertNotSent(fn ($r) => str_contains((string) $r->url(), '/api/shelves'));
|
||||||
|
});
|
||||||
54
src/tests/Feature/BookStackSearchTagQueryTest.php
Normal file
54
src/tests/Feature/BookStackSearchTagQueryTest.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Services\BookStackClient;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
function enableBookstackForSearch(string $searchBy = 'both'): void
|
||||||
|
{
|
||||||
|
Settings::set('bookstack_enabled', '1');
|
||||||
|
Settings::set('bookstack_base_url', 'https://wiki.test');
|
||||||
|
Settings::set('bookstack_token_id', 'id');
|
||||||
|
Settings::set('bookstack_token_secret', 'secret');
|
||||||
|
Settings::set('bookstack_search_by', $searchBy);
|
||||||
|
Settings::set('bookstack_allowed_shelf_ids_creation', '1');
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'wiki.test/api/shelves/1' => Http::response(['books' => [['id' => 5]]]),
|
||||||
|
'wiki.test/api/shelves*' => Http::response(['data' => [['id' => 1, 'name' => 'IT']]]),
|
||||||
|
'wiki.test/api/search*' => Http::response(['data' => []]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('with search_by=both, the tags-variant query uses tagQuery while the name-variant keeps the full query', function () {
|
||||||
|
enableBookstackForSearch('both');
|
||||||
|
|
||||||
|
app(BookStackClient::class)->search('IT-Pomoc Drukarki i skanery', 5, BookStackClient::CONTEXT_CREATION, 'Drukarki i skanery');
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => str_contains((string) $request->url(), '/api/search')
|
||||||
|
&& ($request['query'] ?? '') === '{in_name:IT-Pomoc Drukarki i skanery}');
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => str_contains((string) $request->url(), '/api/search')
|
||||||
|
&& ($request['query'] ?? '') === '[Drukarki i skanery]');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('omitting tagQuery falls back to the full query for backward compatibility', function () {
|
||||||
|
enableBookstackForSearch('tags');
|
||||||
|
|
||||||
|
app(BookStackClient::class)->search('IT-Pomoc Drukarki i skanery');
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => str_contains((string) $request->url(), '/api/search')
|
||||||
|
&& ($request['query'] ?? '') === '[IT-Pomoc Drukarki i skanery]');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('search_by=tags alone sends only the tag-form query built from tagQuery, never the plain category+subcategory text', function () {
|
||||||
|
enableBookstackForSearch('tags');
|
||||||
|
|
||||||
|
app(BookStackClient::class)->search('IT-Pomoc Drukarki i skanery', 5, BookStackClient::CONTEXT_CREATION, 'Drukarki i skanery');
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => str_contains((string) $request->url(), '/api/search')
|
||||||
|
&& ($request['query'] ?? '') === '[Drukarki i skanery]');
|
||||||
|
|
||||||
|
Http::assertNotSent(fn ($request) => str_contains((string) $request->url(), '/api/search')
|
||||||
|
&& str_contains($request['query'] ?? '', 'IT-Pomoc'));
|
||||||
|
});
|
||||||
147
src/tests/Feature/GlobalSearchAndRecentlyViewedTest.php
Normal file
147
src/tests/Feature/GlobalSearchAndRecentlyViewedTest.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\GlobalSearch;
|
||||||
|
use App\Livewire\Operator\Queue;
|
||||||
|
use App\Livewire\Operator\TicketShow as OperatorTicketShow;
|
||||||
|
use App\Models\User;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('opening a ticket records a view that surfaces in the operator sidebar, most recent first', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('recent-view@example.com');
|
||||||
|
$ticketA = makeTicket(['number' => '1001', 'subject' => 'First one']);
|
||||||
|
$ticketB = makeTicket(['number' => '1002', 'subject' => 'Second one']);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticketA]);
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticketB]);
|
||||||
|
|
||||||
|
$queue = Livewire::actingAs($operator)->test(Queue::class);
|
||||||
|
$recent = $queue->instance()->recentlyViewed;
|
||||||
|
|
||||||
|
expect($recent->pluck('id')->all())->toBe([$ticketB->id, $ticketA->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('re-opening the same ticket bumps it to the top instead of duplicating it', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('recent-view-bump@example.com');
|
||||||
|
$ticketA = makeTicket(['number' => '1001']);
|
||||||
|
$ticketB = makeTicket(['number' => '1002']);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticketA]);
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticketB]);
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticketA]);
|
||||||
|
|
||||||
|
$recent = Livewire::actingAs($operator)->test(Queue::class)->instance()->recentlyViewed;
|
||||||
|
|
||||||
|
expect($recent->pluck('id')->all())->toBe([$ticketA->id, $ticketB->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('global search only returns tickets the searching user is allowed to see', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-operator@example.com');
|
||||||
|
$clientA = User::query()->create(['name' => 'Client A', 'email' => 'client-a@example.com', 'roles' => ['client']]);
|
||||||
|
$clientB = User::query()->create(['name' => 'Client B', 'email' => 'client-b@example.com', 'roles' => ['client']]);
|
||||||
|
|
||||||
|
$ticketA = makeTicket(['number' => '2001', 'subject' => 'Unikalny temat A', 'customer_id' => $clientA->id, 'email' => $clientA->email]);
|
||||||
|
makeTicket(['number' => '2002', 'subject' => 'Unikalny temat B', 'customer_id' => $clientB->id, 'email' => $clientB->email]);
|
||||||
|
|
||||||
|
// Operator sees both, scoped only by the search term.
|
||||||
|
$operatorResults = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'Unikalny')
|
||||||
|
->instance()->results;
|
||||||
|
expect($operatorResults)->toHaveCount(2);
|
||||||
|
|
||||||
|
// Client A only ever sees their own ticket, even when the term matches both.
|
||||||
|
$clientResults = Livewire::actingAs($clientA)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'Unikalny')
|
||||||
|
->instance()->results;
|
||||||
|
expect($clientResults->pluck('id')->all())->toBe([$ticketA->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('global search returns nothing for a blank query', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-blank@example.com');
|
||||||
|
makeTicket(['number' => '3001']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)->instance()->results;
|
||||||
|
|
||||||
|
expect($results)->toBeEmpty();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the od: operator matches the reporter, not ticket content', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-od@example.com');
|
||||||
|
$byKacper = makeTicket(['number' => '4001', 'name' => 'Kacper Zbikowski', 'email' => 'kacper@example.com', 'subject' => 'Nieistotny temat']);
|
||||||
|
makeTicket(['number' => '4002', 'name' => 'Ktos Inny', 'email' => 'ktos@example.com', 'subject' => 'Kacper w temacie']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'od:Kacper')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$byKacper->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the temat: operator matches only the subject', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-temat@example.com');
|
||||||
|
$matching = makeTicket(['number' => '4101', 'subject' => 'Awaria drukarki', 'body' => 'coś innego']);
|
||||||
|
makeTicket(['number' => '4102', 'subject' => 'Coś innego', 'body' => 'Awaria drukarki w opisie']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'temat:drukarki')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$matching->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the treść: operator matches only ticket/message body, not the subject', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-tresc@example.com');
|
||||||
|
$matching = makeTicket(['number' => '4201', 'subject' => 'Coś innego', 'body' => 'Drukarka nie działa od rana']);
|
||||||
|
makeTicket(['number' => '4202', 'subject' => 'Drukarka znów nie działa', 'body' => 'coś innego']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'treść:drukarka')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$matching->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the numer: operator matches the ticket number', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-numer@example.com');
|
||||||
|
$matching = makeTicket(['number' => '9999']);
|
||||||
|
makeTicket(['number' => '1111']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'numer:9999')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$matching->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('operators combine with AND, matching Gmail-style multi-field search', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-combo@example.com');
|
||||||
|
$matching = makeTicket(['number' => '4301', 'name' => 'Kacper Zbikowski', 'subject' => 'Awaria drukarki']);
|
||||||
|
makeTicket(['number' => '4302', 'name' => 'Kacper Zbikowski', 'subject' => 'Inny temat']);
|
||||||
|
makeTicket(['number' => '4303', 'name' => 'Ktos Inny', 'subject' => 'Awaria drukarki']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'od:Kacper temat:drukarki')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$matching->id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an unrecognized "key:value" token is treated as free text instead of being silently dropped', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('search-unrecognized@example.com');
|
||||||
|
$matching = makeTicket(['number' => '4401', 'subject' => 'status:pilne coś']);
|
||||||
|
|
||||||
|
$results = Livewire::actingAs($operator)->test(GlobalSearch::class)
|
||||||
|
->set('search', 'status:pilne')
|
||||||
|
->instance()->results;
|
||||||
|
|
||||||
|
expect($results->pluck('id')->all())->toBe([$matching->id]);
|
||||||
|
});
|
||||||
43
src/tests/Feature/OperatorAiSummaryRegenerateTest.php
Normal file
43
src/tests/Feature/OperatorAiSummaryRegenerateTest.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Operator\TicketShow;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('operator can manually trigger AI summary regeneration from the ticket sidebar', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
Settings::set('ai_summary_enabled', '1');
|
||||||
|
Http::fake(['ai.test/*' => Http::response([
|
||||||
|
'choices' => [['message' => ['content' => '{"summary": "Ręcznie wygenerowane.", "suggested_action": null}']]],
|
||||||
|
])]);
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket();
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('regenerateAiSummary')
|
||||||
|
->call('loadAiSummary')
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Ręcznie wygenerowane.');
|
||||||
|
|
||||||
|
expect($ticket->refresh()->ai_summary)->toBe('Ręcznie wygenerowane.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a failed manual regeneration shows an error and leaves the previous summary intact', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
Settings::set('ai_enabled', '0');
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket();
|
||||||
|
$ticket->update(['ai_summary' => 'stare podsumowanie']);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('regenerateAiSummary')
|
||||||
|
->assertSet('aiSummaryRegenerateError', 'Nie udało się wygenerować podsumowania. Sprawdź konfigurację integracji AI.');
|
||||||
|
|
||||||
|
expect($ticket->refresh()->ai_summary)->toBe('stare podsumowanie');
|
||||||
|
});
|
||||||
47
src/tests/Feature/OperatorClientSearchTest.php
Normal file
47
src/tests/Feature/OperatorClientSearchTest.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Operator\ClientSearch;
|
||||||
|
use App\Models\User;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('searching by name or email finds matching accounts, empty search shows nothing', function () {
|
||||||
|
$operator = operatorUser('client-search-op@example.com');
|
||||||
|
$anna = User::query()->create(['name' => 'Anna Kowalska', 'email' => 'anna.kowalska@example.com', 'roles' => ['client']]);
|
||||||
|
User::query()->create(['name' => 'Jan Nowak', 'email' => 'jan.nowak@example.com', 'roles' => ['client']]);
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(ClientSearch::class);
|
||||||
|
expect($component->instance()->results)->toHaveCount(0);
|
||||||
|
|
||||||
|
$component->set('search', 'Kowalska');
|
||||||
|
expect($component->instance()->results->pluck('id')->all())->toBe([$anna->id]);
|
||||||
|
|
||||||
|
$component->set('search', 'jan.nowak@example.com');
|
||||||
|
expect($component->instance()->results)->toHaveCount(1);
|
||||||
|
|
||||||
|
$component->set('search', 'nobody-matches-this');
|
||||||
|
expect($component->instance()->results)->toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('results include the ticket count and are capped at 20', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('client-search-op2@example.com');
|
||||||
|
$client = User::query()->create(['name' => 'Piotr Testowy', 'email' => 'piotr@example.com', 'roles' => ['client']]);
|
||||||
|
makeTicket(['number' => '2001', 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name]);
|
||||||
|
makeTicket(['number' => '2002', 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name]);
|
||||||
|
|
||||||
|
foreach (range(1, 25) as $i) {
|
||||||
|
User::query()->create(['name' => "Testowy Kandydat {$i}", 'email' => "cand{$i}@example.com", 'roles' => ['client']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(ClientSearch::class)->set('search', 'Testowy');
|
||||||
|
expect($component->instance()->results)->toHaveCount(20);
|
||||||
|
|
||||||
|
$component->set('search', 'Piotr');
|
||||||
|
expect($component->instance()->results->first()->tickets_as_customer_count)->toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a client cannot reach the operator client-search page', function () {
|
||||||
|
$client = User::query()->create(['name' => 'Client', 'email' => 'not-operator@example.com', 'roles' => ['client']]);
|
||||||
|
|
||||||
|
$this->actingAs($client)->get(route('operator.clients'))->assertForbidden();
|
||||||
|
});
|
||||||
@@ -91,7 +91,7 @@ test('a non-admin operator can still open a ticket outside their team if it is p
|
|||||||
->assertOk();
|
->assertOk();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the team reassignment dropdown on a ticket only offers a non-admin operator their own teams', function () {
|
test('the team reassignment dropdown on a ticket offers a non-admin operator every team, not just their own', function () {
|
||||||
seedStatusesAndPriorities();
|
seedStatusesAndPriorities();
|
||||||
$operator = operatorUser('scoped-5@example.com');
|
$operator = operatorUser('scoped-5@example.com');
|
||||||
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
@@ -101,9 +101,25 @@ test('the team reassignment dropdown on a ticket only offers a non-admin operato
|
|||||||
$ticket = makeTicket(['number' => '5001', 'team_id' => $myTeam->id]);
|
$ticket = makeTicket(['number' => '5001', 'team_id' => $myTeam->id]);
|
||||||
|
|
||||||
$teamNames = Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
$teamNames = Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
->instance()->teams->pluck('name')->all();
|
->instance()->teams->pluck('name')->sort()->values()->all();
|
||||||
|
|
||||||
expect($teamNames)->toBe(['Infrastruktura']);
|
expect($teamNames)->toBe(['Aplikacje', 'Infrastruktura']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a non-admin operator can reassign a ticket to a team they do not belong to', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('scoped-7@example.com');
|
||||||
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
|
$otherTeam = Team::query()->create(['name' => 'Aplikacje']);
|
||||||
|
$operator->teams()->attach($myTeam->id);
|
||||||
|
|
||||||
|
$ticket = makeTicket(['number' => '5002', 'team_id' => $myTeam->id]);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('setTeam', (string) $otherTeam->id)
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($ticket->fresh()->team_id)->toBe($otherTeam->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('merging cannot pull in a ticket outside the operators scope via a crafted selection', function () {
|
test('merging cannot pull in a ticket outside the operators scope via a crafted selection', function () {
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Operator\TicketShow;
|
||||||
|
use App\Models\Team;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('an operator viewing a ticket is sent to the queue instead of erroring when it is deleted by someone else', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-1@example.com');
|
||||||
|
$ticket = makeTicket(['number' => '6001', 'team_id' => null]);
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket]);
|
||||||
|
|
||||||
|
Ticket::query()->whereKey($ticket->id)->delete();
|
||||||
|
|
||||||
|
$component->call('onQueueChanged', $ticket->id)
|
||||||
|
->assertRedirect(route('operator.queue'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator is sent to the queue when a live update moves the ticket to a team outside their scope', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-2@example.com');
|
||||||
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
|
$otherTeam = Team::query()->create(['name' => 'Aplikacje']);
|
||||||
|
$operator->teams()->attach($myTeam->id);
|
||||||
|
|
||||||
|
$ticket = makeTicket(['number' => '6002', 'team_id' => $myTeam->id]);
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket]);
|
||||||
|
|
||||||
|
$ticket->update(['team_id' => $otherTeam->id]);
|
||||||
|
|
||||||
|
$component->call('onQueueChanged', $ticket->id)
|
||||||
|
->assertRedirect(route('operator.queue'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator is not redirected by a live update for a ticket still personally assigned to them', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-3@example.com');
|
||||||
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
|
$otherTeam = Team::query()->create(['name' => 'Aplikacje']);
|
||||||
|
$operator->teams()->attach($myTeam->id);
|
||||||
|
|
||||||
|
$ticket = makeTicket(['number' => '6003', 'team_id' => $myTeam->id, 'assignee_id' => $operator->id]);
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket]);
|
||||||
|
|
||||||
|
$ticket->update(['team_id' => $otherTeam->id]);
|
||||||
|
|
||||||
|
$component->call('onQueueChanged', $ticket->id)
|
||||||
|
->assertNoRedirect();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator who reassigns a ticket to a team outside their own scope is redirected immediately', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-4@example.com');
|
||||||
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
|
$otherTeam = Team::query()->create(['name' => 'Aplikacje']);
|
||||||
|
$operator->teams()->attach($myTeam->id);
|
||||||
|
|
||||||
|
$ticket = makeTicket(['number' => '6004', 'team_id' => $myTeam->id]);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('setTeam', (string) $otherTeam->id)
|
||||||
|
->assertRedirect(route('operator.queue'));
|
||||||
|
|
||||||
|
expect($ticket->fresh()->team_id)->toBe($otherTeam->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator who reassigns a ticket to their own team is not redirected', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-5@example.com');
|
||||||
|
$myTeam = Team::query()->create(['name' => 'Infrastruktura']);
|
||||||
|
$operator->teams()->attach($myTeam->id);
|
||||||
|
|
||||||
|
$ticket = makeTicket(['number' => '6005', 'team_id' => null]);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('setTeam', (string) $myTeam->id)
|
||||||
|
->assertNoRedirect();
|
||||||
|
|
||||||
|
expect($ticket->fresh()->team_id)->toBe($myTeam->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a direct link to a since-deleted ticket redirects an operator to their queue instead of a 404', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('redirect-6@example.com');
|
||||||
|
$ticket = makeTicket(['number' => '6006']);
|
||||||
|
$url = route('operator.ticket', $ticket);
|
||||||
|
$ticket->delete();
|
||||||
|
|
||||||
|
$this->actingAs($operator)->get($url)->assertRedirect(route('operator.queue'));
|
||||||
|
});
|
||||||
46
src/tests/Feature/PageTitleTest.php
Normal file
46
src/tests/Feature/PageTitleTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Testing\TestResponse;
|
||||||
|
|
||||||
|
function assertTitle(TestResponse $response, string $expectedContext): void
|
||||||
|
{
|
||||||
|
$response->assertOk();
|
||||||
|
preg_match('#<title>(.*?)</title>#s', $response->getContent(), $m);
|
||||||
|
expect($m[1] ?? null)->toBe($expectedContext.' — Servicedesk');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('login and landing pages get a page-specific title', function () {
|
||||||
|
assertTitle($this->get('/login'), 'Logowanie');
|
||||||
|
assertTitle($this->get('/'), 'Zgłoś problem');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('client pages carry a distinct, ticket-specific title', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$client = User::query()->create(['name' => 'Client', 'email' => 'title-client@example.com', 'roles' => ['client']]);
|
||||||
|
$ticket = makeTicket(['number' => '6001', 'subject' => 'Drukarka nie działa', 'customer_id' => $client->id, 'email' => $client->email]);
|
||||||
|
|
||||||
|
assertTitle($this->actingAs($client)->get('/client'), 'Moje zgłoszenia');
|
||||||
|
assertTitle($this->actingAs($client)->get('/client/new'), 'Nowe zgłoszenie');
|
||||||
|
assertTitle($this->actingAs($client)->get(route('client.ticket', $ticket)), '#6001 — Drukarka nie działa');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('operator queue title reflects the currently selected queue', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('title-operator@example.com');
|
||||||
|
$ticket = makeTicket(['number' => '6101', 'subject' => 'Awaria monitora']);
|
||||||
|
|
||||||
|
assertTitle($this->actingAs($operator)->get('/operator'), 'Otwarte');
|
||||||
|
assertTitle($this->actingAs($operator)->get('/operator?queue=mine'), 'Moje zgłoszenia');
|
||||||
|
assertTitle($this->actingAs($operator)->get('/operator/new'), 'Nowe zgłoszenie');
|
||||||
|
assertTitle($this->actingAs($operator)->get('/operator/stats'), 'Statystyki');
|
||||||
|
assertTitle($this->actingAs($operator)->get('/operator/clients'), 'Klienci');
|
||||||
|
assertTitle($this->actingAs($operator)->get(route('operator.ticket', $ticket)), '#6101 — Awaria monitora');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('admin panel title reflects the currently selected tab', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
assertTitle($this->actingAs($admin)->get('/admin'), 'Kategorie');
|
||||||
|
assertTitle($this->actingAs($admin)->get('/admin?tab=users'), 'Użytkownicy');
|
||||||
|
});
|
||||||
45
src/tests/Feature/RefreshBadgesConfiguredIntervalTest.php
Normal file
45
src/tests/Feature/RefreshBadgesConfiguredIntervalTest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Client\TicketShow as ClientTicketShow;
|
||||||
|
use App\Livewire\NotificationBell;
|
||||||
|
use App\Livewire\Operator\Queue;
|
||||||
|
use App\Livewire\Operator\TicketShow as OperatorTicketShow;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('operator ticket view renders the configured interval and a working click-to-refresh handler', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
Settings::set('refresh_ticket_view_seconds', '45');
|
||||||
|
$ticket = makeTicket(['number' => '7001']);
|
||||||
|
|
||||||
|
Livewire::actingAs(operatorUser())->test(OperatorTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->assertSeeHtml('remaining: 45, total: 45')
|
||||||
|
->assertSeeHtml('remaining = total; $wire.refreshTicketData()');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('client ticket view renders the configured interval and a working click-to-refresh handler', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
Settings::set('refresh_ticket_view_seconds', '50');
|
||||||
|
$client = User::query()->create(['name' => 'Anna Kowalska', 'email' => 'client-refresh@example.com', 'roles' => ['client']]);
|
||||||
|
$ticket = makeTicket(['number' => '7002', 'customer_id' => $client->id]);
|
||||||
|
|
||||||
|
Livewire::actingAs($client)->test(ClientTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->assertSeeHtml('remaining: 50, total: 50')
|
||||||
|
->assertSeeHtml('remaining = total; $wire.refreshTicketData()');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('operator queue renders the configured interval and a working click-to-refresh handler', function () {
|
||||||
|
Settings::set('refresh_queue_seconds', '75');
|
||||||
|
|
||||||
|
Livewire::actingAs(operatorUser())->test(Queue::class)
|
||||||
|
->assertSeeHtml('remaining: 75, total: 75')
|
||||||
|
->assertSeeHtml('remaining = total; $wire.refreshQueue()');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('notification bell polls at the configured interval', function () {
|
||||||
|
Settings::set('refresh_notifications_seconds', '15');
|
||||||
|
|
||||||
|
Livewire::actingAs(operatorUser())->test(NotificationBell::class)
|
||||||
|
->assertSeeHtml('wire:poll.15s="$refresh"');
|
||||||
|
});
|
||||||
43
src/tests/Feature/RefreshIntervalsConfigTest.php
Normal file
43
src/tests/Feature/RefreshIntervalsConfigTest.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Admin\Panel;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('admin can save custom refresh and schedule intervals from the Konfiguracja tab', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'config')
|
||||||
|
->set('systemConfig.refreshTicketViewSeconds', '45')
|
||||||
|
->set('systemConfig.refreshQueueSeconds', '90')
|
||||||
|
->set('systemConfig.refreshNotificationsSeconds', '20')
|
||||||
|
->set('systemConfig.scheduleSlaCheckMinutes', '10')
|
||||||
|
->set('systemConfig.scheduleAutomationRulesMinutes', '10')
|
||||||
|
->set('systemConfig.scheduleImapFetchMinutes', '2')
|
||||||
|
->set('systemConfig.scheduleAiAutomationMinutes', '2')
|
||||||
|
->call('saveSystemConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('refresh_ticket_view_seconds'))->toBe('45');
|
||||||
|
expect(Settings::get('refresh_queue_seconds'))->toBe('90');
|
||||||
|
expect(Settings::get('refresh_notifications_seconds'))->toBe('20');
|
||||||
|
expect(Settings::get('schedule_sla_check_minutes'))->toBe('10');
|
||||||
|
expect(Settings::get('schedule_automation_rules_minutes'))->toBe('10');
|
||||||
|
expect(Settings::get('schedule_imap_fetch_minutes'))->toBe('2');
|
||||||
|
expect(Settings::get('schedule_ai_automation_minutes'))->toBe('2');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saving a zero or negative interval clamps it to 1', function () {
|
||||||
|
$admin = adminUser();
|
||||||
|
|
||||||
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
|
->call('setTab', 'config')
|
||||||
|
->set('systemConfig.refreshQueueSeconds', '0')
|
||||||
|
->set('systemConfig.scheduleImapFetchMinutes', '-3')
|
||||||
|
->call('saveSystemConfig')
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect(Settings::get('refresh_queue_seconds'))->toBe('1');
|
||||||
|
expect(Settings::get('schedule_imap_fetch_minutes'))->toBe('1');
|
||||||
|
});
|
||||||
@@ -98,6 +98,24 @@ test('sending via a status-changing quick action updates the ticket status', fun
|
|||||||
->and($ticket->fresh()->messages()->where('body', 'Naprawione, proszę potwierdzić.')->exists())->toBeTrue();
|
->and($ticket->fresh()->messages()->where('body', 'Naprawione, proszę potwierdzić.')->exists())->toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sending via a status-changing quick action changes the status select\'s wire:key so the browser is forced to redraw it', function () {
|
||||||
|
// The <select> is bound via wire:change, not wire:model, so Livewire's
|
||||||
|
// morph step otherwise preserves whatever the browser already has
|
||||||
|
// selected instead of applying the freshly rendered "selected" option —
|
||||||
|
// a documented Livewire/Alpine-morph quirk for uncontrolled form
|
||||||
|
// elements. Keying the element to status_key forces a real replace.
|
||||||
|
$this->seed();
|
||||||
|
$operator = operatorUser('quickaction-wirekey@example.com');
|
||||||
|
$ticket = makeTicket(['number' => '1002', 'status_key' => 'new']);
|
||||||
|
$action = ReplyQuickAction::query()->where('label', 'Wyślij i oznacz jako rozwiązane')->firstOrFail();
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(TicketShow::class, ['ticket' => $ticket])
|
||||||
|
->assertSeeHtml('wire:key="ticket-status-select-new"')
|
||||||
|
->set('reply', 'Naprawione, proszę potwierdzić.')
|
||||||
|
->call('sendAndTransition', $action->id)
|
||||||
|
->assertSeeHtml('wire:key="ticket-status-select-closed"');
|
||||||
|
});
|
||||||
|
|
||||||
test('sending via a "nie zmieniaj" quick action posts the reply without changing the status', function () {
|
test('sending via a "nie zmieniaj" quick action posts the reply without changing the status', function () {
|
||||||
seedStatusesAndPriorities();
|
seedStatusesAndPriorities();
|
||||||
$operator = operatorUser('quickaction-nochange@example.com');
|
$operator = operatorUser('quickaction-nochange@example.com');
|
||||||
|
|||||||
36
src/tests/Feature/RunAiTicketAutomationCommandTest.php
Normal file
36
src/tests/Feature/RunAiTicketAutomationCommandTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Priority;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
test('the scheduled command runs both triage and summary in one pass', function () {
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
Settings::set('ai_triage_set_priority', '1');
|
||||||
|
Settings::set('ai_summary_enabled', '1');
|
||||||
|
|
||||||
|
Priority::query()->create(['key' => 'high', 'label' => 'Wysoki', 'color' => '#000', 'sort_order' => 1]);
|
||||||
|
|
||||||
|
Ticket::query()->create([
|
||||||
|
'number' => '900100',
|
||||||
|
'email' => 'client@example.com',
|
||||||
|
'name' => 'Test Client',
|
||||||
|
'subject' => 'Test',
|
||||||
|
'body' => 'Treść zgłoszenia.',
|
||||||
|
'status_key' => 'new',
|
||||||
|
'priority_key' => 'medium',
|
||||||
|
'custom_fields' => [],
|
||||||
|
]);
|
||||||
|
|
||||||
|
Http::fake(['ai.test/*' => Http::response(['choices' => [
|
||||||
|
['message' => ['content' => '{"category": null, "subcategory": null, "subject": null, "priority": "high"}']],
|
||||||
|
]])]);
|
||||||
|
|
||||||
|
$this->artisan('ai:run-ticket-automation')
|
||||||
|
->assertSuccessful()
|
||||||
|
->expectsOutputToContain('AI triage: scanned 1, changed 1, failed 0.')
|
||||||
|
->expectsOutputToContain('AI summaries: scanned 1,');
|
||||||
|
});
|
||||||
42
src/tests/Feature/SettingsCronExpressionTest.php
Normal file
42
src/tests/Feature/SettingsCronExpressionTest.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
test('dueEveryMinutes is true on a minute that is a multiple of the configured interval', function () {
|
||||||
|
Carbon::setTestNow(Carbon::parse('2026-01-01 12:14:00'));
|
||||||
|
Settings::set('schedule_imap_fetch_minutes', '7');
|
||||||
|
|
||||||
|
expect(Settings::dueEveryMinutes('schedule_imap_fetch_minutes', 5))->toBeTrue();
|
||||||
|
|
||||||
|
Carbon::setTestNow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dueEveryMinutes is false on a minute that is not a multiple of the configured interval', function () {
|
||||||
|
Carbon::setTestNow(Carbon::parse('2026-01-01 12:15:00'));
|
||||||
|
Settings::set('schedule_imap_fetch_minutes', '7');
|
||||||
|
|
||||||
|
expect(Settings::dueEveryMinutes('schedule_imap_fetch_minutes', 5))->toBeFalse();
|
||||||
|
|
||||||
|
Carbon::setTestNow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dueEveryMinutes falls back to the given default when unset', function () {
|
||||||
|
Carbon::setTestNow(Carbon::parse('2026-01-01 12:15:00'));
|
||||||
|
|
||||||
|
expect(Settings::dueEveryMinutes('schedule_ai_automation_minutes', 5))->toBeTrue();
|
||||||
|
|
||||||
|
Carbon::setTestNow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dueEveryMinutes clamps a zero or negative stored value to 1, so it is always due', function () {
|
||||||
|
Carbon::setTestNow(Carbon::parse('2026-01-01 12:13:00'));
|
||||||
|
|
||||||
|
Settings::set('schedule_sla_check_minutes', '0');
|
||||||
|
expect(Settings::dueEveryMinutes('schedule_sla_check_minutes', 15))->toBeTrue();
|
||||||
|
|
||||||
|
Settings::set('schedule_sla_check_minutes', '-4');
|
||||||
|
expect(Settings::dueEveryMinutes('schedule_sla_check_minutes', 15))->toBeTrue();
|
||||||
|
|
||||||
|
Carbon::setTestNow();
|
||||||
|
});
|
||||||
@@ -31,16 +31,16 @@ test('every page renders without error against fully seeded data', function () {
|
|||||||
$this->get('/')->assertOk()->assertSee('Jak możemy pomóc');
|
$this->get('/')->assertOk()->assertSee('Jak możemy pomóc');
|
||||||
$this->get('/login')->assertOk()->assertSee('Nowe zgłoszenie bez logowania');
|
$this->get('/login')->assertOk()->assertSee('Nowe zgłoszenie bez logowania');
|
||||||
|
|
||||||
$this->actingAs($client)->get('/client')->assertOk()->assertSee('Moje zgłoszenia')->assertSee('Panel Klienta');
|
$this->actingAs($client)->get('/client')->assertOk()->assertSee('Moje zgłoszenia')->assertSee('Klient');
|
||||||
$this->actingAs($client)->get('/client/new')->assertOk()->assertSee('Panel Klienta');
|
$this->actingAs($client)->get('/client/new')->assertOk()->assertSee('Klient');
|
||||||
$this->actingAs($client)->get(route('client.ticket', $clientTicket))->assertOk()->assertSee($clientTicket->subject)->assertSee('Panel Klienta');
|
$this->actingAs($client)->get(route('client.ticket', $clientTicket))->assertOk()->assertSee($clientTicket->subject)->assertSee('Klient');
|
||||||
|
|
||||||
$this->actingAs($operator)->get('/operator')->assertOk()->assertSee('Otwarte')->assertSee('Panel Operatora');
|
$this->actingAs($operator)->get('/operator')->assertOk()->assertSee('Otwarte')->assertSee('Operator');
|
||||||
$this->actingAs($operator)->get('/operator/new')->assertOk()->assertSee($client->email)->assertSee('Panel Operatora');
|
$this->actingAs($operator)->get('/operator/new')->assertOk()->assertSee($client->email)->assertSee('Operator');
|
||||||
$this->actingAs($operator)->get(route('operator.ticket', $anyTicket))->assertOk()->assertSee($anyTicket->subject)->assertSee('Panel Operatora');
|
$this->actingAs($operator)->get(route('operator.ticket', $anyTicket))->assertOk()->assertSee($anyTicket->subject)->assertSee('Operator');
|
||||||
|
|
||||||
foreach (['categories', 'fields', 'users', 'teams', 'user-fields', 'reply-quick-actions', 'response-templates', 'statuses', 'priorities', 'templates', 'branding', 'config', 'about'] as $tab) {
|
foreach (['categories', 'fields', 'users', 'teams', 'user-fields', 'reply-quick-actions', 'response-templates', 'statuses', 'priorities', 'templates', 'branding', 'config', 'about'] as $tab) {
|
||||||
$this->actingAs($admin)->get('/admin')->assertOk()->assertSee('Panel Administratora');
|
$this->actingAs($admin)->get('/admin')->assertOk()->assertSee('Administrator');
|
||||||
Livewire::actingAs($admin)->test(Panel::class)
|
Livewire::actingAs($admin)->test(Panel::class)
|
||||||
->call('setTab', $tab)
|
->call('setTab', $tab)
|
||||||
->assertOk();
|
->assertOk();
|
||||||
|
|||||||
146
src/tests/Feature/SnipeItClientTest.php
Normal file
146
src/tests/Feature/SnipeItClientTest.php
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Services\SnipeItClient;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
function enableSnipeit(): void
|
||||||
|
{
|
||||||
|
Settings::set('snipeit_enabled', '1');
|
||||||
|
Settings::set('snipeit_base_url', 'https://assets.test');
|
||||||
|
Settings::set('snipeit_api_token', 'tok');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('enabled requires enabled flag, base url and api token', function () {
|
||||||
|
expect(app(SnipeItClient::class)->enabled())->toBeFalse();
|
||||||
|
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
expect(app(SnipeItClient::class)->enabled())->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('assetsForEmail looks up the Snipe-IT user by e-mail, then lists what is checked out to them', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'assets.test/api/v1/users?*' => Http::response(['rows' => [
|
||||||
|
['id' => 7, 'email' => 'jan@example.com', 'name' => 'Jan Kowalski'],
|
||||||
|
]]),
|
||||||
|
'assets.test/api/v1/users/7/assets*' => Http::response(['rows' => [
|
||||||
|
[
|
||||||
|
'id' => 100, 'asset_tag' => 'SI-001', 'name' => 'Laptop Jana', 'serial' => 'SN12345',
|
||||||
|
'manufacturer' => ['name' => 'Dell'], 'model' => ['name' => 'Latitude 5420'],
|
||||||
|
'category' => ['name' => 'Laptopy'], 'status_label' => ['name' => 'Deployed'],
|
||||||
|
],
|
||||||
|
]]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$assets = app(SnipeItClient::class)->assetsForEmail('jan@example.com');
|
||||||
|
|
||||||
|
expect($assets)->toHaveCount(1);
|
||||||
|
expect($assets[0]['id'])->toBe(100);
|
||||||
|
expect($assets[0]['label'])->toBe('SI-001 - SN12345 - Dell Latitude 5420');
|
||||||
|
expect($assets[0]['category'])->toBe('Laptopy');
|
||||||
|
expect($assets[0]['status'])->toBe('Deployed');
|
||||||
|
expect($assets[0]['url'])->toBe('https://assets.test/hardware/100');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('normalizeAsset joins only whichever of asset tag / serial / manufacturer+model are present, falling back to the asset id', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/hardware/1' => Http::response([
|
||||||
|
'id' => 1, 'asset_tag' => 'SI-100', 'serial' => null, 'manufacturer' => null, 'model' => null,
|
||||||
|
])]);
|
||||||
|
expect(app(SnipeItClient::class)->asset(1)['label'])->toBe('SI-100');
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/hardware/2' => Http::response([
|
||||||
|
'id' => 2, 'asset_tag' => null, 'serial' => null, 'manufacturer' => null, 'model' => null,
|
||||||
|
])]);
|
||||||
|
expect(app(SnipeItClient::class)->asset(2)['label'])->toBe('Zasób #2');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('assetsForEmail returns nothing when no Snipe-IT user matches the e-mail', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/users?*' => Http::response(['rows' => []])]);
|
||||||
|
|
||||||
|
expect(app(SnipeItClient::class)->assetsForEmail('nobody@example.com'))->toBe([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('assetsForEmail returns an empty list without an HTTP call when the integration is disabled', function () {
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
expect(app(SnipeItClient::class)->assetsForEmail('jan@example.com'))->toBe([]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('searchAssets hits the hardware list endpoint with the search query', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/hardware?*' => Http::response(['rows' => [
|
||||||
|
[
|
||||||
|
'id' => 55, 'asset_tag' => 'SI-055', 'name' => null, 'serial' => null,
|
||||||
|
'manufacturer' => ['name' => 'HP'], 'model' => ['name' => 'LaserJet Pro'],
|
||||||
|
'category' => ['name' => 'Drukarki'], 'status_label' => ['name' => 'Ready to Deploy'],
|
||||||
|
],
|
||||||
|
]])]);
|
||||||
|
|
||||||
|
$results = app(SnipeItClient::class)->searchAssets('drukarka');
|
||||||
|
|
||||||
|
expect($results)->toHaveCount(1);
|
||||||
|
expect($results[0]['label'])->toBe('SI-055 - HP LaserJet Pro');
|
||||||
|
expect($results[0]['category'])->toBe('Drukarki');
|
||||||
|
|
||||||
|
Http::assertSent(fn ($request) => str_contains((string) $request->url(), 'search=drukarka'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('searchAssets returns nothing for a blank query without calling out', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
expect(app(SnipeItClient::class)->searchAssets(' '))->toBe([]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('asset fetches live detail including serial, category and current assignment', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/hardware/100' => Http::response([
|
||||||
|
'id' => 100, 'asset_tag' => 'SI-001', 'name' => 'Laptop Jana', 'serial' => 'ABC123',
|
||||||
|
'manufacturer' => ['name' => 'Dell'], 'model' => ['name' => 'Latitude 5420'],
|
||||||
|
'category' => ['name' => 'Laptopy'], 'status_label' => ['name' => 'Deployed'],
|
||||||
|
'assigned_to' => ['name' => 'Jan Kowalski'],
|
||||||
|
])]);
|
||||||
|
|
||||||
|
$asset = app(SnipeItClient::class)->asset(100);
|
||||||
|
|
||||||
|
expect($asset['label'])->toBe('SI-001 - ABC123 - Dell Latitude 5420');
|
||||||
|
expect($asset['serial'])->toBe('ABC123');
|
||||||
|
expect($asset['category'])->toBe('Laptopy');
|
||||||
|
expect($asset['assignedTo'])->toBe('Jan Kowalski');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('asset returns null when the asset no longer exists in Snipe-IT', function () {
|
||||||
|
enableSnipeit();
|
||||||
|
|
||||||
|
Http::fake(['assets.test/api/v1/hardware/999' => Http::response(['status' => 'error'], 404)]);
|
||||||
|
|
||||||
|
expect(app(SnipeItClient::class)->asset(999))->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testConnection reports ok on a successful response', function () {
|
||||||
|
Http::fake(['assets.test/api/v1/hardware?*' => Http::response(['rows' => []])]);
|
||||||
|
|
||||||
|
$result = app(SnipeItClient::class)->testConnection('https://assets.test', 'tok', true);
|
||||||
|
|
||||||
|
expect($result)->toBe(['ok' => true, 'message' => null]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('testConnection reports the API error message on failure', function () {
|
||||||
|
Http::fake(['assets.test/api/v1/hardware?*' => Http::response(['status' => 'error', 'messages' => 'Unauthenticated.'], 401)]);
|
||||||
|
|
||||||
|
$result = app(SnipeItClient::class)->testConnection('https://assets.test', 'bad-tok', true);
|
||||||
|
|
||||||
|
expect($result['ok'])->toBeFalse();
|
||||||
|
expect($result['message'])->toBe('Unauthenticated.');
|
||||||
|
});
|
||||||
241
src/tests/Feature/SnipeitAssetLinkingTest.php
Normal file
241
src/tests/Feature/SnipeitAssetLinkingTest.php
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Client\NewTicket as ClientNewTicket;
|
||||||
|
use App\Livewire\Operator\TicketShow as OperatorTicketShow;
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
function enableSnipeitForLinkingTest(array $overrides = []): void
|
||||||
|
{
|
||||||
|
Settings::set('snipeit_enabled', '1');
|
||||||
|
Settings::set('snipeit_base_url', 'https://assets.test');
|
||||||
|
Settings::set('snipeit_api_token', 'tok');
|
||||||
|
Settings::set('snipeit_client_can_select_asset', $overrides['client_can_select_asset'] ?? '1');
|
||||||
|
Settings::set('snipeit_operator_view_requester_assets', $overrides['operator_view_requester_assets'] ?? '1');
|
||||||
|
Settings::set('snipeit_operator_search_inventory', $overrides['operator_search_inventory'] ?? '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
function fakeSnipeitUserAsset(string $email = 'client-snipeit@example.com'): void
|
||||||
|
{
|
||||||
|
Http::fake([
|
||||||
|
'assets.test/api/v1/users?*' => Http::response(['rows' => [
|
||||||
|
['id' => 7, 'email' => $email, 'name' => 'Test Client'],
|
||||||
|
]]),
|
||||||
|
'assets.test/api/v1/users/7/assets*' => Http::response(['rows' => [
|
||||||
|
[
|
||||||
|
'id' => 100, 'asset_tag' => 'SI-001', 'name' => 'Laptop klienta', 'serial' => 'SN123',
|
||||||
|
'manufacturer' => ['name' => 'Dell'], 'model' => ['name' => 'Latitude 5420'],
|
||||||
|
'category' => ['name' => 'Laptopy'], 'status_label' => ['name' => 'Deployed'],
|
||||||
|
],
|
||||||
|
]]),
|
||||||
|
'assets.test/api/v1/hardware/100' => Http::response([
|
||||||
|
'id' => 100, 'asset_tag' => 'SI-001', 'name' => 'Laptop klienta', 'serial' => 'SN123',
|
||||||
|
'manufacturer' => ['name' => 'Dell'], 'model' => ['name' => 'Latitude 5420'],
|
||||||
|
'category' => ['name' => 'Laptopy'], 'status_label' => ['name' => 'Deployed'],
|
||||||
|
'assigned_to' => ['name' => 'Test Client'],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a client can link one of their own Snipe-IT assets while creating a ticket, shown as serial - manufacturer model / category', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$email = 'client-snipeit@example.com';
|
||||||
|
fakeSnipeitUserAsset($email);
|
||||||
|
|
||||||
|
$client = User::query()->create(['name' => 'Test Client', 'email' => $email, 'roles' => ['client']]);
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$sub = $category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
|
||||||
|
enableSnipeitForLinkingTest();
|
||||||
|
Settings::set('snipeit_client_asset_subcategory_ids', (string) $sub->id);
|
||||||
|
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('selectCategory', $category->id)
|
||||||
|
->call('selectSubcategory', $sub->id)
|
||||||
|
->call('loadSnipeitAssets')
|
||||||
|
->assertSee('SI-001 - SN123 - Dell Latitude 5420')
|
||||||
|
->assertSee('Laptopy')
|
||||||
|
->call('selectSnipeitAsset', 100)
|
||||||
|
->assertSet('selectedSnipeitAssetId', 100)
|
||||||
|
->set('subject', 'Nie działa laptop')
|
||||||
|
->set('body', 'Opis problemu')
|
||||||
|
->call('submit');
|
||||||
|
|
||||||
|
$ticket = Ticket::query()->where('subject', 'Nie działa laptop')->firstOrFail();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBe(100);
|
||||||
|
expect($ticket->snipeit_asset_name)->toBe('SI-001 - SN123 - Dell Latitude 5420');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('selecting the same asset twice deselects it', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableSnipeitForLinkingTest();
|
||||||
|
$email = 'client-snipeit2@example.com';
|
||||||
|
fakeSnipeitUserAsset($email);
|
||||||
|
|
||||||
|
$client = User::query()->create(['name' => 'Test Client', 'email' => $email, 'roles' => ['client']]);
|
||||||
|
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('loadSnipeitAssets')
|
||||||
|
->call('selectSnipeitAsset', 100)
|
||||||
|
->assertSet('selectedSnipeitAssetId', 100)
|
||||||
|
->call('selectSnipeitAsset', 100)
|
||||||
|
->assertSet('selectedSnipeitAssetId', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the client asset picker is empty when "klient może wybrać sprzęt" is off, even for an allow-listed subcategory', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$email = 'client-snipeit3@example.com';
|
||||||
|
fakeSnipeitUserAsset($email);
|
||||||
|
|
||||||
|
$client = User::query()->create(['name' => 'Test Client', 'email' => $email, 'roles' => ['client']]);
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$sub = $category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
|
||||||
|
enableSnipeitForLinkingTest(['client_can_select_asset' => '0']);
|
||||||
|
Settings::set('snipeit_client_asset_subcategory_ids', (string) $sub->id);
|
||||||
|
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('selectCategory', $category->id)
|
||||||
|
->call('selectSubcategory', $sub->id)
|
||||||
|
->call('loadSnipeitAssets')
|
||||||
|
->assertDontSee('SN123');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the client asset picker only shows for subcategories the admin allow-listed', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$email = 'client-snipeit4@example.com';
|
||||||
|
fakeSnipeitUserAsset($email);
|
||||||
|
|
||||||
|
$client = User::query()->create(['name' => 'Test Client', 'email' => $email, 'roles' => ['client']]);
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$allowedSub = $category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
$otherSub = $category->subcategories()->create(['name' => 'Telefon']);
|
||||||
|
|
||||||
|
enableSnipeitForLinkingTest();
|
||||||
|
Settings::set('snipeit_client_asset_subcategory_ids', (string) $allowedSub->id);
|
||||||
|
|
||||||
|
// Allow-listed subcategory: the picker shows.
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('selectCategory', $category->id)
|
||||||
|
->call('selectSubcategory', $allowedSub->id)
|
||||||
|
->call('loadSnipeitAssets')
|
||||||
|
->assertSee('SI-001 - SN123 - Dell Latitude 5420');
|
||||||
|
|
||||||
|
// A subcategory not in the allow-list: the picker stays hidden.
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('selectCategory', $category->id)
|
||||||
|
->call('selectSubcategory', $otherSub->id)
|
||||||
|
->call('loadSnipeitAssets')
|
||||||
|
->assertDontSee('SN123');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing subcategory clears a previously selected asset', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$email = 'client-snipeit5@example.com';
|
||||||
|
fakeSnipeitUserAsset($email);
|
||||||
|
|
||||||
|
$client = User::query()->create(['name' => 'Test Client', 'email' => $email, 'roles' => ['client']]);
|
||||||
|
$category = Category::query()->create(['name' => 'Sprzęt']);
|
||||||
|
$sub = $category->subcategories()->create(['name' => 'Laptop']);
|
||||||
|
|
||||||
|
enableSnipeitForLinkingTest();
|
||||||
|
Settings::set('snipeit_client_asset_subcategory_ids', (string) $sub->id);
|
||||||
|
|
||||||
|
Livewire::actingAs($client)->test(ClientNewTicket::class)
|
||||||
|
->call('selectCategory', $category->id)
|
||||||
|
->call('selectSubcategory', $sub->id)
|
||||||
|
->call('selectSnipeitAsset', 100)
|
||||||
|
->assertSet('selectedSnipeitAssetId', 100)
|
||||||
|
->call('selectSubcategory', $sub->id)
|
||||||
|
->assertSet('selectedSnipeitAssetId', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator can link a Snipe-IT asset found via inventory search to an existing ticket', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableSnipeitForLinkingTest();
|
||||||
|
Http::fake([
|
||||||
|
'assets.test/api/v1/users?*' => Http::response(['rows' => []]),
|
||||||
|
'assets.test/api/v1/hardware?*' => Http::response(['rows' => [
|
||||||
|
[
|
||||||
|
'id' => 55, 'asset_tag' => 'SI-055', 'name' => null, 'serial' => null,
|
||||||
|
'manufacturer' => ['name' => 'HP'], 'model' => ['name' => 'LaserJet Pro'],
|
||||||
|
'category' => ['name' => 'Drukarki'], 'status_label' => ['name' => 'Ready to Deploy'],
|
||||||
|
],
|
||||||
|
]]),
|
||||||
|
'assets.test/api/v1/hardware/55' => Http::response([
|
||||||
|
'id' => 55, 'asset_tag' => 'SI-055', 'name' => null, 'serial' => null,
|
||||||
|
'manufacturer' => ['name' => 'HP'], 'model' => ['name' => 'LaserJet Pro'],
|
||||||
|
'category' => ['name' => 'Drukarki'], 'status_label' => ['name' => 'Ready to Deploy'],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket();
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->set('snipeitSearchQuery', 'drukarka')
|
||||||
|
->call('searchSnipeitAssets')
|
||||||
|
->assertSee('SI-055 - HP LaserJet Pro')
|
||||||
|
->call('linkSnipeitAsset', 55);
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBe(55);
|
||||||
|
expect($ticket->snipeit_asset_name)->toBe('SI-055 - HP LaserJet Pro');
|
||||||
|
expect($ticket->histories()->latest()->first()->text)->toContain('Powiązano sprzęt');
|
||||||
|
|
||||||
|
// Unlinking works regardless of the two view/search toggles (see next test).
|
||||||
|
$component->call('unlinkSnipeitAsset');
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('linking is a no-op when neither requester-assets view nor inventory search is enabled for the operator', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableSnipeitForLinkingTest(['operator_view_requester_assets' => '0', 'operator_search_inventory' => '0']);
|
||||||
|
Http::fake(['assets.test/*' => Http::response(['rows' => []])]);
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket();
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('linkSnipeitAsset', 55);
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unlinking stays available even when both operator view/search toggles are off', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableSnipeitForLinkingTest(['operator_view_requester_assets' => '0', 'operator_search_inventory' => '0']);
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket(['snipeit_asset_id' => 100, 'snipeit_asset_name' => 'SI-001 - SN123 - Dell Latitude 5420']);
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->call('unlinkSnipeitAsset');
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an operator cannot link an asset found via search when inventory search is disabled, even if the id is valid', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
enableSnipeitForLinkingTest(['operator_search_inventory' => '0']);
|
||||||
|
Http::fake(['assets.test/api/v1/hardware/55' => Http::response([
|
||||||
|
'id' => 55, 'asset_tag' => 'SI-055', 'serial' => null, 'manufacturer' => ['name' => 'HP'], 'model' => ['name' => 'LaserJet Pro'],
|
||||||
|
])]);
|
||||||
|
|
||||||
|
$operator = operatorUser();
|
||||||
|
$ticket = makeTicket();
|
||||||
|
|
||||||
|
Livewire::actingAs($operator)->test(OperatorTicketShow::class, ['ticket' => $ticket])
|
||||||
|
->set('snipeitSearchResults', [['id' => 55, 'label' => 'HP LaserJet Pro']])
|
||||||
|
->call('linkSnipeitAsset', 55);
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->snipeit_asset_id)->toBeNull();
|
||||||
|
});
|
||||||
170
src/tests/Feature/TicketAiSummaryServiceTest.php
Normal file
170
src/tests/Feature/TicketAiSummaryServiceTest.php
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Services\TicketAiSummaryService;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
function enableAiSummary(): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
Settings::set('ai_summary_enabled', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
function summaryTicket(array $overrides = []): Ticket
|
||||||
|
{
|
||||||
|
return Ticket::query()->create(array_merge([
|
||||||
|
'number' => (string) random_int(100000, 999999),
|
||||||
|
'email' => 'client@example.com',
|
||||||
|
'name' => 'Test Client',
|
||||||
|
'subject' => 'Problem z drukarką',
|
||||||
|
'body' => 'Drukarka nie działa od rana.',
|
||||||
|
'status_key' => 'new',
|
||||||
|
'priority_key' => 'medium',
|
||||||
|
'custom_fields' => [],
|
||||||
|
], $overrides));
|
||||||
|
}
|
||||||
|
|
||||||
|
function fakeAiSummaryChat(string $content): void
|
||||||
|
{
|
||||||
|
Http::fake(['ai.test/*' => Http::response(['choices' => [['message' => ['content' => $content]]]])]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('generates and stores a summary + suggested action for a fresh ticket', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
fakeAiSummaryChat('{"summary": "Klient zgłasza awarię drukarki.", "suggested_action": "Poproś o model drukarki."}');
|
||||||
|
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'updated' => 1, 'failed' => 0]);
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->ai_summary)->toBe('Klient zgłasza awarię drukarki.');
|
||||||
|
expect($ticket->ai_suggested_action)->toBe('Poproś o model drukarki.');
|
||||||
|
expect($ticket->ai_summary_generated_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a ticket with a newer message than its last summary is picked up again', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
$ticket->messages()->create(['author_name' => 'Test Client', 'body' => 'Pierwsza wiadomość.']);
|
||||||
|
$ticket->update(['ai_summary' => 'stare podsumowanie', 'ai_summary_generated_at' => now()->subDay()]);
|
||||||
|
|
||||||
|
// A message created "now" postdates the day-old summary.
|
||||||
|
$ticket->messages()->create(['author_name' => 'Operator', 'body' => 'Nowa odpowiedź operatora.']);
|
||||||
|
|
||||||
|
fakeAiSummaryChat('{"summary": "Zaktualizowane podsumowanie.", "suggested_action": null}');
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'updated' => 1, 'failed' => 0]);
|
||||||
|
expect($ticket->refresh()->ai_summary)->toBe('Zaktualizowane podsumowanie.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a ticket whose summary is already newer than its latest message is not reprocessed', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
$ticket->messages()->create(['author_name' => 'Test Client', 'body' => 'Jedyna wiadomość.']);
|
||||||
|
$ticket->update(['ai_summary' => 'aktualne podsumowanie', 'ai_summary_generated_at' => now()]);
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 0, 'updated' => 0, 'failed' => 0]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an unrelated update() that only touches updated_at does not trigger re-summarization', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
$ticket->messages()->create(['author_name' => 'Test Client', 'body' => 'Jedyna wiadomość.']);
|
||||||
|
$ticket->update(['ai_summary' => 'aktualne podsumowanie', 'ai_summary_generated_at' => now()]);
|
||||||
|
|
||||||
|
// Simulates e.g. a priority/status change touching tickets.updated_at
|
||||||
|
// without any new ticket_messages row.
|
||||||
|
$ticket->update(['priority_key' => 'high']);
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 0, 'updated' => 0, 'failed' => 0]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a malformed AI response leaves the previous summary untouched and keeps the ticket stale', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
$ticket->update(['ai_summary' => 'stare podsumowanie', 'ai_summary_generated_at' => null]);
|
||||||
|
fakeAiSummaryChat('to nie jest JSON');
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'updated' => 0, 'failed' => 1]);
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->ai_summary)->toBe('stare podsumowanie');
|
||||||
|
expect($ticket->ai_summary_generated_at)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the transcript sent to the AI includes the ticket subject, its own body, and every message tagged by role', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket(['subject' => 'Problem z drukarką', 'body' => 'Drukarka nie działa od rana.']);
|
||||||
|
$ticket->messages()->create(['author_name' => 'Test Client', 'body' => 'Dodatkowy szczegół.'])->attachAuthor(null, 'client');
|
||||||
|
$ticket->messages()->create(['author_name' => 'Operator', 'body' => 'Sprawdzam sprawę.'])->attachAuthor(null, 'operator');
|
||||||
|
|
||||||
|
fakeAiSummaryChat('{"summary": "ok", "suggested_action": null}');
|
||||||
|
|
||||||
|
app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
Http::assertSent(function ($request) {
|
||||||
|
$userMessage = collect($request->data()['messages'])->firstWhere('role', 'user')['content'];
|
||||||
|
|
||||||
|
return str_contains($userMessage, 'Temat: Problem z drukarką')
|
||||||
|
&& str_contains($userMessage, 'Treść:')
|
||||||
|
&& str_contains($userMessage, 'Drukarka nie działa od rana.')
|
||||||
|
&& str_contains($userMessage, '[klient] Test Client: Dodatkowy szczegół.')
|
||||||
|
&& str_contains($userMessage, '[operator] Operator: Sprawdzam sprawę.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('generateFor() regenerates a single ticket immediately, ignoring the staleness check', function () {
|
||||||
|
enableAiSummary();
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
$ticket->update(['ai_summary' => 'aktualne podsumowanie', 'ai_summary_generated_at' => now()]);
|
||||||
|
|
||||||
|
fakeAiSummaryChat('{"summary": "Świeże podsumowanie.", "suggested_action": null}');
|
||||||
|
|
||||||
|
$result = app(TicketAiSummaryService::class)->generateFor($ticket);
|
||||||
|
|
||||||
|
expect($result)->toBeTrue();
|
||||||
|
expect($ticket->refresh()->ai_summary)->toBe('Świeże podsumowanie.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('generateFor() returns false without calling the AI when the integration is disabled', function () {
|
||||||
|
Settings::set('ai_enabled', '0');
|
||||||
|
$ticket = summaryTicket();
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
expect(app(TicketAiSummaryService::class)->generateFor($ticket))->toBeFalse();
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ai_summary_enabled=0 makes no AI calls', function () {
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
Settings::set('ai_summary_enabled', '0');
|
||||||
|
summaryTicket();
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
$totals = app(TicketAiSummaryService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 0, 'updated' => 0, 'failed' => 0]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
245
src/tests/Feature/TicketAiTriageServiceTest.php
Normal file
245
src/tests/Feature/TicketAiTriageServiceTest.php
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Priority;
|
||||||
|
use App\Models\Subcategory;
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Services\TicketAiTriageService;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
function enableAiForTriage(): void
|
||||||
|
{
|
||||||
|
Settings::set('ai_enabled', '1');
|
||||||
|
Settings::set('ai_base_url', 'https://ai.test');
|
||||||
|
Settings::set('ai_model', 'llama-3.3-70b-versatile');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{cat1: Category, sub1: Subcategory, sub2: Subcategory, cat2: Category} */
|
||||||
|
function seedCategoriesForTriage(): array
|
||||||
|
{
|
||||||
|
$cat1 = Category::query()->create(['name' => 'IT-Pomoc']);
|
||||||
|
$sub1 = $cat1->subcategories()->create(['name' => 'Drukarki i skanery']);
|
||||||
|
$sub2 = $cat1->subcategories()->create(['name' => 'VPN']);
|
||||||
|
$cat2 = Category::query()->create(['name' => 'Zamówienia']);
|
||||||
|
$cat2->subcategories()->create(['name' => 'Nowe zamówienie']);
|
||||||
|
|
||||||
|
return compact('cat1', 'sub1', 'sub2', 'cat2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedPrioritiesForTriage(): void
|
||||||
|
{
|
||||||
|
Priority::query()->create(['key' => 'low', 'label' => 'Niski', 'color' => '#000', 'sort_order' => 4]);
|
||||||
|
Priority::query()->create(['key' => 'medium', 'label' => 'Średni', 'color' => '#000', 'sort_order' => 3]);
|
||||||
|
Priority::query()->create(['key' => 'high', 'label' => 'Wysoki', 'color' => '#000', 'sort_order' => 2]);
|
||||||
|
Priority::query()->create(['key' => 'critical', 'label' => 'Krytyczny', 'color' => '#000', 'sort_order' => 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function triageTicket(array $overrides = []): Ticket
|
||||||
|
{
|
||||||
|
return Ticket::query()->create(array_merge([
|
||||||
|
'number' => (string) random_int(100000, 999999),
|
||||||
|
'email' => 'client@example.com',
|
||||||
|
'name' => 'Test Client',
|
||||||
|
'subject' => 'Problem z drukarką',
|
||||||
|
'body' => 'Drukarka HP w biurze nie drukuje od rana, pokazuje błąd papieru mimo że jest papier.',
|
||||||
|
'status_key' => 'new',
|
||||||
|
'priority_key' => 'medium',
|
||||||
|
'custom_fields' => [],
|
||||||
|
], $overrides));
|
||||||
|
}
|
||||||
|
|
||||||
|
function fakeAiChat(string $content): void
|
||||||
|
{
|
||||||
|
Http::fake(['ai.test/*' => Http::response(['choices' => [['message' => ['content' => $content]]]])]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('category_when_missing assigns category+subcategory to a fully unclassified ticket', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
['sub1' => $sub1] = seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_category_when_missing', '1');
|
||||||
|
fakeAiChat('{"category": "IT-Pomoc", "subcategory": "Drukarki i skanery", "subject": null, "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => null, 'subcategory_id' => null]);
|
||||||
|
|
||||||
|
$totals = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'changed' => 1, 'failed' => 0]);
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->subcategory_id)->toBe($sub1->id);
|
||||||
|
expect($ticket->category_id)->toBeNull();
|
||||||
|
expect($ticket->ai_triaged_at)->not->toBeNull();
|
||||||
|
expect($ticket->histories()->pluck('text')->all())->toBe([
|
||||||
|
'Kategoria zmieniona na: IT-Pomoc / Drukarki i skanery',
|
||||||
|
'Automatyzacja: klasyfikacja AI',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('subcategory_when_category_only restricts the prompt to the ticket\'s existing category and picks within it', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
['cat1' => $cat1, 'sub2' => $sub2] = seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_subcategory_when_category_only', '1');
|
||||||
|
fakeAiChat('{"category": null, "subcategory": "VPN", "subject": null, "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => $cat1->id, 'subcategory_id' => null]);
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->subcategory_id)->toBe($sub2->id);
|
||||||
|
expect($ticket->category_id)->toBeNull();
|
||||||
|
|
||||||
|
Http::assertSent(function ($request) {
|
||||||
|
$content = $request['messages'][0]['content'] ?? '';
|
||||||
|
|
||||||
|
return str_contains($content, 'Drukarki i skanery')
|
||||||
|
&& str_contains($content, 'VPN')
|
||||||
|
&& ! str_contains($content, 'Nowe zamówienie');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('recheck_categorized moves an already-categorized ticket to a better-matching subcategory', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
['sub1' => $sub1, 'sub2' => $sub2] = seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_recheck_categorized', '1');
|
||||||
|
fakeAiChat('{"category": null, "subcategory": "VPN", "subject": null, "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => null, 'subcategory_id' => $sub1->id]);
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($ticket->refresh()->subcategory_id)->toBe($sub2->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('recheck_categorized confirming the existing subcategory leaves no history and no changed count', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
['sub1' => $sub1] = seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_recheck_categorized', '1');
|
||||||
|
fakeAiChat('{"category": null, "subcategory": "Drukarki i skanery", "subject": null, "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => null, 'subcategory_id' => $sub1->id]);
|
||||||
|
|
||||||
|
$totals = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'changed' => 0, 'failed' => 0]);
|
||||||
|
expect($ticket->refresh()->subcategory_id)->toBe($sub1->id);
|
||||||
|
expect($ticket->histories()->count())->toBe(0);
|
||||||
|
expect($ticket->ai_triaged_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fix_subject rewrites an unclear subject', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
Settings::set('ai_triage_fix_subject', '1');
|
||||||
|
fakeAiChat('{"category": null, "subcategory": null, "subject": "Awaria drukarki HP w biurze", "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['subject' => 'pomocy!!!']);
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->subject)->toBe('Awaria drukarki HP w biurze');
|
||||||
|
expect($ticket->histories()->pluck('text')->all())->toBe([
|
||||||
|
'Temat zmieniony na: „Awaria drukarki HP w biurze”',
|
||||||
|
'Automatyzacja: klasyfikacja AI',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('set_priority assigns a priority based on content', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
seedPrioritiesForTriage();
|
||||||
|
Settings::set('ai_triage_set_priority', '1');
|
||||||
|
fakeAiChat('{"category": null, "subcategory": null, "subject": null, "priority": "high"}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['priority_key' => 'medium']);
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->priority_key)->toBe('high');
|
||||||
|
expect($ticket->histories()->pluck('text')->all())->toBe([
|
||||||
|
'Priorytet zmieniony na: Wysoki',
|
||||||
|
'Automatyzacja: klasyfikacja AI',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a multi-field change writes one mechanical line per changed field plus a single attribution line', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
seedPrioritiesForTriage();
|
||||||
|
['sub1' => $sub1, 'sub2' => $sub2] = seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_recheck_categorized', '1');
|
||||||
|
Settings::set('ai_triage_set_priority', '1');
|
||||||
|
// ticket currently sits under sub2 (VPN); AI moves it to sub1 (Drukarki i
|
||||||
|
// skanery) AND bumps priority — both fields change in the same pass.
|
||||||
|
fakeAiChat('{"category": null, "subcategory": "Drukarki i skanery", "subject": null, "priority": "critical"}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => null, 'subcategory_id' => $sub2->id, 'priority_key' => 'medium']);
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->subcategory_id)->toBe($sub1->id);
|
||||||
|
expect($ticket->priority_key)->toBe('critical');
|
||||||
|
expect($ticket->histories()->pluck('text')->all())->toBe([
|
||||||
|
'Kategoria zmieniona na: IT-Pomoc / Drukarki i skanery',
|
||||||
|
'Priorytet zmieniony na: Krytyczny',
|
||||||
|
'Automatyzacja: klasyfikacja AI',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('idempotency: a second run does not rescan an already-triaged ticket', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
Settings::set('ai_triage_set_priority', '1');
|
||||||
|
seedPrioritiesForTriage();
|
||||||
|
fakeAiChat('{"category": null, "subcategory": null, "subject": null, "priority": "high"}');
|
||||||
|
|
||||||
|
triageTicket();
|
||||||
|
|
||||||
|
app(TicketAiTriageService::class)->run();
|
||||||
|
$second = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($second)->toBe(['scanned' => 0, 'changed' => 0, 'failed' => 0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a malformed AI response changes nothing but still stamps ai_triaged_at and counts as failed', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
Settings::set('ai_triage_set_priority', '1');
|
||||||
|
seedPrioritiesForTriage();
|
||||||
|
fakeAiChat('to nie jest JSON');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['priority_key' => 'medium']);
|
||||||
|
|
||||||
|
$totals = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 1, 'changed' => 0, 'failed' => 1]);
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->priority_key)->toBe('medium');
|
||||||
|
expect($ticket->ai_triaged_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a hallucinated category name is silently dropped rather than applied', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
seedCategoriesForTriage();
|
||||||
|
Settings::set('ai_triage_category_when_missing', '1');
|
||||||
|
fakeAiChat('{"category": "Kategoria Zmyślona Przez Model", "subcategory": null, "subject": null, "priority": null}');
|
||||||
|
|
||||||
|
$ticket = triageTicket(['category_id' => null, 'subcategory_id' => null]);
|
||||||
|
|
||||||
|
$totals = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($totals['changed'])->toBe(0);
|
||||||
|
$ticket->refresh();
|
||||||
|
expect($ticket->category_id)->toBeNull();
|
||||||
|
expect($ticket->subcategory_id)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('with every triage toggle off, run makes no AI calls at all', function () {
|
||||||
|
enableAiForTriage();
|
||||||
|
triageTicket(['category_id' => null, 'subcategory_id' => null]);
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
|
||||||
|
$totals = app(TicketAiTriageService::class)->run();
|
||||||
|
|
||||||
|
expect($totals)->toBe(['scanned' => 0, 'changed' => 0, 'failed' => 0]);
|
||||||
|
Http::assertNothingSent();
|
||||||
|
});
|
||||||
80
src/tests/Feature/TicketListPaginationTest.php
Normal file
80
src/tests/Feature/TicketListPaginationTest.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Livewire\Client\Dashboard;
|
||||||
|
use App\Livewire\Client\TicketShow;
|
||||||
|
use App\Livewire\Operator\Queue;
|
||||||
|
use App\Models\User;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('the operator queue paginates instead of rendering every matching ticket at once', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('queue-page@example.com');
|
||||||
|
|
||||||
|
foreach (range(1, 55) as $i) {
|
||||||
|
makeTicket(['number' => str_pad($i, 4, '0', STR_PAD_LEFT)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(Queue::class);
|
||||||
|
|
||||||
|
expect($component->instance()->filteredTickets)->toHaveCount(50)
|
||||||
|
->and($component->instance()->filteredTickets->total())->toBe(55);
|
||||||
|
|
||||||
|
$component->call('gotoPage', 2);
|
||||||
|
|
||||||
|
expect($component->instance()->filteredTickets)->toHaveCount(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing the queue search resets the operator to page 1', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$operator = operatorUser('queue-page-reset@example.com');
|
||||||
|
|
||||||
|
foreach (range(1, 55) as $i) {
|
||||||
|
makeTicket(['number' => str_pad($i, 4, '0', STR_PAD_LEFT), 'subject' => 'Zgłoszenie']);
|
||||||
|
}
|
||||||
|
makeTicket(['number' => '9999', 'subject' => 'Unikalny temat']);
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($operator)->test(Queue::class)->call('gotoPage', 2);
|
||||||
|
expect($component->instance()->filteredTickets->currentPage())->toBe(2);
|
||||||
|
|
||||||
|
$component->set('search', 'Unikalny');
|
||||||
|
|
||||||
|
expect($component->instance()->filteredTickets->currentPage())->toBe(1)
|
||||||
|
->and($component->instance()->filteredTickets)->toHaveCount(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the client dashboard paginates current/archive tickets separately', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$client = User::query()->create(['name' => 'Client', 'email' => 'dash-page@example.com', 'roles' => ['client']]);
|
||||||
|
|
||||||
|
foreach (range(1, 25) as $i) {
|
||||||
|
makeTicket(['number' => str_pad($i, 4, '0', STR_PAD_LEFT), 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name, 'status_key' => 'new']);
|
||||||
|
}
|
||||||
|
foreach (range(1, 3) as $i) {
|
||||||
|
makeTicket(['number' => '90'.$i, 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name, 'status_key' => 'closed']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($client)->test(Dashboard::class);
|
||||||
|
|
||||||
|
expect($component->instance()->currentTickets)->toHaveCount(20)
|
||||||
|
->and($component->instance()->currentTickets->total())->toBe(25)
|
||||||
|
->and($component->instance()->archiveTickets)->toHaveCount(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('"Inne Twoje zgłoszenia" shows only a handful until "Pokaż wszystkie" is clicked', function () {
|
||||||
|
seedStatusesAndPriorities();
|
||||||
|
$client = User::query()->create(['name' => 'Client', 'email' => 'other-tickets@example.com', 'roles' => ['client']]);
|
||||||
|
$viewed = makeTicket(['number' => '5000', 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name]);
|
||||||
|
|
||||||
|
foreach (range(1, 8) as $i) {
|
||||||
|
makeTicket(['number' => '60'.$i, 'customer_id' => $client->id, 'email' => $client->email, 'name' => $client->name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$component = Livewire::actingAs($client)->test(TicketShow::class, ['ticket' => $viewed]);
|
||||||
|
|
||||||
|
expect($component->instance()->otherTickets)->toHaveCount(5)
|
||||||
|
->and($component->instance()->otherTicketsCount)->toBe(8);
|
||||||
|
|
||||||
|
$component->call('revealAllOtherTickets');
|
||||||
|
|
||||||
|
expect($component->instance()->otherTickets)->toHaveCount(8);
|
||||||
|
});
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
Panel administratora (`/admin`) to jedno miejsce do konfiguracji całego systemu:
|
Panel administratora (`/admin`) to jedno miejsce do konfiguracji całego systemu:
|
||||||
struktura zgłoszeń (kategorie, pola, statusy, priorytety, SLA), automatyzacje
|
struktura zgłoszeń (kategorie, pola, statusy, priorytety, SLA), automatyzacje
|
||||||
(reguły SLA, wyzwalacze), użytkownicy i zespoły, treści (szablony, szybkie
|
(reguły SLA, wyzwalacze, automatyzacja AI zgłoszeń), użytkownicy i zespoły,
|
||||||
akcje, e-maile), wygląd/branding oraz integracje (LDAP, poczta SMTP/IMAP,
|
treści (szablony, szybkie akcje, e-maile), wygląd/branding oraz integracje
|
||||||
BookStack, API).
|
(LDAP, poczta SMTP/IMAP, BookStack, AI, API).
|
||||||
|
|
||||||
Domyślnie każde konto ląduje po zalogowaniu w panelu Klienta; przełącz się do
|
Domyślnie każde konto ląduje po zalogowaniu w panelu Klienta; przełącz się do
|
||||||
panelu Administratora przez menu profilu (prawy górny róg).
|
panelu Administratora suwakiem Klient/Operator/Administrator na środku
|
||||||
|
górnego paska.
|
||||||
|
|
||||||
## Kategorie i pola dodatkowe
|
## Kategorie i pola dodatkowe
|
||||||
|
|
||||||
@@ -173,6 +174,14 @@ ważne + treść HTML).
|
|||||||
numerem przestaje działać. REST API (`/api/v1/...`) tego nie dotyczy —
|
numerem przestaje działać. REST API (`/api/v1/...`) tego nie dotyczy —
|
||||||
tam zgłoszenia zawsze identyfikuje się po `id`, niezależnie od tego
|
tam zgłoszenia zawsze identyfikuje się po `id`, niezależnie od tego
|
||||||
ustawienia.
|
ustawienia.
|
||||||
|
- **Częstotliwość odświeżania i harmonogramu** — dwie grupy pól:
|
||||||
|
- **Odświeżanie w przeglądarce** — co ile sekund odświeża się (poza
|
||||||
|
aktualizacjami na żywo) widok zgłoszenia (klient i operator), lista
|
||||||
|
zgłoszeń operatora, i dzwonek powiadomień.
|
||||||
|
- **Zadania w tle** — co ile minut uruchamiają się sprawdzanie naruszeń
|
||||||
|
SLA, reguły automatyzacji, pobieranie e-maili (IMAP) i automatyzacja AI
|
||||||
|
zgłoszeń. Zmiana obowiązuje od najbliższego tyknięcia harmonogramu (co
|
||||||
|
minutę), bez potrzeby restartu czy redeployu.
|
||||||
|
|
||||||
SMTP (host, port, szyfrowanie, użytkownik/hasło, adres/nazwa nadawcy, z
|
SMTP (host, port, szyfrowanie, użytkownik/hasło, adres/nazwa nadawcy, z
|
||||||
przyciskiem **„Testuj połączenie”**) konfiguruje się w zakładce **Poczta**,
|
przyciskiem **„Testuj połączenie”**) konfiguruje się w zakładce **Poczta**,
|
||||||
@@ -230,10 +239,12 @@ razem, zamiast być rozrzucone po różnych zakładkach.
|
|||||||
|
|
||||||
## Integracje
|
## Integracje
|
||||||
|
|
||||||
- **LDAP** — host, port, base DN, bind DN + hasło, SSL, filtr użytkownika
|
- **LDAP** — **Typ katalogu** (LLDAP/OpenLDAP domyślnie, albo Active
|
||||||
(`(uid={0})` domyślnie), auto-provisioning gości, ograniczenie tworzenia
|
Directory — zmienia oczekiwany schemat i domyślny atrybut logowania), host,
|
||||||
kont/zgłaszania tylko przez LDAP. Przycisk **„Testuj połączenie”** sprawdza
|
port, base DN, bind DN + hasło, SSL, filtr użytkownika (`(uid={0})` dla
|
||||||
bind bez zapisywania zmian.
|
LLDAP, `(sAMAccountName={0})` dla AD), auto-provisioning gości, ograniczenie
|
||||||
|
tworzenia kont/zgłaszania tylko przez LDAP. Przycisk **„Testuj połączenie”**
|
||||||
|
sprawdza bind bez zapisywania zmian.
|
||||||
|
|
||||||
> Po świeżej instalacji (`migrate:fresh --seed`) LDAP i SMTP zawierają
|
> Po świeżej instalacji (`migrate:fresh --seed`) LDAP i SMTP zawierają
|
||||||
> **przykładowe wartości** (`ldap.example.com`, `smtp.example.com`,
|
> **przykładowe wartości** (`ldap.example.com`, `smtp.example.com`,
|
||||||
@@ -248,7 +259,12 @@ razem, zamiast być rozrzucone po różnych zakładkach.
|
|||||||
zapytania kończą się błędem 403 mimo poprawnych danych logowania.
|
zapytania kończą się błędem 403 mimo poprawnych danych logowania.
|
||||||
- **Weryfikuj certyfikat SSL** — włączone domyślnie; wyłącz tylko jeśli
|
- **Weryfikuj certyfikat SSL** — włączone domyślnie; wyłącz tylko jeśli
|
||||||
instancja BookStack korzysta z certyfikatu self-signed/prywatnego CA.
|
instancja BookStack korzysta z certyfikatu self-signed/prywatnego CA.
|
||||||
- **Przeszukuj** — strony i książki / tylko strony / tylko książki.
|
- **Przeszukuj** — trzy niezależne checkboxy: Książki / Strony / Rozdziały
|
||||||
|
(dowolna kombinacja).
|
||||||
|
- **Szukaj po** — słowa kluczowe w nazwie / tagi / oba. Wyszukiwanie po
|
||||||
|
tagach dopasowuje artykuły oznaczone w BookStacku tagiem o nazwie zgodnej
|
||||||
|
z podkategorią zgłoszenia (np. tag „Drukarki i skanery”) — patrz
|
||||||
|
automatyczne tagowanie niżej, żeby nie robić tego ręcznie dla całej wiki.
|
||||||
- **Dozwolone półki** — dwie **niezależne** checklisty: jedna dla podpowiedzi
|
- **Dozwolone półki** — dwie **niezależne** checklisty: jedna dla podpowiedzi
|
||||||
przy tworzeniu zgłoszenia (klient, operator, formularz gościa na stronie
|
przy tworzeniu zgłoszenia (klient, operator, formularz gościa na stronie
|
||||||
głównej), druga dla panelu bocznego operatora na widoku istniejącego
|
głównej), druga dla panelu bocznego operatora na widoku istniejącego
|
||||||
@@ -263,6 +279,79 @@ razem, zamiast być rozrzucone po różnych zakładkach.
|
|||||||
- Przycisk **„Testuj połączenie”** sprawdza niezapisane wartości formularza
|
- Przycisk **„Testuj połączenie”** sprawdza niezapisane wartości formularza
|
||||||
(analogicznie do LDAP/SMTP) i pokazuje dokładny komunikat błędu z
|
(analogicznie do LDAP/SMTP) i pokazuje dokładny komunikat błędu z
|
||||||
BookStacka, jeśli połączenie się nie powiedzie.
|
BookStacka, jeśli połączenie się nie powiedzie.
|
||||||
|
- **Automatyczne tagowanie treści (AI)** — przyciski **„Otaguj nową
|
||||||
|
treść”** (pomija już otagowane pozycje) i **„Otaguj wszystko ponownie”**
|
||||||
|
(klasyfikuje od nowa całą wiki) używają integracji AI (niżej) do
|
||||||
|
otagowania każdej książki/strony/rozdziału nazwami pasujących podkategorii
|
||||||
|
helpdesku — bez tego wyszukiwanie „po tagach” wyżej nic nie znajdzie.
|
||||||
|
Wymaga wcześniej skonfigurowanej i włączonej integracji AI. Dostępne też
|
||||||
|
z linii poleceń: `php artisan bookstack:tag-content` (`--dry-run`,
|
||||||
|
`--force`, `--limit=N`).
|
||||||
|
|
||||||
|
- **Snipe-IT (ewidencja sprzętu)** — opcjonalna integracja, **domyślnie
|
||||||
|
wyłączona**. Po włączeniu:
|
||||||
|
- **Adres API, Klucz API** — osobisty token API generuje się w Snipe-IT:
|
||||||
|
profil użytkownika → „Create New Token”.
|
||||||
|
- **Nie sprawdzaj SSL** — zaznacz tylko, jeśli instancja Snipe-IT korzysta
|
||||||
|
z certyfikatu self-signed/prywatnego CA.
|
||||||
|
- **Klient może wybrać sprzęt, którego dotyczy zgłoszenie** — przy
|
||||||
|
tworzeniu zgłoszenia klient widzi listę swojego sprzętu z Snipe-IT
|
||||||
|
(dopasowanego po adresie e-mail) i może je powiązać ze zgłoszeniem. Po
|
||||||
|
zaznaczeniu pojawia się dodatkowa lista wielokrotnego wyboru **„Ogranicz
|
||||||
|
do podkategorii”** — wybór sprzętu pokaże się klientowi **tylko** dla
|
||||||
|
zaznaczonych tam podkategorii; jeśli nic nie jest zaznaczone, opcja nie
|
||||||
|
pojawi się w żadnej podkategorii (tak samo jak dozwolone półki BookStack
|
||||||
|
wyżej — trzeba świadomie wskazać zakres).
|
||||||
|
- **Operator może zobaczyć sprzęt zgłaszającego w widoku zgłoszenia** — ta
|
||||||
|
sama lista sprzętu zgłaszającego, tym razem w panelu bocznym operatora
|
||||||
|
na widoku zgłoszenia, z przyciskiem „Powiąż” przy każdej pozycji.
|
||||||
|
- **Zezwól operatorowi na przeszukiwanie całego inwentarza** — pole
|
||||||
|
wyszukiwania z przyciskiem „Szukaj” w tym samym panelu bocznym (nie
|
||||||
|
osobna podstrona), pozwalające powiązać dowolny sprzęt z Snipe-IT, nie
|
||||||
|
tylko sprzęt zgłaszającego — przydatne dla współdzielonego sprzętu, np.
|
||||||
|
drukarek.
|
||||||
|
- Powiązany sprzęt pokazuje się na widoku zgłoszenia jako „numer środka -
|
||||||
|
numer seryjny - producent model” oraz kategoria, z bieżącym statusem
|
||||||
|
pobieranym na żywo z Snipe-IT. Przycisk „Odepnij” jest dostępny dla
|
||||||
|
operatora zawsze, niezależnie od dwóch powyższych przełączników —
|
||||||
|
odpięcie już powiązanego sprzętu to korekta, nie nowy dostęp do
|
||||||
|
Snipe-IT.
|
||||||
|
- Przycisk **„Testuj połączenie”** działa tak samo jak przy pozostałych
|
||||||
|
integracjach.
|
||||||
|
|
||||||
|
- **Integracja AI** — opcjonalna, **domyślnie wyłączona**, ogólne połączenie z
|
||||||
|
dostawcą modelu językowego (nie tylko dla BookStacka — patrz
|
||||||
|
„Automatyzacja AI dla zgłoszeń” niżej). Pola: **adres API** (dowolny
|
||||||
|
dostawca kompatybilny z OpenAI — np. Groq, OpenAI, lokalny Ollama),
|
||||||
|
**klucz API** (opcjonalny — zostaw puste dla lokalnych instancji bez
|
||||||
|
autoryzacji), **model**, **weryfikacja SSL** (wyłącz tylko dla instancji z
|
||||||
|
certyfikatem self-signed, np. lokalny Ollama). Przycisk **„Testuj
|
||||||
|
połączenie”** jak przy pozostałych integracjach.
|
||||||
|
|
||||||
|
- **Automatyzacja AI dla zgłoszeń** — wymaga włączonej integracji AI powyżej.
|
||||||
|
Zgłoszenia przetwarzane są w tle, cyklicznie (`ai:run-ticket-automation`,
|
||||||
|
interwał konfigurowalny w Konfiguracji) — nie synchronicznie przy
|
||||||
|
składaniu zgłoszenia, więc nie spowalnia to klienta.
|
||||||
|
- **Automatyczna kategoryzacja** — pięć niezależnych przełączników: przypisz
|
||||||
|
kategorię/podkategorię, gdy zgłoszenie nie ma żadnej; dobierz podkategorię,
|
||||||
|
gdy ma tylko kategorię; zweryfikuj i ewentualnie popraw już przypisaną
|
||||||
|
podkategorię; popraw temat zgłoszenia, jeśli jest niejasny; ustaw
|
||||||
|
priorytet na podstawie treści. Każde zgłoszenie jest sprawdzane **tylko
|
||||||
|
raz** — zmiany trafiają do historii zgłoszenia z adnotacją
|
||||||
|
„Automatyzacja: klasyfikacja AI” (patrz „Historia” w przewodniku
|
||||||
|
operatora).
|
||||||
|
- **Podsumowanie AI dla operatora** — osobny przełącznik generuje krótkie
|
||||||
|
podsumowanie + sugerowaną kolejną akcję dla **każdego** zgłoszenia,
|
||||||
|
widoczne tylko operatorowi (panel boczny „Podsumowanie AI” w widoku
|
||||||
|
zgłoszenia). Domyślnie odświeża się cyklicznie, wraz z pozostałą
|
||||||
|
automatyzacją AI powyżej (interwał w Konfiguracji) — operator może też
|
||||||
|
w każdej chwili kliknąć **„Wygeneruj teraz”** przy podsumowaniu, żeby
|
||||||
|
odświeżyć je natychmiast. Osobny przełącznik **„Regeneruj podsumowanie
|
||||||
|
od razu po każdej nowej wiadomości”** (domyślnie wyłączony) sprawia, że
|
||||||
|
podsumowanie odświeża się samo zaraz po każdej odpowiedzi/notatce, bez
|
||||||
|
czekania na najbliższy cykl automatyzacji.
|
||||||
|
- **Prompt systemowy podsumowania** — edytowalne pole tekstowe z gotową
|
||||||
|
wartością domyślną i przyciskiem **„Resetuj”**.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
Panel klienta (`/client`) służy do zgłaszania problemów/próśb i śledzenia ich
|
Panel klienta (`/client`) służy do zgłaszania problemów/próśb i śledzenia ich
|
||||||
rozwiązania. Po zalogowaniu każde konto domyślnie ląduje właśnie tutaj — nawet jeśli
|
rozwiązania. Po zalogowaniu każde konto domyślnie ląduje właśnie tutaj — nawet jeśli
|
||||||
posiada też uprawnienia operatora lub administratora (przełączysz się przez menu
|
posiada też uprawnienia operatora lub administratora (przełączysz się suwakiem
|
||||||
profilu w prawym górnym rogu). Dzwoneczek powiadomień w górnym pasku pokazuje
|
Klient/Operator/Administrator na środku górnego paska — pokazuje tylko te panele,
|
||||||
|
do których masz dostęp). Dzwoneczek powiadomień w górnym pasku pokazuje
|
||||||
tylko **nieprzeczytane** powiadomienia — kliknięcie usuwa je z listy.
|
tylko **nieprzeczytane** powiadomienia — kliknięcie usuwa je z listy.
|
||||||
|
|
||||||
## Zgłaszanie nowej sprawy
|
## Zgłaszanie nowej sprawy
|
||||||
@@ -18,10 +19,15 @@ tylko **nieprzeczytane** powiadomienia — kliknięcie usuwa je z listy.
|
|||||||
4. Opcjonalnie dodaj **załączniki** — przeciągnij pliki na pole załączników albo
|
4. Opcjonalnie dodaj **załączniki** — przeciągnij pliki na pole załączników albo
|
||||||
kliknij, żeby wybrać je z dysku (limit rozmiaru/liczby/plików ustala admin —
|
kliknij, żeby wybrać je z dysku (limit rozmiaru/liczby/plików ustala admin —
|
||||||
komunikat o błędzie poinformuje, jeśli coś przekracza limit).
|
komunikat o błędzie poinformuje, jeśli coś przekracza limit).
|
||||||
5. Jeśli administrator włączył podpowiedzi z bazy wiedzy, przy wyborze
|
5. Jeśli administrator włączył wybór sprzętu dla wybranej podkategorii,
|
||||||
|
zobaczysz listę Twojego sprzętu z ewidencji (Snipe-IT/inwentarza),
|
||||||
|
dopasowaną po Twoim adresie e-mail — kliknij „Powiąż” przy urządzeniu,
|
||||||
|
którego dotyczy zgłoszenie (opcjonalne, ponowne kliknięcie odznacza wybór).
|
||||||
|
Dostępne tylko dla podkategorii, które administrator do tego dopuścił.
|
||||||
|
6. Jeśli administrator włączył podpowiedzi z bazy wiedzy, przy wyborze
|
||||||
kategorii/podkategorii może pojawić się lista pasujących artykułów — warto
|
kategorii/podkategorii może pojawić się lista pasujących artykułów — warto
|
||||||
je sprawdzić, zanim wyślesz zgłoszenie.
|
je sprawdzić, zanim wyślesz zgłoszenie.
|
||||||
6. Wyślij zgłoszenie. Otrzymasz e-mail potwierdzający (jeśli powiadomienia są
|
7. Wyślij zgłoszenie. Otrzymasz e-mail potwierdzający (jeśli powiadomienia są
|
||||||
włączone) z linkiem do podglądu, oraz — jeśli jesteś zalogowany — powiadomienie
|
włączone) z linkiem do podglądu, oraz — jeśli jesteś zalogowany — powiadomienie
|
||||||
w dzwoneczku w górnym pasku.
|
w dzwoneczku w górnym pasku.
|
||||||
|
|
||||||
@@ -38,7 +44,10 @@ Dashboard klienta dzieli zgłoszenia na dwie zakładki:
|
|||||||
- **Archiwum** — zgłoszenia zamknięte.
|
- **Archiwum** — zgłoszenia zamknięte.
|
||||||
|
|
||||||
Pole wyszukiwania nad listą przeszukuje numer, temat i treść zgłoszenia (oraz
|
Pole wyszukiwania nad listą przeszukuje numer, temat i treść zgłoszenia (oraz
|
||||||
odpowiedzi w wątku).
|
odpowiedzi w wątku). Obie zakładki są stronicowane (20 zgłoszeń na stronę),
|
||||||
|
niezależnie od siebie — przełączenie zakładki nie cofa Cię na pierwszą stronę
|
||||||
|
drugiej. **Ctrl+K**/**Cmd+K** otwiera też globalną wyszukiwarkę zgłoszeń z
|
||||||
|
dowolnego miejsca w aplikacji (tylko Twoich zgłoszeń).
|
||||||
|
|
||||||
Otwórz dowolne zgłoszenie, by zobaczyć:
|
Otwórz dowolne zgłoszenie, by zobaczyć:
|
||||||
|
|
||||||
@@ -48,14 +57,18 @@ Otwórz dowolne zgłoszenie, by zobaczyć:
|
|||||||
nie są widoczne dla klienta); załączone obrazy pokazują się jako miniatury,
|
nie są widoczne dla klienta); załączone obrazy pokazują się jako miniatury,
|
||||||
- **historię zmian** — log statusu/priorytetu/zespołu/przypisania z datą,
|
- **historię zmian** — log statusu/priorytetu/zespołu/przypisania z datą,
|
||||||
- **SLA** — orientacyjny czas do rozwiązania wg priorytetu sprawy,
|
- **SLA** — orientacyjny czas do rozwiązania wg priorytetu sprawy,
|
||||||
|
- jeśli zgłoszenie jest powiązane z konkretnym sprzętem (przez Ciebie przy
|
||||||
|
tworzeniu zgłoszenia albo przez operatora później) — jego nazwa w panelu
|
||||||
|
bocznym „Powiązany sprzęt”,
|
||||||
- jeśli administrator włączył integrację z bazą wiedzy — panel z artykułami
|
- jeśli administrator włączył integrację z bazą wiedzy — panel z artykułami
|
||||||
dopasowanymi do kategorii/podkategorii sprawy (te same podpowiedzi, co przy
|
dopasowanymi do kategorii/podkategorii sprawy (te same podpowiedzi, co przy
|
||||||
tworzeniu zgłoszenia).
|
tworzeniu zgłoszenia).
|
||||||
|
|
||||||
Wszystko na tej stronie aktualizuje się **na żywo** — jeśli operator odpowie
|
Wszystko na tej stronie aktualizuje się **na żywo** — jeśli operator odpowie
|
||||||
albo zmieni status/przypisanie, zobaczysz to bez odświeżania strony. Mały
|
albo zmieni status/przypisanie, zobaczysz to bez odświeżania strony. Mały
|
||||||
licznik przy przycisku „Wróć do listy” to niezależny, okresowy fallback (co
|
licznik przy przycisku „Wróć do listy” to niezależny, okresowy fallback
|
||||||
ok. 30 s), na wypadek gdyby połączenie w tle się zerwało.
|
(domyślnie co ok. 30 s), na wypadek gdyby połączenie w tle się zerwało —
|
||||||
|
kliknięcie licznika od razu odświeża stronę i resetuje odliczanie.
|
||||||
|
|
||||||
## Odpowiadanie
|
## Odpowiadanie
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ Panel operatora (`/operator`) to miejsce pracy z kolejką zgłoszeń: przegląd,
|
|||||||
odpowiadanie, zmiana statusu/priorytetu/przypisania oraz statystyki zespołu.
|
odpowiadanie, zmiana statusu/priorytetu/przypisania oraz statystyki zespołu.
|
||||||
|
|
||||||
Domyślnie każde konto ląduje po zalogowaniu w panelu Klienta; przełącz się do
|
Domyślnie każde konto ląduje po zalogowaniu w panelu Klienta; przełącz się do
|
||||||
panelu Operatora przez menu profilu (prawy górny róg), jeśli konto ma tę rolę.
|
panelu Operatora suwakiem Klient/Operator/Administrator na środku górnego
|
||||||
|
paska, jeśli konto ma tę rolę.
|
||||||
Dzwoneczek powiadomień w górnym pasku (widoczny we wszystkich panelach) pokazuje
|
Dzwoneczek powiadomień w górnym pasku (widoczny we wszystkich panelach) pokazuje
|
||||||
Twoje **nieprzeczytane** powiadomienia, aktualizowane **na żywo** w chwili ich
|
Twoje **nieprzeczytane** powiadomienia, aktualizowane **na żywo** w chwili ich
|
||||||
utworzenia (niezależny od tego 30-sekundowy fallback dogrywa to, co ominęłoby
|
utworzenia (niezależny od tego 30-sekundowy fallback dogrywa to, co ominęłoby
|
||||||
@@ -31,7 +32,20 @@ Panel główny (`/operator`) pokazuje listę zgłoszeń z zakładkami po lewej s
|
|||||||
widzi wszystkie zespoły; też bez zamkniętych).
|
widzi wszystkie zespoły; też bez zamkniętych).
|
||||||
|
|
||||||
Nie-administratorzy widzą tylko zgłoszenia swoich zespołów, zgłoszenia bez
|
Nie-administratorzy widzą tylko zgłoszenia swoich zespołów, zgłoszenia bez
|
||||||
przypisanego zespołu, oraz wszystko przypisane bezpośrednio do nich.
|
przypisanego zespołu, oraz wszystko przypisane bezpośrednio do nich. Lista
|
||||||
|
jest stronicowana (50 zgłoszeń na stronę) — zmiana filtra/wyszukiwania/
|
||||||
|
zakładki wraca automatycznie na pierwszą stronę.
|
||||||
|
|
||||||
|
Na pasku bocznym, nad zakładkami: przycisk **„Szukaj”** otwiera globalną
|
||||||
|
wyszukiwarkę zgłoszeń (dostępną z każdej strony też pod **Ctrl+K**/**Cmd+K**)
|
||||||
|
— oprócz zwykłego szukania po treści rozumie też operatory `od:`, `temat:`,
|
||||||
|
`treść:` i `numer:` (np. `od:kowalski temat:drukarka`), które można łączyć.
|
||||||
|
Niżej — **„Ostatnio przeglądane”**: ostatnie 6 zgłoszeń, które faktycznie
|
||||||
|
otworzyłeś, najnowsze na górze.
|
||||||
|
|
||||||
|
**Klienci** (przycisk nad tabelą) — osobna wyszukiwarka po imieniu/nazwisku/
|
||||||
|
e-mailu dowolnego konta (nie tylko klientów), pokazuje liczbę jego zgłoszeń i
|
||||||
|
prowadzi od razu do kolejki przefiltrowanej do tego klienta.
|
||||||
|
|
||||||
**Filtry** nad tabelą: status, priorytet, kategoria, wyszukiwanie po numerze/
|
**Filtry** nad tabelą: status, priorytet, kategoria, wyszukiwanie po numerze/
|
||||||
temacie/kliencie/treści zgłoszenia i odpowiedzi w wątku. **Kolumny** można dowolnie
|
temacie/kliencie/treści zgłoszenia i odpowiedzi w wątku. **Kolumny** można dowolnie
|
||||||
@@ -60,16 +74,24 @@ konkretnej wiadomości w wątku zgłoszenia.
|
|||||||
Kolejka aktualizuje się **na żywo** — nowe zgłoszenie, zmiana statusu/priorytetu/
|
Kolejka aktualizuje się **na żywo** — nowe zgłoszenie, zmiana statusu/priorytetu/
|
||||||
przypisania czy nowa odpowiedź pojawiają się bez odświeżania strony. Obok
|
przypisania czy nowa odpowiedź pojawiają się bez odświeżania strony. Obok
|
||||||
przycisku „Kolumny” widać mały licznik odliczający do zera — to niezależny od
|
przycisku „Kolumny” widać mały licznik odliczający do zera — to niezależny od
|
||||||
połączenia na żywo, okresowy fallback (co ok. 60 s), na wypadek gdyby
|
połączenia na żywo, okresowy fallback (interwał ustawia administrator w
|
||||||
połączenie sieciowe w tle się zerwało.
|
Konfiguracji, domyślnie co ok. 60 s), na wypadek gdyby połączenie sieciowe w
|
||||||
|
tle się zerwało. **Licznik jest też klikalny** — kliknięcie od razu odświeża
|
||||||
|
listę i resetuje odliczanie, zamiast czekać na naturalny koniec.
|
||||||
|
|
||||||
## Praca ze zgłoszeniem
|
## Praca ze zgłoszeniem
|
||||||
|
|
||||||
Widok zgłoszenia też aktualizuje się na żywo — nowa wiadomość klienta pojawia
|
Widok zgłoszenia też aktualizuje się na żywo — nowa wiadomość klienta pojawia
|
||||||
się od razu (bez odświeżania), podobnie jak zmiana statusu/priorytetu/zespołu
|
się od razu (bez odświeżania), podobnie jak zmiana statusu/priorytetu/zespołu
|
||||||
zrobiona przez innego operatora albo przez regułę automatyzacji SLA. Licznik
|
zrobiona przez innego operatora, przez regułę automatyzacji SLA albo przez
|
||||||
przy przycisku „Wróć do listy” to taki sam fallbackowy zegar jak w kolejce
|
automatyzację AI (patrz „Historia” niżej). Licznik przy przycisku „Wróć do
|
||||||
(co ok. 30 s).
|
listy” to taki sam fallbackowy, klikalny zegar jak w kolejce (domyślnie co
|
||||||
|
ok. 30 s, konfigurowalny przez administratora).
|
||||||
|
|
||||||
|
Jeśli zgłoszenie, które akurat oglądasz, zostanie usunięte przez kogoś
|
||||||
|
innego, albo trafi (przez zmianę zespołu) poza Twój zakres widoczności —
|
||||||
|
zostaniesz automatycznie przeniesiony z powrotem do swojej kolejki, zamiast
|
||||||
|
zobaczyć błąd.
|
||||||
|
|
||||||
W widoku pojedynczego zgłoszenia:
|
W widoku pojedynczego zgłoszenia:
|
||||||
|
|
||||||
@@ -78,7 +100,10 @@ W widoku pojedynczego zgłoszenia:
|
|||||||
„Obserwowane zgłoszenia” w Twoich preferencjach powiadomień
|
„Obserwowane zgłoszenia” w Twoich preferencjach powiadomień
|
||||||
(`/settings/notifications`).
|
(`/settings/notifications`).
|
||||||
- **Zmiana statusu / priorytetu / zespołu / przypisanego operatora** — z listy
|
- **Zmiana statusu / priorytetu / zespołu / przypisanego operatora** — z listy
|
||||||
rozwijanej; „Przypisz do mnie” to skrót jednym kliknięciem.
|
rozwijanej; „Przypisz do mnie” to skrót jednym kliknięciem. Zespół można
|
||||||
|
zmienić na **dowolny**, nie tylko taki, do którego sam należysz — jeśli
|
||||||
|
przeniesiesz zgłoszenie do zespołu spoza swojego zakresu widoczności,
|
||||||
|
zostaniesz automatycznie przeniesiony do swojej kolejki.
|
||||||
- **Odpowiedź publiczna** — widoczna dla klienta; można wybrać **szablon
|
- **Odpowiedź publiczna** — widoczna dla klienta; można wybrać **szablon
|
||||||
odpowiedzi** (wstawia gotowy tekst do edycji) i wysłać razem ze zmianą statusu
|
odpowiedzi** (wstawia gotowy tekst do edycji) i wysłać razem ze zmianą statusu
|
||||||
jedną **szybką akcją** (np. „Wyślij i zamknij”) zamiast dwóch osobnych kroków.
|
jedną **szybką akcją** (np. „Wyślij i zamknij”) zamiast dwóch osobnych kroków.
|
||||||
@@ -91,6 +116,24 @@ W widoku pojedynczego zgłoszenia:
|
|||||||
boczny podpowiada artykuły pasujące do kategorii/podkategorii zgłoszenia;
|
boczny podpowiada artykuły pasujące do kategorii/podkategorii zgłoszenia;
|
||||||
kliknięcie otwiera artykuł, przycisk „Kopiuj link" kopiuje adres bez
|
kliknięcie otwiera artykuł, przycisk „Kopiuj link" kopiuje adres bez
|
||||||
wychodzenia ze zgłoszenia (np. do wklejenia w odpowiedzi).
|
wychodzenia ze zgłoszenia (np. do wklejenia w odpowiedzi).
|
||||||
|
- **Sprzęt (jeśli administrator włączył integrację z Snipe-IT)** — panel
|
||||||
|
boczny może pokazywać do trzech rzeczy, zależnie od tego, co administrator
|
||||||
|
włączył: sprzęt już powiązany ze zgłoszeniem (nazwa jako „numer środka -
|
||||||
|
numer seryjny - producent model” + kategoria, status na żywo z Snipe-IT,
|
||||||
|
przycisk „Odepnij”), listę sprzętu przypisanego zgłaszającemu z przyciskiem
|
||||||
|
„Powiąż” przy każdej pozycji, oraz pole wyszukiwania „Przeszukaj inwentarz”
|
||||||
|
z przyciskiem „Szukaj”, pozwalające powiązać dowolny sprzęt z Snipe-IT (nie
|
||||||
|
tylko sprzęt zgłaszającego) — przydatne np. dla drukarki współdzielonej
|
||||||
|
przez kilka osób. „Odepnij” działa zawsze, nawet gdy administrator wyłączył
|
||||||
|
obie powyższe listy.
|
||||||
|
- **Podsumowanie AI** (jeśli administrator włączył automatyzację AI
|
||||||
|
zgłoszeń) — panel boczny widoczny tylko w panelu operatora, pokazuje krótkie
|
||||||
|
podsumowanie sprawy i sugerowaną kolejną akcję. Domyślnie odświeża się samo
|
||||||
|
cyklicznie (razem z pozostałą automatyzacją AI); przycisk **„Wygeneruj
|
||||||
|
teraz”** przy podsumowaniu odświeża je natychmiast na żądanie, a jeśli
|
||||||
|
administrator włączył „Regeneruj podsumowanie od razu po każdej nowej
|
||||||
|
wiadomości”, odświeży się samo zaraz po każdej nowej odpowiedzi/notatce,
|
||||||
|
bez czekania na cykl automatyzacji.
|
||||||
- **Ocena obsługi** — jeśli klient już ocenił zgłoszenie, ocena (gwiazdki +
|
- **Ocena obsługi** — jeśli klient już ocenił zgłoszenie, ocena (gwiazdki +
|
||||||
ewentualny komentarz) pokazuje się w panelu bocznym, tylko do odczytu.
|
ewentualny komentarz) pokazuje się w panelu bocznym, tylko do odczytu.
|
||||||
- **Licznik czasu pracy** — start/stop/reset przy zgłoszeniu; czas zapisuje się
|
- **Licznik czasu pracy** — start/stop/reset przy zgłoszeniu; czas zapisuje się
|
||||||
@@ -100,9 +143,12 @@ W widoku pojedynczego zgłoszenia:
|
|||||||
po jego zamknięciu; wcześniej naliczony czas można wciąż ręcznie skorygować.
|
po jego zamknięciu; wcześniej naliczony czas można wciąż ręcznie skorygować.
|
||||||
- **Edycja danych zgłoszenia** — temat, opis, podkategoria, pola dodatkowe;
|
- **Edycja danych zgłoszenia** — temat, opis, podkategoria, pola dodatkowe;
|
||||||
zmiana kategorii może wysłać powiadomienie do klienta.
|
zmiana kategorii może wysłać powiadomienie do klienta.
|
||||||
- **Historia** — log każdej zmiany (status, priorytet, zespół, przypisanie) z
|
- **Historia** — log każdej zmiany (status, priorytet, zespół, przypisanie,
|
||||||
datą; wpis zaczynający się od „Automatyzacja: …” oznacza, że zmianę wykonała
|
kategoria/podkategoria, temat) z datą; wpis „Automatyzacja: nazwa reguły”
|
||||||
reguła automatyzacji SLA (Admin > Automatyzacja SLA), nie operator ręcznie.
|
oznacza regułę automatyzacji SLA (Admin > Automatyzacja SLA), a
|
||||||
|
„Automatyzacja: klasyfikacja AI” — automatyczną kategoryzację/priorytet
|
||||||
|
ustawione przez integrację AI (Admin > Integracje) — w obu przypadkach nie
|
||||||
|
operator ręcznie.
|
||||||
|
|
||||||
## Statystyki (`/operator/stats`)
|
## Statystyki (`/operator/stats`)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user