Notification centre¶
The notification center keeps one EasyNotification per user and entity (an issue) and shows it in the service-bar bell. Every change that concerns the user is an immutable EasyNotificationEvent under that notification, so a user who is assigned, then sees a due date change and a mention gets one bell entry with three events, not three entries. Nothing is snapshotted: cards render from the live issue and journals. Issue e-mail is the legacy channel (see Issue email notifications); for users who have the mail channel it is sent from the same events.
Tables¶
easy_notifications: one row per (user, entity):
| Column | Meaning |
|---|---|
user_id |
recipient |
entity_type, entity_id |
polymorphic grouping key (Issue) |
actor_id |
user behind the latest event |
last_event_at |
time of the latest event of either channel, taken from the source (created_on), not from the job clock |
center_event_at |
time of the latest center event; NULL when the user has only e-mail events |
seen_at |
when the user last viewed it; never reset by new events |
created_at, updated_at |
Rails timestamps |
Unique index on (user_id, entity_type, entity_id); (user_id, center_event_at, seen_at) serves the list and the badge, which read only center events.
easy_notification_events: one immutable row per (notification, source):
| Column | Meaning |
|---|---|
easy_notification_id |
parent; deleted through the association, no FK |
source_type, source_id |
Journal, or the Issue itself for its creation |
actor_id |
user who caused the event |
kind |
create_issue, edit_issue, mention, or a plugin kind |
center |
the event is shown in the notification center (default true) |
email |
the event is sent by EasyNotificationMailJob (default false); cleared when the mail is skipped |
mailed_at |
when EasyNotificationMailJob claimed the event for delivery |
created_at |
source time |
A mentioned user gets kind mention for that event even when they are also an ordinary recipient, and regardless of their mail_notification setting: easy_notifiable_mentions checks only visibility (and view_private_notes on journals). Users on the mail channel get their mention e-mail by the same rule, unless they switched the mention e-mail off. Every mentioned user, on the mail channel or not, also gets the instant mention mail (EasyJournalMailer), sent after commit to the users EasyMentionable parsed from the text (mentioned_users: active, internal, visible to the author), with no mail_notification or record visibility check. The actor never gets an event.
Seen state¶
GET /easy_notifications?seen=1 ("Show seen" toggle) also lists seen notifications whose last event lies within EasyNotification::SEEN_WINDOW (5 days); their cards show the center events inside that window (#display_events) and carry no mark-seen button. The mark-seen buttons pass seen=1 along so the streamed list keeps the mode.
Unseen means center_event_at IS NOT NULL AND (seen_at IS NULL OR center_event_at >= seen_at). Marking seen (PATCH /easy_notifications/:id/seen, PATCH /easy_notifications/seen_all, or opening the issue through ActsAsUserReadable#mark_as_read) stores the current time floored to the second; sources stamp events with whole seconds, so the compare is inclusive: a change in the same second is shown again rather than lost. A later event makes the notification unseen again without touching seen_at, and "what is new" is EasyNotification#new_events, the center events at or after seen_at; e-mail-only events never appear on a card. History stays until cleanup.
Center recipients for issues come from Issue#easy_notifiable_recipients: author, assignee and watchers always; the former assignee, all project members and recipients of an already closed issue only when the user's rule is on. mail_notification, no_notification_ever, Setting.notified_events and the subtask-change setting are not consulted; e-mail keeps notified_users. The journal filter (notes or notified visible details, private-note permission) is shared with the mail path. Groups are expanded to their users, and every recipient must be active and see the issue. Issue#easy_notifiable_group_recipients returns the recipients whose only path is a group (assignee group, watcher group, former-assignee group); their events carry via_group and the card shows the "via your group" badge. Author, personal assignee, personal watcher, personal former assignee, all_project_changes members and mentioned users are direct and never tagged. The creation of a closed issue and the journal that closes it count as closing, so they reach users with closed_issues off; only later edits of an already closed issue are filtered.
Registering a source¶
Include EasyNotifiable and declare one easy_notifiable per kind. Options accept a symbol (public method on the source) or a callable receiving the source.
class Issue < ApplicationRecord
include EasyNotifiable
easy_notifiable kind: "create_issue",
actor: :author,
if: ->(issue) { issue.notify? && issue.easy_notifiable_project? },
recipients: :easy_notifiable_recipients,
mentions: :easy_notifiable_mentions
end
class Journal < ApplicationRecord
include EasyNotifiable
easy_notifiable kind: "edit_issue",
actor: :user,
entity: :journalized,
if: :easy_notifiable_issue_journal?,
recipients: ->(journal) { journal.journalized.easy_notifiable_recipients(journal) },
mentions: :easy_notifiable_mentions
end
| Option | Required | Runs in | Meaning |
|---|---|---|---|
kind |
yes | none | event kind for ordinary recipients; unique per class |
recipients |
yes | job | users who get an event |
entity |
no (the source) | job | record the notification is grouped under |
actor |
no (:author) |
job | excluded from recipients, stored on the event and the notification |
event_at |
no (:created_at) |
job | event time; Issue and Journal pass :created_on |
if |
no | after-commit callback | guard; may read transient state such as notify? |
mentions |
no | callback | users who get a mention event; runs before commit because acts_as_mentionable fills mentioned_users only on the saving instance, the job receives the ids |
mail_recipients |
no (no e-mail events) | job | users who get an email event, see Mail channel |
group_recipients |
no | job | subset of recipients reached only through a group (assignee group, watcher group); their event gets via_group, shown as the "via your group" badge |
Every kind must also be registered in an initializer so the settings page can list it (config/initializers/09_easy_notification_kinds.rb; a plugin adds its own file):
require "easy_notification_kinds"
EasyNotificationKinds.register("create_easy_crm_case", label: :label_easy_notification_kind_create_easy_crm_case, position: 110)
position orders the page, label is the caption key. An unregistered kind is still written but cannot be switched off and does not appear on the page. The registry (easy_lib/easy_notification_kinds.rb) is not reloadable and is filled from initializers, so the page lists the kinds of every installed plugin before its models load. Core registers create_issue, edit_issue and mention; easy_crm registers create_easy_crm_case and edit_easy_crm_case in config/initializers/16_easy_notification_kinds.rb.
easy_notifiable installs has_many :easy_notification_events, as: :source, dependent: :delete_all plus destroy hooks that drop notifications left without events and re-align last_event_at, and an after_create_commit that enqueues EasyNotificationJob.perform_later(source, kind, mentioned_user_ids). Nothing is enqueued inside Mailer.with_deliveries(false) (project copy or template without notifications, imports, merges), so those operations create neither center notifications nor e-mail events; Mailer.deliveries_suppressed? tells such a block from an installation that merely has no e-mail configuration. A source grouped under itself (default entity) also gets has_many :easy_notifications, as: :entity, dependent: :destroy; a source grouped under another record (Journal under Issue) relies on that record being a source itself. Declare on the base class of an STI hierarchy. Plugins declare inside their model patches; the card renders the same for every kind, only mention gets a badge after the actor name.
Registered sources: Issue and its Journal (create_issue, edit_issue) in core; EasyCrmCase and its Journal (create_easy_crm_case, edit_easy_crm_case) in easy_crm, with the card partial easy_crm_2_0/easy_crm/app/views/easy_notifications/_easy_crm_case.html.erb. CRM recipients are the EasyCrmMailer set (notified_users | notified_watchers), private notes need view_private_notes on the case project; easy_notifiable_journal_recipients restores the former assignee from the journal's assigned_to_id detail because the queued job works on a reloaded record. Recipients resolved in the job see no dirty-tracking state in general: a source whose recipient rule depends on it must read the journal instead. Seen-on-read comes from acts_as_user_readable#mark_as_read, which every entity with that concern already calls on show.
Control panel¶
/my/notification_settings (EasyNotificationSettingsController, behind easy_notification_center_enabled, reachable from the bell header and from My account) stores EasyNotificationSetting rows (user_id, channel, name, enabled) only for values that differ from the default; a checkbox returned to its default deletes its row, unique on the triple, channel is center or mail. name is a registered kind or one of the scope rules previous_assignee (default on), all_project_changes (default off), closed_issues (default on); kinds default to on. EasyNotificationSetting.values_for(user) returns every name with its stored or default value; enabled_user_ids(ids, name) is the query the job and the issue resolver use for known recipients; the issue resolver reads all_project_changes (default off) through the enabled_for scope as a subquery on the project members. update_for assigns each posted name through safe_attributes (enabled is the only safe attribute), destroys the row when the value equals the default and saves it otherwise; unknown names in the form are ignored. The enabled column defaults to true, but every row is written with an explicit value.
The page has two sections saved separately and needs nothing beyond login and the feature toggle for your own settings. The center checkboxes go through update. The e-mail section (_mail.html.erb) goes through PATCH /my/notification_settings/mail (update_mail), which assigns params[:user] and params[:pref] through safe_attributes and redirects with 303. It stores users.mail_notification, members.mail_notification (through core User#notified_project_ids=) and the UserPreference flags. For a user with EasyNotification.mail_enabled? the e-mail options also contain the mention checkbox (easy_notification_mail_settings[mention], default on), stored as an EasyNotificationSetting row of the mail channel; mention is the only name of that channel, every other e-mail follows mail_notification.
The selected projects subsection shows only the first 5 notified projects with their ancestors (notified_projects_preview(user, limit: 5) in EasyNotificationSettingsHelper, built from user.members.where(mail_notification: true)). The tree is rendered by ApplicationHelper#render_project_nested_lists and the browser redraws it with the same markup. The full list is edited in a dialog (_projects_dialog.html.erb) with the project autocomplete. easy_notification_settings.js, wired by the easy-notification-settings Stimulus controller, rewrites the hidden user[notified_project_ids][] inputs and redraws the tree, and nothing is saved until the section's Save. The hidden inputs, including the empty reset one, are submitted in every mode, so saving another mode clears every membership flag through User#update_notified_project_ids; otherwise Project#notified_users would keep mailing the user about the formerly selected projects.
An administrator or a lesser administrator for :users opens the page for another user at /users/:user_id/notification_settings (user_notification_settings_path, with PATCH /users/:user_id/notification_settings/mail for the e-mail section). find_user applies require_admin_or_lesser_admin(:users), the rule of users#edit, and loads the user with User.logged; a lesser administrator may also edit an administrator. The feature toggle is read for the editor, not for the edited user. The project picker lists the projects where the edited user is a member and can see: member_projects in EasyAutocompletes::ProjectCollections takes user_id, honoured only for an administrator or a lesser administrator for :users. When there is no such project the dialog shows an explanation instead of the autocomplete.
The admin user form (easy_extensions/app/views/users/_form.html.erb) links an existing user to this page while the feature is on and renders users/mail_notifications unchanged with it off. users/new has no notification settings with the feature on, because the page needs a saved user.
While the feature is on, My account (easy_extensions/app/views/my/account.html.erb) shows a link to the page instead of users/_mail_notifications; with the feature off it renders the partial unchanged.
The data migration SeedEasyNotificationSettingsFromMailPreferences (easy_engines/easy_extensions/db/data/, because easy8:install runs only engine and plugin data migrations) seeded the rules from those flags once (all โ all_project_changes, no_notified_as_previous_assignee โ previous_assignee off, no_notified_if_issue_closing โ closed_issues off). It writes nothing for users with default preferences and can run twice (insert_all skips duplicates through the unique index). Users with none, only_assigned or only_owner now get their own events in the center; selected users lose project-wide center rows until project-level settings exist.
closed? and the recipient set are read when the job runs, not when the change was made (the same model as phase 1). A comment followed quickly by a journal that closes the issue can therefore be dropped for users with closed_issues off.
Project-level rows (project_id) and global defaults are the planned next layers.
Job¶
EasyNotificationJob receives the source (GlobalID) and the mentioned user ids, resolves entity, actor and recipients, drops the actor, then keeps only recipients whose setting for the event's kind is on (enabled_user_ids), a mentioned user with mention off gets the ordinary kind when they are also an ordinary recipient, otherwise nothing (a mentioned user who also gets the mention e-mail keeps the mention kind, so the mail can mark the mention), an ordinary event of a user returned by group_recipients who is not mentioned is written with via_group, then runs three autocommit statements: upsert_all of the notifications (ON DUPLICATE KEY UPDATE with GREATEST so a retried or reordered job never moves last_event_at backwards), a pluck of their ids, and insert_all of the events (INSERT IGNORE through the unique index). When EasyNotification.mail_channel_active? (the mail feature is enabled for anyone), the job also resolves mail_recipients, adds the mentioned users who left the mention e-mail on (mention in the mail channel) and sets email on the event of each of them with mail_enabled?; the actor stays in this set when the resolver returns them. A user who gets only an e-mail event is written with center: false and leaves center_event_at untouched. Retries are no-ops; EasyActiveJob retries ActiveRecord::Deadlocked. A missing source or entity is ignored.
Mail channel¶
Each event carries two independent flags: center (listed in the bell, counted in the badge) and email (sent by EasyNotificationMailJob). A user can have either or both on one event; a user with only e-mail events has a notification with center_event_at NULL, which the list and the badge ignore.
A source takes part by declaring mail_recipients; without it a source writes no e-mail events. Issue#easy_notifiable_mail_recipients(journal = nil) returns the legacy set: the mail_notification modes, selected projects, watchers and visibility rules of get_notified_users_for_issue_new and get_notified_users_for_issue_edit, minus everyone when the acting user has no_notification_ever, and minus the acting user with no_self_notified (on creation and on update). Mentioned users are added to the candidates unless they switched the mention e-mail off; such a user gets an e-mail event only as an ordinary recipient, with the ordinary kind.
A recipient gets email: true only when EasyNotification.mail_enabled?(user): the center feature easy_notification_center_enabled and the feature easy_notification_mail_enabled are both on for that user. The mail feature has no effect without the center feature. Enable it like the center feature, for example Flipper.enable_actor(:easy_notification_mail_enabled, user).
The feature adds mails and takes none away: the legacy senders (ProcessMailQueue, Mailer.deliver_issue_add, the instant mention mail) do not read the flag, so a user with it gets the legacy mail and the EasyNotificationMailJob mail for the same change. Turning the feature off stops only the mails of the job, including events still pending for the user: the job drops them.
While both mails are sent, the mail of the job has the subject prefix [Notifications 2.0] and its own Message-ID (the legacy token with a marker in the user segment), so mail clients do not merge it with the legacy mail of the same change.
EasyNotificationMailJob runs from cron (EASY_NOTIFICATION_MAIL_CRON, default */15 * * * *). Runs do not overlap: the job holds an activejob-unique lock (until_and_while_executing, lock_ttl 15 minutes). It claims pending events (email = true AND mailed_at IS NULL) in batches with FOR UPDATE SKIP LOCKED and stamps mailed_at before delivering, so a mail is sent at most once and a failed delivery is not retried. A notification is claimed whole: with the events of a batch the job also claims every other pending event of the same notifications, so one run never splits a user's issue into two mails. Only active users get an email event in the first place. An event shown in the center (center: true) and older than the notification's seen_at is not mailed and its email flag is cleared, so a user who dismissed the card or opened the issue before the job ran gets no mail. An e-mail-only event is on no card, so the bell does not cover it; opening the issue drops it (EasyNotification.mark_read!). The user's own change is exempt: saving redirects them to the issue, and it is still mailed unless no_self_notified removed them from the mail set. Events of inactive users, invisible issues and deleted sources are dropped the same way. Issue visibility and private notes are checked again when the mail is sent: a journal made private, or a view_private_notes permission revoked, after the change is not mailed. An event that fails this check with an error is logged and dropped, so it cannot block the queue; a database error (ActiveRecord::StatementInvalid, for example a lock timeout) instead fails the run and leaves the event pending for the next one.
Per user and issue the job sends one EmailNotificationsMailer#issue_notification mail. It uses the issue_changes templates of the journal mail queue and covers the issue creation, when it is among the claimed events, and all pending journals, with the final value of every changed field (EasyNotification.latest_details). The creation is a block before the journals with the author and the issue description; a mail that contains the creation takes the subject of the legacy new-issue mail. A creation or journal with a mention event is marked inside the mail. Mailer#issue_add is not used by this channel.
Has only the legacy mail:
- A mention added by editing the description of an existing issue or the notes of an existing comment: instant mail for everyone.
Setting.notified_events: applies only to the legacy path; users with the channel get events regardless of it.- Planned-project activation mails (
Project#deliver_all_planned_emails).
Cleanup¶
EasyNotificationsCleanupJob runs daily (EASY_NOTIFICATIONS_CLEANUP_CRON, default 30 3 * * *) and deletes, with their events, notifications seen more than 30 days ago without newer events and notifications whose last event is older than 60 days. Each batch deletes the notifications first (conditions re-checked in the DELETE) and then only the events whose notification is gone, so a notification renewed by a concurrent EasyNotificationJob keeps its new event. E-mail-only events keep a notification alive after its center events are pruned, so the job finally clears a center_event_at older than 60 days; the notification then leaves the list and the badge.
UI¶
Feature toggle :easy_notification_center_enabled (registered in config/initializers/04_easy_features.rb, read through EasyNotification.center_enabled?) decides which bell the service bar shows: the notification center, or the toolbar activity feed (easy_activities#show_toolbar, easy_activity background service) it is meant to replace. Notifications and events are written regardless of the toggle, so both bells can run side by side during A/B testing. Enable per user with Flipper.enable_actor(:easy_notification_center_enabled, user) or globally with Flipper.enable(:easy_notification_center_enabled).
Turbo frame easy-notification-center in the service-bar sliding panel; EasyNotificationsController#index renders easy_notifications/_center (unseen notifications up to EasySetting.value("easy_select_limit"), latest event first) and is available to users with the activity_feed user type. Mark-seen actions answer with Turbo Streams that replace #easy_notification_center_body (the list and the footer, easy_notifications/_body) and #easy_notification_center_badge, so the panel title stays; the full page /easy_notifications renders the same partial without a frame. The bell's inline onclick calls window.EasyNotificationCenter.open (app/frontend/src/easy_notification_center.js, loaded by the application entrypoint), which recreates the Turbo frame if the panel's close handler removed it, loads it through frame.src, and opens the legacy panel; before the JS is ready the link falls back to the full page.
_easy_notification.html.erb renders the partial named after the entity class (easy_notifications/_issue.html.erb, resolved by notification_card_partial, which raises EasyNotification::MissingCard when none exists); a plugin entity ships its own _<entity_type.underscore>.html.erb, wraps its body in render layout: "easy_notifications/card", locals: { notification:, events:, title:, project: } for the common shell (actor with the mention badge, time, mark-seen button, title, parent project and project) and renders easy_notifications/card_body with text: and detail_strings: notification_detail_strings(events) inside it. title: is required: the link to the entity. The issue card shows: the latest actor (+N when several) followed by a mentioned you badge when any new event is a mention, or a via your group badge (text_easy_notification_via_group) when every visible event is via_group and none is a mention (li[data-via-group] carries the verdict), time of the latest event, project, the issue link as the title (opens the issue page in a new window, anchored to the newest journal), one text excerpt (the newest visible journal notes, else the issue description when the creation is among the new events), and chips with the final value of every changed field (EasyNotification.latest_details keeps the last journal that touched each attribute or custom field; relation and attachment details stay one per event; three fields, then label_easy_notification_more_details). Visibility is re-checked at render (Issue#visible?, private notes, Journal#visible_details), so a note made private later disappears from the card; a card with nothing visible renders nothing.
Live badge¶
EasyNotificationJob ends by calling EasyNotificationChannel.broadcast_unseen_counts for the users it wrote events for. The channel (app/channels/easy_notification_channel.rb) streams easy_notifications_<user_id> per logged-in user and sends one message, { unseen_count: N }, per user; nothing is rendered on the server. The client calls the refresh action from connected(), which Action Cable fires only after the stream listener is registered, and the channel answers with the current count; the client resubscribes after every reconnect, so a tab that was offline while an event was broadcast catches up without missing a broadcast made during the handshake. subscribeNotificationCenter in easy_notification_center.js subscribes a tab when the bell trigger is in the DOM, writes the count into #easy_notification_center_badge, and calls reload() on the easy-notification-center frame when the panel is open, so the list re-fetches with the newest card on top and keeps its show-seen mode. Marking seen in another tab or by opening the issue does not push a count; the next page render corrects the badge. In development the async cable adapter stays inside one process, so a job executed outside the web server needs the Redis adapter in config/cable.yml to reach the browser.
Not implemented¶
- Phase 2 (done 2026-10): notification control panel for the center channel and the mention e-mail checkbox; e-mail per-kind column, admin defaults and project-level rules follow.
- Phase 3 (partly done): the mail channel sends issue e-mail from events for users with the feature. Still open: honouring the control panel's e-mail settings beyond the mention, other sources than issues and journals, and retiring the journal mail queue.
- Phase 4: REST API and Swagger for notifications and events,
EasyWebHookregistration; browser push is in place throughEasyNotificationChannel.