Mattermost: several channels, private messages and report author #14

Merged
Gilles merged 1 commit from feat/13-mattermost-targets into master 2026-10-26 05:24:02 +00:00
Owner

Closes #13

Backend part. The rule form comes in an argus/frontend PR.

What's in it

  • Model: EventRule.mattermost_channels ([{id, name}]), mattermost_users ([{id, username}]) and mattermost_notify_author replace mattermost_channel_id/_name.
    • Migration 0002_mattermost_targets moves an existing single channel into the list; the migration is reversible.
    • EventDelivery.progress records the targets already sent.
  • Sending: channels, then private-message recipients, then the author.
    • Private messages go through the bot's direct channel (POST /channels/direct).
    • A user who is both a recipient and the author gets a single message.
    • If any target fails, the others still go out. The delivery is marked failed and retried, and only the failed targets are resent.
    • The detail lists the targets, e.g. ~Famille / CI, @alice, @gilles (auteur).
  • Author lookup: Report.actor (Forgejo login) → Forgejo email (service token) → GET /users/email/…, then GET /users/username/<login>.
    • A 403/404 from Mattermost counts as "not found". This covers a member bot on an instance that hides emails.
    • If the author is unknown, that target is noted (auteur X introuvable) without failing the delivery.
  • API
    • GET /api/mattermost/users/?q=: bot autocomplete, without bots or deactivated accounts.
    • "Test this rule" uses the requesting user as the author.
  • Validation
    • The Mattermost channel needs at least one target (channel, recipient or author).
    • Ids must be 26 lowercase alphanumerics: they end up in API paths.

Tests

9 new pytest cases (178 in total):

  • a fake Mattermost API: several channels and private messages, de-duplicated recipients, author found by email then by login, unknown or missing author, partial retry;
  • the test endpoint, user search, target validation and round trip, the data migration.

pylint 10/10; autopep8 and bandit clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_014BSmBtGWeFBD9z4mYm9SjA

Closes #13 Backend part. The rule form comes in an argus/frontend PR. ## What's in it - **Model**: `EventRule.mattermost_channels` (`[{id, name}]`), `mattermost_users` (`[{id, username}]`) and `mattermost_notify_author` replace `mattermost_channel_id`/`_name`. - Migration `0002_mattermost_targets` moves an existing single channel into the list; the migration is reversible. - `EventDelivery.progress` records the targets already sent. - **Sending**: channels, then private-message recipients, then the author. - Private messages go through the bot's direct channel (`POST /channels/direct`). - A user who is both a recipient and the author gets a single message. - If any target fails, the others still go out. The delivery is marked failed and retried, and only the failed targets are resent. - The detail lists the targets, e.g. `~Famille / CI, @alice, @gilles (auteur)`. - **Author lookup**: `Report.actor` (Forgejo login) → Forgejo email (service token) → `GET /users/email/…`, then `GET /users/username/<login>`. - A 403/404 from Mattermost counts as "not found". This covers a member bot on an instance that hides emails. - If the author is unknown, that target is noted (`auteur X introuvable`) without failing the delivery. - **API** - `GET /api/mattermost/users/?q=`: bot autocomplete, without bots or deactivated accounts. - "Test this rule" uses the requesting user as the author. - **Validation** - The Mattermost channel needs at least one target (channel, recipient or author). - Ids must be 26 lowercase alphanumerics: they end up in API paths. ## Tests 9 new pytest cases (178 in total): - a fake Mattermost API: several channels and private messages, de-duplicated recipients, author found by email then by login, unknown or missing author, partial retry; - the test endpoint, user search, target validation and round trip, the data migration. pylint 10/10; autopep8 and bandit clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014BSmBtGWeFBD9z4mYm9SjA
Mattermost: several channels, private messages and report author
All checks were successful
ci / test (pull_request) Successful in 3m18s
ci / e2e (pull_request) Has been skipped
ci / docker (pull_request) Has been skipped
ci / deploy (pull_request) Has been skipped
85f8cdbd56
argus/backend#13:
- EventRule.mattermost_channels/mattermost_users (lists) and
  mattermost_notify_author replace the single mattermost_channel_id;
  data migration keeps existing rules' channel.
- Private messages through the bot's direct channel; the author (CI
  actor) is resolved by Forgejo email, then by the same login, and
  reported as skipped when unknown without failing other targets.
- Per-target progress on EventDelivery so a retry only resends the
  targets that failed.
- GET mattermost/users/?q= for the recipient picker; "test this rule"
  uses the requesting user as the author.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014BSmBtGWeFBD9z4mYm9SjA
Author
Owner
<!-- argus-link-bot:argus/backend --> 📊 [Rapports Argus pour cette PR](https://reports.stationmyr.net/argus/backend/pr/14)
Gilles merged commit 23653d512a into master 2026-10-26 05:24:02 +00:00
Gilles deleted branch feat/13-mattermost-targets 2026-10-26 05:24:02 +00:00
Sign in to join this conversation.
No description provided.