Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix[Op#58142]: render error flash in error case

Kabiru Mwenjac09cffc5c70e
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 2864a27adf1..06f01a8bd13 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -30,6 +30,7 @@
class WorkPackages::ActivitiesTabController < ApplicationController
include OpTurbo::ComponentStream
+ include FlashMessagesOutputSafetyHelper
before_action :find_work_package
before_action :find_project
@@ -142,31 +143,32 @@ class WorkPackages::ActivitiesTabController < ApplicationController
respond_with_turbo_streams
end
- def toggle_reaction
- call = if @journal.emoji_reactions.exists?(user: User.current, emoji: params[:emoji])
- EmojiReactions::DeleteService.new(
- user: User.current,
- model: @journal.emoji_reactions.find_by(user: User.current, emoji: params[:emoji])
- ).call
- else
- EmojiReactions::CreateService.new(
- user: User.current
- ).call(
- user: User.current,
- reactable: @journal,
- emoji: params[:emoji]
- )
- end
-
- if call.success?
+ def toggle_reaction # rubocop:disable Metrics/AbcSize
+ emoji_reaction_service =
+ if @journal.emoji_reactions.exists?(user: User.current, emoji: params[:emoji])
+ EmojiReactions::DeleteService
+ .new(user: User.current,
+ model: @journal.emoji_reactions.find_by(user: User.current, emoji: params[:emoji]))
+ .call
+ else
+ EmojiReactions::CreateService
+ .new(user: User.current)
+ .call(user: User.current, reactable: @journal, emoji: params[:emoji])
+ end
+
+ emoji_reaction_service.on_success do
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent::Show.new(
journal: @journal,
filter: params[:filter]&.to_sym || :all
)
)
- else
- # TODO: handle errors
+ end
+
+ emoji_reaction_service.on_failure do
+ render_error_flash_message_via_turbo_stream(
+ message: join_flash_messages(emoji_reaction_service.errors.full_messages)
+ )
end
respond_with_turbo_streams
diff --git a/config/locales/en.yml b/config/locales/en.yml
index faaf4f37599..5ae80738fb3 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -929,6 +929,7 @@ en:
could_not_be_copied: "%{dependency} could not be (fully) copied."
does_not_exist: "does not exist."
error_enterprise_only: "%{action} is only available in the OpenProject Enterprise edition"
+ error_not_found: "not found."
error_unauthorized: "may not be accessed."
error_readonly: "was attempted to be written but is not writable."
error_conflict: "Information has been updated by at least one other user in the meantime."