Skip to content

[SE-641] Allow to create mentions via the API - #26028

Open
judithroth wants to merge 4 commits into
devfrom
feature/se-641-mention-users-in-documents-backend-part-1
Open

judithroth wants to merge 4 commits into
devfrom
feature/se-641-mention-users-in-documents-backend-part-1

Conversation

@judithroth

@judithroth judithroth commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

This is best reviewed commit by commit :)

Ticket

https://community.openproject.org/wp/SE-641

What are you trying to accomplish?

Allow to create notifications (e.g. when a user is created in a document) via the API. So far this only uses a email notification; in app notifications will follow in a separate PR, as well as using this new API endpoint.

Screenshots

image

What approach did you choose and why?

Allow to create notifications via the API because

  • There will be deep changes to how we save documents and their journals in the future.
  • We can not for sure determine the user who created the mention from the document's journal entry when multiple users are editing a document simultaneously.
  • We don't want to carry over the information which user created the mention via the block properties and markdown export, because this could be manipulated by users. It also carries some risks when mentions are copied (could still hold wrong mentioner) or dragged.
  • This opens up the possibility to have mentions from external sources which use block note extensions in the future (if we want that)

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@judithroth judithroth self-assigned this Oct 14, 2026
@judithroth
judithroth requested a balanced review from Copilot October 14, 2026 14:04
@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new public API operation is missing from the OpenAPI specification.

1 open finding
What changed in this PR

Adds API-driven document mentions, including email delivery, BlockNote support, validation, and notification lifecycle handling.

Changes:

  • Adds POST /api/v3/notifications for document mentions.
  • Adds mention rendering, emails, preferences, and cleanup.
  • Adds frontend/editor support and comprehensive tests.
File Description
app/​contracts/​notifications/​create_mention_from_api_contract.rb Validates API mentions and permissions.
app/​models/​notification_setting.rb Registers the enabled-settings scope.
app/​models/​notification_settings/​scopes/​enabled_for.rb Resolves enabled project settings.
app/​services/​notifications/​create_from_api_service.rb Creates API mention notifications.
app/​services/​notifications/​create_from_model_service.rb Shares strategy lookup and tightens cleanup scope.
config/​locales/​en.yml Adds validation messages.
extensions/​op-blocknote-hocuspocus/​src/​extensions/​openProjectApi.ts Supports mention serialization.
extensions/​op-blocknote-hocuspocus/​test/​extensions/​openProjectApi.test.ts Tests mention serialization.
frontend/​src/​react/​components/​OpBlockNoteEditor.tsx Enables user mentions in BlockNote.
lib/​api/​v3/​notifications/​notification_created_representer.rb Adds reduced creation response.
lib/​api/​v3/​notifications/​notifications_api.rb Adds the creation endpoint.
modules/​documents/​app/​mailers/​documents_mailer.rb Sends document mention emails.
modules/​documents/​app/​models/​document.rb Cleans up associated notifications.
modules/​documents/​app/​services/​notifications/​create_from_model_service/​document_strategy.rb Opts documents into API mentions.
modules/​documents/​app/​services/​notifications/​mail_service/​document_strategy.rb Dispatches mention emails.
modules/​documents/​app/​views/​documents_mailer/​mentioned.html.erb Adds HTML email content.
modules/​documents/​app/​views/​documents_mailer/​mentioned.text.erb Adds text email content.
modules/​documents/​config/​locales/​en.yml Adds email translations.
modules/​documents/​spec/​mailers/​documents_mailer_spec.rb Tests mention emails.
modules/​documents/​spec/​models/​document_spec.rb Tests notification cleanup.
modules/​documents/​spec/​services/​notifications/​create_from_model_service/​document_strategy_spec.rb Tests document strategy behavior.
modules/​documents/​spec/​services/​notifications/​mail_service_spec.rb Tests mail dispatch preferences.
spec/​contracts/​notifications/​create_mention_from_api_contract_spec.rb Tests mention validation.
spec/​lib/​api/​v3/​notifications/​notification_created_representer_rendering_spec.rb Tests reduced representation.
spec/​mailers/​previews/​documents_mailer_preview.rb Adds mail previews.
spec/​requests/​api/​v3/​notifications/​notifications_api_create_resource_spec.rb Tests endpoint behavior.
spec/​services/​notifications/​create_from_api_service_spec.rb Tests notification creation service.
spec/​services/​notifications/​create_from_model_service_comment_spec.rb Tests scoped notification cleanup.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/api/v3/notifications/notifications_api.rb
Comment thread lib/api/v3/notifications/notifications_api.rb Fixed
@judithroth
judithroth force-pushed the feature/se-641-mention-users-in-documents-backend-part-1 branch from 2ced463 to 56066dc Compare October 14, 2026 14:17
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/work_packages/table/inline_create/create_work_packages_spec.rb[1:1:1:1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26028, linked for reference only):

- `rspec ./spec/features/work_packages/table/inline_create/create_work_packages_spec.rb[1:1:1:1:1]`

Treat this as a standalone task, unrelated to PR #26028. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26028 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @judithroth to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @judithroth, and request a review from @judithroth.
On every commit, set @judithroth as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@judithroth
judithroth force-pushed the feature/se-641-mention-users-in-documents-backend-part-1 branch 2 times, most recently from 4c859f3 to e94a426 Compare October 15, 2026 09:58
@judithroth
judithroth marked this pull request as ready for review October 15, 2026 10:05
@judithroth
judithroth requested a review from a team October 15, 2026 10:57
@judithroth
judithroth force-pushed the feature/se-641-mention-users-in-documents-backend-part-1 branch from e94a426 to c1cdaf7 Compare October 16, 2026 10:54
@ihordubas99
ihordubas99 added this pull request to stack #26090 October 16, 2026 11:03
include API::Decorators::LinkedResource
extend API::Decorators::PolymorphicResource

property :id

@judithroth judithroth Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id behind exposing this is to enable:

  • deleting the notification if the user removes the mention right after creating it (e.g. some seconds later)
  • being able to somehow use this as an "anchor", so when we show documents in the notification center in a split screen, we can scroll to where the user was mentioned.

Both is not implemented yet but would be really nice.

@brunopagno brunopagno left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a code standpoint this looks good. This opens up the API to do cool stuff 😁

BUT... I catch myself thinking if we need extra gates to protect client applications from sending "ghost" notifications, or from sending multiple notifications for a single event.

Initial brain dump~ we could do something like enqueue a job to send the notification with a delay (30 secs? something short enough) and then the job checks the state of the data and decides if we discard or actually send the notification. I don't know enough of this area of the codebase to make a better informed decision.

In any case, I think this is the right path. Approved because awesome 🎉

Comment on lines +39 to +42
def enabled_for(reason, project)
where(reason => true)
.applicable(project)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These auto injected things kinda get me off guard every time.

My feeling is that it would be nicer to have this simple scope explicit on the class it's being used. Unless it's used in multiple places, then I guess extracting into a concern kidna makes sense.

Still no action necessary, just me preferring explicitness.

@user = user
end

# @param reason [String, Symbol] has to be "mentioned"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parameter has to be the same constant value, do we need it?

@ihordubas99
ihordubas99 force-pushed the feature/se-641-mention-users-in-documents-backend-part-1 branch from c1cdaf7 to 2392f56 Compare October 23, 2026 13:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. Passion time

Development

Successfully merging this pull request may close these issues.

4 participants