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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Prevent watcher button from becoming nil
Oliver Günther6e5193f84d15
diff --git a/app/components/messages/show_page_header_component.html.erb b/app/components/messages/show_page_header_component.html.erbindex 7b7ce34f532..4cec4fedc5d 100644--- a/app/components/messages/show_page_header_component.html.erb+++ b/app/components/messages/show_page_header_component.html.erb@@ -3,11 +3,7 @@header.with_title { @topic.subject }header.with_breadcrumbs(breadcrumb_items)- watcher_button_args = watcher_button_arguments(@topic, User.current)- header.with_action_button(**watcher_button_args) do |button|- button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])- watcher_button_args[:mobile_label]- end+ watcher_action_button(header, @topic)if [email protected]? && authorize_for('messages', 'reply')header.with_action_button(tag: :a,diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rbindex 27f883a66b9..198d7703705 100644--- a/app/helpers/watchers_helper.rb+++ b/app/helpers/watchers_helper.rb@@ -44,6 +44,16 @@ module WatchersHelperlink_to_watcher_button(watched, path, html_options)end+ def watcher_action_button(container, object)+ watcher_button_args = watcher_button_arguments(object, User.current)+ return if watcher_button_args.nil?++ container.with_action_button(**watcher_button_args) do |button|+ button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])+ watcher_button_args[:mobile_label]+ end+ end+def watcher_button_arguments(object, user)return nil unless user&.logged? && object.respond_to?(:watched_by?)diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erbindex 0d7e4a48b97..3f0ddfa7389 100644--- a/app/views/forums/show.html.erb+++ b/app/views/forums/show.html.erb@@ -57,13 +57,8 @@ See COPYRIGHT and LICENSE files for more details.header.with_breadcrumbs([{ href: project_overview_path(@project.id), text: @project.name },{ href: project_forums_path(@project), text: t(:label_forum_plural) },@forum.name])- unless User.current.anonymous?- watcher_button_args = watcher_button_arguments(@forum, User.current)- header.with_action_button(**watcher_button_args) do |button|- button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])- watcher_button_args[:mobile_label]- end- end++ watcher_action_button(header, @forum)end%><% if authorize_for(:messages, :new) %>@@ -75,7 +70,7 @@ See COPYRIGHT and LICENSE files for more details.title: t(:label_message_new),tag: :a,class: 'add-message-button',- href: url_for({controller: '/messages', action: 'new', forum_id: @forum})) do |button|+ href: url_for({ controller: '/messages', action: 'new', forum_id: @forum })) do |button|button.with_leading_visual_icon(icon: :plus)t(:label_message)enddiff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erbindex 317fc5b8a42..9b0fd627fb1 100644--- a/app/views/news/show.html.erb+++ b/app/views/news/show.html.erb@@ -47,11 +47,9 @@ See COPYRIGHT and LICENSE files for more details.t(:button_edit)endend- watcher_button_args = watcher_button_arguments(@news, User.current)- header.with_action_button(**watcher_button_args) do |button|- button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])- watcher_button_args[:mobile_label]- end++ watcher_action_button(header, @news)+if User.current.allowed_in_project?(:manage_news, @project)header.with_action_button(scheme: :danger,tag: :a,