Repository navigation
[SE-641] Allow to create mentions via the API - #26028
judithroth wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 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/notificationsfor 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.
2ced463 to
56066dc
Compare
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy 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. |
4c859f3 to
e94a426
Compare
e94a426 to
c1cdaf7
Compare
| include API::Decorators::LinkedResource | ||
| extend API::Decorators::PolymorphicResource | ||
|
|
||
| property :id |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 🎉
| def enabled_for(reason, project) | ||
| where(reason => true) | ||
| .applicable(project) | ||
| end |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
If the parameter has to be the same constant value, do we need it?
c1cdaf7 to
2392f56
Compare

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
What approach did you choose and why?
Allow to create notifications via the API because
AI involvement
Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.
Merge checklist