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
Use component in storages
Mir Bhatiac96720334b8c
diff --git a/modules/storages/app/components/storages/admin/side_panel/email_updates_switch_component.rb b/modules/storages/app/components/storages/admin/side_panel/email_updates_switch_component.rbnew file mode 100644index 00000000000..eea134863d6--- /dev/null+++ b/modules/storages/app/components/storages/admin/side_panel/email_updates_switch_component.rb@@ -0,0 +1,61 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 SidePanel::EmailUpdatesSwitchComponent < ApplicationComponent+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ def initialize(storage:)+ super++ @storage = storage+ end++ def render?+ @storage.automatic_management_enabled?+ end++ def call+ component_wrapper do+ render OpPrimer::EmailUpdatesSwitchComponent.new(+ toggle: @storage.health_notifications_should_be_sent?,+ path: change_health_notifications_enabled_admin_settings_storage_path(@storage),+ title: I18n.t("storages.health_email_notifications.title"),+ enabled_description: I18n.t("storages.health_email_notifications.description_enabled"),+ disabled_description: I18n.t("storages.health_email_notifications.description_disabled"),+ method: :patch+ )+ end+ end+ end+ end+enddiff --git a/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erbindex 452bcd00939..f0272abe837 100644--- a/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb+++ b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb@@ -59,41 +59,6 @@ See COPYRIGHT and LICENSE files for more details.endendend-- notifications_container.with_row(mt: 2) do- render(Primer::Beta::Text.new(font_weight: :bold)) { t("storages.health_email_notifications.title") }- end-- notifications_container.with_row(mt: 2) do- form_for(- @storage, method: :patch,- url: change_health_notifications_enabled_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_should_be_sent? ? "0" : "1")- end-- notification_status_actions.with_row(test_selector: "storage-health-notifications-button") 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, test_selector: "storage-health-notifications-description") do- render(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }- endendendenddiff --git a/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rbindex ca6a1a3667b..c5ab8c83acf 100644--- a/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb+++ b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb@@ -46,18 +46,6 @@ module Storagesprivate- def notification_status- if @storage.health_notifications_should_be_sent?- { icon: :"bell-slash",- label: I18n.t("storages.health_email_notifications.unsubscribe"),- description: I18n.t("storages.health_email_notifications.description_subscribed") }- else- { icon: :bell,- label: I18n.t("storages.health_email_notifications.subscribe"),- description: I18n.t("storages.health_email_notifications.description_unsubscribed") }- end- end-def health_status_indicatorcase @storage.health_statuswhen "healthy"diff --git a/modules/storages/app/components/storages/admin/side_panel_component.html.erb b/modules/storages/app/components/storages/admin/side_panel_component.html.erbindex 0a699dd5f40..7b9bdeb16ca 100644--- a/modules/storages/app/components/storages/admin/side_panel_component.html.erb+++ b/modules/storages/app/components/storages/admin/side_panel_component.html.erb@@ -5,6 +5,8 @@if @storage.automatic_management_enabled?panel.with_section(Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))++ panel.with_section(Storages::Admin::SidePanel::EmailUpdatesSwitchComponent.new(storage: @storage))endendenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 563173f4839..5643454f0f1 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -159,10 +159,8 @@ class Storages::Admin::StoragesController < ApplicationControllerenddef change_health_notifications_enabled- return head :bad_request 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::SidePanel::HealthNotificationsComponent.new(storage: @storage))+ if @storage.update(health_notifications_enabled: [email protected]_notifications_enabled)+ update_via_turbo_stream(component: Storages::Admin::SidePanel::EmailUpdatesSwitchComponent.new(storage: @storage))respond_with_turbo_streamselseflash.now[:error] = I18n.t("storages.health_email_notifications.error_could_not_be_saved")diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 12b682841e8..3c3fbe5029e 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -340,12 +340,10 @@ en:warning: Some checks returned a warning. This can lead to unexpected behaviour.title: Health status reporthealth_email_notifications:- description_subscribed: All administrators receive health status email notifications for this storage.- description_unsubscribed: Health status email notifications for this storage have been turned off for all administrators.+ description_disabled: Admins will not receive updates by email when there are important updates.+ description_enabled: Admins will receive updates by email when there are important updates.error_could_not_be_saved: Email notification settings could not be saved. Please try again.- subscribe: Subscribe- title: Email notifications- unsubscribe: Unsubscribe+ title: Email updates to adminshelp_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.project_folder_bulk: The project folder is the default folder for file uploads for all the projects selected. You can modify this individually in each project settings. Users can nevertheless still upload files to other locations.diff --git a/modules/storages/spec/components/storages/admin/side_panel/email_updates_switch_component_spec.rb b/modules/storages/spec/components/storages/admin/side_panel/email_updates_switch_component_spec.rbnew file mode 100644index 00000000000..75a89f2b8a3--- /dev/null+++ b/modules/storages/spec/components/storages/admin/side_panel/email_updates_switch_component_spec.rb@@ -0,0 +1,71 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#+++#+require "spec_helper"+require_module_spec_helper++RSpec.describe Storages::Admin::SidePanel::EmailUpdatesSwitchComponent, type: :component do+ describe "storage without automatically managed project folders" do+ let(:storage) { build_stubbed(:nextcloud_storage, :as_not_automatically_managed) }++ it "does not render" do+ render_inline described_class.new(storage:)+ expect(page.text).to be_empty+ end+ end++ describe "storage with automatically managed project folders" do+ before do+ render_inline(described_class.new(storage:))+ end++ describe "email notifications" do+ context "when email notifications are enabled" do+ let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_enabled, :as_automatically_managed) }++ it "renders a 'Disable' option with info" do+ text = "Admins will receive updates by email when there are important updates."+ expect(page).to have_test_selector("email-updates-switch", text: text)+ expect(page).to have_selector(:link_or_button, "Disable")+ end+ end++ context "when email notifications are disabled" do+ let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_disabled, :as_automatically_managed) }++ it "renders an 'Enable' option with info" do+ text = "Admins will not receive updates by email when there are important updates."+ expect(page).to have_test_selector("email-updates-switch", text:)+ expect(page).to have_selector(:link_or_button, "Enable")+ end+ end+ end+ end+enddiff --git a/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb b/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rbindex a6f02e8679f..7cf678a7f50 100644--- a/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb+++ b/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb@@ -115,29 +115,5 @@ RSpec.describe Storages::Admin::SidePanel::HealthNotificationsComponent, type: :endendend-- describe "email notifications" do- context "when subscribed to email notifications" do- let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_enabled, :as_automatically_managed) }-- it "renders an unsubscribe option with info" do- expect(page).to have_css("input[type=hidden][value='0']", visible: :hidden)- text = "All administrators receive health status email notifications for this storage."- expect(page).to have_test_selector("storage-health-notifications-description", text: text)- expect(page).to have_button("Unsubscribe")- end- end-- context "when unsubscribed to email notifications" do- let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_disabled, :as_automatically_managed) }-- it "renders an unsubscribe option with info" do- expect(page).to have_css("input[type=hidden][value='1']", visible: :hidden)- text = "Health status email notifications for this storage have been turned off for all administrators."- expect(page).to have_test_selector("storage-health-notifications-description", text:)- expect(page).to have_button("Subscribe")- end- end- endendenddiff --git a/modules/storages/spec/features/storages/admin/edit_storage_spec.rb b/modules/storages/spec/features/storages/admin/edit_storage_spec.rbindex 6a0b9f2e211..e297b033638 100644--- a/modules/storages/spec/features/storages/admin/edit_storage_spec.rb+++ b/modules/storages/spec/features/storages/admin/edit_storage_spec.rb@@ -229,15 +229,15 @@ RSpec.describe "Admin Edit File storage",aggregate_failures "Health notifications" doexpect(page).to have_test_selector("storage-health-status", text: "Pending")- expect(page).to have_test_selector("storage-health-notifications-button", text: "Unsubscribe")- expect(page).to have_test_selector("storage-health-notifications-description",- text: "All administrators receive health status email notifications for this storage.")+ expect(page).to have_test_selector("email-updates-switch-button", text: "Disable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will receive updates by email when there are important updates.")- click_on "Unsubscribe"+ click_on "Disable"- expect(page).to have_test_selector("storage-health-notifications-button", text: "Subscribe")- expect(page).to have_test_selector("storage-health-notifications-description",- text: "Health status email notifications for this storage have been turned off for all administrators.")+ expect(page).to have_test_selector("email-updates-switch-button", text: "Enable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will not receive updates by email when there are important updates.")endendend@@ -357,17 +357,16 @@ RSpec.describe "Admin Edit File storage",aggregate_failures "Health notifications" doexpect(page).to have_test_selector("storage-health-status", text: "Pending")- expect(page).to have_test_selector("storage-health-notifications-button", text: "Unsubscribe")- expect(page).to have_test_selector("storage-health-notifications-description",- text: "All administrators receive health status email notifications for this storage.")- click_on "Unsubscribe"+ expect(page).to have_test_selector("email-updates-switch-button", text: "Disable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will receive updates by email when there are important updates.")- expect(page).to have_test_selector("storage-health-notifications-button", text: "Subscribe")- expect(page).to have_test_selector(- "storage-health-notifications-description",- text: "Health status email notifications for this storage have been turned off for all administrators."- )+ click_on "Disable"++ expect(page).to have_test_selector("email-updates-switch-button", text: "Enable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will not receive updates by email when there are important updates.")endend@@ -492,15 +491,16 @@ RSpec.describe "Admin Edit File storage",aggregate_failures "Health notifications" doexpect(page).to have_test_selector("storage-health-status", text: "Pending")- expect(page).to have_test_selector("storage-health-notifications-button", text: "Unsubscribe")- expect(page).to have_test_selector("storage-health-notifications-description",- text: "All administrators receive health status email notifications for this storage.")- click_on "Unsubscribe"+ expect(page).to have_test_selector("email-updates-switch-button", text: "Disable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will receive updates by email when there are important updates.")++ click_on "Disable"- expect(page).to have_test_selector("storage-health-notifications-button", text: "Subscribe")- expect(page).to have_test_selector("storage-health-notifications-description",- text: "Health status email notifications for this storage have been turned off for all administrators.")+ expect(page).to have_test_selector("email-updates-switch-button", text: "Enable")+ expect(page).to have_test_selector("email-updates-switch",+ text: "Admins will not receive updates by email when there are important updates.")endendend