From 93bf2e3e39357ecbdf5f393b9faad4c1909633fc Mon Sep 17 00:00:00 2001 From: studio-prisma <282898618+studio-prisma@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:56:13 +0100 Subject: [PATCH 1/2] feat: closing statuses that never ask, note when the question is sent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A closed status like "Duplicate" or "Hinfällig" means nothing was done; closing with one of the excluded statuses now never asks. Preselected by name. In mail mode the ticket gets an internal note after the question went out: short (recipient, scale, valid until), with the mail as sent including its rating links, or none. A failed send always gets a note, so nobody assumes the customer was asked. INSTALL: osTicket 1.18 doesn't store checkbox defaults when an instance is created; open it again and check the boxes. --- README.de.md | 6 +++- README.md | 6 +++- SECURITY.md | 1 + class.FeedbackPlugin.php | 5 +-- config.php | 43 ++++++++++++++++++++++ docs/INSTALL.de.md | 12 ++++--- docs/INSTALL.md | 12 ++++--- src/FeedbackActions.php | 17 +++++++++ src/FeedbackI18n.php | 16 +++++++++ src/FeedbackMail.php | 30 ++++++++++++++++ src/FeedbackRules.php | 5 ++- src/FeedbackSettings.php | 7 ++++ src/FeedbackTrigger.php | 18 +++++++++- tests/e2e/8-status-note.spec.js | 64 +++++++++++++++++++++++++++++++++ tests/unit.php | 31 ++++++++++++++-- 15 files changed, 256 insertions(+), 17 deletions(-) create mode 100644 tests/e2e/8-status-note.spec.js diff --git a/README.de.md b/README.de.md index 36de00a..81cfd2a 100644 --- a/README.de.md +++ b/README.de.md @@ -23,6 +23,7 @@ Die Bewertungen bleiben in der Datenbank des Helpdesks. Kein Umfragedienst, kein - Tickets, die ein KI-Agent schließt (Agenten mit dem Backend `ai-agent`, wie [AI Actions](https://github.com/studio-prisma/osticket-plugin-ai-actions) sie anlegt), auch wenn das im Cron passiert - Unter-Tickets - Abteilungen, Hilfethemen und Absender-Domains aus den Einstellungen; standardmäßig die eigenen Domains des Helpdesks +- Schließen mit einem Status wie „Dublette“ oder „Spam“ (Einstellung, nach Namen vorausgewählt) - Tickets, zu denen schon gefragt wurde ## Voraussetzungen @@ -47,7 +48,8 @@ Schritt für Schritt mit Prüfpunkten: **[docs/INSTALL.de.md](docs/INSTALL.de.md | Bad means | Sterne bis … / NPS bis … | 2 / 6 | | Link valid for | Tage (1–90) | 14 | | Comment field after the click | an / aus | an | -| Never ask for | Abteilungen, Hilfethemen, Absender-Domains, eigene Domains | Abteilungen mit „Alert“/„Protokoll“ im Namen, eigene Domains | +| Note at the ticket when asked | keine / kurz / mit der gesendeten Mail | kurz; ein gescheiterter Versand bekommt immer eine Notiz | +| Never ask for | Abteilungen, Hilfethemen, Status beim Schließen, Absender-Domains, eigene Domains | Abteilungen mit „Alert“/„Protokoll“ im Namen, Status mit „Duplicate“/„Spam“/„Hinfällig“ im Namen, eigene Domains | | Texte | Betreff, Mailtext, Frage, Zeile, KI-Hinweis; leer = eingebauter Text | eingebaut, Deutsch (du) oder Englisch | | Accent colour | `#rrggbb` | `#330066` | @@ -66,6 +68,8 @@ Die Mailtexte verstehen osTicket-Variablen wie `%{ticket.number}` und `%{recipie - **Spitze Klammern in Kommentaren** erscheinen in der Notiz als ‹ ›, weil der Sanitizer von osTicket alles entfernt, was wie ein Tag aussieht. - **Modus „Zeile“** braucht eine Antwort, die den Status auf geschlossen setzt. Schließen ohne Antwort fragt in diesem Modus niemanden, und eine Antwort mit „Antworten an: niemand“ trägt keine Zeile und zählt nicht als gefragt. - **Safe Links mit JavaScript:** Ein Scanner, der das JavaScript der Seite in einer Sandbox ausführt, würde die Bewertung abschicken. Bisher nicht beobachtet; im echten Microsoft-365-Tenant zu prüfen. +- **Häkchen-Standardwerte bei einer neuen Instanz:** osTicket 1.18 speichert sie beim ersten Speichern nicht. Nach dem Anlegen die Instanz noch einmal öffnen und die Häkchen prüfen (siehe INSTALL, Schritt 2). +- **Notiz „mit der Mail“** legt die Bewertungslinks des Kunden ans Ticket. Jeder Agent, der das Ticket öffnen darf, kann ihnen folgen; das ist der Preis dafür, genau zu sehen, was rausging. - **Nur eine Frage,** keine Erinnerungen, kein Export, keine Bewertung einzelner Agenten. Das ist bewusst außerhalb des Umfangs. - **Wochenzusammenfassung von AI Actions:** Das Plugin beantwortet das Signal `feedback.digest` mit einer Zeile. AI Actions schickt es noch nicht. diff --git a/README.md b/README.md index e13b6f4..6ffee99 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Ratings stay in the help desk's own database. No survey service, no tracking pix - tickets an AI agent closes (agents with the backend `ai-agent`, as [AI Actions](https://github.com/studio-prisma/osticket-plugin-ai-actions) creates them), including closes it makes in osTicket's cron - sub-tickets - departments, help topics and sender domains from the settings; the help desk's own domains by default +- closes with a status like "Duplicate" or "Spam" (setting, preselected by name) - tickets that were already asked ## Requirements @@ -47,7 +48,8 @@ Step by step with checkpoints: **[docs/INSTALL.md](docs/INSTALL.md)**. Short ver | Bad means | stars up to … / NPS up to … | 2 / 6 | | Link valid for | days (1–90) | 14 | | Comment field after the click | on / off | on | -| Never ask for | departments, help topics, sender domains, own domains | departments named like "Alert"/"Protokoll", own domains | +| Note at the ticket when asked | none / short / with the mail as sent | short; a failed send always gets a note | +| Never ask for | departments, help topics, closing statuses, sender domains, own domains | departments named like "Alert"/"Protokoll", statuses named like "Duplicate"/"Spam"/"Hinfällig", own domains | | Texts | subject, mail text, question, line, AI notice; empty = built-in text | built-in, German (informal) or English | | Accent colour | `#rrggbb` | `#330066` | @@ -66,6 +68,8 @@ The mail texts accept osTicket variables such as `%{ticket.number}` and `%{recip - **Angle brackets in comments** appear as ‹ › in the note, because osTicket's sanitizer strips anything that looks like a tag. - **"Line" mode** needs a reply that sets the closed status. Closing without a reply asks nobody in that mode, and a reply posted with "Reply to: none" carries no line and doesn't count as asked. - **Safe Links with JavaScript:** a scanner that runs the page's JavaScript in a sandbox would submit the rating. Not observed so far; to be checked against a real Microsoft 365 tenant. +- **Checkbox defaults on a new instance:** osTicket 1.18 doesn't store them on the first save. Open the instance again after creating it and check the boxes (see INSTALL, step 2). +- **"With the mail" note** puts the customer's rating links into the ticket. Any agent who can open the ticket can follow them; that is a trade-off for seeing exactly what went out. - **Only one question,** no reminders, no export, no per-agent rating. These are out of scope on purpose. - **AI Actions weekly summary:** the plugin answers the signal `feedback.digest` with one line. AI Actions doesn't send it yet. diff --git a/SECURITY.md b/SECURITY.md index 8b07129..b0cd171 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -42,6 +42,7 @@ Expected response: an acknowledgement within 7 days, an assessment within 30. Th These are documented design decisions, not findings: - **Anyone who has the mail can rate.** The link is the authorisation, like a password-reset link. A forwarded mail lets the recipient rate and change the rating while it's valid. +- **Agents with the "with the mail" note can rate.** That setting copies the sent mail, links included, into an internal note. Every agent who can open the ticket can follow them. The default note has no links. - **A link scanner that runs JavaScript** submits the rating like a person would. The confirmation step stops scanners that only fetch the page; one that executes the page in a sandbox is indistinguishable from a click. - **Rate limit per IP** counts all customers behind one NAT together (60 requests per 10 minutes, about 20 ratings). - **No revocation of single links** other than switching the plugin off (all links) or deleting the row in `feedback_request`. diff --git a/class.FeedbackPlugin.php b/class.FeedbackPlugin.php index 15ebcf8..256cac4 100644 --- a/class.FeedbackPlugin.php +++ b/class.FeedbackPlugin.php @@ -41,7 +41,7 @@ class FeedbackPlugin extends Plugin { /** Mirrors plugin.php. */ - public const VERSION = '0.1.0'; + public const VERSION = '0.1.1'; /** Route bases, relative to the help desk root. */ public const CLIENT_BASE = 'ajax.php/feedback'; @@ -74,7 +74,8 @@ public function bootstrap(): void } $raw = array(); foreach (array('enabled', 'mode', 'scale', 'on_bad', 'bad_stars', 'bad_nps', 'valid_days', 'exclude_depts', - 'exclude_topics', 'exclude_domains', 'exclude_own', 'comment_on', 'language', 'subject', 'text', + 'exclude_topics', 'exclude_statuses', 'exclude_domains', 'exclude_own', 'comment_on', 'note_sent', + 'language', 'subject', 'text', 'question', 'line', 'foot_on', 'foot', 'accent') as $k) { $raw[$k] = $config->get($k); } diff --git a/config.php b/config.php index eba2328..becc15b 100644 --- a/config.php +++ b/config.php @@ -89,6 +89,18 @@ public function getOptions() ), )), + 'note_sent' => new ChoiceField(array( + 'label' => 'Note at the ticket when asked', + 'default' => 'short', + 'choices' => array( + 'off' => 'No note', + 'short' => 'Short note: recipient, scale, valid until', + 'full' => 'Short note plus the mail as sent, with its rating links', + ), + 'hint' => 'Own mail only. A failed send always gets a note. With the mail, every agent who ' + . 'opens the ticket sees the customer\'s rating links.', + )), + 'sec_except' => new SectionBreakField(array( 'label' => 'Never ask for', )), @@ -108,6 +120,15 @@ public function getOptions() 'configuration' => array('multiselect' => true, 'prompt' => 'None'), )), + 'exclude_statuses' => new ChoiceField(array( + 'label' => 'Closing statuses', + 'default' => self::defaultStatuses(), + 'choices' => self::closedStatuses(), + 'hint' => 'Closing with one of these never asks, e.g. duplicates or spam. Preselected: closed ' + . 'statuses named like "Duplicate", "Spam", "Rejected" or "Hinfällig".', + 'configuration' => array('multiselect' => true, 'prompt' => 'None'), + )), + 'exclude_domains' => new TextareaField(array( 'label' => 'Sender domains', 'default' => '', @@ -208,6 +229,28 @@ private static function topics(): array return $out; } + /** Statuses whose state is "closed". @return array */ + private static function closedStatuses(): array + { + $out = array(); + if (!function_exists('db_query') || !defined('TICKET_STATUS_TABLE')) { + return $out; + } + $res = db_query(sprintf("SELECT id, name FROM %s WHERE state='closed' ORDER BY sort, name", TICKET_STATUS_TABLE)); + while ($res && ($r = db_fetch_row($res))) { + $out[(int) $r[0]] = (string) $r[1]; + } + return $out; + } + + /** Closing statuses that mean "nothing was done", by name. @return array */ + private static function defaultStatuses(): array + { + return array_filter(self::closedStatuses(), static function (string $name): bool { + return preg_match('/duplicate|dublette|spam|reject|abgelehnt|hinf(ä|ae)llig|obsolete|invalid/iu', $name) === 1; + }); + } + /** Departments for alerts and logs, by name. @return array */ private static function defaultDepts(): array { diff --git a/docs/INSTALL.de.md b/docs/INSTALL.de.md index 3d78639..ca288a8 100644 --- a/docs/INSTALL.de.md +++ b/docs/INSTALL.de.md @@ -48,9 +48,12 @@ Prüfung: `include/plugins/feedback/` enthält `plugin.php`, `config.php`, `clas 3. Reiter „Instanzen“ → „Neue Instanz hinzufügen“, Name z. B. `Feedback`, Haken bei „Aktiv“. 4. In der Instanz die Einstellungen durchgehen. **„Ask customers“ bleibt aus.** - „Never ask for → Departments“: Abteilungen für Alerts, Monitoring, Protokolle. Vorausgewählt sind Abteilungen mit „Alert“, „Protokoll“ oder „Monitoring“ im Namen. + - „Closing statuses“: Schließen mit einem dieser Status fragt nie, z. B. „Dublette“ oder „Spam“. Vorausgewählt sind geschlossene Status mit „Duplicate“, „Spam“, „Rejected“ oder „Hinfällig“ im Namen. - „Help topics“ und „Sender domains“ nach Bedarf, z. B. Domains von Partnern, die nicht gefragt werden sollen. + - „Note at the ticket when asked“: kurz (Standard), mit der gesendeten Mail oder keine. Mit der Mail sieht jeder Agent, der das Ticket öffnet, die Bewertungslinks des Kunden. - Texte leer lassen für den eingebauten Text (Du-Form). „Language of the built-in texts“ auf „Deutsch (du)“, wenn das Helpdesk nicht auf Deutsch steht. 5. Speichern. +6. **Instanz noch einmal öffnen und die Häkchen prüfen.** osTicket 1.18 speichert beim Anlegen einer Instanz die Standardwerte von Häkchen nicht: Nach dem ersten Speichern können „Comment field after the click“, „Own domains“ und „Footer with AI notice“ aus sein, obwohl sie standardmäßig an sind. Gewünschte Häkchen wieder setzen, Speichern, erneut öffnen und prüfen, dass sie bleiben. Prüfung: Agentenpanel → Anwendungen → „Feedback“ öffnet die Auswertung mit „Status: aus“ und ohne rote Meldung. @@ -74,10 +77,11 @@ Prüfung: beides gesetzt. Ohne Schritt 2 wird das Ticket trotzdem geöffnet und 1. „Ask customers“ an, Speichern. 2. Testticket mit der Testadresse aus Schritt 0 anlegen, als Agent darauf antworten, Ticket schließen. 3. In der Testadresse liegt eine Mail „Kurze Frage zu deinem Ticket [Nummer]“ mit 👍/👎. -4. 👍 klicken: Seite „Danke!“, am Ticket die interne Notiz „Kundenbewertung · Bewertung: Daumen hoch (zufrieden)“. Das Ticket bleibt zu. -5. Zweites Testticket, gleicher Ablauf, 👎 klicken, Kommentar schreiben, „Kommentar senden“: Das Ticket ist offen, dem Agenten zugewiesen, der geantwortet hat, und er hat eine Zuweisungsmail mit Bewertung und Kommentar. +4. Am Ticket: interne Notiz „Zufriedenheitsfrage“ mit Empfänger und Gültigkeit. Steht dort „konnte nicht gesendet werden“, ist der Mailversand von osTicket gescheitert (Systemprotokoll; bei OAuth das Token des ausgehenden Kontos prüfen). +5. 👍 klicken: Seite „Danke!“, am Ticket die interne Notiz „Kundenbewertung · Bewertung: Daumen hoch (zufrieden)“. Das Ticket bleibt zu. +6. Zweites Testticket, gleicher Ablauf, 👎 klicken, Kommentar schreiben, „Kommentar senden“: Das Ticket ist offen, dem Agenten zugewiesen, der geantwortet hat, und er hat eine Zuweisungsmail mit Bewertung und Kommentar. -Abbruch, wenn: bei Schritt 3 keine Mail kommt. Dann zuerst prüfen: Ist die Kundenadresse eine eigene Domain? Hat ein Agent geantwortet (keine KI)? Ist die Abteilung ausgenommen? Steht im Systemprotokoll ein Eintrag „Feedback plugin“? +Abbruch, wenn: bei Schritt 3 keine Mail kommt. Dann zuerst prüfen: Steht am Ticket eine Notiz „Zufriedenheitsfrage“ (siehe Schritt 4)? Ist die Kundenadresse eine eigene Domain? Hat ein Agent geantwortet (keine KI)? Ist die Abteilung oder der Status beim Schließen ausgenommen? Steht im Systemprotokoll ein Eintrag „Feedback plugin“? --- @@ -107,5 +111,5 @@ Gespeichert werden Ticket-ID, Bewertung, Kommentar, Zeit und ein Hash der IP-Adr ## 7. Update und Entfernen -- **Update:** neuen Ordner über den alten entpacken. Die Tabellen bleiben, Einstellungen auch. +- **Update:** neuen Ordner über den alten entpacken. Die Tabellen bleiben, Einstellungen auch. Neue Einstellungen gelten mit ihrem eingebauten Standard, bis die Instanz einmal gespeichert ist: Instanz öffnen, neue Felder prüfen, Speichern. - **Entfernen:** Instanz löschen, Plugin deinstallieren, Ordner löschen. Die Tabellen `feedback_request` und `feedback_hit` bleiben in der Datenbank, bis du sie selbst löschst (`DROP TABLE`). Die Notizen an den Tickets bleiben. diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 7e6c996..68b34af 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -48,9 +48,12 @@ Check: `include/plugins/feedback/` holds `plugin.php`, `config.php`, `class.Feed 3. Tab "Instances" → "Add New Instance", name e.g. `Feedback`, tick "Active". 4. Go through the instance settings. **"Ask customers" stays off.** - "Never ask for → Departments": departments for alerts, monitoring, logs. Preselected are departments with "Alert", "Protokoll" or "Monitoring" in their name. + - "Closing statuses": closing with one of these never asks, e.g. "Duplicate" or "Spam". Preselected are closed statuses with "Duplicate", "Spam", "Rejected" or "Hinfällig" in their name. - "Help topics" and "Sender domains" as needed, e.g. partner domains that shouldn't be asked. + - "Note at the ticket when asked": short (default), with the mail as sent, or none. With the mail, every agent who opens the ticket sees the customer's rating links. - Leave the texts empty for the built-in text. "Language of the built-in texts" decides between German (informal "du") and English; "Help desk language" follows the system language. 5. Save. +6. **Open the instance again and check the checkboxes.** osTicket 1.18 doesn't store checkbox defaults when an instance is created: after the first save "Comment field after the click", "Own domains" and "Footer with AI notice" can be off although they are on by default. Tick them again where wanted, Save, open once more and check they stay ticked. Check: agent panel → Applications → "Feedback" opens the evaluation with "State: off" and no red message. @@ -74,10 +77,11 @@ Check: both set. Without step 2 the ticket is still reopened and assigned, only 1. "Ask customers" on, Save. 2. Create a test ticket with the test address from step 0, reply as an agent, close the ticket. 3. The test mailbox has a mail "A quick question about your ticket [number]" (German: "Kurze Frage zu deinem Ticket") with 👍/👎. -4. Click 👍: page "Thank you!", at the ticket the internal note "Customer rating · Rating: thumbs up (satisfied)". The ticket stays closed. -5. Second test ticket, same steps, click 👎, write a comment, "Send comment": the ticket is open, assigned to the agent who replied, and that agent has an assignment alert with rating and comment. +4. At the ticket: internal note "Satisfaction question" with recipient and validity. "Could not be sent" there means osTicket's outgoing mail failed (system log; with OAuth check the token of the outgoing account). +5. Click 👍: page "Thank you!", at the ticket the internal note "Customer rating · Rating: thumbs up (satisfied)". The ticket stays closed. +6. Second test ticket, same steps, click 👎, write a comment, "Send comment": the ticket is open, assigned to the agent who replied, and that agent has an assignment alert with rating and comment. -Stop if: no mail arrives in step 3. Check first: is the customer address an own domain? Did a human agent reply (not an AI agent)? Is the department excluded? Is there a "Feedback plugin" entry in the system log? +Stop if: no mail arrives in step 3. Check first: is there a note "Satisfaction question" at the ticket (see step 4)? Is the customer address an own domain? Did a human agent reply (not an AI agent)? Is the department or the closing status excluded? Is there a "Feedback plugin" entry in the system log? --- @@ -107,5 +111,5 @@ Stored: ticket ID, rating, comment, time and a hash of the IP address (for the r ## 7. Update and removal -- **Update:** unzip the new folder over the old one. Tables and settings stay. +- **Update:** unzip the new folder over the old one. Tables and settings stay. New settings apply their built-in default until the instance is saved once: open the instance, check the new fields, Save. - **Removal:** delete the instance, uninstall the plugin, delete the folder. The tables `feedback_request` and `feedback_hit` stay in the database until you drop them yourself. The notes at the tickets stay. diff --git a/src/FeedbackActions.php b/src/FeedbackActions.php index b29b41e..0feecfb 100644 --- a/src/FeedbackActions.php +++ b/src/FeedbackActions.php @@ -151,6 +151,23 @@ private static function mailAgent(Ticket $ticket, array $s, array $t, string $la $email->sendAlert($staff, FeedbackMail::oneLine((string) $msg['subj']), (string) $msg['body']); } + /** After the question went out: a note, unless switched off. Mail mode only. */ + public static function sentNote(Ticket $ticket, array $s, string $to, int $expires, string $subject, string $body): void + { + if ($s['note_sent'] === FeedbackSettings::NOTE_OFF) { + return; + } + $t = self::strings(); + self::note($ticket, $t['note_sent_title'], FeedbackMail::sentNote($s, $t, $to, $expires, $subject, $body)); + } + + /** A question that couldn't be sent: always a note, so nobody believes the customer was asked. */ + public static function failedNote(Ticket $ticket, string $to): void + { + $t = self::strings(); + self::note($ticket, $t['note_sent_title'], FeedbackMail::e(sprintf($t['note_failed'], $to !== '' ? $to : '?'))); + } + private static function note(Ticket $ticket, string $title, string $html): void { $ticket->logNote($title, $html, $title, false); diff --git a/src/FeedbackI18n.php b/src/FeedbackI18n.php index 8f64ac0..6c21816 100644 --- a/src/FeedbackI18n.php +++ b/src/FeedbackI18n.php @@ -63,6 +63,14 @@ public static function strings(string $lang): array 'note_comment' => 'Kommentar: %s', 'note_comment_title' => 'Kommentar zur Bewertung', 'note_no_agent' => 'Der letzte Bearbeiter ist nicht verfügbar, das Ticket ist offen und nicht zugewiesen.', + 'note_sent_title'=> 'Zufriedenheitsfrage', + 'note_sent' => 'Zufriedenheitsfrage per Mail gesendet an %1$s (Skala: %2$s, Link gültig bis %3$s).', + 'note_mail' => 'Gesendete Mail „%s“:', + 'note_failed' => 'Die Zufriedenheitsfrage an %s konnte nicht gesendet werden und wird nicht wiederholt. Den Grund nennt das Systemprotokoll.', + 'scale_thumbs' => 'Daumen', + 'scale_stars' => 'Sterne', + 'scale_nps' => 'NPS', + 'date_format' => 'd.m.Y', 'agent_subject' => 'Schlechte Bewertung: %{ticket.subject} [%{ticket.number}]', 'agent_lead' => 'Der Kunde hat das abgeschlossene Ticket schlecht bewertet. Das Ticket bleibt geschlossen.', 'agent_open' => 'Ticket öffnen', @@ -107,6 +115,14 @@ public static function strings(string $lang): array 'note_comment' => 'Comment: %s', 'note_comment_title' => 'Comment on the rating', 'note_no_agent' => 'The last agent who replied is not available; the ticket is open and unassigned.', + 'note_sent_title'=> 'Satisfaction question', + 'note_sent' => 'Satisfaction question sent by mail to %1$s (scale: %2$s, link valid until %3$s).', + 'note_mail' => 'Mail as sent, "%s":', + 'note_failed' => 'The satisfaction question to %s could not be sent and is not retried. The system log names the reason.', + 'scale_thumbs' => 'Thumbs', + 'scale_stars' => 'Stars', + 'scale_nps' => 'NPS', + 'date_format' => 'Y-m-d', 'agent_subject' => 'Bad rating: %{ticket.subject} [%{ticket.number}]', 'agent_lead' => 'The customer gave the closed ticket a bad rating. The ticket stays closed.', 'agent_open' => 'Open ticket', diff --git a/src/FeedbackMail.php b/src/FeedbackMail.php index 98e355b..5e9345e 100644 --- a/src/FeedbackMail.php +++ b/src/FeedbackMail.php @@ -133,6 +133,36 @@ public static function paragraphs(string $text): string return $out; } + /** + * The internal note after a sent question. "full" appends the mail as + * sent, links included. Characters beyond U+FFFF (the thumbs emojis, as + * entity or literal) are removed: osTicket decodes entities before saving + * and the 3-byte utf8 connection would drop them; the buttons keep their + * words ("Gut", "Nicht gut"). + * + * @param array $s FeedbackSettings::get() + * @param array $t FeedbackI18n::strings() + */ + public static function sentNote(array $s, array $t, string $to, int $expires, string $subject, string $body): string + { + $scale = $t['scale_' . $s['scale']] ?? $s['scale']; + $html = self::e(sprintf($t['note_sent'], $to, $scale, date($t['date_format'], $expires))); + if ($s['note_sent'] === FeedbackSettings::NOTE_FULL) { + $html .= '

' . self::e(sprintf($t['note_mail'], $subject)) . '
' . self::noBeyondBmp($body); + } + return $html; + } + + /** Removes characters beyond U+FFFF, literal or as numeric entity, and the space after an entity. */ + public static function noBeyondBmp(string $html): string + { + $html = (string) preg_replace_callback('/&#(x[0-9a-f]{1,8}|[0-9]{1,10});\s?/i', static function (array $m): string { + $n = ($m[1][0] === 'x' || $m[1][0] === 'X') ? hexdec(substr($m[1], 1)) : (int) $m[1]; + return $n > 0xFFFF ? '' : $m[0]; + }, $html); + return (string) preg_replace('/[\x{10000}-\x{10FFFF}]\s?/u', '', $html); + } + /** A subject line never carries a line break (header injection) or markup. */ public static function oneLine(string $s): string { diff --git a/src/FeedbackRules.php b/src/FeedbackRules.php index 0123949..033c056 100644 --- a/src/FeedbackRules.php +++ b/src/FeedbackRules.php @@ -12,7 +12,7 @@ final class FeedbackRules * Empty string: ask. Otherwise the reason not to. * * @param array $s FeedbackSettings::get() - * @param array $facts closed, child, dept, topic, email, own_domains, human_replies, ai_closer, asked + * @param array $facts closed, child, dept, topic, status, email, own_domains, human_replies, ai_closer, asked */ public static function skipReason(array $s, array $facts): string { @@ -40,6 +40,9 @@ public static function skipReason(array $s, array $facts): string if (in_array((int) ($facts['topic'] ?? 0), $s['exclude_topics'], true)) { return 'topic'; } + if (in_array((int) ($facts['status'] ?? 0), $s['exclude_statuses'], true)) { + return 'status'; + } $domain = self::domain((string) ($facts['email'] ?? '')); if ($domain === '') { return 'no_email'; diff --git a/src/FeedbackSettings.php b/src/FeedbackSettings.php index 280c2fa..8575f44 100644 --- a/src/FeedbackSettings.php +++ b/src/FeedbackSettings.php @@ -12,6 +12,9 @@ final class FeedbackSettings public const MODE_LINE = 'line'; public const BAD_REOPEN = 'reopen'; public const BAD_NOTIFY = 'notify'; + public const NOTE_OFF = 'off'; + public const NOTE_SHORT = 'short'; + public const NOTE_FULL = 'full'; /** @var array|null */ private static $current = null; @@ -39,6 +42,7 @@ public static function normalise(array $raw): array $bad = (string) ($raw['on_bad'] ?? ''); $lang = (string) ($raw['language'] ?? ''); $accent = (string) ($raw['accent'] ?? ''); + $note = (string) ($raw['note_sent'] ?? ''); return array( 'enabled' => self::flag($raw['enabled'] ?? false), 'mode' => in_array($mode, array(self::MODE_MAIL, self::MODE_LINE), true) ? $mode : self::MODE_MAIL, @@ -49,9 +53,12 @@ public static function normalise(array $raw): array 'valid_days' => self::int($raw['valid_days'] ?? null, 14, 1, 90), 'exclude_depts' => self::ids($raw['exclude_depts'] ?? null), 'exclude_topics' => self::ids($raw['exclude_topics'] ?? null), + 'exclude_statuses' => self::ids($raw['exclude_statuses'] ?? null), 'exclude_domains'=> self::domains((string) ($raw['exclude_domains'] ?? '')), 'exclude_own' => self::flag($raw['exclude_own'] ?? true), 'comment_on' => self::flag($raw['comment_on'] ?? true), + 'note_sent' => in_array($note, array(self::NOTE_OFF, self::NOTE_SHORT, self::NOTE_FULL), true) + ? $note : self::NOTE_SHORT, 'language' => in_array($lang, array('de', 'en'), true) ? $lang : 'auto', 'accent' => preg_match('/^#[0-9a-fA-F]{6}$/D', $accent) === 1 ? strtolower($accent) : '#330066', 'subject' => self::text($raw['subject'] ?? '', 200), diff --git a/src/FeedbackTrigger.php b/src/FeedbackTrigger.php index fc2fdbe..2c66855 100644 --- a/src/FeedbackTrigger.php +++ b/src/FeedbackTrigger.php @@ -161,6 +161,8 @@ public static function send(int $id): void if (!FeedbackStore::claim($id)) { return; } + $ticket = null; + $to = ''; try { $row = FeedbackStore::find($id); $ticket = $row ? Ticket::lookup((int) $row['ticket_id']) : null; @@ -179,8 +181,10 @@ public static function send(int $id): void $owner = $ticket->getOwner(); $dept = $ticket->getDept(); $email = ($dept ? $dept->getEmail() : null) ?: ($cfg ? $cfg->getDefaultEmail() : null); + $to = $owner ? (string) $owner->getEmail() : ''; if (!$owner || !$email) { FeedbackStore::failed($id); + FeedbackActions::failedNote($ticket, $to); return; } $nonce = FeedbackToken::nonce(); @@ -196,12 +200,23 @@ public static function send(int $id): void // Threading: a reply to this mail lands in the ticket. $options['thread'] = $last; } - if ($email->send($owner, FeedbackMail::oneLine((string) $msg['subj']), (string) $msg['body'], null, $options) === false) { + $subject = FeedbackMail::oneLine((string) $msg['subj']); + if ($email->send($owner, $subject, (string) $msg['body'], null, $options) === false) { FeedbackStore::failed($id); + FeedbackActions::failedNote($ticket, $to); + return; } + FeedbackActions::sentNote($ticket, $s, $to, $expires, $subject, (string) $msg['body']); } catch (\Throwable $e) { FeedbackStore::failed($id); self::log('send', $e); + if ($ticket) { + try { + FeedbackActions::failedNote($ticket, $to); + } catch (\Throwable $e2) { + self::log('note', $e2); + } + } } } @@ -224,6 +239,7 @@ public static function facts(Ticket $ticket): array 'child' => (int) $ticket->getPid() > 0, 'dept' => (int) $ticket->getDeptId(), 'topic' => (int) $ticket->getTopicId(), + 'status' => (int) $ticket->getStatusId(), 'email' => $email, 'own_domains' => self::ownDomains(), 'human_replies' => self::humanReplies($ticket), diff --git a/tests/e2e/8-status-note.spec.js b/tests/e2e/8-status-note.spec.js new file mode 100644 index 0000000..38d2ea5 --- /dev/null +++ b/tests/e2e/8-status-note.spec.js @@ -0,0 +1,64 @@ +// @ts-check +// 0.1.1: closing statuses that never ask, and the note after a sent question. +const { test, expect } = require('@playwright/test'); +const { seed, newTicket, reply, close, setStatus, row, notes, setting, clearMail, feedbackMails, links, resetSettings } + = require('./support'); + +test.beforeEach(async ({ request }) => { + resetSettings(); + await clearMail(request); +}); + +const sentNote = (id) => notes(id).find((n) => n.title === 'Zufriedenheitsfrage'); + +test('excluded closing status: no mail, no row, a later normal close still asks', async ({ request }) => { + setting('exclude_statuses', JSON.stringify({ [seed.status.resolved]: 'Resolved' })); + const id = newTicket('0.1.1 excluded status'); + reply(id, 'hanna', 'Dublette, bitte im anderen Ticket weiter.'); + expect(setStatus(id, 'hanna', seed.status.resolved)).toBe('ok'); + expect(await feedbackMails(request, id)).toHaveLength(0); + expect(row(id)).toBeNull(); + expect(sentNote(id)).toBeUndefined(); + + setStatus(id, 'hanna', seed.status.open); + expect(close(id)).toBe('ok'); + expect(await feedbackMails(request, id)).toHaveLength(1); +}); + +test('short note (default): recipient, scale and validity, no links', async ({ request }) => { + const id = newTicket('0.1.1 short note'); + reply(id, 'hanna', 'Erledigt.'); + close(id); + expect(await feedbackMails(request, id)).toHaveLength(1); + await expect.poll(() => sentNote(id)).toBeDefined(); + const n = sentNote(id); + expect(n.body).toContain('Zufriedenheitsfrage per Mail gesendet an alice@acme.example'); + expect(n.body).toContain('Skala: Daumen'); + expect(n.body).not.toContain('/ajax.php/feedback/'); +}); + +test('full note: the mail as sent, with working links and the button words', async ({ request }) => { + setting('note_sent', 'full'); + const id = newTicket('0.1.1 full note'); + reply(id, 'hanna', 'Erledigt.'); + close(id); + const fb = await feedbackMails(request, id); + expect(fb).toHaveLength(1); + await expect.poll(() => sentNote(id)).toBeDefined(); + const n = sentNote(id); + expect(n.body).toContain('Gesendete Mail'); + expect(n.body).toContain('Nicht gut'); + // The same links as in the mail. + const sent = links(fb[0].html); + expect(n.body).toContain(sent[0]); + expect(n.body).toContain(sent[1]); +}); + +test('note switched off: nothing at the ticket', async ({ request }) => { + setting('note_sent', 'off'); + const id = newTicket('0.1.1 no note'); + reply(id, 'hanna', 'Erledigt.'); + close(id); + expect(await feedbackMails(request, id)).toHaveLength(1); + expect(sentNote(id)).toBeUndefined(); +}); diff --git a/tests/unit.php b/tests/unit.php index 20739c7..cc8dd35 100644 --- a/tests/unit.php +++ b/tests/unit.php @@ -57,8 +57,8 @@ function check(string $name, bool $ok, string $detail = ''): void && $builtIn['bad_stars'] === 2 && $builtIn['bad_nps'] === 6); check('config: off until switched on', $builtIn['enabled'] === false); foreach (array('enabled', 'mode', 'scale', 'on_bad', 'bad_stars', 'bad_nps', 'valid_days', 'exclude_depts', 'exclude_topics', - 'exclude_domains', 'exclude_own', 'comment_on', 'language', 'subject', 'text', 'question', 'line', 'foot_on', - 'foot', 'accent') as $k) { + 'exclude_statuses', 'exclude_domains', 'exclude_own', 'comment_on', 'note_sent', 'language', 'subject', 'text', + 'question', 'line', 'foot_on', 'foot', 'accent') as $k) { check("config: field $k exists", isset($opts[$k])); } @@ -82,6 +82,13 @@ function check(string $name, bool $ok, string $detail = ''): void check('settings: checkbox values', FeedbackSettings::normalise(array('enabled' => '0'))['enabled'] === false && FeedbackSettings::normalise(array('enabled' => true))['enabled'] === true && FeedbackSettings::normalise(array('comment_on' => ''))['comment_on'] === false); +check('settings: note after sending is short by default, unknown falls back', + FeedbackSettings::normalise(array())['note_sent'] === 'short' + && FeedbackSettings::normalise(array('note_sent' => 'full'))['note_sent'] === 'full' + && FeedbackSettings::normalise(array('note_sent' => 'off'))['note_sent'] === 'off' + && FeedbackSettings::normalise(array('note_sent' => 'loud'))['note_sent'] === 'short'); +check('settings: closing statuses from a multiselect', FeedbackSettings::normalise(array('exclude_statuses' => '{"3":"Hinfällig"}'))['exclude_statuses'] === array(3) + && FeedbackSettings::normalise(array())['exclude_statuses'] === array()); // -------------------------------------------------------------------- scale @@ -189,10 +196,27 @@ function check(string $name, bool $ok, string $detail = ''): void check('agent mail: comment escaped with line breaks', strpos($agent['body'], 'Gar <nicht> gut') === false); +$full = FeedbackMail::sentNote(FeedbackSettings::normalise(array('note_sent' => 'full')), $de, 'kim@acme.example', $exp, + 'Kurze Frage [001]', $mail['body']); +check('sent note: full carries the mail with both links', strpos($full, '
') !== false && substr_count($full, '?v=') === 2 + && strpos($full, 'Kurze Frage [001]') !== false); +check('sent note: full keeps the button words, drops the emojis (3-byte utf8)', strpos($full, 'Nicht gut') !== false + && stripos($full, 'ὄ') === false && preg_match('/[\x{10000}-\x{10FFFF}]/u', $full) === 0); +check('sent note: recipient escaped', strpos(FeedbackMail::sentNote($s, $de, 'x', $exp, '', ''), '') === false); +check('beyond BMP: entities and literals removed, the rest kept', FeedbackMail::noBeyondBmp('a 👍 b 👎 c 👍 d ★ &') + === 'a b c d ★ &', FeedbackMail::noBeyondBmp('a 👍 b 👎 c 👍 d ★ &')); +check('i18n: no 4-byte characters in the sent notes', preg_match('/[\x{10000}-\x{10FFFF}]/u', + $de['note_sent_title'] . $de['note_sent'] . $de['note_mail'] . $de['note_failed']) === 0); + // -------------------------------------------------------------------- rules $on = FeedbackSettings::normalise(array('enabled' => '1', 'exclude_depts' => array(9), 'exclude_topics' => array(4), - 'exclude_domains' => 'partner.example')); + 'exclude_domains' => 'partner.example', 'exclude_statuses' => array(3))); $facts = array('closed' => true, 'child' => false, 'dept' => 1, 'topic' => 1, 'email' => 'alice@acme.example', 'own_domains' => array('support.example.com', 'example.com'), 'human_replies' => 1, 'ai_closer' => false, 'asked' => false); check('rules: plain case asks', FeedbackRules::skipReason($on, $facts) === ''); @@ -205,6 +229,7 @@ function check(string $name, bool $ok, string $detail = ''): void 'no_reply' => array($on, array('human_replies' => 0)), 'dept' => array($on, array('dept' => 9)), 'topic' => array($on, array('topic' => 4)), + 'status' => array($on, array('status' => 3)), 'no_email' => array($on, array('email' => '')), ); foreach ($cases as $reason => $c) { From b05bdd9ed5c563db67f92e4aee32f73cbc918889 Mon Sep 17 00:00:00 2001 From: studio-prisma <282898618+studio-prisma@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:56:15 +0100 Subject: [PATCH 2/2] chore(release): v0.1.1 --- CHANGELOG.md | 16 +++++++++++++++- plugin.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a39cb16..0521a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.1] - 2026-11-08 + +### Added + +- **Closing statuses that never ask** (setting "Never ask for → Closing statuses"). Preselected: closed statuses named like "Duplicate", "Spam", "Rejected" or "Hinfällig". Closing with such a status leaves no trace; a later close with another status still asks. +- **Note at the ticket when asked** (own mail mode): short (recipient, scale, valid until; default), short plus the mail as sent with its rating links, or none. +- **Note on a failed send**, always: the question couldn't be sent and isn't retried. + +### Documentation + +- INSTALL: after creating the instance, open it again and check the checkboxes. osTicket 1.18 doesn't store checkbox defaults on the first save. +- INSTALL: new settings apply their built-in default until the instance is saved once. + ## [0.1.0] - 2026-11-03 ### Added @@ -22,5 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Retention: rows are deleted after 24 months; the IP is stored only as a keyed hash. - Mail in the style of a brand line over an accent rule, buttons as table cells, a grey footer with an AI notice; texts editable, German (informal) and English built in. -[Unreleased]: https://github.com/studio-prisma/osticket-plugin-feedback/compare/v0.1.0...HEAD +[Unreleased]: https://github.com/studio-prisma/osticket-plugin-feedback/compare/v0.1.1...HEAD +[0.1.1]: https://github.com/studio-prisma/osticket-plugin-feedback/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/studio-prisma/osticket-plugin-feedback/releases/tag/v0.1.0 diff --git a/plugin.php b/plugin.php index 9f5150d..b18067f 100644 --- a/plugin.php +++ b/plugin.php @@ -9,7 +9,7 @@ return array( 'id' => 'studio-prisma:feedback', - 'version' => '0.1.0', + 'version' => '0.1.1', 'ost_version' => '1.18', 'name' => 'Feedback', 'author' => 'Studio Prisma',