Skip to content

feat(notifications): human-readable assigned_task messages - #25

Merged
SrStamm merged 1 commit into
mainfrom
fix/notification-messages
Oct 20, 2026
Merged

SrStamm merged 1 commit into
mainfrom
fix/notification-messages

Conversation

@SrStamm

@SrStamm SrStamm commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Context

B10 of the portfolio fixes, implementing odd/tasks/notification-messages-spec.md. Notification toasts showed raw database ids (You are assigned to the task 9 in project 3) instead of something a human can act on. The frontend renders payload.message verbatim (NotificationToasts.tsx:17 -> toast.info(p.message)), so the message text is the product.

The constraint that shapes the fix

When the assignee is offline, save_notification_in_db persists only type and the message string. On reconnect, send_pending_notifications rebuilds the event from those two columns. Any structured field added to the live payload is therefore dropped for offline users — message is the only channel that survives both paths. The human-readable text must be built at the source, server-side; the frontend needs zero changes.

Changes

  • R1/R2 — human message on create and reassignment:
    Fuiste asignado a la tarea «{task_title}» en el proyecto «{project_title}» por {actor_username}.
    One phrasing for both paths.
  • R3 — thread the actor: TaskService.create now receives actor_user_id and actor_username from the router; the update path resolves the username from the user_id it already had.
  • R4 — fill related_entity_id: new optional parameter on format_notification (core/event_ws.py), passed the task id from both sites. Known limitation (accepted): the offline path drops it.
  • R5 — never break the mutation: name resolution is best-effort. ProjectService.get_project_title_or_none returns None on failure and _resolve_username swallows lookup errors; the builder then falls back to the previous id-based message.
  • Self-assignment: the actor is not notified about their own assignment.
  • New repository/service lookup get_project_by_project_id to resolve the title by project id alone (the existing get_project_by_id requires a group_id not available at the notification site).

Contract

Unchanged: notification_type stays assigned_task, the envelope shape is the same, and there is no DB migration. save_notification_in_db and send_pending_notifications are untouched — the human message flows through both the live and offline paths for free.

Out of scope

The seven other raw-id notification sites (comments, groups, projects) — same defect class, tracked separately.

Verification

  • 6 new tests in test/test_services/test_notification_messages.py covering the human message, self-assignment suppression, the id-based fallback, actor omission, greeting related_entity_id, and both create/reassign paths.
  • Mutation testing: 4/4 branch mutations killed (self-assign guard, fallback branch, actor-omission branch, related_entity_id wiring), so each test genuinely exercises its branch.
  • pytest -q -> 183 passed (was 177; baseline 155).

Replace raw database ids in assignment notifications with a natural sentence
carrying the task title, the project name and the actor:

  Fuiste asignado a la tarea «{task_title}» en el proyecto «{project_title}»
  por {actor_username}.

- Both assignment sites (task create and reassignment) build the message at the
  source, since the offline persistence path stores only the message string.
- Thread the authenticated actor from the router into TaskService.create; the
  update path resolves the username from the actor id it already receives.
- Do not notify the actor about their own assignment.
- Fill related_entity_id (task id) so online clients can deep-link later.
- Name resolution is best-effort: any lookup failure falls back to the previous
  id-based message and never fails the task mutation.
- Contract unchanged: notification_type stays assigned_task, no DB migration.
@SrStamm
SrStamm merged commit 3fc6a00 into main Oct 20, 2026
1 check passed
@SrStamm
SrStamm deleted the fix/notification-messages branch October 20, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant