Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebf48b0707 | ||
|
|
30e644a001 | ||
|
|
860e8b7bbb | ||
|
|
1ffc0765ea | ||
|
|
578b235f08 | ||
|
|
27717205cd | ||
|
|
ed684cca4f | ||
|
|
0904292c73 | ||
|
|
e84123654e | ||
|
|
ada16cb101 | ||
|
|
7c7c52cb1c | ||
|
|
dfec88d396 | ||
|
|
28b4edc811 | ||
|
|
0e66319a06 | ||
|
|
43648f3728 | ||
|
|
ce749e63a4 | ||
|
|
b203ba35f8 | ||
|
|
ef973af4b5 | ||
|
|
a95d5e2d8a | ||
|
|
2d2f3ca19c | ||
|
|
a6dde35249 | ||
|
|
7ca728e79c | ||
|
|
be6faa7b42 | ||
|
|
131ef2e938 | ||
|
|
b4057809ed |
No files matched your search
@@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: gitea-runner-server03
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['8.2', '8.3', '8.4']
|
||||
php-version: ['8.4', '8.5']
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.3'
|
||||
php-version: '8.4'
|
||||
extensions: sqlite, pdo_sqlite
|
||||
coverage: none
|
||||
|
||||
|
||||
@@ -1,157 +1,157 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
Leitfaden für Claude Code (claude.ai/code) in diesem Repository.
|
||||
|
||||
## What this is
|
||||
## Worum es geht
|
||||
|
||||
A Nextcloud app (`workflow_deck_automation`, namespace `WorkflowDeckAutomation`) targeting **Nextcloud Hub 26 Spring (server 34.x)**. It lets each user configure, from their personal settings, automation "workflows" that move overdue [Deck](https://github.com/nextcloud/deck) cards from one stack to another, with optional assigned-user/label filters and an email notification. A background `TimedJob` evaluates all enabled workflows every 5 minutes.
|
||||
Nextcloud-App `workflow_deck_automation` (Namespace `WorkflowDeckAutomation`) für **Nextcloud 35** (`main`, `min-version="35" max-version="35"`). Jeder Nutzer legt in seinen persönlichen Einstellungen „Workflows“ an, die überfällige [Deck](https://github.com/nextcloud/deck)-Karten von einem Stack in einen anderen verschieben, optional mit Mail. Es gibt bewusst **keine Kartenfilter**: ein Workflow verschiebt *jede* überfällige Karte seines Quell-Stacks. Ein Hintergrund-`Job` wertet alle aktiven Workflows bei jedem Cron-Lauf aus.
|
||||
|
||||
## Non-negotiable architectural constraint
|
||||
## Harte Vorgabe: keine HTTP/OCS-Aufrufe gegen Deck
|
||||
|
||||
**No HTTP/OCS calls against Deck, anywhere.** Every read (boards, stacks, cards, labels, assigned users) and the card move itself must go through Deck's own internal PHP classes (`OCA\Deck\Service\CardService`, `StackService`, `BoardService`, `OCA\Deck\Db\CardMapper`, …), resolved in-process via `\OCP\Server::get()`. This was an explicit, repeated product requirement from the user — do not "fix" it by switching to `IClientService`/`curl` against `/ocs/...`, even though that would be the more conventional cross-app integration approach.
|
||||
Alle Lesezugriffe (Boards, Stacks, Karten) und das Verschieben laufen über Decks interne PHP-Klassen (`OCA\Deck\Service\*`, `OCA\Deck\Db\*`), in-process per `\OCP\Server::get()`. Das ist eine ausdrückliche, wiederholte Anforderung des Nutzers – nicht auf `IClientService`/`curl` gegen `/ocs/...` „umbauen“.
|
||||
|
||||
All Deck access is funneled through `lib/Service/DeckIntegrationService.php` — it is the *only* class that references `OCA\Deck\*`. If you need new Deck data, extend that class rather than reaching into Deck internals from elsewhere. Every call in there is wrapped (`class_exists()` checks, `IAppManager::isEnabledForUser('deck', …)`, try/catch → `DeckUnavailableException`) because `OCA\Deck\*` is not a documented/stable public API — it has no `@since` markers and can change between Deck releases without notice.
|
||||
**Nur `lib/Service/DeckIntegrationService.php` referenziert `OCA\Deck\*`.** Neue Deck-Daten → diese Klasse erweitern. Jeder Aufruf dort ist abgesichert (`class_exists()`, `IAppManager::isEnabledForUser('deck', …)`, try/catch → `DeckUnavailableException`), weil `OCA\Deck\*` keine stabile, dokumentierte API ist (keine `@since`-Marker).
|
||||
|
||||
## Per-user impersonation in the background job
|
||||
## Impersonation im Hintergrundjob – Decks eingefrorene `$userId`
|
||||
|
||||
Deck's ACL/permission checks read the *live* `IUserSession`, not a value frozen at construction. `RunWorkflowsJob` (a `TimedJob`) has no logged-in user by default and must evaluate workflows belonging to many different users within one PHP process. `lib/Service/WorkflowRunner.php` therefore groups workflows by owner and, per owner, temporarily impersonates them (`IUserSession::setUser()`, restored in a `finally`) before touching Deck. Don't remove this — without it, Deck's permission checks inside the cron run would be evaluated against no user (or the wrong user).
|
||||
`WorkflowRunner` gruppiert Workflows nach Owner und impersoniert jeden nacheinander, in zwei Schritten (beide im `finally` via `clearImpersonation()` zurückgesetzt):
|
||||
|
||||
The filter-matching logic (`WorkflowRunner::cardMatchesFilters()`, `::isOverdue()`) is deliberately `static` and side-effect-free so it's unit-testable without a real Deck installation — see `tests/Unit/Service/WorkflowRunnerFilterTest.php`.
|
||||
1. `IUserSession::setUser()` + `IRootFolder::getUserFolder()` – für die wenigen Dienste, die die Session lesen. Nebensächlich.
|
||||
2. `DeckIntegrationService::beginUserContext()` – **der tragende Teil.**
|
||||
|
||||
**Not everything in Deck reads the live session, though.** `BoardService` takes the current user as `private ?string $userId` — a plain string frozen when the container builds it. `getUserBoards()` uses exactly that, so in the background job (one process, many users, a container-cached `BoardService`) it answers for whoever happened to be impersonated at first resolution, or for `null`. `listBoardsForCurrentUser()` is therefore **request-only**; the job asks `findStackIds()` instead, which goes through `StackService::findAll()` → `PermissionService` → live session. Before using any other `OCA\Deck\*` service from the runner, check which of the two kinds it is — the failure mode is silent and user-crossing, not an error.
|
||||
**Deck liest für Berechtigungen nie die Session.** `PermissionService` (hinter jeder Prüfung, auch in `CardService::reorder()`), `CardService`, `BoardService` und `ActivityManager` halten `private ?string $userId` aus dem `userId`-Service des Deck-Containers – *shared*, also einmal pro Prozess aufgelöst. Im Cron ist das nie der impersonierte Nutzer, sondern `null` (wenn vorher ein Deck-Job lief) oder der erste Owner. `null` lässt jede Prüfung mit `NoPermissionException` scheitern.
|
||||
|
||||
## Workflows are auto-disabled when their Deck targets vanish
|
||||
`beginUserContext()` überschreibt daher das private Feld per Reflection und `endUserContext()` stellt es wieder her. `PermissionService` ist Pflicht: klappt das Pinnen nicht, wirft die Methode und der Runner **überspringt den Nutzer komplett**. Die anderen drei sind best effort (nur Activity-Zuordnung/Unread-Zähler).
|
||||
|
||||
`WorkflowRunner::findBrokenTarget()` checks board and stacks before every run and, if something is gone, switches the workflow off (`enabled = false`) and sends a one-off mail. Two invariants hold this together and must survive refactors:
|
||||
**Regel:** Bevor ein weiterer `OCA\Deck\*`-Dienst im Runner genutzt wird, prüfen, ob er eine eingefrorene `$userId` trägt – der Fehler ist still und nutzerübergreifend. Bevorzugt Mapper (QBMapper ohne Nutzerzustand) oder Methoden mit explizitem uid-Parameter verwenden. Deshalb wird `BoardService::getUserBoards()` nicht verwendet.
|
||||
|
||||
- **Only positive knowledge disables.** `DeckIntegrationService::findStackIds()` returns `null` only for "board missing/not readable" (`DoesNotExistException`, Deck's `NoPermissionException`/`NotFoundException`) and *throws* for everything else. The runner skips the workflow on a throw. If you make that method degrade to `[]`/`null` on generic errors, a Deck outage will disable every workflow on the instance and mail every user about it.
|
||||
- **The mail ignores the `notifyEmail` flag** — that flag is about moved cards; this is a notice that the user's configuration stopped working. It stays a one-off simply because a disabled workflow is not picked up by `findAllEnabled()` again.
|
||||
Die Fälligkeitslogik `WorkflowRunner::isOverdue()` und die Empfängerregel `NotificationPolicy::shouldNotify()` sind bewusst `static` und seiteneffektfrei, also ohne Deck unit-testbar (`tests/Unit/Service/`). Das sind die einzigen getesteten Teile der App. Neue reine Logik in dieser Form halten.
|
||||
|
||||
Archived boards deliberately do *not* trigger this (they stay readable, so `findStackIds()` succeeds), even though they're filtered out of the settings dropdowns.
|
||||
## Workflows werden deaktiviert, wenn Board/Stack verschwinden
|
||||
|
||||
## Job interval comes from config.php
|
||||
`WorkflowRunner::findBrokenTarget()` prüft vor jedem Lauf Board und Stacks; fehlt etwas, wird der Workflow abgeschaltet (`enabled = false`) und einmalig gemailt. Invarianten:
|
||||
|
||||
`RunWorkflowsJob` reads `workflow_deck_automation.interval` (seconds, default 300, clamped to a 60s minimum) via `IConfig::getSystemValueInt()` in its constructor. That works *because* `TimedJob` re-reads `$this->interval` on every cron pass from the freshly constructed job — so editing `config.php` takes effect immediately, with no `occ` command and no re-registration. Don't move this into `appinfo/info.xml` or a stored app config; the constants (`INTERVAL_CONFIG_KEY`, `DEFAULT_INTERVAL`, `MINIMUM_INTERVAL`) on the job are the single source of truth and are referenced from the README.
|
||||
- **Nur positives Wissen deaktiviert.** `findStackIds()` liefert `null` nur bei „Board-Zeile weg“ (`DoesNotExistException`, Decks `NotFoundException`), „Board im Papierkorb“ (`deleted_at > 0`) oder „uid hat keine Leserechte“ – alles andere *wirft*, und der Runner überspringt den Workflow. Degradiert die Methode auf `[]`/`null`, deaktiviert ein Deck-Ausfall alle Workflows der Instanz und mailt alle Nutzer an.
|
||||
- **`findStackIds()` fragt nie einen Deck-Dienst, *wer* fragt.** Sie bekommt die uid als Argument und nutzt nur `BoardMapper`/`StackMapper` plus `PermissionService::getPermissions($boardId, $userId)` mit expliziter uid. Nicht zu `StackService::findAll($boardId)` „vereinfachen“ – genau das prüfte gegen die eingefrorene `null`-uid, warf `NoPermissionException`, wurde als „Board weg“ gelesen und verschickte Deaktivierungsmails für intakte Boards.
|
||||
- **`NoPermissionException` beweist nichts** und steht deshalb bewusst nicht in `isMissing()`.
|
||||
- **Die Deaktivierungsmail ignoriert `notifyMode`** (das betrifft verschobene Karten) und geht immer nur an den Owner. Sie bleibt einmalig, weil `findAllEnabled()` deaktivierte Workflows nicht mehr lädt.
|
||||
|
||||
**The job must stay `IJob::TIME_SENSITIVE`.** It was `TIME_INSENSITIVE` at first, which looked harmless and was not: `OC\Core\Service\CronService::runCli()` reads `maintenance_window_start` (default `100`, i.e. unset) and, whenever the current UTC hour is outside `[start, start+4]`, calls `jobList->getNext($onlyTimeSensitive = true)` — time-insensitive jobs are then skipped for the other 20 hours of the day. On an instance with a maintenance window configured (Nextcloud's admin overview nags admins into setting one) the job simply never ran, showing `last_run = 1970-01-01` in `occ background-job:list` indefinitely. Note this gate only exists in `runCli()`, so it doesn't apply to ajax/webcron mode, and passing job classes explicitly (`occ background-job:worker '<class>'`) bypasses it — which is exactly why manual testing can look fine while cron does nothing.
|
||||
Archivierte Boards lösen das nicht aus (sie bleiben lesbar), werden aber in den Dropdowns ausgeblendet.
|
||||
|
||||
**Changing the sensitivity in code does not fix an already-registered job.** `getNext()` filters on the `time_sensitive` *column* of `oc_jobs`, and `JobList::setLastRun()` is a one-way ratchet:
|
||||
## Ein Workflow gehört dem Board-Owner, nicht seinem Ersteller
|
||||
|
||||
```php
|
||||
if ($job instanceof TimedJob && !$job->isTimeSensitive()) {
|
||||
$query->set('time_sensitive', $query->createNamedParameter(IJob::TIME_INSENSITIVE));
|
||||
}
|
||||
```
|
||||
Wird ein Board in Deck übertragen, wandern seine Workflows mit.
|
||||
|
||||
There is no `else`. Once a job has run while declaring itself insensitive, the row is stamped `TIME_INSENSITIVE` for good — and nothing resets it: `JobList::add()` only writes the column in its *insert* branch, and re-registering an existing job (app update, `app:enable`) takes the *update* branch, which leaves it alone. So after deploying the `TIME_SENSITIVE` change, an existing instance still needs its row fixed once:
|
||||
- **„Meine Boards“** = `listOwnedBoards($uid)` → `BoardMapper::findAllByOwner($uid)` (keine geteilten Boards, keine eingefrorene uid). Diese Mapper-Methode filtert weder Papierkorb noch Archiv: Papierkorb-Boards werden verworfen, archivierte mit `archived: true` behalten (Workflows sichtbar, aber nicht im Dropdown, von `validate()` abgelehnt). Wirft statt `[]` zurückzugeben – `[]` würde alle Workflows des Nutzers verstecken.
|
||||
- **Auflisten/Bearbeiten/Löschen** nur über `board_id IN (listOwnedBoards)` (`WorkflowMapper::findAllForBoards()`, `WorkflowController::findOwnWorkflow()`). `user_id` spielt keine Rolle – keine `user_id`-Abfragen im Controller wieder einführen.
|
||||
- **Anlegen/Speichern** validiert gegen dieselbe Liste und setzt `user_id` auf den aktuellen Nutzer.
|
||||
- **Runner:** `followBoardOwner()` → `findBoardOwner()` (`BoardMapper::find()`) schreibt einen abweichenden Owner in `user_id` zurück. Lauf und Mails gehen also an den aktuellen Owner. Ein verschwundenes Board behält den letzten Owner, damit `findBrokenTarget()` ihn anmailen kann.
|
||||
|
||||
`user_id` heißt also nur „als wer läuft der Job / wer bekommt Mail“.
|
||||
|
||||
## Mails über verschobene Karten folgen Decks Benachrichtigungseinstellung
|
||||
|
||||
`notify_mode` (`NotificationPolicy::MODES`) ersetzt seit `Version1002…`/`Version1003…` das frühere `notify_email` (`true` → `owner`):
|
||||
|
||||
- `off`: keine Mail. `owner`: nur der Board-Owner, ohne Rücksicht auf seine Deck-Einstellung (altes Verhalten).
|
||||
- `board`: alle Board-Berechtigten, gefiltert nach deren Deck-Nutzereinstellung `deck` / `board:<id>:notify-due` (`off`/`assigned`/`all`, Default `assigned`). `NotificationPolicy::shouldNotify()` bildet Decks Regel aus `NotificationHelper::sendCardDuedate()` nach und ist reine, getestete Logik. Dazu gehört: Der Owner eines ungeteilten Boards wird außer bei `off` immer benachrichtigt.
|
||||
- `DeckIntegrationService::findNotificationRecipients()` nutzt nur uid-explizite Bausteine: `PermissionService::findUsers($boardId, true)` (Owner + ACL, löst Gruppen/Circles auf, `true` umgeht den Prozess-Cache), `AssignmentMapper::isUserAssigned()` (auch Gruppen-/Circle-Zuweisungen) und `IConfig`. `FederatedUser` wird übersprungen. Bei jedem Fehler wirft die Methode, und der Runner verschickt dann **keine** Mail, statt an eine falsch aufgelöste Empfängerliste zu schicken.
|
||||
- Der Runner sammelt verschobene Karten in `$pendingMails` und verschickt **nach** der Nutzer-Schleife (also ohne Impersonation) eine Sammelmail pro Empfänger und Lauf.
|
||||
|
||||
## Nur Deutsch, keine Übersetzungen
|
||||
|
||||
Die App wird nur intern genutzt und spricht ausschließlich Deutsch. Oberfläche, Controller-Fehlermeldungen (erscheinen im Formular), Sektionsname und Mails sind direkt auf Deutsch geschrieben. Es gibt kein `IL10N` und keinen `l10n/`-Ordner. Nextclouds eigene Mail-Fußzeile wird per `addFooter('', 'de')` ebenfalls deutsch, sonst würde sie im Cron der Instanz-Standardsprache folgen. Log-Meldungen bleiben englisch. Neue nutzersichtbare Texte auf Deutsch schreiben, mit „du“ wie im Rest der App.
|
||||
|
||||
## Fälligkeit wird als UTC-Zeitpunkt verglichen
|
||||
|
||||
Decks `duedate` ist eine `DATETIME`-Spalte ohne Zeitzone mit UTC-Uhrzeit (Frontend sendet `toISOString()`). `Entity` baut daraus `new \DateTime($string)` in PHPs Standardzone, die Nextcloud auf UTC setzt. `WorkflowRunner::asStoredUtc()` legt die Uhrzeit trotzdem ausdrücklich auf UTC fest, damit das Ergebnis nicht von dieser Standardzone abhängt. Decks eigene Pfade `Card::getDaysUntilDue()` (tagesgenau) und `CardMapper::findOverdue()` (vergleicht mit dem `NOW()` der Datenbank, also Ortszeit) sind dafür ungeeignet und werden nicht verwendet.
|
||||
|
||||
## Kartenfilter wurden entfernt
|
||||
|
||||
Die früheren Filter (`filter_user_ids`/`filter_label_ids`) wurden auf Wunsch entfernt. `Version1001Date20260930120000` löscht die Spalten, und gefilterte Workflows laufen seitdem *ungefiltert* weiter (bewusste Entscheidung). Die Spalten müssen gelöscht bleiben: `Entity::fromRow()` ruft pro Spalte einen Setter auf, den `Workflow` nicht mehr hat. Mit entfernt wurden: Labels-/Participants-Endpunkte, `listLabels()`/`listParticipants()`/`findFilterOptions()` und `CardService::enrichCards()` in `getActiveCardsInStack()` (lief über `BoardService::find()` mit eingefrorener uid). Die Karten dort sind also **nicht angereichert** (keine `assignedUsers`/Labels).
|
||||
|
||||
## Der Job hat kein Intervall
|
||||
|
||||
`RunWorkflowsJob` erweitert `OCP\BackgroundJob\Job`, **nicht** `TimedJob`: ein Lauf pro Cron-Durchgang, kein Intervall, keine Konfiguration (der frühere `config.php`-Schlüssel `workflow_deck_automation.interval` ist seit v0.2.0 weg). Nicht wieder einführen.
|
||||
|
||||
**Zeitkritikalität entscheidet, ob der Job überhaupt läuft.** `CronService::runCli()` holt außerhalb des Wartungsfensters (`maintenance_window_start` … +4 h UTC) nur zeitkritische Jobs (`getNext($onlyTimeSensitive = true)`). Eine frühere Version war `TIME_INSENSITIVE` und lief auf Instanzen mit Wartungsfenster nie (`last_run = 1970-01-01`). Manuelle Tests (`background-job:worker '<Klasse>'`, Ajax/Webcron) umgehen dieses Gate, deshalb wirkt dort alles normal.
|
||||
|
||||
Als einfacher `Job` ist das ausgeschlossen: `JobList::add()` schreibt die Spalte `time_sensitive` nicht (Default `TIME_SENSITIVE`), und nur `JobList::setLastRun()` senkt sie – ausschließlich für `TimedJob && !isTimeSensitive()`, ohne Rückweg. Alte, einmal als insensitive gestempelte Zeilen bleiben es (auch nach App-Update). Einmalig reparieren:
|
||||
|
||||
```sql
|
||||
UPDATE oc_jobs SET time_sensitive = 0
|
||||
WHERE class = 'OCA\\WorkflowDeckAutomation\\BackgroundJob\\RunWorkflowsJob';
|
||||
```
|
||||
|
||||
or, without DB access, `occ background-job:delete <id>` followed by `occ app:disable workflow_deck_automation && occ app:enable workflow_deck_automation` to get a freshly inserted row. Fresh installs are unaffected.
|
||||
oder `occ background-job:delete <id>`, dann `occ app:disable workflow_deck_automation && occ app:enable workflow_deck_automation`.
|
||||
|
||||
To debug this job on a server: `occ background-job:list --class '<class>'` for its id and last run, then `occ background-job:execute <id> --force-execute` to run it right now regardless of the interval. `occ background-job:worker` takes **job classes**, not an app id.
|
||||
Debuggen: `occ background-job:list --class '<Klasse>'` (ID, letzter Lauf), dann `occ background-job:execute <id> --force-execute`. `background-job:worker` erwartet **Job-Klassen**, keine App-ID.
|
||||
|
||||
## Registration is declarative, not Bootstrap-based
|
||||
## Registrierung deklarativ statt über Bootstrap
|
||||
|
||||
Background jobs and classic personal settings are registered in `appinfo/info.xml` (`<background-jobs>`, `<settings><personal>/<personal-section>`), **not** via `IRegistrationContext` in `lib/AppInfo/Application.php` — that interface has no `registerBackgroundJob()`/`registerSettings()` methods on NC 34. `Application.php` is intentionally near-empty.
|
||||
Hintergrundjob und persönliche Einstellungen stehen in `appinfo/info.xml` (`<background-jobs>`, `<settings><personal>/<personal-section>`). `IRegistrationContext` hat dafür keine Methoden. `lib/AppInfo/Application.php` ist absichtlich fast leer.
|
||||
|
||||
## Commands
|
||||
## Architektur
|
||||
|
||||
**PHP and npm are not available in the local dev sandbox this repo is normally edited from.** Do not try to run `composer`, `php`, or `npm` locally to verify changes — they will fail with "command not found". Verification happens by pushing to `main` (or opening a PR) and checking the Gitea Actions run; the self-hosted runner tag is `gitea-runner-server03` (see `.gitea/workflows/*.yml`, all pinned to that `runs-on:` label).
|
||||
- **UI:** `src/PersonalSettings.vue` (Vue 3), gemountet aus `templates/settings/personal.php` (Sektion: `lib/Settings/PersonalSection.php` + `Personal.php`) → `src/api.js` → `lib/Controller/WorkflowController.php` (`OCSController`, Routen in `appinfo/routes.php`, `/ocs/v2.php/apps/workflow_deck_automation/api/v1/...`).
|
||||
- **Speicher:** `lib/Db/Workflow.php` / `WorkflowMapper.php`, Tabelle `wfda_workflows` (Migrationen in `lib/Migration/`).
|
||||
- **Automation:** `RunWorkflowsJob` → `WorkflowRunner` → `DeckIntegrationService` (alle Deck-Aufrufe) und `NotificationMailer` (`IMailer`, an die Account-Adressen der Empfänger, nie an eine eingegebene Adresse).
|
||||
- Controller (Dropdowns) und Runner (Karten lesen/verschieben) nutzen denselben `DeckIntegrationService`.
|
||||
|
||||
Commands as they'd run in CI/on a machine that has the tools:
|
||||
## Befehle und Verifikation
|
||||
|
||||
**Lokal gibt es kein PHP und kein npm** (Windows, siehe `CLAUDE.local.md`) – `composer`/`php`/`npm` nicht lokal ausführen. Verifiziert wird über Push/PR und den Gitea-Actions-Lauf (Runner `gitea-runner-server03`).
|
||||
|
||||
```bash
|
||||
composer install
|
||||
composer run lint # php -l over lib/ and tests/
|
||||
composer run cs:check # nextcloud/coding-standard (php-cs-fixer); composer run cs:fix to auto-fix
|
||||
composer run test:unit # PHPUnit — pure logic only, no live Deck/Nextcloud instance needed
|
||||
composer run lint # php -l über lib/ und tests/
|
||||
composer run cs:check # nextcloud/coding-standard; cs:fix korrigiert
|
||||
composer run test:unit # PHPUnit, nur reine Logik
|
||||
vendor/bin/phpunit --filter <testName> tests/Unit/Service/WorkflowRunnerTest.php
|
||||
|
||||
npm install # no package-lock.json is committed (gitignored) — use install, not `npm ci`
|
||||
npm run build # production build
|
||||
npm run watch # rebuild on change during development
|
||||
npm install # nicht `npm ci`: Lockfiles sind absichtlich nicht committet
|
||||
npm run build # bzw. npm run watch
|
||||
```
|
||||
|
||||
To run a single PHPUnit test: `vendor/bin/phpunit --filter testUserFilterIsOrAgainstAssignedUsers tests/Unit/Service/WorkflowRunnerFilterTest.php`.
|
||||
`composer.lock` und `package-lock.json` stehen in `.gitignore` → CI muss `composer install`/`npm install` verwenden (`npm ci` hat den Build schon einmal gebrochen). Die Deck-Integration lässt sich nur auf einer echten Nextcloud+Deck-Instanz testen.
|
||||
|
||||
There is no meaningful way to test the Deck integration itself outside a real Nextcloud+Deck instance (`php occ background-job:worker 'OCA\WorkflowDeckAutomation\BackgroundJob\RunWorkflowsJob'` — the argument is a job *class*, not an app id) — the unit tests intentionally stop at the pure filter logic.
|
||||
## Release und CI
|
||||
|
||||
### Release process
|
||||
**Versionsschema:** `<Nextcloud-Major>.<minor>.<patch>`. Die erste Zahl entspricht `min-/max-version` in `info.xml` und ändert sich nur mit der unterstützten NC-Major (dann `minor.patch` = `0.0`). `0.x`-Versionen stammen aus der Zeit davor. Die 34er-Linie existiert nur noch als Tags (`v34.*`). Kein Branch.
|
||||
|
||||
1. Bump `<version>` in `appinfo/info.xml` and `version` in `package.json` (keep them in sync).
|
||||
2. Commit, push to `main`, confirm the run of `.gitea/workflows/build-main.yml` is green.
|
||||
3. `git tag vX.Y.Z && git push origin vX.Y.Z` — this triggers the tag branch of the same workflow, which re-runs the checks, builds the frontend, runs `make appstore`, and attaches `workflow_deck_automation.tar.gz` as the asset on a normal (non-pre-) release for that tag.
|
||||
1. `<version>` in `appinfo/info.xml` und `version` in `package.json` synchron erhöhen.
|
||||
2. Committen, nach `main` pushen, `build-main.yml` muss grün sein.
|
||||
3. `git tag vX.Y.Z && git push origin vX.Y.Z` → Checks, Frontend-Build, `make appstore`, Release mit `workflow_deck_automation.tar.gz`.
|
||||
|
||||
**If the tagged build fails and no artifact was ever produced**, fix the issue on `main` and *move* the existing tag to the fixed commit instead of bumping to a new version number (`git tag -d vX.Y.Z && git tag -a vX.Y.Z -m "..." && git push origin :refs/tags/vX.Y.Z && git push origin vX.Y.Z`) — this is how `v0.1.0` was handled through several build fixes before it first built successfully. The job deletes any pre-existing *release* for the tag before creating the new one, so a moved tag republishes cleanly instead of failing on a duplicate asset name. Once a version has actually produced a published artifact, don't move its tag anymore; bump normally instead.
|
||||
Ist ein Tag-Build fehlgeschlagen und **nie ein Artefakt entstanden**, den Tag auf den Fix verschieben statt die Version zu erhöhen (`git tag -d vX.Y.Z && git tag -a vX.Y.Z -m "..." && git push origin :refs/tags/vX.Y.Z && git push origin vX.Y.Z`). Der Job löscht ein vorhandenes Release vorher. Nach einem veröffentlichten Artefakt den Tag nicht mehr verschieben.
|
||||
|
||||
**No `actions/upload-artifact` anywhere — and don't reintroduce it.** This self-hosted Gitea instance identifies as GHES to the official `actions/*` JS actions, which refuse to run `@actions/artifact` v2.0.0+ (used internally by `upload-artifact@v4` and later) against GHES: `GHESNotSupportedError`, which pinned us to `@v3` for a while. Publishing through the Gitea release REST API with `curl` sidesteps that version-specific backend API entirely, so the build workflow uses that instead. `actions/checkout` and `actions/setup-node` were never affected — only the artifact upload/download actions are, because they're the ones talking to a versioned backend rather than just running local commands — and can stay on their latest majors.
|
||||
**`.gitea/workflows/build-main.yml` ist der einzige Workflow** (Checks `php-lint` 8.2–8.4, `xml-lint`, `unit-tests` + Job `package`), damit `needs:` das Release an grüne Checks koppelt. Nicht wieder aufteilen.
|
||||
|
||||
### One workflow for everything
|
||||
- `package` baut *und* veröffentlicht in einem Job und braucht nur Node (`make appstore` ist reines `mkdir`/`tar`/`rm`).
|
||||
- Bei `pull_request` wird `Publish release` übersprungen (`if: gitea.event_name == 'push'`) und der Job ist nur ein Build-Check.
|
||||
- Push auf `main` → Pre-Release `latest-main`, Release *und* Tag werden jedes Mal neu erzeugt (Download-Link zeigt immer den neuesten Build). `v*`-Tag → normales Release. Dabei wird **nie der Tag** gelöscht (Flag `RECREATE_TAG`).
|
||||
- **Kein `actions/upload-artifact`:** Gitea gibt sich als GHES aus, `@actions/artifact` ≥ 2 verweigert dann (`GHESNotSupportedError`). Veröffentlicht wird per `curl` gegen die Gitea-Release-API. `checkout`/`setup-node` sind nicht betroffen.
|
||||
- **Kein PAT nötig:** Auth über das automatische `secrets.GITEA_TOKEN` mit `permissions: contents: write`. Bei 403: prüfen, ob die Token-Berechtigung des Repos/der Org auf *Restricted* steht (deckelt `permissions:`). Das ist eine Einstellung, kein Workflow-Bug.
|
||||
|
||||
`.gitea/workflows/build-main.yml` is the *only* workflow: it carries the checks (`php-lint` across 8.2/8.3/8.4, `xml-lint`, `unit-tests`) and the `package` job that builds and publishes. They used to be four separate workflow files, which meant they all triggered independently on the same push and a `latest-main` release was published even when PHPUnit was red. `needs:` only works between jobs of the same workflow (and Gitea's `workflow_run` can depend on one workflow at a time), so gating the release on the checks required merging them into this file. Don't split them back out.
|
||||
## Frontend-Build-Fallen (alle erst in CI aufgefallen)
|
||||
|
||||
Consequences of that shape, all intentional:
|
||||
- **`vite` muss zum Peer von `@nextcloud/vite-config` passen** (aktuell `vite@^7.3.6`), sonst `ERESOLVE`. Beim Update von `vite-config` dessen `peerDependencies.vite` prüfen.
|
||||
- **`"type": "module"` in `package.json`**, sonst scheitert `vite.config.js` am ESM-only-Paket.
|
||||
- **`tsconfig.json` und `typescript` als devDependency sind Pflicht**, obwohl es kein TypeScript gibt: `@nextcloud/vite-config` importiert über sein Barrel `vite-plugin-dts`, das `typescript` als Peer braucht. Ohne das Paket crasht es beim Laden (`Cannot read properties of undefined (reading 'useCaseSensitiveFileNames')`). `typescript` nahe an der Version von `vite-config` halten (aktuell `^5.9.3`).
|
||||
- **`createAppConfig` stellt die App-ID vor jeden Entry-Namen:** `personal-settings` → `js/workflow_deck_automation-personal-settings.mjs`. `Util::addScript()`/`addStyle()` in `lib/Settings/Personal.php` brauchen diesen vollen Namen (`Application::APP_ID . '-personal-settings'`). Falsch → **leere Einstellungsseite**, nur `Could not find resource …` im Log. Umbenennungen in `vite.config.js` auch dort nachziehen.
|
||||
- Die eigentliche CSS steckt in einem gehashten `*.chunk.css`. Die Entry-CSS ist ein ~100-Byte-Stub (`createEmptyCSSEntryPoints`). Das ist korrekt, also Code-Splitting nicht abschalten.
|
||||
|
||||
- **`package` builds *and* publishes in one job.** Handing the tarball to a separate publish job would need `actions/upload-artifact` (unusable here, see above) or `actions/cache` — a second Gitea backend API in the critical path for no gain.
|
||||
- **The workflow also runs on `pull_request`**, where the `Publish release` step is skipped via `if: gitea.event_name == 'push'` and the job degrades into a frontend-build check. That matters: `npm run build` used to run only on `main`, so no PR ever exercised it.
|
||||
- **Tags now get linted and tested too.** Previously the check workflows triggered only on `main` pushes and PRs, so a `v*` tag published completely unverified.
|
||||
## `@nextcloud/vue` 9 (Vue 3) – v8-Idiome scheitern still
|
||||
|
||||
It runs on pushes to `main` **and** on `v*` tags, and the publish step branches on `gitea.ref`:
|
||||
- **Kein `.sync`:** `NcTextField`/`NcCheckboxRadioSwitch` → `v-model`. `:value.sync` lässt den Wert auf dem Startwert stehen.
|
||||
- **`NcSelect`: `label` ist der Anzeige-Schlüssel der Optionen** (vue-select), die Beschriftung ist `input-label`. `label="Board"` rendert überall `undefined`.
|
||||
- **`NcButton`: `variant` = Stil, `type` = nativer Button-Typ**, `native-type` gibt es nicht mehr. Ein übrig gebliebenes `type="primary"` wird zu `submit`, und Abbrechen schickt das Formular ab.
|
||||
- `NcSelect`s `reduce` erreicht vue-select nur per Attribut-Fallthrough (funktioniert, ist aber undokumentiert).
|
||||
- `NcNoteCard` nutzt weiterhin `type` (`success|info|warning|error`).
|
||||
|
||||
- **`main`** → rolling pre-release tagged `latest-main`; both the release *and* the tag are deleted and recreated each run, so the download URL for `workflow_deck_automation.tar.gz` always serves the newest `main` build.
|
||||
- **`v*`** → normal release on the tag that was just pushed. Only a stale release is deleted here — **never the tag**, since deleting it would destroy the ref that triggered the run. That's what the `RECREATE_TAG` flag guards.
|
||||
## Deck-Interna, die man kennen muss
|
||||
|
||||
The `latest-main` half exists so a build can be grabbed and copied onto the server (`nextcloud.gnilebein.de`) without cutting a version tag first — it produced `v0.1.0`-shaped raw-repo confusion once already when the app directory was populated by copying the git working tree instead of a built package; this gives a one-click alternative to that mistake.
|
||||
|
||||
Note that `make appstore` is pure `mkdir`/`tar`/`rm` — no `composer`, no `php`. The `package` job therefore needs Node only; a `setup-php` step *there* would be dead weight (the deleted release workflow had one). PHP is set up in the check jobs, which is a different job and a different container.
|
||||
|
||||
**No manually created token is needed.** The publish step authenticates with `secrets.GITEA_TOKEN`, the token Gitea injects into every Actions job automatically (Gitea 1.27.1 here). The job declares `permissions: contents: write`, which Gitea maps to *Code: write* (needed to delete the `latest-main` tag) plus *Releases: write* (creating the release and uploading the asset).
|
||||
|
||||
This replaced an earlier hand-made `RELEASE_TOKEN` repo secret. If the publish step ever starts returning 403s, check the repo/org **default token permission mode**: `permissions:` requests are clamped by `MaxTokenPermissions`, so a repository switched from *Permissive* (the backwards-compatible default) to *Restricted* silently downgrades releases to read-only and no `permissions:` block can raise it back. That's a repo setting, not a workflow bug — don't "fix" it by reintroducing a PAT before checking.
|
||||
|
||||
## Data flow / architecture map
|
||||
|
||||
- **UI**: `src/PersonalSettings.vue` (Vue 3, mounted from `templates/settings/personal.php` into the section registered by `lib/Settings/PersonalSection.php` + `lib/Settings/Personal.php`) talks to `lib/Controller/WorkflowController.php` (an `OCSController`) via `src/api.js`, hitting OCS routes declared in `appinfo/routes.php` (`/ocs/v2.php/apps/workflow_deck_automation/api/v1/...`).
|
||||
- **Storage**: `lib/Db/Workflow.php` (Entity) / `lib/Db/WorkflowMapper.php` (QBMapper) over the `wfda_workflows` table, created in `lib/Migration/Version1000Date20260813120000.php`. Filter fields (`filter_user_ids`, `filter_label_ids`) are stored as JSON-encoded arrays in text columns, not join tables.
|
||||
- **Automation**: `lib/BackgroundJob/RunWorkflowsJob.php` (5 min `TimedJob`) → `lib/Service/WorkflowRunner.php` (per-user impersonation + filtering, both filters OR-within-themselves and AND-between-each-other) → `lib/Service/DeckIntegrationService.php` (all actual Deck class calls) and `lib/Service/NotificationMailer.php` (email via `OCP\Mail\IMailer` to the workflow owner's account address, never a manually-entered address).
|
||||
- Both the controller's board/stack/label/participant lookups (for populating the settings UI dropdowns) and the runner's card reads/moves go through the same `DeckIntegrationService` — there is no separate read path.
|
||||
|
||||
## Composer/npm lockfiles are intentionally not committed
|
||||
|
||||
`.gitignore` excludes `composer.lock` and `package-lock.json`. This means CI must use `composer install`/`npm install`, not `composer install --no-dev` assumptions tied to a lock file or `npm ci` (which hard-requires a lock file and will fail otherwise — this has already broken the build workflow once). If you add a lockfile-dependent step, either commit the lockfile deliberately or keep using the non-`ci`/non-locked install form.
|
||||
|
||||
## Frontend build gotchas already hit (don't reintroduce)
|
||||
|
||||
None of these were discoverable locally — there's no npm here (see "Local-only notes" below), so all three were only caught by an actual Gitea Actions run against the build workflow:
|
||||
|
||||
- **`vite` version must satisfy `@nextcloud/vite-config`'s peer requirement.** `package.json` pins `@nextcloud/vite-config` to `^2.2.0`, which currently resolves to `2.5.4` and peer-requires `vite@^7.3.6`. If you bump `@nextcloud/vite-config`, check its `peerDependencies.vite` and bump our `vite` devDependency to match, or `npm install` fails with `ERESOLVE`.
|
||||
- **`package.json` needs `"type": "module"`.** `vite.config.js` uses `import`/`export` syntax and `@nextcloud/vite-config` is ESM-only; without `"type": "module"`, Node treats `.js` as CommonJS and `vite build` fails trying to `require()` an ESM-only package.
|
||||
- **A `tsconfig.json` must exist at the repo root, even though this project has no TypeScript source.** `@nextcloud/vite-config`'s `index.js` barrel statically re-exports `createLibConfig` from `libConfig.js`, which imports `vite-plugin-dts` at module scope — that import chain runs just from importing `createAppConfig`, regardless of whether `createLibConfig` is ever called. The minimal `tsconfig.json` in this repo exists to give that a config to resolve, not because we write TypeScript. On its own this did **not** fix the crash below — see the next bullet.
|
||||
- **`typescript` must be an explicit devDependency.** `vite-plugin-dts` (pulled in transitively by the bullet above, version `^4.5.4` as of `@nextcloud/vite-config@2.5.4`) peer-depends on `typescript: "*"` but doesn't install it itself. Without a `typescript` devDependency in our own `package.json`, nothing provides that package, and `vite-plugin-dts`'s `@volar/typescript` integration crashes at module-load time — before `vite.config.js`'s own code or `tsconfig.json` are ever consulted — with `Cannot read properties of undefined (reading 'useCaseSensitiveFileNames')` (`proxyCreateProgram`). This is the actual fix; `tsconfig.json` existing is necessary but not sufficient. Keep `typescript` reasonably close to the version `@nextcloud/vite-config` itself develops against (currently `^5.9.3`) if you bump either.
|
||||
- **`createAppConfig` prefixes every entry name with the app id**, so the entry `personal-settings` is emitted as `js/workflow_deck_automation-personal-settings.mjs` and `css/workflow_deck_automation-personal-settings.css`. `Util::addScript()`/`addStyle()` take that *full on-disk basename* (minus extension), not the bare entry name — `lib/Settings/Personal.php` therefore passes `Application::APP_ID . '-personal-settings'`. Getting this wrong produces a **silently blank settings page**: the template's empty mount `<div>` renders fine, and the only symptom is `Could not find resource workflow_deck_automation/js/….js to load` (`jsresourceloader`) plus a matching `Could not find resource file "/apps/workflow_deck_automation/css/….css"` in `nextcloud.log`. If you rename the entry in `vite.config.js`, rename it in `Personal.php` too.
|
||||
- **The bulk of the CSS lives in a hashed `*.chunk.css`**, loaded at runtime by the `.mjs` bundle (`cssCodeSplit: true`). The `css/workflow_deck_automation-personal-settings.css` that `addStyle()` points at is the ~100-byte stub produced by `createEmptyCSSEntryPoints: true`. A near-empty entry CSS file is expected — don't "fix" it by turning off code splitting.
|
||||
|
||||
## `@nextcloud/vue` 9 component API (Vue 3) — the v8 idioms silently do nothing
|
||||
|
||||
This app is on `@nextcloud/vue` ^9 / Vue 3. The v8 (Vue 2) prop spellings that most Nextcloud app code online still uses either fail silently or, worse, land as stray DOM attributes instead of erroring:
|
||||
|
||||
- **No `.sync`.** Vue 3 removed it. `NcTextField` and `NcCheckboxRadioSwitch` both bind through `modelValue`/`update:modelValue`, so it's `v-model="x"` — `:value.sync="x"` / `:checked.sync="x"` leave the bound state permanently at its initial value. That's how `form.title` stayed `''` and every save died on "Bitte einen Titel angeben."
|
||||
- **`NcSelect`'s `label` prop is the *option display key*, not a caption** (it's vue-select's). Passing `label="Board"` makes it read `option.Board` on every option and render `undefined` for all of them. The visible caption prop is `input-label`.
|
||||
- **`NcButton`: `variant` is the style, `type` is the native button type**, and `native-type` no longer exists (v8's `type="primary"` + `native-type="submit"` → v9's `variant="primary"` + `type="submit"`). A leftover `type="primary"` renders `<button type="primary">`, which HTML treats as the invalid-value default `submit` — so a *cancel* button silently submits the form.
|
||||
- `NcSelect`'s `reduce` is not declared on `NcSelect` itself; it reaches vue-select through attribute fallthrough (NcSelect's root element *is* the `VueSelect` component and it doesn't set `inheritAttrs: false`). It works, but it's fallthrough, not a documented prop.
|
||||
- `NcNoteCard`'s prop is still `type` (`success|info|warning|error`) — not everything was renamed to `variant`.
|
||||
|
||||
## Deck entities are "relational": getters don't return the uid string
|
||||
|
||||
Deck's `RelationalEntity` swaps resolved relations for an `OCA\Deck\Db\RelationalObject` once an entity is enriched. So on an enriched board/card, `$acl->getParticipant()`, `$board->getOwner()` and a card assignment's participant return a `RelationalObject` (wrapping `OCA\Deck\Db\User`/`Group`/`Circle`), **not** a uid — the uid is its `getPrimaryKey()`. Probing for `getUID()` on the returned object finds nothing and yields `null`, which is how the settings UI's user dropdown came up empty *and* why the runner's assigned-user filter could never match. `DeckIntegrationService::unwrapUid()` handles both shapes (bare string and `RelationalObject`); route any new participant/owner field through it.
|
||||
|
||||
Two more Deck facts that bit us in the same pass: a board's ACL does **not** contain its owner (a private board has an empty ACL, so participants must be seeded with `$board->getOwner()`), and ACL entries can be groups (`type === 1`) whose members have to be expanded via `IGroupManager`.
|
||||
|
||||
**`BoardService::getUserBoards()` defaults to `$includeArchived = true`, and that flag also gates the `deleted_at = 0` condition** — with the default you get archived *and* trashed boards back. We call `getUserBoards(null, false)` (with a fallback to the no-arg form if Deck ever changes the signature) and still dedupe by id afterwards, because it merges own/group/circle boards and can return the same board twice. Stacks need no such handling: `StackMapper::findAll()` filters `deleted_at = 0` unconditionally and stacks have no archived state.
|
||||
|
||||
## Local-only notes
|
||||
|
||||
`CLAUDE.local.md` (gitignored) carries session-specific environment notes (e.g. "no PHP/npm available locally"). Check it at the start of work in this repo — it's not duplicated here since it can change independently of the committed guidance.
|
||||
- **Relationale Entities:** Auf angereicherten Entities liefern `$acl->getParticipant()`, `$board->getOwner()` oder Assignment-Teilnehmer ein `RelationalObject` statt einer uid (uid = `getPrimaryKey()`). Neue Teilnehmer-/Owner-Felder immer über `DeckIntegrationService::unwrapUid()` laufen lassen.
|
||||
- Die ACL eines Boards enthält **nicht** den Owner (privates Board = leere ACL). ACL-Einträge können Gruppen (`type === 1`) oder Circles sein.
|
||||
- `StackMapper::findAll()` filtert `deleted_at = 0` selbst. Stacks haben keinen Archivstatus.
|
||||
- Der Deck-Quellcode liegt lokal unter `C:\Users\pani\Documents\git-privat\nextcloud-deck` und dient zum Nachprüfen von Interna.
|
||||
@@ -1,6 +1,6 @@
|
||||
# Deck Workflow-Automatisierung
|
||||
|
||||
Nextcloud-App für **Nextcloud Hub 26 Spring (Server 34.x)**, die überfällige Karten der [Deck](https://github.com/nextcloud/deck)-App automatisch von einem Stapel in einen anderen verschiebt und optional eine E-Mail-Benachrichtigung verschickt.
|
||||
Nextcloud-App für **Nextcloud Hub Summer 26 (Server 35.x)**, die überfällige Karten der [Deck](https://github.com/nextcloud/deck)-App automatisch von einem Stapel in einen anderen verschiebt und optional eine E-Mail-Benachrichtigung verschickt.
|
||||
|
||||
Ersetzt das früher genutzte eigenständige PHP-Cron-Skript durch eine vollwertige App mit Oberfläche in den **persönlichen Einstellungen** — jeder Nutzer kann dort seine eigenen Regeln ("Workflows") anlegen, ohne Admin-Rechte oder Server-Zugriff zu benötigen.
|
||||
|
||||
@@ -9,19 +9,24 @@ Ersetzt das früher genutzte eigenständige PHP-Cron-Skript durch eine vollwerti
|
||||
Pro Workflow lässt sich konfigurieren:
|
||||
|
||||
- Quell-Board und Quell-Stapel
|
||||
- Ziel-Stapel, in den überfällige Karten verschoben werden
|
||||
- optionaler Filter auf zugewiesene Benutzer (Karte muss **mindestens einem** der gewählten Benutzer zugewiesen sein)
|
||||
- optionaler Filter auf Labels/Tags (Karte muss **mindestens eines** der gewählten Labels haben)
|
||||
- Checkbox: E-Mail-Benachrichtigung an den Workflow-Besitzer, sobald eine Karte verschoben wurde
|
||||
- Ziel-Stapel, in den **alle** überfälligen Karten des Quell-Stapels verschoben werden
|
||||
- E-Mail-Benachrichtigung über verschobene Karten, in drei Stufen:
|
||||
- **Keine E-Mail**
|
||||
- **Nur an mich** – an den Board-Eigentümer, unabhängig von seinen Deck-Einstellungen
|
||||
- **An Board-Mitglieder laut Deck-Einstellung** – an alle, die das Board sehen dürfen (Eigentümer, freigegebene Nutzer, Mitglieder freigegebener Gruppen und Teams), gefiltert nach deren eigener Deck-Einstellung *Benachrichtigungen* für dieses Board: *Alle Karten* → immer, *Zugewiesene Karten* (Deck-Standard) → nur wenn man der Karte direkt oder über eine Gruppe/ein Team zugewiesen ist, *Keine* → nie. Der Eigentümer eines nicht geteilten Boards bekommt wie in Deck jede Karte, außer er hat *Keine* gewählt.
|
||||
|
||||
Ein Nutzer kann beliebig viele Workflows anlegen, bearbeiten, deaktivieren oder löschen.
|
||||
Pro Lauf des Hintergrundjobs bekommt jeder Empfänger höchstens **eine** Sammelmail mit allen für ihn verschobenen Karten.
|
||||
|
||||
Die App ist für den internen Einsatz gedacht und durchgehend **deutschsprachig** (Oberfläche, Fehlermeldungen, E-Mails). Es gibt keine Übersetzungsdateien.
|
||||
|
||||
Workflows lassen sich nur für Boards anlegen, deren Eigentümer man ist. Ein Workflow gehört dem jeweiligen Board-Eigentümer, nicht dem, der ihn angelegt hat: Wird ein Board in Deck übertragen, sieht und verwaltet ab sofort der neue Eigentümer seine Workflows, und der Hintergrundjob läuft in dessen Namen. Ein Nutzer kann beliebig viele Workflows anlegen, bearbeiten, deaktivieren oder löschen.
|
||||
|
||||
## Architektur
|
||||
|
||||
- **Keine HTTP/OCS-Aufrufe gegen Deck.** Alles Lesen (Boards, Stapel, Karten, Labels, zugewiesene Benutzer) und das Verschieben von Karten läuft ausschließlich über Decks eigene interne PHP-Klassen (`OCA\Deck\Service\CardService`, `StackService`, `BoardService`, `OCA\Deck\Db\CardMapper`, …), aufgelöst per Dependency Injection direkt im selben PHP-Prozess. Sämtlicher Deck-Zugriff ist in [`lib/Service/DeckIntegrationService.php`](lib/Service/DeckIntegrationService.php) gebündelt.
|
||||
- **Hintergrundjob statt Seitenaufruf.** [`lib/BackgroundJob/RunWorkflowsJob.php`](lib/BackgroundJob/RunWorkflowsJob.php) ist ein `TimedJob`, der standardmäßig alle 5 Minuten läuft (abhängig vom Nextcloud-Cron-Intervall) und [`lib/Service/WorkflowRunner.php`](lib/Service/WorkflowRunner.php) aufruft. Das Intervall ist über die `config.php` einstellbar, siehe unten.
|
||||
- **Rechte-Kontext je Nutzer.** Da Decks Berechtigungsprüfungen die aktuell eingeloggte Session lesen, ein Hintergrundjob aber standardmäßig keinen eingeloggten Nutzer hat und Regeln mehrerer Nutzer in einem einzigen Lauf auswerten muss, "verkörpert" der `WorkflowRunner` für die Dauer der jeweiligen Workflows kurzzeitig den entsprechenden Besitzer (`IUserSession::setUser()`), bevor die Deck-Klassen aufgerufen werden.
|
||||
- **E-Mail** läuft über Nextclouds eigenen `IMailer` (nutzt also den in der Nextcloud-Administration hinterlegten Mailserver) und geht an die im Profil des Workflow-Besitzers hinterlegte Adresse.
|
||||
- **Keine HTTP/OCS-Aufrufe gegen Deck.** Alles Lesen (Boards, Stapel, Karten) und das Verschieben von Karten läuft ausschließlich über Decks eigene interne PHP-Klassen (`OCA\Deck\Service\CardService`, `StackService`, `BoardService`, `OCA\Deck\Db\CardMapper`, …), aufgelöst per Dependency Injection direkt im selben PHP-Prozess. Sämtlicher Deck-Zugriff ist in [`lib/Service/DeckIntegrationService.php`](lib/Service/DeckIntegrationService.php) gebündelt.
|
||||
- **Hintergrundjob statt Seitenaufruf.** [`lib/BackgroundJob/RunWorkflowsJob.php`](lib/BackgroundJob/RunWorkflowsJob.php) ist ein einfacher `Job` ohne eigenes Intervall: Er läuft bei jedem Cron-Durchlauf von Nextcloud (üblicherweise alle 5 Minuten) und ruft [`lib/Service/WorkflowRunner.php`](lib/Service/WorkflowRunner.php) auf.
|
||||
- **Rechte-Kontext je Nutzer.** Ein Hintergrundjob hat standardmäßig keinen eingeloggten Nutzer, muss aber die Regeln mehrerer Nutzer in einem einzigen Lauf auswerten. Der `WorkflowRunner` "verkörpert" deshalb für die Dauer der jeweiligen Workflows kurzzeitig den entsprechenden Besitzer. Dazu gehört mehr als `IUserSession::setUser()`: Decks Berechtigungsprüfungen lesen die Session gar nicht, sondern eine Benutzer-ID, die beim Bau des Deck-Containers einmal pro Prozess eingefroren wird. `DeckIntegrationService::beginUserContext()` setzt diesen Wert für die Dauer der Verkörperung auf den Workflow-Besitzer und stellt ihn danach wieder her; schlägt das fehl, wird der Nutzer in diesem Lauf übersprungen, statt unter fremden Rechten zu arbeiten.
|
||||
- **E-Mail** läuft über Nextclouds eigenen `IMailer` (nutzt also den in der Nextcloud-Administration hinterlegten Mailserver) und geht an die im Profil der jeweiligen Empfänger hinterlegte Adresse. Die Empfänger und ihre Deck-Einstellungen ermittelt die App ebenfalls über Decks interne Klassen bzw. die Nutzereinstellung `deck` / `board:<id>:notify-due`.
|
||||
|
||||
### Wichtiger Hinweis zu Decks internen Klassen
|
||||
|
||||
@@ -36,7 +41,7 @@ Ein Nutzer kann beliebig viele Workflows anlegen, bearbeiten, deaktivieren oder
|
||||
|
||||
## Benutzung
|
||||
|
||||
Jeder Nutzer findet die Einstellungen unter **Persönliche Einstellungen → Deck Workflow-Automatisierung**. Dort können neue Workflows angelegt, bestehende bearbeitet oder gelöscht werden. Die Dropdowns für Board/Stapel/Label/Benutzer werden live aus Deck geladen. Zur Auswahl stehen nur aktive Boards — archivierte und im Papierkorb liegende Boards sowie gelöschte Stapel blendet Deck bzw. die App aus.
|
||||
Jeder Nutzer findet die Einstellungen unter **Persönliche Einstellungen → Deck Workflow-Automatisierung**. Dort können neue Workflows angelegt, bestehende bearbeitet oder gelöscht werden. Die Dropdowns für Board und Stapel werden live aus Deck geladen. Zur Auswahl stehen nur aktive Boards, deren Eigentümer man ist — geteilte, archivierte und im Papierkorb liegende Boards sowie gelöschte Stapel blendet die App aus.
|
||||
|
||||
### Gelöschte Boards und Stapel
|
||||
|
||||
@@ -44,27 +49,19 @@ Ein Workflow verweist per ID auf ein Board und zwei Stapel. Wird eines davon in
|
||||
|
||||
- **Beim Speichern** werden Board und Stapel geprüft; ein Workflow auf nicht mehr existierende Ziele lässt sich gar nicht erst anlegen.
|
||||
- **In der Übersicht** wird ein betroffener Workflow rot markiert („Board nicht mehr vorhanden", „Quell-Stapel nicht mehr vorhanden" …).
|
||||
- **Im Hintergrundjob** wird der Workflow automatisch deaktiviert und der Besitzer einmalig per E-Mail informiert — unabhängig davon, ob für den Workflow „E-Mail senden" aktiviert ist, denn hier geht es nicht um verschobene Karten, sondern darum, dass die Automatisierung nicht mehr läuft. Danach bleibt es still: Ein deaktivierter Workflow wird nicht erneut ausgewertet.
|
||||
- **Im Hintergrundjob** wird der Workflow automatisch deaktiviert und der Besitzer einmalig per E-Mail informiert — unabhängig von der E-Mail-Einstellung des Workflows, denn hier geht es nicht um verschobene Karten, sondern darum, dass die Automatisierung nicht mehr läuft. Danach bleibt es still: Ein deaktivierter Workflow wird nicht erneut ausgewertet.
|
||||
|
||||
Ist Deck vorübergehend nicht erreichbar, wird **nicht** deaktiviert — der Job überspringt den Workflow und versucht es beim nächsten Lauf erneut. Archivierte Boards lösen die Deaktivierung ebenfalls nicht aus, sie sind nur in den Auswahlfeldern ausgeblendet.
|
||||
|
||||
## Konfiguration
|
||||
## Ausführungstakt
|
||||
|
||||
Das Prüfintervall des Hintergrundjobs lässt sich in der `config.php` setzen (Wert in **Sekunden**):
|
||||
Der Hintergrundjob hat **kein eigenes Intervall** und ist auch nicht konfigurierbar: Er läuft bei **jedem** Cron-Durchlauf von Nextcloud. Der Takt ist damit exakt der des System-Crons — üblicherweise alle 5 Minuten, bei einem häufiger eingerichteten Cron entsprechend öfter.
|
||||
|
||||
```php
|
||||
'workflow_deck_automation.interval' => 300,
|
||||
```
|
||||
|
||||
- Standard ohne Eintrag: `300` (5 Minuten).
|
||||
- Minimum: `60` — kleinere Werte werden auf 60 Sekunden angehoben.
|
||||
- Die Änderung greift beim nächsten Cron-Durchlauf; ein `occ`-Befehl oder eine Neuinstallation der App ist nicht nötig.
|
||||
|
||||
Zu beachten: Das ist eine *Untergrenze* für den Abstand zwischen zwei Läufen, keine Garantie. Nextclouds Cron selbst läuft üblicherweise nur alle 5 Minuten — ein Intervall von 60 Sekunden führt also nur dann zu minütlichen Läufen, wenn der System-Cron entsprechend häufig ausgeführt wird.
|
||||
> Bis einschließlich v0.1.0 gab es dafür die `config.php`-Option `workflow_deck_automation.interval`. Sie ist entfallen und wird ignoriert; ein vorhandener Eintrag kann aus der `config.php` entfernt werden.
|
||||
|
||||
### Der Job läuft nur nachts bzw. gar nicht
|
||||
|
||||
Der Job ist als `TIME_SENSITIVE` deklariert und läuft damit rund um die Uhr. Nextcloud merkt sich die Zeitsensitivität aber zusätzlich in der Spalte `time_sensitive` der Tabelle `oc_jobs`, und `JobList::setLastRun()` setzt sie nur in eine Richtung — von „zeitkritisch" auf „unkritisch", nie zurück. Wer eine ältere Version dieser App installiert hatte (bis einschließlich v0.1.0 war der Job `TIME_INSENSITIVE`), hat diesen Stempel noch in der Datenbank. Er wird weder durch ein App-Update noch durch `app:enable` zurückgesetzt.
|
||||
Nextcloud merkt sich in der Spalte `time_sensitive` der Tabelle `oc_jobs`, ob ein Job zeitkritisch ist, und überspringt „unkritische" Jobs außerhalb des Wartungsfensters. `JobList::setLastRun()` setzt diese Spalte nur in eine Richtung — von „zeitkritisch" auf „unkritisch", nie zurück. Wer eine ältere Version dieser App installiert hatte (bis einschließlich v0.1.0 war der Job `TIME_INSENSITIVE`), hat diesen Stempel noch in der Datenbank. Er wird weder durch ein App-Update noch durch `app:enable` zurückgesetzt.
|
||||
|
||||
Symptom: Ist in der `config.php` ein `maintenance_window_start` gesetzt, läuft der Job nur in diesem 4-Stunden-Fenster und den Rest des Tages gar nicht.
|
||||
|
||||
@@ -102,7 +99,7 @@ npm run watch # Entwicklung mit automatischem Rebuild
|
||||
```bash
|
||||
composer run lint # php -l über lib/ und tests/
|
||||
composer run cs:check # nextcloud/coding-standard (php-cs-fixer)
|
||||
composer run test:unit # PHPUnit — reine Filter-Logik, benötigt keine Deck-Installation
|
||||
composer run test:unit # PHPUnit — reine Logik (Fälligkeitsprüfung), benötigt keine Deck-Installation
|
||||
```
|
||||
|
||||
Ein echter End-to-End-Test (Karte anlegen, Workflow konfigurieren, Hintergrundjob auslösen, Verschiebung + Mail prüfen) lässt sich nur gegen eine echte Nextcloud-34-Instanz mit installierter Deck-App durchführen, z. B. per:
|
||||
@@ -111,7 +108,7 @@ Ein echter End-to-End-Test (Karte anlegen, Workflow konfigurieren, Hintergrundjo
|
||||
# Job-ID und letzten Lauf anzeigen
|
||||
php occ background-job:list --class 'OCA\WorkflowDeckAutomation\BackgroundJob\RunWorkflowsJob'
|
||||
|
||||
# Sofort ausführen, unabhängig vom Intervall
|
||||
# Sofort ausführen, ohne auf den nächsten Cron-Durchlauf zu warten
|
||||
php occ background-job:execute <id> --force-execute
|
||||
|
||||
# Oder dauerhaft als Worker laufen lassen (Argument ist die Job-Klasse, keine App-ID)
|
||||
@@ -139,7 +136,7 @@ In [`.gitea/workflows/`](.gitea/workflows/):
|
||||
|
||||
## Datenmodell
|
||||
|
||||
Workflows werden in der Tabelle `wfda_workflows` gespeichert (siehe [`lib/Migration/Version1000Date20260813120000.php`](lib/Migration/Version1000Date20260813120000.php)): eine Zeile pro Workflow, mit `user_id`-Bezug, Board-/Stapel-IDs, JSON-kodierten Filterlisten sowie `enabled`/`notify_email`/`last_run`.
|
||||
Workflows werden in der Tabelle `wfda_workflows` gespeichert (siehe [`lib/Migration/Version1000Date20260813120000.php`](lib/Migration/Version1000Date20260813120000.php)): eine Zeile pro Workflow, mit Board-/Stapel-IDs, `user_id` (der Board-Eigentümer, in dessen Namen der Job läuft — wird bei jedem Lauf aus Deck aktualisiert) sowie `enabled`/`notify_mode`/`last_run`. Die früheren Filter-Spalten `filter_user_ids`/`filter_label_ids` entfernt [`Version1001Date20260930120000`](lib/Migration/Version1001Date20260930120000.php). [`Version1002Date20261001120000`](lib/Migration/Version1002Date20261001120000.php) ersetzt das frühere Ja/Nein-Feld `notify_email` durch `notify_mode` (`off`/`owner`/`board`; gesetztes Häkchen → `owner`), [`Version1003Date20261001120100`](lib/Migration/Version1003Date20261001120100.php) entfernt die alte Spalte.
|
||||
|
||||
## Lizenz
|
||||
|
||||
|
||||
+7
-11
@@ -7,28 +7,24 @@
|
||||
<summary lang="de">Verschiebt überfällige Deck-Karten automatisch anhand konfigurierbarer Regeln</summary>
|
||||
<summary lang="en">Automatically moves overdue Deck cards based on configurable rules</summary>
|
||||
<description lang="de"><![CDATA[
|
||||
Diese App erlaubt es jedem Nutzer, in den persönlichen Einstellungen eigene Automatisierungs-Workflows für die Deck-App anzulegen:
|
||||
Diese App erlaubt es jedem Nutzer, in den persönlichen Einstellungen Automatisierungs-Workflows für seine eigenen Deck-Boards anzulegen:
|
||||
|
||||
* Quell-Board und Quell-Stapel wählen
|
||||
* Ziel-Stapel wählen, in den überfällige Karten verschoben werden
|
||||
* optional nach zugewiesenen Benutzern filtern
|
||||
* optional nach Labels/Tags filtern
|
||||
* optional eine E-Mail-Benachrichtigung an sich selbst aktivieren
|
||||
* optional per E-Mail benachrichtigen: nur sich selbst oder alle Board-Mitglieder gemäß ihrer Deck-Benachrichtigungseinstellung
|
||||
|
||||
Ein Hintergrundjob prüft regelmäßig alle aktiven Workflows und verschiebt Karten, deren Fälligkeitsdatum überschritten wurde, ausschließlich über die internen PHP-Klassen der Deck-App (keine HTTP/OCS-Aufrufe).
|
||||
]]></description>
|
||||
<description lang="en"><![CDATA[
|
||||
This app lets every user configure their own Deck automation workflows from Personal settings:
|
||||
This app lets every user configure Deck automation workflows for the boards they own from Personal settings:
|
||||
|
||||
* pick a source board and source stack
|
||||
* pick a destination stack overdue cards get moved to
|
||||
* optionally filter by assigned users
|
||||
* optionally filter by labels/tags
|
||||
* optionally enable an email notification to themselves
|
||||
* optionally notify by email: themselves only, or every board member according to their Deck notification setting
|
||||
|
||||
A background job periodically evaluates all enabled workflows and moves cards whose due date has passed, using Deck's own internal PHP classes only (no HTTP/OCS calls).
|
||||
]]></description>
|
||||
<version>0.1.0</version>
|
||||
<version>35.2.2</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="patrick@niebel.ing">Patrick Niebeling</author>
|
||||
<namespace>WorkflowDeckAutomation</namespace>
|
||||
@@ -36,11 +32,11 @@ A background job periodically evaluates all enabled workflows and moves cards wh
|
||||
<category>tools</category>
|
||||
<bugs>https://github.com/pniebeling/workflow_deck_automation/issues</bugs>
|
||||
<dependencies>
|
||||
<php min-version="8.2" max-version="8.4"/>
|
||||
<php min-version="8.4" max-version="8.5"/>
|
||||
<database min-version="9.4">pgsql</database>
|
||||
<database>sqlite</database>
|
||||
<database min-version="8.0">mysql</database>
|
||||
<nextcloud min-version="34" max-version="34"/>
|
||||
<nextcloud min-version="35" max-version="35"/>
|
||||
</dependencies>
|
||||
<background-jobs>
|
||||
<job>OCA\WorkflowDeckAutomation\BackgroundJob\RunWorkflowsJob</job>
|
||||
|
||||
@@ -11,7 +11,5 @@ return [
|
||||
|
||||
['name' => 'workflow#boards', 'url' => '/api/v1/boards', 'verb' => 'GET'],
|
||||
['name' => 'workflow#stacks', 'url' => '/api/v1/boards/{boardId}/stacks', 'verb' => 'GET'],
|
||||
['name' => 'workflow#labels', 'url' => '/api/v1/boards/{boardId}/labels', 'verb' => 'GET'],
|
||||
['name' => 'workflow#participants', 'url' => '/api/v1/boards/{boardId}/participants', 'verb' => 'GET'],
|
||||
],
|
||||
];
|
||||
@@ -6,51 +6,47 @@ namespace OCA\WorkflowDeckAutomation\BackgroundJob;
|
||||
|
||||
use OCA\WorkflowDeckAutomation\Service\WorkflowRunner;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\IJob;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\IConfig;
|
||||
|
||||
class RunWorkflowsJob extends TimedJob {
|
||||
/**
|
||||
* config.php key holding how often (in seconds) workflows are checked.
|
||||
*/
|
||||
public const INTERVAL_CONFIG_KEY = 'workflow_deck_automation.interval';
|
||||
|
||||
public const DEFAULT_INTERVAL = 5 * 60;
|
||||
|
||||
/**
|
||||
* Nextcloud's cron itself only ticks every 5 minutes by default, so
|
||||
* anything below a minute would only add load without running more
|
||||
* often. Values under this are clamped rather than rejected.
|
||||
*/
|
||||
public const MINIMUM_INTERVAL = 60;
|
||||
use OCP\BackgroundJob\Job;
|
||||
|
||||
/**
|
||||
* Evaluates all enabled workflows, once per cron pass.
|
||||
*
|
||||
* Deliberately a plain `Job`, not a `TimedJob`: there is no interval to
|
||||
* configure and none to compare against, so the cadence is exactly
|
||||
* Nextcloud's cron cadence — every pass, no matter how often cron is set
|
||||
* up to run. `TimedJob` with `setInterval(0)` would behave almost the
|
||||
* same, but it keeps an interval concept around that nothing uses.
|
||||
*
|
||||
* **Time sensitivity still matters, and it comes for free here.**
|
||||
* `OC\Core\Service\CronService::runCli()` reads `maintenance_window_start`
|
||||
* (default `100`, i.e. unset) and, whenever the current UTC hour is outside
|
||||
* `[start, start+4]`, asks `JobList::getNext($onlyTimeSensitive = true)`,
|
||||
* which filters on the `time_sensitive` *column* of `oc_jobs`. A job stamped
|
||||
* insensitive is then skipped for the other 20 hours of the day — this app
|
||||
* shipped that way once and the job looked completely dead, showing
|
||||
* `last_run = 1970-01-01` in `occ background-job:list` indefinitely. Note
|
||||
* the gate only exists in `runCli()`, so ajax/webcron are unaffected and
|
||||
* `occ background-job:worker '<class>'` bypasses it, which is why manual
|
||||
* testing can look fine while cron does nothing.
|
||||
*
|
||||
* A plain `Job` can never acquire that stamp: `JobList::add()` leaves the
|
||||
* column at its `TIME_SENSITIVE` default, and the one place that ever
|
||||
* downgrades it, `JobList::setLastRun()`, is guarded by
|
||||
* `$job instanceof TimedJob && !$job->isTimeSensitive()` — with no `else`.
|
||||
* Rows written by an older version of this app keep whatever they were
|
||||
* stamped with, though, so an instance that ran the `TIME_INSENSITIVE`
|
||||
* version still needs the one-off `UPDATE oc_jobs SET time_sensitive = 0`
|
||||
* documented in the README.
|
||||
*/
|
||||
class RunWorkflowsJob extends Job {
|
||||
public function __construct(
|
||||
ITimeFactory $time,
|
||||
IConfig $config,
|
||||
private WorkflowRunner $runner,
|
||||
) {
|
||||
parent::__construct($time);
|
||||
// TimedJob compares against this value on every cron pass, so a
|
||||
// changed config.php takes effect on the next pass — no occ command
|
||||
// and no re-registration of the job needed.
|
||||
$this->setInterval(self::resolveInterval($config));
|
||||
// Must stay TIME_SENSITIVE. If `maintenance_window_start` is set in
|
||||
// config.php — and Nextcloud's admin overview actively nags admins
|
||||
// to set it — CronService only picks up TIME_INSENSITIVE jobs during
|
||||
// those 4 hours and skips them for the rest of the day. A job whose
|
||||
// whole point is a 5-minute (configurable down to 60s) reaction time
|
||||
// would then run a handful of times per night and look completely
|
||||
// dead in between.
|
||||
$this->setTimeSensitivity(IJob::TIME_SENSITIVE);
|
||||
$this->setAllowParallelRuns(false);
|
||||
}
|
||||
|
||||
private static function resolveInterval(IConfig $config): int {
|
||||
$interval = $config->getSystemValueInt(self::INTERVAL_CONFIG_KEY, self::DEFAULT_INTERVAL);
|
||||
return max(self::MINIMUM_INTERVAL, $interval);
|
||||
}
|
||||
|
||||
protected function run($argument): void {
|
||||
$this->runner->run();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use OCA\WorkflowDeckAutomation\Db\Workflow;
|
||||
use OCA\WorkflowDeckAutomation\Db\WorkflowMapper;
|
||||
use OCA\WorkflowDeckAutomation\Service\DeckIntegrationService;
|
||||
use OCA\WorkflowDeckAutomation\Service\DeckUnavailableException;
|
||||
use OCA\WorkflowDeckAutomation\Service\NotificationPolicy;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
@@ -33,46 +34,41 @@ class WorkflowController extends OCSController {
|
||||
private function currentUserId(): string {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
throw new OCSPreconditionFailedException('Not logged in');
|
||||
throw new OCSPreconditionFailedException('Nicht angemeldet');
|
||||
}
|
||||
return $user->getUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every workflow on a board the user owns, no matter who created it: a
|
||||
* workflow belongs to its board's owner, and follows the board when
|
||||
* Deck transfers it.
|
||||
*/
|
||||
#[NoAdminRequired]
|
||||
public function index(): DataResponse {
|
||||
$workflows = $this->workflowMapper->findAllForUser($this->currentUserId());
|
||||
$workflows = $this->workflowMapper->findAllForBoards($this->ownedBoardIds());
|
||||
return new DataResponse(array_map(static fn (Workflow $w) => $w->jsonSerialize(), $workflows));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $filterUserIds
|
||||
* @param int[] $filterLabelIds
|
||||
*/
|
||||
#[NoAdminRequired]
|
||||
public function create(
|
||||
string $title,
|
||||
int $boardId,
|
||||
int $sourceStackId,
|
||||
int $targetStackId,
|
||||
array $filterUserIds = [],
|
||||
array $filterLabelIds = [],
|
||||
bool $notifyEmail = false,
|
||||
string $notifyMode = NotificationPolicy::MODE_OFF,
|
||||
bool $enabled = true,
|
||||
): DataResponse {
|
||||
$this->validate($title, $boardId, $sourceStackId, $targetStackId);
|
||||
$this->validate($title, $boardId, $sourceStackId, $targetStackId, $notifyMode);
|
||||
|
||||
$workflow = new Workflow();
|
||||
$workflow->setUserId($this->currentUserId());
|
||||
$this->applyFields($workflow, $title, $boardId, $sourceStackId, $targetStackId, $filterUserIds, $filterLabelIds, $notifyEmail, $enabled);
|
||||
$this->applyFields($workflow, $title, $boardId, $sourceStackId, $targetStackId, $notifyMode, $enabled);
|
||||
|
||||
$workflow = $this->workflowMapper->insert($workflow);
|
||||
return new DataResponse($workflow->jsonSerialize(), Http::STATUS_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $filterUserIds
|
||||
* @param int[] $filterLabelIds
|
||||
*/
|
||||
#[NoAdminRequired]
|
||||
public function update(
|
||||
int $id,
|
||||
@@ -80,20 +76,16 @@ class WorkflowController extends OCSController {
|
||||
int $boardId,
|
||||
int $sourceStackId,
|
||||
int $targetStackId,
|
||||
array $filterUserIds = [],
|
||||
array $filterLabelIds = [],
|
||||
bool $notifyEmail = false,
|
||||
string $notifyMode = NotificationPolicy::MODE_OFF,
|
||||
bool $enabled = true,
|
||||
): DataResponse {
|
||||
$this->validate($title, $boardId, $sourceStackId, $targetStackId);
|
||||
$workflow = $this->findOwnWorkflow($id);
|
||||
$this->validate($title, $boardId, $sourceStackId, $targetStackId, $notifyMode);
|
||||
|
||||
try {
|
||||
$workflow = $this->workflowMapper->findForUser($id, $this->currentUserId());
|
||||
} catch (DoesNotExistException $e) {
|
||||
throw new OCSNotFoundException('Workflow not found');
|
||||
}
|
||||
|
||||
$this->applyFields($workflow, $title, $boardId, $sourceStackId, $targetStackId, $filterUserIds, $filterLabelIds, $notifyEmail, $enabled);
|
||||
// Kept in step with the board owner so the job runs as, and mails,
|
||||
// the right user; validate() made sure the editor owns the board.
|
||||
$workflow->setUserId($this->currentUserId());
|
||||
$this->applyFields($workflow, $title, $boardId, $sourceStackId, $targetStackId, $notifyMode, $enabled);
|
||||
$workflow = $this->workflowMapper->update($workflow);
|
||||
|
||||
return new DataResponse($workflow->jsonSerialize());
|
||||
@@ -101,12 +93,7 @@ class WorkflowController extends OCSController {
|
||||
|
||||
#[NoAdminRequired]
|
||||
public function destroy(int $id): DataResponse {
|
||||
try {
|
||||
$workflow = $this->workflowMapper->findForUser($id, $this->currentUserId());
|
||||
} catch (DoesNotExistException $e) {
|
||||
throw new OCSNotFoundException('Workflow not found');
|
||||
}
|
||||
|
||||
$workflow = $this->findOwnWorkflow($id);
|
||||
$this->workflowMapper->delete($workflow);
|
||||
return new DataResponse([]);
|
||||
}
|
||||
@@ -114,7 +101,7 @@ class WorkflowController extends OCSController {
|
||||
#[NoAdminRequired]
|
||||
public function boards(): DataResponse {
|
||||
$this->assertDeck();
|
||||
return new DataResponse($this->deckService->listBoardsForCurrentUser());
|
||||
return new DataResponse($this->ownedBoards());
|
||||
}
|
||||
|
||||
#[NoAdminRequired]
|
||||
@@ -123,36 +110,61 @@ class WorkflowController extends OCSController {
|
||||
return new DataResponse($this->deckService->listStacks($boardId));
|
||||
}
|
||||
|
||||
#[NoAdminRequired]
|
||||
public function labels(int $boardId): DataResponse {
|
||||
$this->assertDeck();
|
||||
return new DataResponse($this->deckService->listLabels($boardId));
|
||||
private function findOwnWorkflow(int $id): Workflow {
|
||||
try {
|
||||
$workflow = $this->workflowMapper->findById($id);
|
||||
} catch (DoesNotExistException $e) {
|
||||
throw new OCSNotFoundException('Workflow nicht gefunden');
|
||||
}
|
||||
|
||||
if (!in_array($workflow->getBoardId(), $this->ownedBoardIds(), true)) {
|
||||
// Same answer as for a missing id: don't reveal other users' workflows.
|
||||
throw new OCSNotFoundException('Workflow nicht gefunden');
|
||||
}
|
||||
return $workflow;
|
||||
}
|
||||
|
||||
#[NoAdminRequired]
|
||||
public function participants(int $boardId): DataResponse {
|
||||
/**
|
||||
* @return array<int, array{id: int, title: string, archived: bool}>
|
||||
*/
|
||||
private function ownedBoards(): array {
|
||||
$userId = $this->currentUserId();
|
||||
$this->assertDeck();
|
||||
return new DataResponse($this->deckService->listParticipants($boardId));
|
||||
try {
|
||||
return $this->deckService->listOwnedBoards($userId);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
throw new OCSPreconditionFailedException('Deine Deck-Boards konnten nicht geladen werden: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
private function ownedBoardIds(): array {
|
||||
return array_map(static fn (array $board) => $board['id'], $this->ownedBoards());
|
||||
}
|
||||
|
||||
private function assertDeck(): void {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
throw new OCSPreconditionFailedException('Not logged in');
|
||||
throw new OCSPreconditionFailedException('Nicht angemeldet');
|
||||
}
|
||||
try {
|
||||
$this->deckService->assertDeckAvailable($user);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
throw new OCSPreconditionFailedException('Deck is not available: ' . $e->getMessage());
|
||||
throw new OCSPreconditionFailedException('Deck ist nicht verfügbar: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function validate(string $title, int $boardId, int $sourceStackId, int $targetStackId): void {
|
||||
private function validate(string $title, int $boardId, int $sourceStackId, int $targetStackId, string $notifyMode): void {
|
||||
if (trim($title) === '') {
|
||||
throw new OCSBadRequestException('Title must not be empty');
|
||||
throw new OCSBadRequestException('Bitte einen Titel angeben.');
|
||||
}
|
||||
if ($sourceStackId === $targetStackId) {
|
||||
throw new OCSBadRequestException('Source and target stack must differ');
|
||||
throw new OCSBadRequestException('Quell- und Ziel-Stapel müssen sich unterscheiden.');
|
||||
}
|
||||
if (!NotificationPolicy::isValidMode($notifyMode)) {
|
||||
throw new OCSBadRequestException('Ungültige E-Mail-Einstellung, erlaubt sind: ' . implode(', ', NotificationPolicy::MODES));
|
||||
}
|
||||
|
||||
// Reject references to boards or stacks that are gone (or were never
|
||||
@@ -161,12 +173,18 @@ class WorkflowController extends OCSController {
|
||||
// not "Deck is unreachable".
|
||||
$this->assertDeck();
|
||||
|
||||
$boardIds = array_map(
|
||||
static fn (array $board) => (int)$board['id'],
|
||||
$this->deckService->listBoardsForCurrentUser(),
|
||||
);
|
||||
if (!in_array($boardId, $boardIds, true)) {
|
||||
throw new OCSBadRequestException('The selected board does not exist or is not accessible');
|
||||
// Only boards the user owns are listed, so this also enforces the
|
||||
// owner rule. Archived boards stay listed (their workflows must stay
|
||||
// visible) but are no target for a new or changed workflow.
|
||||
$board = null;
|
||||
foreach ($this->ownedBoards() as $candidate) {
|
||||
if ($candidate['id'] === $boardId) {
|
||||
$board = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($board === null || $board['archived']) {
|
||||
throw new OCSBadRequestException('Das gewählte Board existiert nicht, ist archiviert oder gehört dir nicht.');
|
||||
}
|
||||
|
||||
$stackIds = array_map(
|
||||
@@ -174,32 +192,24 @@ class WorkflowController extends OCSController {
|
||||
$this->deckService->listStacks($boardId),
|
||||
);
|
||||
if (!in_array($sourceStackId, $stackIds, true) || !in_array($targetStackId, $stackIds, true)) {
|
||||
throw new OCSBadRequestException('The selected stack does not exist on this board');
|
||||
throw new OCSBadRequestException('Der gewählte Stapel existiert auf diesem Board nicht.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $filterUserIds
|
||||
* @param int[] $filterLabelIds
|
||||
*/
|
||||
private function applyFields(
|
||||
Workflow $workflow,
|
||||
string $title,
|
||||
int $boardId,
|
||||
int $sourceStackId,
|
||||
int $targetStackId,
|
||||
array $filterUserIds,
|
||||
array $filterLabelIds,
|
||||
bool $notifyEmail,
|
||||
string $notifyMode,
|
||||
bool $enabled,
|
||||
): void {
|
||||
$workflow->setTitle($title);
|
||||
$workflow->setBoardId($boardId);
|
||||
$workflow->setSourceStackId($sourceStackId);
|
||||
$workflow->setTargetStackId($targetStackId);
|
||||
$workflow->setFilterUserIds($filterUserIds === [] ? null : json_encode(array_values($filterUserIds)));
|
||||
$workflow->setFilterLabelIds($filterLabelIds === [] ? null : json_encode(array_values($filterLabelIds)));
|
||||
$workflow->setNotifyEmail($notifyEmail);
|
||||
$workflow->setNotifyMode($notifyMode);
|
||||
$workflow->setEnabled($enabled);
|
||||
}
|
||||
}
|
||||
+5
-40
@@ -18,12 +18,8 @@ use OCP\DB\Types;
|
||||
* @method void setSourceStackId(int $sourceStackId)
|
||||
* @method int getTargetStackId()
|
||||
* @method void setTargetStackId(int $targetStackId)
|
||||
* @method string|null getFilterUserIds()
|
||||
* @method void setFilterUserIds(?string $filterUserIds)
|
||||
* @method string|null getFilterLabelIds()
|
||||
* @method void setFilterLabelIds(?string $filterLabelIds)
|
||||
* @method bool getNotifyEmail()
|
||||
* @method void setNotifyEmail(bool $notifyEmail)
|
||||
* @method string getNotifyMode()
|
||||
* @method void setNotifyMode(string $notifyMode)
|
||||
* @method bool getEnabled()
|
||||
* @method void setEnabled(bool $enabled)
|
||||
* @method \DateTime|null getLastRun()
|
||||
@@ -35,9 +31,7 @@ class Workflow extends Entity implements \JsonSerializable {
|
||||
protected $boardId;
|
||||
protected $sourceStackId;
|
||||
protected $targetStackId;
|
||||
protected $filterUserIds;
|
||||
protected $filterLabelIds;
|
||||
protected $notifyEmail;
|
||||
protected $notifyMode;
|
||||
protected $enabled;
|
||||
protected $lastRun;
|
||||
|
||||
@@ -48,38 +42,11 @@ class Workflow extends Entity implements \JsonSerializable {
|
||||
$this->addType('boardId', Types::INTEGER);
|
||||
$this->addType('sourceStackId', Types::INTEGER);
|
||||
$this->addType('targetStackId', Types::INTEGER);
|
||||
$this->addType('filterUserIds', Types::STRING);
|
||||
$this->addType('filterLabelIds', Types::STRING);
|
||||
$this->addType('notifyEmail', Types::BOOLEAN);
|
||||
$this->addType('notifyMode', Types::STRING);
|
||||
$this->addType('enabled', Types::BOOLEAN);
|
||||
$this->addType('lastRun', Types::DATETIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFilterUserIdsArray(): array {
|
||||
return $this->decodeIds($this->getFilterUserIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getFilterLabelIdsArray(): array {
|
||||
return array_map('intval', $this->decodeIds($this->getFilterLabelIds()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function decodeIds(?string $json): array {
|
||||
if ($json === null || $json === '') {
|
||||
return [];
|
||||
}
|
||||
$decoded = json_decode($json, true);
|
||||
return is_array($decoded) ? array_values($decoded) : [];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
@@ -88,9 +55,7 @@ class Workflow extends Entity implements \JsonSerializable {
|
||||
'boardId' => $this->getBoardId(),
|
||||
'sourceStackId' => $this->getSourceStackId(),
|
||||
'targetStackId' => $this->getTargetStackId(),
|
||||
'filterUserIds' => $this->getFilterUserIdsArray(),
|
||||
'filterLabelIds' => $this->getFilterLabelIdsArray(),
|
||||
'notifyEmail' => (bool)$this->getNotifyEmail(),
|
||||
'notifyMode' => (string)$this->getNotifyMode(),
|
||||
'enabled' => (bool)$this->getEnabled(),
|
||||
'lastRun' => $this->getLastRun()?->format(\DateTimeInterface::ATOM),
|
||||
];
|
||||
|
||||
@@ -22,24 +22,27 @@ class WorkflowMapper extends QBMapper {
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function findForUser(int $id, string $userId): Workflow {
|
||||
public function findById(int $id): Workflow {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
|
||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
|
||||
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $boardIds
|
||||
* @return Workflow[]
|
||||
*/
|
||||
public function findAllForUser(string $userId): array {
|
||||
public function findAllForBoards(array $boardIds): array {
|
||||
if ($boardIds === []) {
|
||||
return [];
|
||||
}
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
|
||||
->where($qb->expr()->in('board_id', $qb->createNamedParameter($boardIds, IQueryBuilder::PARAM_INT_ARRAY)))
|
||||
->orderBy('id', 'ASC');
|
||||
|
||||
return $this->findEntities($qb);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
/**
|
||||
* Drops the assigned-user and label filters. Workflows that had one keep
|
||||
* running, now unfiltered — that was an explicit product decision.
|
||||
*
|
||||
* The columns have to go rather than just be ignored: Entity::fromRow()
|
||||
* calls a setter for every selected column, and the Workflow entity no
|
||||
* longer has these properties.
|
||||
*/
|
||||
class Version1001Date20260930120000 extends SimpleMigrationStep {
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if (!$schema->hasTable('wfda_workflows')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = $schema->getTable('wfda_workflows');
|
||||
$changed = false;
|
||||
foreach (['filter_user_ids', 'filter_label_ids'] as $column) {
|
||||
if ($table->hasColumn($column)) {
|
||||
$table->dropColumn($column);
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $changed ? $schema : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\DB\Types;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
/**
|
||||
* Replaces the yes/no `notify_email` flag with `notify_mode`
|
||||
* (off / owner / board, see NotificationPolicy::MODES).
|
||||
*
|
||||
* Existing workflows keep behaving exactly as before: a set flag becomes
|
||||
* `owner` — the only recipient the flag ever had — everything else `off`.
|
||||
* The old column is dropped by the next step, once the values are copied.
|
||||
*/
|
||||
class Version1002Date20261001120000 extends SimpleMigrationStep {
|
||||
public function __construct(
|
||||
private IDBConnection $db,
|
||||
) {
|
||||
}
|
||||
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if (!$schema->hasTable('wfda_workflows')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = $schema->getTable('wfda_workflows');
|
||||
if ($table->hasColumn('notify_mode')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table->addColumn('notify_mode', Types::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 16,
|
||||
'default' => 'off',
|
||||
]);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
if (!$schema->hasTable('wfda_workflows') || !$schema->getTable('wfda_workflows')->hasColumn('notify_email')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->update('wfda_workflows')
|
||||
->set('notify_mode', $qb->createNamedParameter('owner'))
|
||||
->where($qb->expr()->eq('notify_email', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)));
|
||||
$qb->executeStatement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
/**
|
||||
* Drops `notify_email` now that Version1002Date20261001120000 has copied it
|
||||
* into `notify_mode`. It has to go rather than be ignored: Entity::fromRow()
|
||||
* calls a setter per selected column, and Workflow no longer has one.
|
||||
*/
|
||||
class Version1003Date20261001120100 extends SimpleMigrationStep {
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if (!$schema->hasTable('wfda_workflows')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = $schema->getTable('wfda_workflows');
|
||||
if (!$table->hasColumn('notify_email')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table->dropColumn('notify_email');
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Service;
|
||||
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use OCA\Deck\Service\CardService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCA\Deck\Service\StackService;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionProperty;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -32,21 +36,124 @@ class DeckIntegrationService {
|
||||
private const DECK_APP_ID = 'deck';
|
||||
|
||||
/**
|
||||
* Deck's Acl::PERMISSION_TYPE_* values, inlined so this class keeps
|
||||
* working (degrading to "treat it as a user") if Deck ever moves or
|
||||
* renames the constants.
|
||||
* Deck's Acl::PERMISSION_READ, inlined so a moved or renamed constant
|
||||
* cannot fatal this class. It is the key under which
|
||||
* PermissionService::getPermissions() reports read access.
|
||||
*/
|
||||
private const ACL_TYPE_USER = 0;
|
||||
private const ACL_TYPE_GROUP = 1;
|
||||
private const ACL_PERMISSION_READ = 0;
|
||||
|
||||
/**
|
||||
* The property through which Deck carries "the current user" — a plain
|
||||
* string frozen at construction rather than a session lookup. See
|
||||
* beginUserContext().
|
||||
*/
|
||||
private const IDENTITY_PROPERTY = 'userId';
|
||||
|
||||
/**
|
||||
* Further Deck classes holding that same frozen uid. Unlike
|
||||
* PermissionService these do not decide access, only whose name ends up
|
||||
* on an activity entry or whose unread-comment counts are computed, so
|
||||
* failing to pin them is logged and shrugged off.
|
||||
*/
|
||||
private const OPTIONAL_IDENTITY_CLASSES = [
|
||||
CardService::class,
|
||||
BoardService::class,
|
||||
'OCA\Deck\Activity\ActivityManager',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var list<array{ReflectionProperty, object, ?string}>
|
||||
*/
|
||||
private array $identityRestore = [];
|
||||
|
||||
public function __construct(
|
||||
private IAppManager $appManager,
|
||||
private IUserManager $userManager,
|
||||
private IGroupManager $groupManager,
|
||||
private IConfig $config,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pins Deck to $user until endUserContext() — mandatory before any Deck
|
||||
* call made on behalf of someone who is not the logged-in web user.
|
||||
*
|
||||
* IUserSession::setUser() alone is not enough, and that is not obvious:
|
||||
* Deck's PermissionService — the class behind *every* permission check,
|
||||
* including the ones inside CardService::reorder() — receives the current
|
||||
* user as `private ?string $userId`. The app container fills that from
|
||||
* `ISession::get('user_id')` through a **shared** service, so Pimple
|
||||
* computes it once and caches it for the rest of the process, and
|
||||
* ServerContainer keeps the app container just as long. Whoever was
|
||||
* active when Deck's container first built PermissionService is therefore
|
||||
* the user every later check is evaluated against.
|
||||
*
|
||||
* In the background job that is never the user we are impersonating: it
|
||||
* is `null` whenever a Deck-owned job ran earlier in the same cron pass
|
||||
* (cron.php works through many jobs in one process), and otherwise the
|
||||
* first workflow owner we happened to touch. `null` fails every check,
|
||||
* which is how intact boards started reporting NoPermissionException and
|
||||
* got their workflows switched off.
|
||||
*
|
||||
* Deck exposes no API for this, so the frozen value is swapped directly
|
||||
* and put back in endUserContext(). PermissionService is required: if it
|
||||
* cannot be pinned this throws, and the caller has to skip the user
|
||||
* rather than run them under someone else's permissions.
|
||||
*
|
||||
* @throws DeckUnavailableException
|
||||
*/
|
||||
public function beginUserContext(IUser $user): void {
|
||||
if ($this->identityRestore !== []) {
|
||||
throw new DeckUnavailableException('A Deck user context is already active');
|
||||
}
|
||||
|
||||
$uid = $user->getUID();
|
||||
|
||||
try {
|
||||
$this->pinDeckIdentity($this->resolve(PermissionService::class), $uid);
|
||||
} catch (Throwable $e) {
|
||||
$this->endUserContext();
|
||||
throw new DeckUnavailableException(
|
||||
'Could not run Deck as ' . $uid . ': ' . $e->getMessage(),
|
||||
0,
|
||||
$e,
|
||||
);
|
||||
}
|
||||
|
||||
foreach (self::OPTIONAL_IDENTITY_CLASSES as $class) {
|
||||
try {
|
||||
$this->pinDeckIdentity($this->resolve($class), $uid);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->debug('Could not pin ' . $class . ' to ' . $uid . ': ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores what beginUserContext() replaced. Idempotent, so it can be
|
||||
* called unconditionally from a finally block.
|
||||
*/
|
||||
public function endUserContext(): void {
|
||||
foreach (array_reverse($this->identityRestore) as [$property, $service, $previous]) {
|
||||
try {
|
||||
$property->setValue($service, $previous);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->warning('Could not restore Deck identity on ' . $service::class . ': ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
]);
|
||||
}
|
||||
}
|
||||
$this->identityRestore = [];
|
||||
}
|
||||
|
||||
private function pinDeckIdentity(object $service, string $uid): void {
|
||||
$property = new ReflectionProperty($service, self::IDENTITY_PROPERTY);
|
||||
$previous = $property->isInitialized($service) ? $property->getValue($service) : null;
|
||||
$property->setValue($service, $uid);
|
||||
$this->identityRestore[] = [$property, $service, is_string($previous) ? $previous : null];
|
||||
}
|
||||
|
||||
public function assertDeckAvailable(IUser $user): void {
|
||||
if (!$this->appManager->isEnabledForUser(self::DECK_APP_ID, $user)) {
|
||||
throw new DeckUnavailableException('Deck is not enabled for user ' . $user->getUID());
|
||||
@@ -57,56 +164,44 @@ class DeckIntegrationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: int, title: string}>
|
||||
* The boards `$userId` owns — the only boards workflows may live on, and
|
||||
* the boards whose workflows that user sees and manages.
|
||||
*
|
||||
* Only ever call this from a *request*: Deck injects the current user id
|
||||
* into BoardService as a plain string frozen at construction time, so in
|
||||
* the background job (one process, many users, a container-cached
|
||||
* BoardService) this would answer for the wrong user — or for none at
|
||||
* all. The job uses findStackIds() instead, which goes through Deck's
|
||||
* PermissionService and therefore reads the live session.
|
||||
* One query: BoardMapper::findAllByOwner() is `WHERE owner = :uid`, so
|
||||
* shared boards never come back, and as a plain QBMapper it has none of
|
||||
* the frozen-uid state of BoardService::getUserBoards(). It does return
|
||||
* archived and trashed boards; trashed ones are dropped here, archived
|
||||
* ones are kept but flagged — their workflows still exist and must stay
|
||||
* visible, they just aren't offered as a new target.
|
||||
*
|
||||
* Throws instead of degrading to `[]`: an empty list would read as "you
|
||||
* own no boards" and hide every workflow the user has.
|
||||
*
|
||||
* @return array<int, array{id: int, title: string, archived: bool}>
|
||||
* @throws DeckUnavailableException
|
||||
*/
|
||||
public function listBoardsForCurrentUser(): array {
|
||||
$boards = $this->call(function () {
|
||||
$boardService = $this->resolve(BoardService::class);
|
||||
try {
|
||||
// getUserBoards(?int $since, bool $includeArchived, …): with
|
||||
// the default $includeArchived = true, Deck skips the
|
||||
// `archived = false AND deleted_at = 0` conditions entirely,
|
||||
// so archived *and* trashed boards come back. Ask for the
|
||||
// filtered query instead of sorting them out afterwards.
|
||||
return $boardService->getUserBoards(null, false);
|
||||
} catch (Throwable $e) {
|
||||
// Older/newer Deck with a different signature: fall back to
|
||||
// the unfiltered call, isBoardHidden() below still filters.
|
||||
return $boardService->getUserBoards();
|
||||
}
|
||||
}, []);
|
||||
public function listOwnedBoards(string $userId): array {
|
||||
$boards = $this->call(
|
||||
fn () => $this->resolve(BoardMapper::class)->findAllByOwner($userId),
|
||||
[],
|
||||
true,
|
||||
);
|
||||
|
||||
// Deck merges own/group/circle boards, so the same board can come
|
||||
// back more than once; and boards in the trash or archived ones are
|
||||
// no useful automation target. Keyed by id => deduplicated.
|
||||
$result = [];
|
||||
foreach ($boards as $board) {
|
||||
$id = (int)$board->getId();
|
||||
if (isset($result[$id]) || $this->isBoardHidden($board)) {
|
||||
if (method_exists($board, 'getDeletedAt') && (int)$board->getDeletedAt() > 0) {
|
||||
continue;
|
||||
}
|
||||
$id = (int)$board->getId();
|
||||
$title = $board->getTitle();
|
||||
$result[$id] = [
|
||||
$result[] = [
|
||||
'id' => $id,
|
||||
'title' => (is_string($title) && $title !== '') ? $title : ('#' . $id),
|
||||
'archived' => method_exists($board, 'getArchived') && (bool)$board->getArchived(),
|
||||
];
|
||||
}
|
||||
|
||||
return array_values($result);
|
||||
}
|
||||
|
||||
private function isBoardHidden(mixed $board): bool {
|
||||
if (method_exists($board, 'getDeletedAt') && (int)$board->getDeletedAt() > 0) {
|
||||
return true;
|
||||
}
|
||||
return method_exists($board, 'getArchived') && $board->getArchived() === true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,23 +222,46 @@ class DeckIntegrationService {
|
||||
* Ids of the board's stacks, for deciding whether a stored workflow still
|
||||
* points at anything real.
|
||||
*
|
||||
* Returns `null` when the board itself is gone or not readable for the
|
||||
* current user — `StackService::findAll()` runs a Deck permission check
|
||||
* first, and that one reads the *live* session, which is what makes this
|
||||
* usable from the impersonating background job. Any other failure throws,
|
||||
* Returns `null` only on positive knowledge that the board is gone, in the
|
||||
* trash, or no longer readable for `$userId`. Every other failure throws,
|
||||
* because "Deck is broken right now" must never be mistaken for "the user
|
||||
* deleted this board".
|
||||
* deleted this board" — the caller reacts by switching the workflow off
|
||||
* and mailing its owner.
|
||||
*
|
||||
* Deliberately assembled from pieces that cannot answer for the wrong
|
||||
* user. BoardMapper and StackMapper are plain QBMappers with no user
|
||||
* state (StackMapper::findAll() filters `deleted_at = 0` itself), and
|
||||
* getPermissions() is handed the uid explicitly instead of falling back
|
||||
* to PermissionService's construction-time `$userId`. Leaning on that
|
||||
* frozen value — which is exactly what `StackService::findAll()` does
|
||||
* internally — is what disabled workflows whose board was perfectly
|
||||
* intact, so this must not be "simplified" back to one service call even
|
||||
* once beginUserContext() has pinned the identity.
|
||||
*
|
||||
* @return int[]|null
|
||||
* @throws DeckUnavailableException
|
||||
*/
|
||||
public function findStackIds(int $boardId): ?array {
|
||||
public function findStackIds(int $boardId, string $userId): ?array {
|
||||
try {
|
||||
$stacks = $this->resolve(StackService::class)->findAll($boardId);
|
||||
$board = $this->resolve(BoardMapper::class)->find($boardId);
|
||||
if (method_exists($board, 'getDeletedAt') && (int)$board->getDeletedAt() > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$permissions = $this->resolve(PermissionService::class)->getPermissions($boardId, $userId);
|
||||
if (!array_key_exists(self::ACL_PERMISSION_READ, $permissions)) {
|
||||
// Unknown shape: say nothing rather than something wrong.
|
||||
throw new DeckUnavailableException('Deck reported no read permission for board ' . $boardId);
|
||||
}
|
||||
if ($permissions[self::ACL_PERMISSION_READ] !== true) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stacks = $this->resolve(StackMapper::class)->findAll($boardId);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
if ($this->isMissingOrForbidden($e)) {
|
||||
if ($this->isMissing($e)) {
|
||||
return null;
|
||||
}
|
||||
$this->logger->error('Could not list stacks of board ' . $boardId . ': ' . $e->getMessage(), [
|
||||
@@ -156,101 +274,166 @@ class DeckIntegrationService {
|
||||
return array_map(static fn ($stack) => (int)$stack->getId(), $stacks);
|
||||
}
|
||||
|
||||
/**
|
||||
* The uid of the board's current owner — the user a workflow on that
|
||||
* board belongs to. Workflows follow the board: when Deck transfers its
|
||||
* ownership, they move to the new owner along with it.
|
||||
*
|
||||
* Read through BoardMapper, a plain QBMapper without user state, so it
|
||||
* answers the same in a request and in cron. Trashed and archived boards
|
||||
* still report their owner. `null` only if the board row is gone; every
|
||||
* other failure throws, like findStackIds().
|
||||
*
|
||||
* @throws DeckUnavailableException
|
||||
*/
|
||||
public function findBoardOwner(int $boardId): ?string {
|
||||
try {
|
||||
$board = $this->resolve(BoardMapper::class)->find($boardId);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
if ($this->isMissing($e)) {
|
||||
return null;
|
||||
}
|
||||
throw new DeckUnavailableException('Could not read owner of board ' . $boardId . ': ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
$owner = $this->unwrapUid($board->getOwner());
|
||||
if ($owner === null) {
|
||||
throw new DeckUnavailableException('Board ' . $boardId . ' has no readable owner');
|
||||
}
|
||||
return $owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Who should hear about each of the given (moved) cards, according to
|
||||
* every board member's own Deck notification setting for this board —
|
||||
* the "Notifications: none / assigned cards / all cards" menu, stored as
|
||||
* the user preference `deck` / `board:<id>:notify-due`. The decision
|
||||
* itself is NotificationPolicy::shouldNotify(), a copy of Deck's rules.
|
||||
*
|
||||
* Like findStackIds(), assembled only from pieces that take the users
|
||||
* explicitly and never consult Deck's frozen `$userId`:
|
||||
* PermissionService::findUsers() reads the owner and ACL through mappers
|
||||
* and expands groups and circles itself; AssignmentMapper is a plain
|
||||
* mapper that also resolves group/circle assignments; the preference is
|
||||
* read straight from IConfig.
|
||||
*
|
||||
* Throws on any failure, so the caller can log and skip the mail instead
|
||||
* of mailing a half-resolved or wrong set of people.
|
||||
*
|
||||
* @param int[] $cardIds
|
||||
* @return array<int, list<string>> card id => uids to notify
|
||||
* @throws DeckUnavailableException
|
||||
*/
|
||||
public function findNotificationRecipients(int $boardId, array $cardIds): array {
|
||||
try {
|
||||
$board = $this->resolve(BoardMapper::class)->find($boardId, false, true);
|
||||
$owner = $this->unwrapUid($board->getOwner());
|
||||
// Deck notifies the owner of a board nobody else can see about
|
||||
// every card: "assigned" means nothing there.
|
||||
$unshared = count($board->getAcl() ?? []) === 0;
|
||||
|
||||
// `true` bypasses PermissionService's per-process cache, which
|
||||
// would otherwise outlive ACL changes for the whole cron pass.
|
||||
$participants = $this->resolve(PermissionService::class)->findUsers($boardId, true);
|
||||
$assignments = $this->resolve(AssignmentMapper::class);
|
||||
|
||||
$settings = [];
|
||||
foreach ($participants as $uid => $participant) {
|
||||
// Users of other instances (FederatedUser) have no local
|
||||
// account and no preference to read.
|
||||
if (!is_a($participant, 'OCA\Deck\Db\User')) {
|
||||
continue;
|
||||
}
|
||||
// Numeric uids come back as integer array keys.
|
||||
$uid = (string)$uid;
|
||||
$settings[$uid] = (string)$this->config->getUserValue(
|
||||
$uid,
|
||||
self::DECK_APP_ID,
|
||||
'board:' . $boardId . ':notify-due',
|
||||
NotificationPolicy::DECK_DEFAULT,
|
||||
);
|
||||
}
|
||||
|
||||
$recipients = [];
|
||||
foreach ($cardIds as $cardId) {
|
||||
$recipients[$cardId] = [];
|
||||
foreach ($settings as $uid => $setting) {
|
||||
$uid = (string)$uid;
|
||||
$notify = NotificationPolicy::shouldNotify(
|
||||
$setting,
|
||||
$unshared && $uid === $owner,
|
||||
static fn (): bool => (bool)$assignments->isUserAssigned($cardId, $uid),
|
||||
);
|
||||
if ($notify) {
|
||||
$recipients[$cardId][] = $uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DeckUnavailableException $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
throw new DeckUnavailableException('Could not resolve notification recipients for board ' . $boardId . ': ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deck's own exception classes are referenced by name: `is_a()` with a
|
||||
* string simply returns false when the class does not exist, so a missing
|
||||
* or renamed Deck degrades to "unknown error" instead of fataling.
|
||||
*
|
||||
* `OCA\Deck\NoPermissionException` is deliberately *not* treated as "the
|
||||
* board is gone" here. It used to be, and that is what switched intact
|
||||
* workflows off: Deck raises it for any check that fails, including every
|
||||
* check evaluated against the wrong frozen uid — which says nothing at
|
||||
* all about whether the board still exists.
|
||||
*/
|
||||
private function isMissingOrForbidden(Throwable $e): bool {
|
||||
private function isMissing(Throwable $e): bool {
|
||||
if ($e instanceof DoesNotExistException) {
|
||||
return true;
|
||||
}
|
||||
foreach (['OCA\Deck\NoPermissionException', 'OCA\Deck\NotFoundException'] as $class) {
|
||||
if (is_a($e, $class)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return is_a($e, 'OCA\Deck\NotFoundException');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: int, title: string, color: string|null}>
|
||||
*/
|
||||
public function listLabels(int $boardId): array {
|
||||
$labels = $this->call(function () use ($boardId) {
|
||||
$board = $this->resolve(BoardService::class)->find($boardId, true);
|
||||
return $board->getLabels() ?? [];
|
||||
}, []);
|
||||
|
||||
return array_map(
|
||||
static fn ($label) => ['id' => $label->getId(), 'title' => $label->getTitle(), 'color' => $label->getColor()],
|
||||
$labels,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Everyone who can hold a card on this board: the board owner (who is
|
||||
* *not* part of the ACL — a private board has an empty ACL) plus every
|
||||
* ACL entry, with group shares expanded to their members.
|
||||
* Titles of a workflow's board and stacks, for the notification mail.
|
||||
*
|
||||
* @return array<int, array{uid: string, displayName: string}>
|
||||
* Best effort by design: this only decorates a mail that is being sent
|
||||
* because a card *was* already moved, so anything unreadable degrades to
|
||||
* `#<id>` rather than costing the user their notification.
|
||||
*
|
||||
* @return array{board: string, sourceStack: string, targetStack: string}
|
||||
*/
|
||||
public function listParticipants(int $boardId): array {
|
||||
$uids = $this->call(function () use ($boardId) {
|
||||
$board = $this->resolve(BoardService::class)->find($boardId, true);
|
||||
|
||||
$uids = [];
|
||||
$owner = $this->unwrapUid($board->getOwner());
|
||||
if ($owner !== null) {
|
||||
$uids[] = $owner;
|
||||
public function describeTargets(int $boardId, int $sourceStackId, int $targetStackId): array {
|
||||
$titles = $this->call(function () use ($boardId) {
|
||||
$stackTitles = [];
|
||||
foreach ($this->resolve(StackMapper::class)->findAll($boardId) as $stack) {
|
||||
$stackTitles[(int)$stack->getId()] = (string)$stack->getTitle();
|
||||
}
|
||||
|
||||
foreach ($board->getAcl() ?? [] as $entry) {
|
||||
$principal = $this->extractParticipantUid($entry);
|
||||
if ($principal === null) {
|
||||
continue;
|
||||
}
|
||||
$type = method_exists($entry, 'getType') ? (int)$entry->getType() : self::ACL_TYPE_USER;
|
||||
if ($type === self::ACL_TYPE_GROUP) {
|
||||
array_push($uids, ...$this->groupMemberUids($principal));
|
||||
} elseif ($type === self::ACL_TYPE_USER) {
|
||||
$uids[] = $principal;
|
||||
}
|
||||
// Circles and federated shares are skipped: their members
|
||||
// cannot be resolved to plain uids here.
|
||||
}
|
||||
|
||||
return $uids;
|
||||
}, []);
|
||||
|
||||
$participants = [];
|
||||
foreach ($uids as $uid) {
|
||||
if (isset($participants[$uid])) {
|
||||
continue;
|
||||
}
|
||||
$participants[$uid] = [
|
||||
'uid' => $uid,
|
||||
'displayName' => $this->userManager->get($uid)?->getDisplayName() ?? $uid,
|
||||
return [
|
||||
'board' => (string)$this->resolve(BoardMapper::class)->find($boardId)->getTitle(),
|
||||
'stacks' => $stackTitles,
|
||||
];
|
||||
}
|
||||
}, ['board' => '', 'stacks' => []]);
|
||||
|
||||
return array_values($participants);
|
||||
return [
|
||||
'board' => self::titleOr($titles['board'], $boardId),
|
||||
'sourceStack' => self::titleOr($titles['stacks'][$sourceStackId] ?? '', $sourceStackId),
|
||||
'targetStack' => self::titleOr($titles['stacks'][$targetStackId] ?? '', $targetStackId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function groupMemberUids(string $groupId): array {
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
return [];
|
||||
}
|
||||
return array_map(static fn (IUser $user) => $user->getUID(), $group->getUsers());
|
||||
private static function titleOr(string $title, int $id): string {
|
||||
return $title !== '' ? $title : ('#' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cards in the given stack that are neither archived, deleted nor marked
|
||||
* done, enriched so getAssignedUsers()/getLabels() are populated.
|
||||
* done.
|
||||
*
|
||||
* The `deletedAt` check is not redundant: Deck's
|
||||
* `CardMapper::findAllByStack()` filters on `stack_id` and
|
||||
@@ -262,11 +445,12 @@ class DeckIntegrationService {
|
||||
*/
|
||||
public function getActiveCardsInStack(int $stackId): array {
|
||||
return $this->call(function () use ($stackId) {
|
||||
$cardMapper = $this->resolve(CardMapper::class);
|
||||
$cardService = $this->resolve(CardService::class);
|
||||
|
||||
$cards = $cardMapper->findAllByStack($stackId);
|
||||
$cards = $cardService->enrichCards($cards);
|
||||
// Deliberately not enriched: CardService::enrichCards() only adds
|
||||
// labels, assignees and comment counts, and runs
|
||||
// BoardService::find(), a permission check against Deck's frozen
|
||||
// uid (see beginUserContext()). Assignments, where needed for
|
||||
// mails, come from findNotificationRecipients() instead.
|
||||
$cards = $this->resolve(CardMapper::class)->findAllByStack($stackId);
|
||||
|
||||
return array_values(array_filter($cards, static function (Card $card) {
|
||||
if (method_exists($card, 'getDeletedAt') && (int)$card->getDeletedAt() > 0) {
|
||||
@@ -277,35 +461,6 @@ class DeckIntegrationService {
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCardAssignedUserIds(Card $card): array {
|
||||
$assigned = $card->getAssignedUsers() ?? [];
|
||||
$uids = [];
|
||||
foreach ($assigned as $entry) {
|
||||
$uid = $this->extractParticipantUid($entry);
|
||||
if ($uid !== null) {
|
||||
$uids[] = $uid;
|
||||
}
|
||||
}
|
||||
return $uids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getCardLabelIds(Card $card): array {
|
||||
$labels = $card->getLabels() ?? [];
|
||||
$ids = [];
|
||||
foreach ($labels as $label) {
|
||||
if (method_exists($label, 'getId')) {
|
||||
$ids[] = (int)$label->getId();
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a card to another stack using Deck's own reorder logic
|
||||
* (the exact same code path behind Deck's "move card" action).
|
||||
@@ -352,31 +507,6 @@ class DeckIntegrationService {
|
||||
return Server::get($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deck's assignment/ACL entries are internal, undocumented value
|
||||
* objects whose exact accessor shape has changed across versions, so
|
||||
* we probe the common accessor names defensively instead of relying
|
||||
* on one fixed method signature.
|
||||
*/
|
||||
private function extractParticipantUid(mixed $entry): ?string {
|
||||
$uid = $this->unwrapUid($entry);
|
||||
if ($uid !== null) {
|
||||
return $uid;
|
||||
}
|
||||
if (!is_object($entry)) {
|
||||
return null;
|
||||
}
|
||||
foreach (['getParticipant', 'getUid', 'getParticipantUid', 'getUserId'] as $method) {
|
||||
if (method_exists($entry, $method)) {
|
||||
$uid = $this->unwrapUid($entry->$method());
|
||||
if ($uid !== null) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns whatever Deck hands out for a "participant"/"owner" field into
|
||||
* a plain uid.
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace OCA\WorkflowDeckAutomation\Service;
|
||||
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\WorkflowDeckAutomation\Db\Workflow;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
@@ -15,69 +14,120 @@ use OCP\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The app is used internally only and speaks German, like its settings
|
||||
* page: texts are written in German directly instead of going through
|
||||
* IL10N with English source strings and a translation file.
|
||||
*/
|
||||
class NotificationMailer {
|
||||
private const APP_ID = 'workflow_deck_automation';
|
||||
|
||||
private const SENDER_NAME = 'Deck Workflow-Automatisierung';
|
||||
|
||||
/**
|
||||
* Descriptions are unbounded in Deck; keep the mail readable and well
|
||||
* clear of any MTA size limits.
|
||||
* Language of Nextcloud's own footer text ("automatically sent email,
|
||||
* please do not reply"), which would otherwise follow the instance
|
||||
* default — in cron there is no request to take a language from.
|
||||
*/
|
||||
private const MAX_DESCRIPTION_LENGTH = 2000;
|
||||
private const FOOTER_LANGUAGE = 'de';
|
||||
|
||||
public function __construct(
|
||||
private IMailer $mailer,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private IL10N $l10n,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public function sendCardMovedNotification(IUser $user, Workflow $workflow, Card $card): void {
|
||||
$email = $user->getEMailAddress();
|
||||
/**
|
||||
* One mail listing every card moved for $recipient in this run — they
|
||||
* may come from several workflows and boards.
|
||||
*
|
||||
* @param non-empty-list<array{workflow: Workflow, card: Card, targets: array{board: string, sourceStack: string, targetStack: string}}> $entries
|
||||
* targets are the titles resolved by DeckIntegrationService::describeTargets()
|
||||
*/
|
||||
public function sendCardsMovedNotification(IUser $recipient, array $entries): void {
|
||||
$email = $recipient->getEMailAddress();
|
||||
if ($email === null || $email === '') {
|
||||
$this->logger->info('Skipping notification for workflow ' . $workflow->getId() . ': user ' . $user->getUID() . ' has no email address', [
|
||||
'app' => 'workflow_deck_automation',
|
||||
$this->logger->info('Skipping moved-cards mail: user ' . $recipient->getUID() . ' has no email address', [
|
||||
'app' => self::APP_ID,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$cardLink = $this->urlGenerator->getAbsoluteURL(
|
||||
'/apps/deck/board/' . $workflow->getBoardId() . '/card/' . $card->getId(),
|
||||
);
|
||||
$count = count($entries);
|
||||
|
||||
$template = $this->mailer->createEMailTemplate('workflow_deck_automation.CardMoved', [
|
||||
'cardTitle' => $card->getTitle(),
|
||||
'workflowTitle' => $workflow->getTitle(),
|
||||
try {
|
||||
$template = $this->mailer->createEMailTemplate(self::APP_ID . '.CardsMoved', [
|
||||
'count' => $count,
|
||||
'cardTitles' => array_map(static fn (array $entry) => $entry['card']->getTitle(), $entries),
|
||||
]);
|
||||
$template->setSubject($this->l10n->t('Deck card moved: %s', [$card->getTitle()]));
|
||||
$template->setSubject($count === 1
|
||||
? sprintf('Deck-Karte verschoben: %s', $entries[0]['card']->getTitle())
|
||||
: sprintf('%d Deck-Karten verschoben', $count));
|
||||
$template->addHeader();
|
||||
$template->addHeading($this->l10n->t('A card was moved automatically'), false);
|
||||
$template->addBodyText($this->l10n->t(
|
||||
'The card "%1$s" was moved because it is overdue (workflow "%2$s").',
|
||||
[$card->getTitle(), $workflow->getTitle()],
|
||||
));
|
||||
$this->addCardDescription($template, $card);
|
||||
$template->addBodyButton($this->l10n->t('Open card'), $cardLink);
|
||||
$template->addFooter();
|
||||
$template->addHeading($count === 1
|
||||
? 'Eine Karte wurde automatisch verschoben'
|
||||
: sprintf('%d Karten wurden automatisch verschoben', $count), false);
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$this->addCard($template, $entry['workflow'], $entry['card'], $entry['targets']);
|
||||
}
|
||||
|
||||
$template->addFooter('', self::FOOTER_LANGUAGE);
|
||||
|
||||
$message = $this->mailer->createMessage();
|
||||
$message->setTo([$email => $user->getDisplayName()]);
|
||||
$message->setFrom([Util::getDefaultEmailAddress('noreply') => $this->l10n->t('Deck Workflow Automation')]);
|
||||
$message->setTo([$email => $recipient->getDisplayName()]);
|
||||
$message->setFrom([Util::getDefaultEmailAddress('noreply') => self::SENDER_NAME]);
|
||||
$message->useTemplate($template);
|
||||
|
||||
$failedRecipients = $this->mailer->send($message);
|
||||
if (!empty($failedRecipients)) {
|
||||
$this->logger->error('Notification mail for card ' . $card->getId() . ' failed for: ' . implode(', ', $failedRecipients), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
$this->logger->error('Moved-cards mail failed for: ' . implode(', ', $failedRecipients), [
|
||||
'app' => self::APP_ID,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('Could not send notification mail for card ' . $card->getId() . ': ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
$this->logger->error('Could not send moved-cards mail to ' . $recipient->getUID() . ': ' . $e->getMessage(), [
|
||||
'app' => self::APP_ID,
|
||||
'exception' => $e,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{board: string, sourceStack: string, targetStack: string} $targets
|
||||
*/
|
||||
private function addCard(IEMailTemplate $template, Workflow $workflow, Card $card, array $targets): void {
|
||||
// The card description and the workflow's name are deliberately left
|
||||
// out — the mail only says what moved where. The card title itself is
|
||||
// the link to the card.
|
||||
$sentence = '„%1$s“ (Board „%2$s“) ist überfällig und wurde von „%3$s“ nach „%4$s“ verschoben.';
|
||||
$url = $this->urlGenerator->getAbsoluteURL('/apps/deck/board/' . $workflow->getBoardId() . '/card/' . $card->getId());
|
||||
|
||||
// With both parts passed, addBodyText() escapes nothing: every title
|
||||
// is user input and has to be escaped here for the HTML part.
|
||||
$html = sprintf(
|
||||
$sentence,
|
||||
'<a href="' . self::escape($url) . '">' . self::escape($card->getTitle()) . '</a>',
|
||||
self::escape($targets['board']),
|
||||
self::escape($targets['sourceStack']),
|
||||
self::escape($targets['targetStack']),
|
||||
);
|
||||
$plain = sprintf(
|
||||
$sentence,
|
||||
$card->getTitle(),
|
||||
$targets['board'],
|
||||
$targets['sourceStack'],
|
||||
$targets['targetStack'],
|
||||
) . PHP_EOL . $url;
|
||||
|
||||
$template->addBodyText($html, $plain);
|
||||
}
|
||||
|
||||
private static function escape(string $text): string {
|
||||
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* One-off notice that a workflow was switched off because the board or
|
||||
* stack it points at is gone.
|
||||
@@ -88,81 +138,53 @@ class NotificationMailer {
|
||||
$email = $user->getEMailAddress();
|
||||
if ($email === null || $email === '') {
|
||||
$this->logger->info('Cannot notify about disabled workflow ' . $workflow->getId() . ': user ' . $user->getUID() . ' has no email address', [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'app' => self::APP_ID,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$reason = match ($brokenTarget) {
|
||||
WorkflowRunner::TARGET_SOURCE_STACK => $this->l10n->t('its source stack no longer exists'),
|
||||
WorkflowRunner::TARGET_TARGET_STACK => $this->l10n->t('its target stack no longer exists'),
|
||||
default => $this->l10n->t('its board no longer exists or is no longer available to you'),
|
||||
WorkflowRunner::TARGET_SOURCE_STACK => 'sein Quell-Stapel nicht mehr existiert',
|
||||
WorkflowRunner::TARGET_TARGET_STACK => 'sein Ziel-Stapel nicht mehr existiert',
|
||||
default => 'sein Board nicht mehr existiert oder für dich nicht mehr verfügbar ist',
|
||||
};
|
||||
|
||||
try {
|
||||
$settingsLink = $this->urlGenerator->getAbsoluteURL('/settings/user/workflow_deck_automation');
|
||||
$settingsLink = $this->urlGenerator->getAbsoluteURL('/settings/user/' . self::APP_ID);
|
||||
|
||||
$template = $this->mailer->createEMailTemplate('workflow_deck_automation.WorkflowDisabled', [
|
||||
$template = $this->mailer->createEMailTemplate(self::APP_ID . '.WorkflowDisabled', [
|
||||
'workflowTitle' => $workflow->getTitle(),
|
||||
]);
|
||||
$template->setSubject($this->l10n->t('Deck workflow deactivated: %s', [$workflow->getTitle()]));
|
||||
$template->setSubject(sprintf('Deck-Workflow deaktiviert: %s', $workflow->getTitle()));
|
||||
$template->addHeader();
|
||||
$template->addHeading($this->l10n->t('A workflow was deactivated'), false);
|
||||
$template->addBodyText($this->l10n->t(
|
||||
'The workflow "%1$s" was switched off automatically because %2$s. No cards are being moved by it any more.',
|
||||
[$workflow->getTitle(), $reason],
|
||||
$template->addHeading('Ein Workflow wurde deaktiviert', false);
|
||||
$template->addBodyText(sprintf(
|
||||
'Der Workflow „%1$s“ wurde automatisch ausgeschaltet, weil %2$s. Er verschiebt keine Karten mehr.',
|
||||
$workflow->getTitle(),
|
||||
$reason,
|
||||
));
|
||||
$template->addBodyText($this->l10n->t(
|
||||
'Delete the workflow or point it at an existing board and stack to reactivate it. You will not be reminded about this workflow again.',
|
||||
));
|
||||
$template->addBodyButton($this->l10n->t('Open settings'), $settingsLink);
|
||||
$template->addFooter();
|
||||
$template->addBodyText(
|
||||
'Lösche den Workflow oder stelle ein vorhandenes Board und vorhandene Stapel ein, um ihn wieder zu aktivieren. An diesen Workflow wirst du nicht noch einmal erinnert.',
|
||||
);
|
||||
$template->addBodyButton('Einstellungen öffnen', $settingsLink);
|
||||
$template->addFooter('', self::FOOTER_LANGUAGE);
|
||||
|
||||
$message = $this->mailer->createMessage();
|
||||
$message->setTo([$email => $user->getDisplayName()]);
|
||||
$message->setFrom([Util::getDefaultEmailAddress('noreply') => $this->l10n->t('Deck Workflow Automation')]);
|
||||
$message->setFrom([Util::getDefaultEmailAddress('noreply') => self::SENDER_NAME]);
|
||||
$message->useTemplate($template);
|
||||
|
||||
$failedRecipients = $this->mailer->send($message);
|
||||
if (!empty($failedRecipients)) {
|
||||
$this->logger->error('Deactivation mail for workflow ' . $workflow->getId() . ' failed for: ' . implode(', ', $failedRecipients), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'app' => self::APP_ID,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('Could not send deactivation mail for workflow ' . $workflow->getId() . ': ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'app' => self::APP_ID,
|
||||
'exception' => $e,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the card's description, if it has one.
|
||||
*
|
||||
* Deck stores the description as Markdown. It is sent as-is rather than
|
||||
* rendered: pulling a Markdown parser in just for the mail would be a
|
||||
* lot of machinery, and unrendered Markdown still reads fine.
|
||||
*/
|
||||
private function addCardDescription(IEMailTemplate $template, Card $card): void {
|
||||
$description = trim((string)$card->getDescription());
|
||||
if ($description === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mb_strlen($description) > self::MAX_DESCRIPTION_LENGTH) {
|
||||
$description = mb_substr($description, 0, self::MAX_DESCRIPTION_LENGTH) . ' […]';
|
||||
}
|
||||
|
||||
$template->addBodyText($this->l10n->t('Card content:'));
|
||||
|
||||
// addBodyText() only runs htmlspecialchars() when it has to build the
|
||||
// plain-text part itself. Passing both parts means escaping is on us
|
||||
// -- and it has to be, because a card description is user input that
|
||||
// would otherwise land unescaped in the HTML mail.
|
||||
$template->addBodyText(
|
||||
nl2br(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), false),
|
||||
$description,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Service;
|
||||
|
||||
/**
|
||||
* Who gets a mail about a moved card — pure logic, no Nextcloud or Deck
|
||||
* dependencies, so it is unit-testable like WorkflowRunner::isOverdue().
|
||||
*/
|
||||
class NotificationPolicy {
|
||||
/** No mail at all. */
|
||||
public const MODE_OFF = 'off';
|
||||
/** Only the workflow's owner (the board owner), regardless of Deck settings. */
|
||||
public const MODE_OWNER = 'owner';
|
||||
/** Everyone with access to the board, filtered by their own Deck setting. */
|
||||
public const MODE_BOARD = 'board';
|
||||
|
||||
public const MODES = [self::MODE_OFF, self::MODE_OWNER, self::MODE_BOARD];
|
||||
|
||||
/**
|
||||
* Values of Deck's per-user, per-board preference
|
||||
* `deck` / `board:<boardId>:notify-due` (Deck's
|
||||
* ConfigService::SETTING_BOARD_NOTIFICATION_DUE_*), inlined so a renamed
|
||||
* constant cannot fatal this app. It is the board's "Notifications" menu
|
||||
* in Deck — the due-date reminder setting, which is exactly what fits a
|
||||
* card being moved because it fell due.
|
||||
*/
|
||||
public const DECK_OFF = 'off';
|
||||
public const DECK_ASSIGNED = 'assigned';
|
||||
public const DECK_ALL = 'all';
|
||||
/** What Deck assumes for a user who never touched the setting. */
|
||||
public const DECK_DEFAULT = self::DECK_ASSIGNED;
|
||||
|
||||
public static function isValidMode(string $mode): bool {
|
||||
return in_array($mode, self::MODES, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors Deck's own decision in NotificationHelper::sendCardDuedate():
|
||||
*
|
||||
* - `off` never notifies — not even the owner of an unshared board;
|
||||
* - `all` always notifies;
|
||||
* - the owner of an unshared board is notified for every card, since on a
|
||||
* board nobody else can see "assigned" would otherwise mean nothing;
|
||||
* - `assigned` notifies users assigned to the card, directly or through a
|
||||
* group or circle.
|
||||
*
|
||||
* An unknown value is treated as Deck's default. Deck rejects anything
|
||||
* else when storing the setting, so that only happens if the preference
|
||||
* was edited by hand.
|
||||
*
|
||||
* @param bool|callable(): bool $isAssigned a callable is only invoked when
|
||||
* the answer actually depends on it — it costs a query per user
|
||||
*/
|
||||
public static function shouldNotify(string $deckSetting, bool $isOwnerOfUnsharedBoard, bool|callable $isAssigned): bool {
|
||||
if (!in_array($deckSetting, [self::DECK_OFF, self::DECK_ASSIGNED, self::DECK_ALL], true)) {
|
||||
$deckSetting = self::DECK_DEFAULT;
|
||||
}
|
||||
|
||||
if ($deckSetting === self::DECK_OFF) {
|
||||
return false;
|
||||
}
|
||||
if ($deckSetting === self::DECK_ALL || $isOwnerOfUnsharedBoard) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return is_callable($isAssigned) ? (bool)$isAssigned() : $isAssigned;
|
||||
}
|
||||
}
|
||||
+246
-54
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\WorkflowDeckAutomation\Db\Workflow;
|
||||
use OCA\WorkflowDeckAutomation\Db\WorkflowMapper;
|
||||
@@ -18,12 +21,15 @@ use Throwable;
|
||||
/**
|
||||
* Evaluates all enabled workflows and moves overdue cards.
|
||||
*
|
||||
* Deck's permission checks read the *live* user session, not a value
|
||||
* frozen at construction, and this runner has to evaluate rules for many
|
||||
* different users within a single background-job process. So workflows
|
||||
* are grouped by owner and, for each owner, we temporarily impersonate
|
||||
* that user (push their IUser onto the session, restore afterwards) —
|
||||
* the standard Nextcloud pattern for multi-user cron jobs.
|
||||
* This runner has to evaluate rules for many different users within a
|
||||
* single background-job process, so workflows are grouped by owner and
|
||||
* each owner is impersonated in turn. Impersonation here means two
|
||||
* things, and the second one is the load-bearing half: pushing the IUser
|
||||
* onto the session (the standard Nextcloud cron pattern), *and* pinning
|
||||
* Deck itself to that user via
|
||||
* DeckIntegrationService::beginUserContext(), because Deck's permission
|
||||
* checks never consult the session — they read a uid frozen once per
|
||||
* process. Both are undone in a finally.
|
||||
*/
|
||||
class WorkflowRunner {
|
||||
public const TARGET_BOARD = 'board';
|
||||
@@ -32,6 +38,13 @@ class WorkflowRunner {
|
||||
|
||||
private ?IUser $impersonationRestore = null;
|
||||
|
||||
/**
|
||||
* Moved cards per recipient uid, collected over the whole run.
|
||||
*
|
||||
* @var array<string, list<array{workflow: Workflow, card: Card, targets: array{board: string, sourceStack: string, targetStack: string}}>>
|
||||
*/
|
||||
private array $pendingMails = [];
|
||||
|
||||
public function __construct(
|
||||
private WorkflowMapper $workflowMapper,
|
||||
private DeckIntegrationService $deckService,
|
||||
@@ -50,8 +63,11 @@ class WorkflowRunner {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->pendingMails = [];
|
||||
$byUser = [];
|
||||
$owners = [];
|
||||
foreach ($workflows as $workflow) {
|
||||
$this->followBoardOwner($workflow, $owners);
|
||||
$byUser[$workflow->getUserId()][] = $workflow;
|
||||
}
|
||||
|
||||
@@ -72,6 +88,57 @@ class WorkflowRunner {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->sendPendingMails();
|
||||
}
|
||||
|
||||
/**
|
||||
* A workflow belongs to its board's owner, not to whoever created it: if
|
||||
* Deck transferred the board, the workflow moves along to the new owner —
|
||||
* it then runs as them, and they get its mails.
|
||||
*
|
||||
* Only a known owner rewrites `user_id`. A board that is gone keeps its
|
||||
* last owner, so findBrokenTarget() can disable the workflow and mail
|
||||
* them; a Deck error keeps it too, and the run just goes ahead as before.
|
||||
*
|
||||
* @param array<int, ?string> $owners per-run cache, board id => owner
|
||||
*/
|
||||
private function followBoardOwner(Workflow $workflow, array &$owners): void {
|
||||
$boardId = $workflow->getBoardId();
|
||||
if (!array_key_exists($boardId, $owners)) {
|
||||
try {
|
||||
$owners[$boardId] = $this->deckService->findBoardOwner($boardId);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->warning('Could not determine the owner of board {board}: ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'board' => $boardId,
|
||||
]);
|
||||
$owners[$boardId] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$owner = $owners[$boardId];
|
||||
if ($owner === null || $owner === $workflow->getUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->info('Workflow {id} follows board {board} to its new owner {owner}.', [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'id' => $workflow->getId(),
|
||||
'board' => $boardId,
|
||||
'owner' => $owner,
|
||||
]);
|
||||
$workflow->setUserId($owner);
|
||||
try {
|
||||
$this->workflowMapper->update($workflow);
|
||||
} catch (Throwable $e) {
|
||||
// Not persisted, but this run still goes to the right user; the
|
||||
// next one tries again.
|
||||
$this->logger->warning('Could not store the new owner of workflow {id}: ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'id' => $workflow->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +160,20 @@ class WorkflowRunner {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->impersonate($user);
|
||||
try {
|
||||
$this->impersonate($user);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
// Deck could not be pinned to this user, so every permission
|
||||
// check would be answered for somebody else. Skipping costs one
|
||||
// run; continuing would move the wrong cards or, worse, read a
|
||||
// denial as "the board is gone" and disable a working workflow.
|
||||
$this->logger->error('Could not impersonate {user} towards Deck: ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'user' => $userId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($workflows as $workflow) {
|
||||
// Same reasoning as in run(): one broken workflow must not
|
||||
@@ -115,7 +195,7 @@ class WorkflowRunner {
|
||||
|
||||
private function runWorkflow(IUser $user, Workflow $workflow): void {
|
||||
try {
|
||||
$brokenTarget = $this->findBrokenTarget($workflow);
|
||||
$brokenTarget = $this->findBrokenTarget($user, $workflow);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
// Could not determine it either way — leave the workflow alone
|
||||
// rather than disabling it over a temporary Deck problem.
|
||||
@@ -141,25 +221,112 @@ class WorkflowRunner {
|
||||
return;
|
||||
}
|
||||
|
||||
$filterUserIds = $workflow->getFilterUserIdsArray();
|
||||
$filterLabelIds = $workflow->getFilterLabelIdsArray();
|
||||
$moved = [];
|
||||
$now = $this->timeFactory->getDateTime();
|
||||
|
||||
foreach ($cards as $card) {
|
||||
if (!self::isOverdue($card->getDaysUntilDue())) {
|
||||
if (!self::isOverdue($card->getDuedate(), $now)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$assignedUserIds = $this->deckService->getCardAssignedUserIds($card);
|
||||
$labelIds = $this->deckService->getCardLabelIds($card);
|
||||
if (!self::cardMatchesFilters($assignedUserIds, $labelIds, $filterUserIds, $filterLabelIds)) {
|
||||
continue;
|
||||
}
|
||||
$this->logger->info('Card {card} ("{title}") matches workflow {id}; moving to stack {target}.', [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'card' => $card->getId(),
|
||||
'title' => $card->getTitle(),
|
||||
'id' => $workflow->getId(),
|
||||
'target' => $workflow->getTargetStackId(),
|
||||
]);
|
||||
|
||||
$this->moveAndNotify($user, $workflow, $card);
|
||||
if ($this->moveCard($workflow, $card)) {
|
||||
$moved[] = $card;
|
||||
}
|
||||
}
|
||||
|
||||
$workflow->setLastRun($this->timeFactory->getDateTime());
|
||||
$this->workflowMapper->update($workflow);
|
||||
|
||||
if ($moved !== []) {
|
||||
$this->queueMails($user, $workflow, $moved);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out who hears about the moved cards and parks them in
|
||||
* $pendingMails; sendPendingMails() delivers them once per recipient at
|
||||
* the end of the run.
|
||||
*
|
||||
* Mails are decoration, not part of the move: nothing in here may fail
|
||||
* the workflow, and if Deck cannot say who wants a mail, nobody gets one
|
||||
* rather than people who asked Deck for silence.
|
||||
*
|
||||
* @param Card[] $cards
|
||||
*/
|
||||
private function queueMails(IUser $owner, Workflow $workflow, array $cards): void {
|
||||
$cardIds = array_map(static fn (Card $card): int => (int)$card->getId(), $cards);
|
||||
|
||||
switch ($workflow->getNotifyMode()) {
|
||||
case NotificationPolicy::MODE_OWNER:
|
||||
$recipients = array_fill_keys($cardIds, [$owner->getUID()]);
|
||||
break;
|
||||
case NotificationPolicy::MODE_BOARD:
|
||||
try {
|
||||
$recipients = $this->deckService->findNotificationRecipients($workflow->getBoardId(), $cardIds);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
$this->logger->warning('No mails for workflow {id}: ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'id' => $workflow->getId(),
|
||||
]);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$targets = $this->deckService->describeTargets(
|
||||
$workflow->getBoardId(),
|
||||
$workflow->getSourceStackId(),
|
||||
$workflow->getTargetStackId(),
|
||||
);
|
||||
|
||||
foreach ($cards as $card) {
|
||||
foreach ($recipients[(int)$card->getId()] ?? [] as $uid) {
|
||||
$this->pendingMails[$uid][] = [
|
||||
'workflow' => $workflow,
|
||||
'card' => $card,
|
||||
'targets' => $targets,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One mail per recipient and run, however many cards and workflows it
|
||||
* covers — a board with twenty overdue cards and fifteen members would
|
||||
* otherwise send three hundred mails at once.
|
||||
*
|
||||
* Runs after the per-user loop, so no impersonation is active any more.
|
||||
*/
|
||||
private function sendPendingMails(): void {
|
||||
$pending = $this->pendingMails;
|
||||
$this->pendingMails = [];
|
||||
|
||||
foreach ($pending as $uid => $entries) {
|
||||
// Same reasoning as in run(): nothing may escape.
|
||||
try {
|
||||
$recipient = $this->userManager->get((string)$uid);
|
||||
if ($recipient === null || !$recipient->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
$this->mailer->sendCardsMovedNotification($recipient, $entries);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('Could not send the moved-cards mail to {user}: ' . $e->getMessage(), [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'user' => $uid,
|
||||
'exception' => $e,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,8 +340,8 @@ class WorkflowRunner {
|
||||
* @return self::TARGET_*|null
|
||||
* @throws DeckUnavailableException if Deck could not be asked
|
||||
*/
|
||||
private function findBrokenTarget(Workflow $workflow): ?string {
|
||||
$stackIds = $this->deckService->findStackIds($workflow->getBoardId());
|
||||
private function findBrokenTarget(IUser $user, Workflow $workflow): ?string {
|
||||
$stackIds = $this->deckService->findStackIds($workflow->getBoardId(), $user->getUID());
|
||||
if ($stackIds === null) {
|
||||
return self::TARGET_BOARD;
|
||||
}
|
||||
@@ -203,14 +370,14 @@ class WorkflowRunner {
|
||||
'target' => $brokenTarget,
|
||||
]);
|
||||
|
||||
// Sent regardless of the workflow's notifyEmail setting: that flag is
|
||||
// Sent to the owner regardless of the workflow's notifyMode: that is
|
||||
// about moved cards, this is a one-off notice that the automation the
|
||||
// user configured has been switched off. It stays one-off because a
|
||||
// disabled workflow is not picked up again.
|
||||
$this->mailer->sendWorkflowDisabledNotification($user, $workflow, $brokenTarget);
|
||||
}
|
||||
|
||||
private function moveAndNotify(IUser $user, Workflow $workflow, Card $card): void {
|
||||
private function moveCard(Workflow $workflow, Card $card): bool {
|
||||
try {
|
||||
$this->deckService->moveCard($card->getId(), $workflow->getTargetStackId());
|
||||
} catch (Throwable $e) {
|
||||
@@ -219,44 +386,58 @@ class WorkflowRunner {
|
||||
'card' => $card->getId(),
|
||||
'id' => $workflow->getId(),
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($workflow->getNotifyEmail()) {
|
||||
$this->mailer->sendCardMovedNotification($user, $workflow, $card);
|
||||
}
|
||||
}
|
||||
|
||||
public static function isOverdue(?int $daysUntilDue): bool {
|
||||
return $daysUntilDue !== null && $daysUntilDue < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure filter-matching logic (kept static/side-effect free so it can
|
||||
* be unit tested without real Deck objects). Both filters are OR
|
||||
* inside themselves and AND between each other: an empty filter list
|
||||
* means "no restriction on this dimension".
|
||||
*
|
||||
* @param string[] $cardAssignedUserIds
|
||||
* @param int[] $cardLabelIds
|
||||
* @param string[] $filterUserIds
|
||||
* @param int[] $filterLabelIds
|
||||
*/
|
||||
public static function cardMatchesFilters(
|
||||
array $cardAssignedUserIds,
|
||||
array $cardLabelIds,
|
||||
array $filterUserIds,
|
||||
array $filterLabelIds,
|
||||
): bool {
|
||||
if ($filterUserIds !== [] && array_intersect($filterUserIds, $cardAssignedUserIds) === []) {
|
||||
return false;
|
||||
}
|
||||
if ($filterLabelIds !== [] && array_intersect($filterLabelIds, $cardLabelIds) === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Moved card {card} ("{title}") to stack {target} for workflow {id}.', [
|
||||
'app' => 'workflow_deck_automation',
|
||||
'card' => $card->getId(),
|
||||
'title' => $card->getTitle(),
|
||||
'target' => $workflow->getTargetStackId(),
|
||||
'id' => $workflow->getId(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the card's actual due timestamp against $now instead of Deck's own
|
||||
* Card::getDaysUntilDue(), which truncates both sides to midnight before diffing
|
||||
* (DateInterval's %a is a whole-day count) and therefore reports 0 - not overdue -
|
||||
* for any card whose due time has already passed today. That silently held back
|
||||
* every card for up to 24h after it actually fell due; comparing the raw datetime
|
||||
* instead matches what Deck's own UI shows (e.g. "vor 2 Stunden") and has no
|
||||
* day-rounding step to get wrong.
|
||||
*
|
||||
* Both sides are compared as absolute instants, and the due date is first
|
||||
* pinned to UTC via asStoredUtc() — see there for why.
|
||||
*/
|
||||
public static function isOverdue(?DateTimeInterface $duedate, DateTimeInterface $now): bool {
|
||||
return $duedate !== null && self::asStoredUtc($duedate) < $now;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deck's `duedate` is a DATETIME column without a zone that holds UTC
|
||||
* wall-clock time: Deck's frontend sends `toISOString()`, and the value is
|
||||
* written as plain `Y-m-d H:i:s`. Entity hydrates it with
|
||||
* `new \DateTime($string)`, i.e. in PHP's *default* timezone — correct only
|
||||
* because Nextcloud sets that default to UTC during bootstrap. Reading the
|
||||
* wall clock and pinning it to UTC explicitly makes the comparison
|
||||
* independent of that default, so a server or CLI running with a local
|
||||
* default zone cannot shift every due date by its UTC offset.
|
||||
*
|
||||
* Deck itself has two timezone-sensitive paths this deliberately avoids:
|
||||
* Card::getDaysUntilDue() (day-truncated, see isOverdue()) and
|
||||
* CardMapper::findOverdue(), which compares the UTC column against the
|
||||
* database's `NOW()` — the DB session's local time.
|
||||
*/
|
||||
private static function asStoredUtc(DateTimeInterface $duedate): DateTimeImmutable {
|
||||
return new DateTimeImmutable($duedate->format('Y-m-d H:i:s.u'), new DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DeckUnavailableException if Deck cannot be pinned to $user
|
||||
*/
|
||||
private function impersonate(IUser $user): void {
|
||||
$this->impersonationRestore = $this->userSession->getUser();
|
||||
$this->userSession->setUser($user);
|
||||
@@ -269,9 +450,20 @@ class WorkflowRunner {
|
||||
'app' => 'workflow_deck_automation',
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
// The session switch above is necessary but nowhere near
|
||||
// sufficient — Deck's permission checks never look at it. See
|
||||
// DeckIntegrationService::beginUserContext().
|
||||
$this->deckService->beginUserContext($user);
|
||||
} catch (DeckUnavailableException $e) {
|
||||
$this->clearImpersonation();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function clearImpersonation(): void {
|
||||
$this->deckService->endUserContext();
|
||||
$this->userSession->setUser($this->impersonationRestore);
|
||||
$this->impersonationRestore = null;
|
||||
}
|
||||
|
||||
@@ -5,13 +5,11 @@ declare(strict_types=1);
|
||||
namespace OCA\WorkflowDeckAutomation\Settings;
|
||||
|
||||
use OCA\WorkflowDeckAutomation\AppInfo\Application;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Settings\IIconSection;
|
||||
|
||||
class PersonalSection implements IIconSection {
|
||||
public function __construct(
|
||||
private IL10N $l10n,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
}
|
||||
@@ -21,7 +19,8 @@ class PersonalSection implements IIconSection {
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->l10n->t('Deck workflow automation');
|
||||
// German only, like the rest of this internal app.
|
||||
return 'Deck Workflow-Automatisierung';
|
||||
}
|
||||
|
||||
public function getPriority(): int {
|
||||
@@ -29,6 +28,6 @@ class PersonalSection implements IIconSection {
|
||||
}
|
||||
|
||||
public function getIcon(): string {
|
||||
return $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg');
|
||||
return $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg');
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "workflow_deck_automation",
|
||||
"version": "0.1.0",
|
||||
"version": "35.2.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Automates moving overdue Deck cards between stacks, configurable per user.",
|
||||
|
||||
+124
-79
@@ -14,17 +14,18 @@
|
||||
<table v-if="workflows.length" class="wfda-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Board</th>
|
||||
<th>Titel</th>
|
||||
<th>Von Stapel</th>
|
||||
<th>Nach Stapel</th>
|
||||
<th>Filter</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Aktiv</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="workflow in workflows" :key="workflow.id">
|
||||
<tr v-for="workflow in sortedWorkflows" :key="workflow.id">
|
||||
<td>{{ boardLabel(workflow.boardId) }}</td>
|
||||
<td>
|
||||
{{ workflow.title }}
|
||||
<span v-if="workflowIssues[workflow.id]" class="wfda-issue">
|
||||
@@ -33,16 +34,8 @@
|
||||
</td>
|
||||
<td>{{ stackLabel(workflow.boardId, workflow.sourceStackId) }}</td>
|
||||
<td>{{ stackLabel(workflow.boardId, workflow.targetStackId) }}</td>
|
||||
<td>
|
||||
<span v-if="!workflow.filterUserIds.length && !workflow.filterLabelIds.length">–</span>
|
||||
<span v-else>
|
||||
<span v-if="workflow.filterUserIds.length">{{ workflow.filterUserIds.length }} Benutzer</span>
|
||||
<span v-if="workflow.filterUserIds.length && workflow.filterLabelIds.length">, </span>
|
||||
<span v-if="workflow.filterLabelIds.length">{{ workflow.filterLabelIds.length }} Label</span>
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ workflow.notifyEmail ? 'Ja' : 'Nein' }}</td>
|
||||
<td>{{ workflow.enabled ? 'Ja' : 'Nein' }}</td>
|
||||
<td>{{ notifyLabel(workflow.notifyMode) }}</td>
|
||||
<td>{{ yesNo(workflow.enabled) }}</td>
|
||||
<td class="wfda-actions">
|
||||
<NcButton variant="tertiary" @click="editWorkflow(workflow)">
|
||||
Bearbeiten
|
||||
@@ -75,6 +68,9 @@
|
||||
:reduce="option => option.value"
|
||||
placeholder="Board wählen"
|
||||
@update:model-value="onBoardChange" />
|
||||
<NcNoteCard v-if="!boardOptions.length" type="info">
|
||||
Workflows können nur für Boards angelegt werden, deren Eigentümer du bist.
|
||||
</NcNoteCard>
|
||||
|
||||
<NcSelect
|
||||
v-model="form.sourceStackId"
|
||||
@@ -92,27 +88,24 @@
|
||||
:disabled="!form.boardId"
|
||||
placeholder="Ziel-Stapel wählen" />
|
||||
|
||||
<NcSelect
|
||||
v-model="form.filterUserIds"
|
||||
input-label="Nur für zugewiesene Benutzer (optional)"
|
||||
:options="participantOptions"
|
||||
:reduce="option => option.value"
|
||||
:disabled="!form.boardId"
|
||||
multiple
|
||||
placeholder="Alle Benutzer" />
|
||||
|
||||
<NcSelect
|
||||
v-model="form.filterLabelIds"
|
||||
input-label="Nur mit Label (optional)"
|
||||
:options="labelOptions"
|
||||
:reduce="option => option.value"
|
||||
:disabled="!form.boardId"
|
||||
multiple
|
||||
placeholder="Alle Labels" />
|
||||
|
||||
<NcCheckboxRadioSwitch v-model="form.notifyEmail">
|
||||
Benachrichtigungs-E-Mail an mich senden
|
||||
</NcCheckboxRadioSwitch>
|
||||
<fieldset class="wfda-notify">
|
||||
<legend>E-Mail bei verschobenen Karten</legend>
|
||||
<NcCheckboxRadioSwitch
|
||||
v-for="option in notifyOptions"
|
||||
:key="option.value"
|
||||
v-model="form.notifyMode"
|
||||
type="radio"
|
||||
name="wfda-notify-mode"
|
||||
:value="option.value">
|
||||
{{ option.label }}
|
||||
</NcCheckboxRadioSwitch>
|
||||
<p v-if="form.notifyMode === 'board'" class="wfda-hint">
|
||||
Jedes Board-Mitglied bekommt die E-Mail entsprechend seiner eigenen
|
||||
Deck-Einstellung „Benachrichtigungen“ für dieses Board: bei „Alle Karten“ immer,
|
||||
bei „Zugewiesene Karten“ nur für Karten, denen es zugewiesen ist, bei „Keine“ nie.
|
||||
Mehrere Karten eines Laufs werden zu einer E-Mail zusammengefasst.
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<NcCheckboxRadioSwitch v-model="form.enabled">
|
||||
Workflow aktiv
|
||||
@@ -148,8 +141,6 @@ import {
|
||||
createWorkflow,
|
||||
deleteWorkflow,
|
||||
fetchBoards,
|
||||
fetchLabels,
|
||||
fetchParticipants,
|
||||
fetchStacks,
|
||||
fetchWorkflows,
|
||||
updateWorkflow,
|
||||
@@ -159,6 +150,7 @@ const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
const workflows = ref([])
|
||||
const boards = ref([])
|
||||
// Per board, and `null` whenever the request failed — see loadStacksFor().
|
||||
const stacksByBoard = reactive({})
|
||||
|
||||
const showForm = ref(false)
|
||||
@@ -167,12 +159,44 @@ const formError = ref('')
|
||||
const editingId = ref(null)
|
||||
|
||||
const stackOptions = ref([])
|
||||
const labelOptions = ref([])
|
||||
const participantOptions = ref([])
|
||||
// Which board the three lists above currently belong to.
|
||||
// Which board the list above currently belongs to.
|
||||
const loadedBoardId = ref(null)
|
||||
|
||||
const boardOptions = computed(() => boards.value.map((board) => ({ value: board.id, label: board.title })))
|
||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
||||
|
||||
// The backend only returns boards the user owns. Archived ones are in there
|
||||
// so their workflows keep a board name, but are no target for new ones.
|
||||
const boardOptions = computed(() => boards.value
|
||||
.filter((board) => !board.archived || board.id === form.boardId)
|
||||
.map((board) => ({ value: board.id, label: board.title }))
|
||||
.sort((a, b) => collator.compare(a.label, b.label)))
|
||||
|
||||
/**
|
||||
* Alphabetical by the columns as displayed, left to right: board, title,
|
||||
* source stack, target stack, e-mail, active.
|
||||
*/
|
||||
const sortedWorkflows = computed(() => {
|
||||
const sortKeys = (workflow) => [
|
||||
boardLabel(workflow.boardId),
|
||||
workflow.title,
|
||||
stackLabel(workflow.boardId, workflow.sourceStackId),
|
||||
stackLabel(workflow.boardId, workflow.targetStackId),
|
||||
notifyLabel(workflow.notifyMode),
|
||||
yesNo(workflow.enabled),
|
||||
]
|
||||
return workflows.value
|
||||
.map((workflow) => ({ workflow, keys: sortKeys(workflow) }))
|
||||
.sort((a, b) => {
|
||||
for (let i = 0; i < a.keys.length; i++) {
|
||||
const result = collator.compare(a.keys[i], b.keys[i])
|
||||
if (result !== 0) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return a.workflow.id - b.workflow.id
|
||||
})
|
||||
.map((entry) => entry.workflow)
|
||||
})
|
||||
|
||||
// Source and target must differ, so each dropdown hides what the other one
|
||||
// already holds — the error message on save stays as the backstop for
|
||||
@@ -195,19 +219,17 @@ const workflowIssues = computed(() => {
|
||||
}
|
||||
|
||||
const stacks = stacksByBoard[workflow.boardId]
|
||||
if (!stacks) {
|
||||
continue
|
||||
}
|
||||
|
||||
const missing = []
|
||||
if (!stacks.some((stack) => stack.id === workflow.sourceStackId)) {
|
||||
missing.push('Quell-Stapel')
|
||||
}
|
||||
if (!stacks.some((stack) => stack.id === workflow.targetStackId)) {
|
||||
missing.push('Ziel-Stapel')
|
||||
}
|
||||
if (missing.length) {
|
||||
issues[workflow.id] = `${missing.join(' und ')} nicht mehr vorhanden`
|
||||
if (stacks) {
|
||||
const missing = []
|
||||
if (!stacks.some((stack) => stack.id === workflow.sourceStackId)) {
|
||||
missing.push('Quell-Stapel')
|
||||
}
|
||||
if (!stacks.some((stack) => stack.id === workflow.targetStackId)) {
|
||||
missing.push('Ziel-Stapel')
|
||||
}
|
||||
if (missing.length) {
|
||||
issues[workflow.id] = `${missing.join(' und ')} nicht mehr vorhanden`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,13 +244,31 @@ function emptyForm() {
|
||||
boardId: null,
|
||||
sourceStackId: null,
|
||||
targetStackId: null,
|
||||
filterUserIds: [],
|
||||
filterLabelIds: [],
|
||||
notifyEmail: false,
|
||||
notifyMode: 'off',
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Values match NotificationPolicy::MODES on the server.
|
||||
const notifyOptions = [
|
||||
{ value: 'off', label: 'Keine E-Mail', short: 'Keine' },
|
||||
{ value: 'owner', label: 'Nur an mich', short: 'Nur ich' },
|
||||
{ value: 'board', label: 'An Board-Mitglieder laut ihrer Deck-Einstellung', short: 'Board-Mitglieder' },
|
||||
]
|
||||
|
||||
function notifyLabel(mode) {
|
||||
return notifyOptions.find((option) => option.value === mode)?.short ?? mode
|
||||
}
|
||||
|
||||
function boardLabel(boardId) {
|
||||
const board = boards.value.find((entry) => entry.id === boardId)
|
||||
return board ? board.title : `#${boardId}`
|
||||
}
|
||||
|
||||
function yesNo(value) {
|
||||
return value ? 'Ja' : 'Nein'
|
||||
}
|
||||
|
||||
function stackLabel(boardId, stackId) {
|
||||
const stacks = stacksByBoard[boardId]
|
||||
if (!stacks) {
|
||||
@@ -242,11 +282,10 @@ async function loadStacksFor(boardId) {
|
||||
if (!boardId || stacksByBoard[boardId]) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
stacksByBoard[boardId] = await fetchStacks(boardId)
|
||||
} catch (e) {
|
||||
stacksByBoard[boardId] = []
|
||||
}
|
||||
// `null`, not `[]` — "could not ask Deck" has to stay distinguishable
|
||||
// from "this board has none", or a single failed request reports every
|
||||
// stack of the board as deleted.
|
||||
stacksByBoard[boardId] = await fetchStacks(boardId).catch(() => null)
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
@@ -265,31 +304,25 @@ async function loadAll() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the stack/label/user dropdowns for a board without touching the
|
||||
* current selection — that separation matters: editing a workflow has to
|
||||
* load the same options but must keep the stored stacks and filters.
|
||||
* Fills the stack dropdowns for a board without touching the current
|
||||
* selection — that separation matters: editing a workflow has to load the
|
||||
* same options but must keep the stored stacks.
|
||||
*/
|
||||
async function loadBoardOptions(boardId) {
|
||||
stackOptions.value = []
|
||||
labelOptions.value = []
|
||||
participantOptions.value = []
|
||||
loadedBoardId.value = boardId ?? null
|
||||
|
||||
if (!boardId) {
|
||||
return
|
||||
}
|
||||
|
||||
// One failing endpoint must not take the other two dropdowns down with it.
|
||||
const [stacks, labels, participants] = await Promise.all([
|
||||
fetchStacks(boardId).catch(() => []),
|
||||
fetchLabels(boardId).catch(() => []),
|
||||
fetchParticipants(boardId).catch(() => []),
|
||||
])
|
||||
const stacks = await fetchStacks(boardId).catch(() => null)
|
||||
|
||||
// Feed the overview's cache too, so its red markers agree with what the
|
||||
// form just loaded. `null` propagates on purpose: it means "unknown".
|
||||
stacksByBoard[boardId] = stacks
|
||||
stackOptions.value = stacks.map((stack) => ({ value: stack.id, label: stack.title }))
|
||||
labelOptions.value = labels.map((label) => ({ value: label.id, label: label.title }))
|
||||
participantOptions.value = participants.map((participant) => ({ value: participant.uid, label: participant.displayName }))
|
||||
|
||||
stackOptions.value = (stacks ?? []).map((stack) => ({ value: stack.id, label: stack.title }))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,8 +337,6 @@ async function onBoardChange(boardId) {
|
||||
|
||||
form.sourceStackId = null
|
||||
form.targetStackId = null
|
||||
form.filterUserIds = []
|
||||
form.filterLabelIds = []
|
||||
|
||||
await loadBoardOptions(boardId)
|
||||
}
|
||||
@@ -324,9 +355,7 @@ async function editWorkflow(workflow) {
|
||||
boardId: workflow.boardId,
|
||||
sourceStackId: workflow.sourceStackId,
|
||||
targetStackId: workflow.targetStackId,
|
||||
filterUserIds: [...workflow.filterUserIds],
|
||||
filterLabelIds: [...workflow.filterLabelIds],
|
||||
notifyEmail: workflow.notifyEmail,
|
||||
notifyMode: workflow.notifyMode,
|
||||
enabled: workflow.enabled,
|
||||
})
|
||||
editingId.value = workflow.id
|
||||
@@ -434,6 +463,22 @@ onMounted(loadAll)
|
||||
border-radius: var(--border-radius-large);
|
||||
}
|
||||
|
||||
.wfda-notify {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.wfda-notify legend {
|
||||
font-weight: bold;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.wfda-hint {
|
||||
color: var(--color-text-maxcontrast);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.wfda-form-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
-10
@@ -33,13 +33,3 @@ export async function fetchStacks(boardId) {
|
||||
const { data } = await axios.get(ocsUrl(`/boards/${boardId}/stacks`))
|
||||
return data.ocs.data
|
||||
}
|
||||
|
||||
export async function fetchLabels(boardId) {
|
||||
const { data } = await axios.get(ocsUrl(`/boards/${boardId}/labels`))
|
||||
return data.ocs.data
|
||||
}
|
||||
|
||||
export async function fetchParticipants(boardId) {
|
||||
const { data } = await axios.get(ocsUrl(`/boards/${boardId}/participants`))
|
||||
return data.ocs.data
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Tests\Unit\Service;
|
||||
|
||||
use OCA\WorkflowDeckAutomation\Service\NotificationPolicy;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class NotificationPolicyTest extends TestCase {
|
||||
public function testOffNeverNotifies(): void {
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('off', false, true));
|
||||
// Not even the owner of an unshared board — "off" is "off" in Deck too.
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('off', true, true));
|
||||
}
|
||||
|
||||
public function testAllAlwaysNotifies(): void {
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('all', false, false));
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('all', true, false));
|
||||
}
|
||||
|
||||
public function testAssignedNotifiesOnlyAssignedUsers(): void {
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', false, true));
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('assigned', false, false));
|
||||
}
|
||||
|
||||
public function testOwnerOfUnsharedBoardIsNotifiedWithAssigned(): void {
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', true, false));
|
||||
}
|
||||
|
||||
public function testUnknownSettingFallsBackToDeckDefault(): void {
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('', false, true));
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('bogus', false, false));
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('bogus', true, false));
|
||||
}
|
||||
|
||||
public function testAssignmentIsOnlyLookedUpWhenItMatters(): void {
|
||||
$lookup = function (): bool {
|
||||
$this->fail('assignment lookup must not run');
|
||||
};
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('off', false, $lookup));
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('all', false, $lookup));
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', true, $lookup));
|
||||
|
||||
$this->assertTrue(NotificationPolicy::shouldNotify('assigned', false, static fn (): bool => true));
|
||||
$this->assertFalse(NotificationPolicy::shouldNotify('assigned', false, static fn (): bool => false));
|
||||
}
|
||||
|
||||
public function testModes(): void {
|
||||
foreach (['off', 'owner', 'board'] as $mode) {
|
||||
$this->assertTrue(NotificationPolicy::isValidMode($mode));
|
||||
}
|
||||
$this->assertFalse(NotificationPolicy::isValidMode(''));
|
||||
$this->assertFalse(NotificationPolicy::isValidMode('all'));
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Tests\Unit\Service;
|
||||
|
||||
use OCA\WorkflowDeckAutomation\Service\WorkflowRunner;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class WorkflowRunnerFilterTest extends TestCase {
|
||||
public function testIsOverdueReturnsFalseWithoutDueDate(): void {
|
||||
$this->assertFalse(WorkflowRunner::isOverdue(null));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsFalseForFutureDueDate(): void {
|
||||
$this->assertFalse(WorkflowRunner::isOverdue(0));
|
||||
$this->assertFalse(WorkflowRunner::isOverdue(3));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsTrueForPastDueDate(): void {
|
||||
$this->assertTrue(WorkflowRunner::isOverdue(-1));
|
||||
$this->assertTrue(WorkflowRunner::isOverdue(-30));
|
||||
}
|
||||
|
||||
public function testNoFiltersMatchesAnyCard(): void {
|
||||
$this->assertTrue(WorkflowRunner::cardMatchesFilters(['alice'], [1, 2], [], []));
|
||||
$this->assertTrue(WorkflowRunner::cardMatchesFilters([], [], [], []));
|
||||
}
|
||||
|
||||
public function testUserFilterIsOrAgainstAssignedUsers(): void {
|
||||
$this->assertTrue(WorkflowRunner::cardMatchesFilters(['alice', 'bob'], [], ['bob', 'carol'], []));
|
||||
$this->assertFalse(WorkflowRunner::cardMatchesFilters(['alice'], [], ['bob', 'carol'], []));
|
||||
}
|
||||
|
||||
public function testLabelFilterIsOrAgainstCardLabels(): void {
|
||||
$this->assertTrue(WorkflowRunner::cardMatchesFilters([], [1, 2], [], [2, 3]));
|
||||
$this->assertFalse(WorkflowRunner::cardMatchesFilters([], [1], [], [2, 3]));
|
||||
}
|
||||
|
||||
public function testUserAndLabelFiltersAreCombinedWithAnd(): void {
|
||||
// user matches, label does not -> overall false
|
||||
$this->assertFalse(WorkflowRunner::cardMatchesFilters(['alice'], [1], ['alice'], [99]));
|
||||
// both match -> true
|
||||
$this->assertTrue(WorkflowRunner::cardMatchesFilters(['alice'], [1], ['alice'], [1]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\WorkflowDeckAutomation\Tests\Unit\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use OCA\WorkflowDeckAutomation\Service\WorkflowRunner;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class WorkflowRunnerTest extends TestCase {
|
||||
private static function utc(string $time): DateTimeImmutable {
|
||||
return new DateTimeImmutable($time, new DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsFalseWithoutDueDate(): void {
|
||||
$this->assertFalse(WorkflowRunner::isOverdue(null, self::utc('2026-01-15 12:00:00')));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsFalseForFutureDueDate(): void {
|
||||
$now = self::utc('2026-01-15 12:00:00');
|
||||
$this->assertFalse(WorkflowRunner::isOverdue($now->modify('+1 hour'), $now));
|
||||
$this->assertFalse(WorkflowRunner::isOverdue($now->modify('+3 days'), $now));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsTrueForPastDueDate(): void {
|
||||
$now = self::utc('2026-01-15 12:00:00');
|
||||
$this->assertTrue(WorkflowRunner::isOverdue($now->modify('-1 hour'), $now));
|
||||
$this->assertTrue(WorkflowRunner::isOverdue($now->modify('-30 days'), $now));
|
||||
}
|
||||
|
||||
public function testIsOverdueReturnsTrueForADueTimeEarlierTheSameDay(): void {
|
||||
// Regression: comparing whole calendar days (as Deck's own
|
||||
// Card::getDaysUntilDue() does) reports a card due earlier today as
|
||||
// "0 days until due", not overdue, until the calendar date rolls
|
||||
// over - holding every card back for up to 24h after it actually
|
||||
// fell due. isOverdue() must compare the real timestamps instead.
|
||||
$now = self::utc('2026-01-15 12:00:00');
|
||||
$this->assertTrue(WorkflowRunner::isOverdue(self::utc('2026-01-15 06:00:00'), $now));
|
||||
}
|
||||
|
||||
public function testIsOverdueReadsTheStoredWallClockAsUtc(): void {
|
||||
// What Entity hydration produces if PHP's default zone is not UTC:
|
||||
// the stored UTC wall clock "12:00", tagged with the local zone.
|
||||
$due = new DateTimeImmutable('2026-07-15 12:00:00', new DateTimeZone('Europe/Berlin'));
|
||||
|
||||
// Taken at face value that would be 10:00 UTC and already overdue.
|
||||
$this->assertFalse(WorkflowRunner::isOverdue($due, self::utc('2026-07-15 11:30:00')));
|
||||
$this->assertTrue(WorkflowRunner::isOverdue($due, self::utc('2026-07-15 12:00:01')));
|
||||
}
|
||||
|
||||
public function testIsOverdueComparesNowAsAnAbsoluteInstant(): void {
|
||||
$due = self::utc('2026-07-15 12:00:00');
|
||||
$berlin = new DateTimeZone('Europe/Berlin');
|
||||
|
||||
// 13:30 in Berlin (CEST) is 11:30 UTC - not yet due.
|
||||
$this->assertFalse(WorkflowRunner::isOverdue($due, new DateTimeImmutable('2026-07-15 13:30:00', $berlin)));
|
||||
// 14:30 in Berlin is 12:30 UTC - due.
|
||||
$this->assertTrue(WorkflowRunner::isOverdue($due, new DateTimeImmutable('2026-07-15 14:30:00', $berlin)));
|
||||
}
|
||||
|
||||
public function testIsOverdueIsFalseAtTheExactDueInstant(): void {
|
||||
$now = self::utc('2026-01-15 12:00:00');
|
||||
$this->assertFalse(WorkflowRunner::isOverdue($now, $now));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user