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
feat[Op#52449]: Add subscribe/unsubscribe via sidebar notifications component
Kabiru Mwenjae4fd5667189c
diff --git a/modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erbnew file mode 100644index 00000000000..b7b219fe036--- /dev/null+++ b/modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erb@@ -0,0 +1,36 @@+<%=+ component_wrapper(data: { turbo: true }) do+ flex_layout do |notifications_container|+ notifications_container.with_row do+ render(Primer::Beta::Heading.new(tag: :h4)) { t("storages.email_notifications.title") }+ end++ notifications_container.with_row(mt: 2) do+ form_for(@storage, method: :patch,+ url: change_health_email_notifications_admin_settings_storage_path(@storage),+ data: { turbo_stream: true }) do |f|+ flex_layout do |notification_status_actions|+ notification_status_actions.with_row do+ f.hidden_field :health_notifications_enabled, value: (storage.health_notifications_enabled? ? "0" : "1")+ end++ notification_status_actions.with_row do+ render(Primer::Beta::Button.new(+ scheme: :default,+ block: :true,+ type: :submit+ )) do |button|+ button.with_leading_visual_icon(icon: notification_status[:icon])+ notification_status[:label]+ end+ end+ end+ end+ end++ notifications_container.with_row(mt: 3) do+ render(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }+ end+ end+ end+%>diff --git a/modules/storages/app/components/storages/admin/sidebar/notifications_component.rb b/modules/storages/app/components/storages/admin/sidebar/notifications_component.rbnew file mode 100644index 00000000000..40ef9fb0431--- /dev/null+++ b/modules/storages/app/components/storages/admin/sidebar/notifications_component.rb@@ -0,0 +1,57 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Storages+ module Admin+ class Sidebar::NotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent+ include ApplicationHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ attr_reader :storage++ def initialize(storage:)+ super++ @storage = storage+ end++ def notification_status+ if storage.health_notifications_enabled?+ { icon: :"bell-slash",+ label: I18n.t("storages.email_notifications.unsubscribe"),+ description: I18n.t("storages.email_notifications.description_subscribed") }+ else+ { icon: :bell,+ label: I18n.t("storages.email_notifications.subscribe"),+ description: I18n.t("storages.email_notifications.description_unsubscribed") }+ end+ end+ end+ end+enddiff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erbindex 8fe170b0d88..a0f4d0d86c1 100644--- a/modules/storages/app/components/storages/admin/sidebar_component.html.erb+++ b/modules/storages/app/components/storages/admin/sidebar_component.html.erb@@ -2,6 +2,7 @@component_wrapper dorender(Primer::OpenProject::BorderGrid.new) do |border_grid|border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }+ border_grid.with_row { render(Storages::Admin::Sidebar::NotificationsComponent.new(storage: @storage)) }endend%>diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 6b06e92efac..23edfe2ad17 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -31,7 +31,9 @@# Purpose: CRUD the global admin page of Storages (=Nextcloud servers)class Storages::Admin::StoragesController < ApplicationControllerusing Storages::Peripherals::ServiceResultRefinements+include FlashMessagesHelper+ include OpTurbo::ComponentStream# See https://guides.rubyonrails.org/layouts_and_rendering.html for reference on layoutlayout "admin"@@ -43,7 +45,8 @@ class Storages::Admin::StoragesController < ApplicationController# and set the @<controller_name> variable to the object referenced in the URL.before_action :require_adminbefore_action :find_model_object,- only: %i[show_oauth_application destroy edit edit_host confirm_destroy update replace_oauth_application]+ only: %i[show_oauth_application destroy edit edit_host confirm_destroy update+ change_health_email_notifications replace_oauth_application]before_action :ensure_valid_provider_type_selected, only: %i[select_provider]before_action :require_ee_token_for_one_drive, only: %i[select_provider]@@ -162,6 +165,20 @@ class Storages::Admin::StoragesController < ApplicationControllerendend+ def change_health_email_notifications+ return head :forbidden unless %w[1 0].include?(permitted_storage_params[:health_notifications_enabled])++ if @storage.update(health_notifications_enabled: permitted_storage_params[:health_notifications_enabled])+ update_via_turbo_stream(component: Storages::Admin::Sidebar::NotificationsComponent.new(storage: @storage.reload))+ respond_with_turbo_streams+ else+ flash.now[:primer_banner] = {+ message: I18n.t("storages.health.email_notifications.error_could_not_be_saved"), scheme: :danger+ }+ render :edit+ end+ end+def confirm_destroy@storage_to_destroy = @storageend@@ -248,7 +265,8 @@ class Storages::Admin::StoragesController < ApplicationController"oauth_client_secret","tenant_id","drive_id",- "automatic_management_enabled")+ "automatic_management_enabled",+ "health_notifications_enabled")enddef storage_provider_parameter_namediff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 87ea4b52f4d..d19421c4042 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -53,6 +53,7 @@ module Storagesself.inheritance_column = :provider_typestore_attribute :provider_fields, :automatically_managed, :boolean+ store_attribute :provider_fields, :health_notifications_enabled, :boolean, default: truehas_many :file_links, class_name: "Storages::FileLink"belongs_to :creator, class_name: "User"diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 2d800a2edfc..1dfc8091c50 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -104,6 +104,13 @@ en:since: since %{datetime}subtitle: Automatically managed project folderstitle: Health status+ email_notifications:+ title: Email notifications+ description_unsubscribed: Health status email notifications for this storage have been turned off for all administrators.+ description_subscribed: Email notifications for this storage have been turned on for all administrators.+ error_could_not_be_saved: Email notification settings could not be saved. Please try again.+ subscribe: Subscribe+ unsubscribe: Unsubscribehelp_texts:project_folder: The project folder is the default folder for file uploads for this project. Users can nevertheless still upload files to other locations.instructions:diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rbindex 0e6cd5119c8..b1f19012d00 100644--- a/modules/storages/config/routes.rb+++ b/modules/storages/config/routes.rb@@ -48,6 +48,7 @@ Rails.application.routes.draw domember doget :show_oauth_applicationget :edit_host+ patch :change_health_email_notificationsget :confirm_destroydelete :replace_oauth_applicationend