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
[#47147] Extend existing view for editing storages to projects
Kabiru Mwenja4a6e9e507227
diff --git a/modules/storages/app/components/storages/projects_storages/row_component.rb b/modules/storages/app/components/storages/projects_storages/row_component.rbindex 08e38dc38cc..e45144c5b7e 100644--- a/modules/storages/app/components/storages/projects_storages/row_component.rb+++ b/modules/storages/app/components/storages/projects_storages/row_component.rb@@ -53,7 +53,14 @@ module Storages::ProjectsStoragesenddef button_links- [delete_link]+ [edit_link, delete_link]+ end++ def edit_link+ link_to '',+ edit_project_settings_projects_storage_path(project_id: project_storage.project, id: project_storage),+ class: 'icon icon-edit',+ title: I18n.t(:button_edit)enddef delete_linkdiff --git a/modules/storages/app/contracts/storages/project_storages/update_contract.rb b/modules/storages/app/contracts/storages/project_storages/update_contract.rbnew file mode 100644index 00000000000..30e6c31cc29--- /dev/null+++ b/modules/storages/app/contracts/storages/project_storages/update_contract.rb@@ -0,0 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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.+#++++# See also: base_contract.rb for comments+module Storages::ProjectStorages+ class UpdateContract < ::Storages::ProjectStorages::BaseContract+ end+enddiff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rbindex f0dae138147..aaef473acb8 100644--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -39,7 +39,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# This defines @object as the model instance.model_object Storages::ProjectStorage- before_action :find_model_object, only: %i[destroy] # Fill @object with ProjectStorage+ before_action :find_model_object, only: %i[edit update destroy] # Fill @object with ProjectStorage# No need to before_action :find_project_by_project_id as SettingsController already checks# No need to check for before_action :authorize, as the SettingsController already checks this.@@ -85,7 +85,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# @project was calculated by before_action :find_optional_project.service_result = ::Storages::ProjectStorages::CreateService.new(user: current_user)- .call(permitted_create_params)+ .call(permitted_storage_settings_params)# Create success/error messages to the userif service_result.success?@@ -97,6 +97,40 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerredirect_to project_settings_projects_storages_path # Redirect: Project -> Settings -> File Storagesend+ # Edit page is very similar to new page, except that we don't need to set+ # default attribute values because the object already exists+ # Called by: Global app/config/routes.rb to serve Web page+ def edit+ # Render existing ProjectStorage object+ # @object was calculated in before_action :find_model_object (see comments above).+ # @project_storage is used in the view in order to render the form for a new object+ @project_storage = @object++ # Right now, we only have a single storage provider.+ # See #create @available_storages on how to filter available storages when we introduce another storage provider.+ @available_storages = [@project_storage.storage]++ render '/storages/project_settings/edit'+ end++ # Update is similar to create above+ # See also: create above+ # See also: https://www.openproject.org/docs/development/concepts/contracted-services/+ # Called by: Global app/config/routes.rb to serve Web page+ def update+ service_result = ::Storages::ProjectStorages::UpdateService+ .new(user: current_user, model: @object)+ .call(permitted_storage_settings_params)++ if service_result.success?+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to project_settings_projects_storages_path # Redirect: Project -> Settings -> File Storages+ else+ @errors = service_result.errors+ render :edit+ end+ end+# Purpose: Destroy a ProjectStorage object# Called by: By pressing a "Delete" icon in the Project's settings ProjectStorages page# It redirects back to the list of ProjectStorages in the project@@ -116,11 +150,11 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# Define the list of permitted parameters for creating/updating a ProjectStorage.# Called by create and update actions above.- def permitted_create_params+ def permitted_storage_settings_params# "params" is an instance of ActionController::Parametersparams.require(:storages_project_storage)- .permit('storage_id')+ .permit('storage_id', 'project_folder_mode').to_h.reverse_merge(project_id: @project.id)enddiff --git a/modules/storages/app/services/storages/project_storages/update_service.rb b/modules/storages/app/services/storages/project_storages/update_service.rbnew file mode 100644index 00000000000..a813e91ac7c--- /dev/null+++ b/modules/storages/app/services/storages/project_storages/update_service.rb@@ -0,0 +1,34 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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.+#++++# Reference: https://www.openproject.org/docs/development/concepts/contracted-services/+# The comments here are also valid for the other *_service.rb files+module Storages::ProjectStorages+ class UpdateService < ::BaseServices::Update+ end+enddiff --git a/modules/storages/app/views/storages/project_settings/_form.html.erb b/modules/storages/app/views/storages/project_settings/_form.html.erbnew file mode 100644index 00000000000..0de69cadf31--- /dev/null+++ b/modules/storages/app/views/storages/project_settings/_form.html.erb@@ -0,0 +1,32 @@+<div class="form--field -required">+ <%= f.select :storage_id,+ available_storages.map { |storage| ["#{storage.name} (#{storage.provider_type})", storage.id] },+ selected: available_storages.first.id.to_s,+ container_class: '-slim' %>+ <% if User.current.admin? %>+ <span class="form--field-instructions">+ <%= t(:"storages.instructions.setting_up_additional_storages") %>+ <%= link_to "#{t(:label_administration)} / #{t(:project_module_storages)}", controller: '/storages/admin/storages', action: :index %>.+ </span>+ <% end %>+</div>++<div class="form--field -required">+ <%= f.radio_button :project_folder_mode,+ 'inactive',+ label: t(:"storages.label_no_specific_folder"),+ container_class: '-slim' %>+ <p class="form--field-instructions">+ <%= t(:"storages.instructions.no_specific_folder") %>+ </p>++ <%= f.radio_button :project_folder_mode,+ 'manual',+ label: t(:"storages.label_existing_manual_folder"),+ container_class: '-slim' %>+ <p class="form--field-instructions">+ <%= t(:"storages.instructions.existing_manual_folder") %>+ </p>+</div>++<%= styled_button_tag t(:button_add), class: "-highlight -with-icon icon-checkmark" %>diff --git a/modules/storages/app/views/storages/project_settings/edit.html.erb b/modules/storages/app/views/storages/project_settings/edit.html.erbnew file mode 100644index 00000000000..a3630ed59ef--- /dev/null+++ b/modules/storages/app/views/storages/project_settings/edit.html.erb@@ -0,0 +1,12 @@+<!-- Standard Ruby view, please see the controller for comments -->+<% html_title t(:label_administration), t("project_module_storages") %>+<% local_assigns[:additional_breadcrumb] = t('storages.label_edit_storage') %>+<%= toolbar title: t("storages.page_titles.project_settings.edit") %>++<%= labelled_tabular_form_for @project_storage, url: project_settings_projects_storage_path(project_id: @project_storage.project, id: @project_storage) do |f| -%>+ <%= error_messages_for_contract @project_storage, @errors %>++ <section class="form--section">+ <%= render partial: '/storages/project_settings/form', locals: { f: f, available_storages: @available_storages } %>+ </section>+<% end %>diff --git a/modules/storages/app/views/storages/project_settings/new.html.erb b/modules/storages/app/views/storages/project_settings/new.html.erbindex 7ac5ca9a62b..b7de0bce88c 100644--- a/modules/storages/app/views/storages/project_settings/new.html.erb+++ b/modules/storages/app/views/storages/project_settings/new.html.erb@@ -8,38 +8,7 @@<section class="form--section"><% if @available_storages.any? %>- <div class="form--field -required">- <%= f.select :storage_id,- @available_storages.map { |storage| ["#{storage.name} (#{storage.provider_type})", storage.id] },- selected: @available_storages.first.id.to_s,- container_class: '-slim' %>- <% if User.current.admin? %>- <span class="form--field-instructions">- <%= t(:"storages.instructions.setting_up_additional_storages") %>- <%= link_to "#{t(:label_administration)} / #{t(:project_module_storages)}", controller: '/storages/admin/storages', action: :index %>.- </span>- <% end %>- </div>-- <div class="form--field -required">- <%= f.radio_button :project_folder_mode,- 'inactive',- label: t(:"storages.label_no_specific_folder"),- container_class: '-slim' %>- <p class="form--field-instructions">- <%= t(:"storages.instructions.no_specific_folder") %>- </p>-- <%= f.radio_button :project_folder_mode,- 'manual',- label: t(:"storages.label_existing_manual_folder"),- container_class: '-slim' %>- <p class="form--field-instructions">- <%= t(:"storages.instructions.existing_manual_folder") %>- </p>- </div>-- <%= styled_button_tag t(:button_add), class: "-highlight -with-icon icon-checkmark" %>+ <%= render partial: '/storages/project_settings/form', locals: { f: f, available_storages: @available_storages } %><% else %><div class="op-toast -info"><div class="op-toast--content">diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 202b6dabed9..6527cb63362 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -53,6 +53,7 @@ en:project_settings:index: "File storages available in this project"new: "Add a file storage to this project"+ edit: "Edit the file storage to this project"instructions:type: "Please make sure you have administration privileges in your Nextcloud instance and have the following application installed before doing the setup:"type_link_text: "“Integration OpenProject”"diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rbindex e06f8382951..0dc103dde65 100644--- a/modules/storages/config/routes.rb+++ b/modules/storages/config/routes.rb@@ -41,7 +41,7 @@ OpenProject::Application.routes.draw doscope 'projects/:project_id', as: 'project' donamespace 'settings' doresources :projects_storages, controller: '/storages/admin/projects_storages',- except: %i[show update]+ except: %i[show]endendenddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 0cc86bf1419..7e2a28fd75c 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -66,7 +66,7 @@ module OpenProject::Storagesdependencies: %i[view_file_links],contract_actions: { file_links: %i[manage] }permission :manage_storages_in_project,- { 'storages/admin/projects_storages': %i[index new create destroy] },+ { 'storages/admin/projects_storages': %i[index new edit update create destroy] },dependencies: %i[]enddiff --git a/modules/storages/spec/features/create_and_delete_project_storage_spec.rb b/modules/storages/spec/features/create_and_delete_project_storage_spec.rbindex 35dcdb69ff8..b19ab56ecb5 100644--- a/modules/storages/spec/features/create_and_delete_project_storage_spec.rb+++ b/modules/storages/spec/features/create_and_delete_project_storage_spec.rb@@ -75,6 +75,21 @@ describe 'Activation of storages in projects', js: true doexpect(page).to have_text('File storages available in this project')expect(page).to have_text('Storage 1')+ # Press Edit icon to change the project folder mode to inactive+ page.find('.icon.icon-edit').click+ expect(page).to have_current_path edit_project_settings_projects_storage_path(project_id: project, id: Storages::ProjectStorage.last)+ expect(page).to have_text('Edit the file storage to this project')+ # The project folder mode should be manual+ expect(page).to have_checked_field('storages_project_storage_project_folder_mode_manual')++ # Change the project folder mode to inactive+ page.find_by_id('storages_project_storage_project_folder_mode_inactive').click+ page.find('button[type=submit]').click++ # The list of enabled file storages should still contain Storage 1+ expect(page).to have_text('File storages available in this project')+ expect(page).to have_text('Storage 1')+# Press Delete icon to remove the storage from the projectpage.find('.icon.icon-delete').clickalert_text = page.driver.browser.switch_to.alert.textdiff --git a/modules/storages/spec/services/storages/project_storages/update_service_spec.rb b/modules/storages/spec/services/storages/project_storages/update_service_spec.rbnew file mode 100644index 00000000000..9b2795905bb--- /dev/null+++ b/modules/storages/spec/services/storages/project_storages/update_service_spec.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 'services/base_services/behaves_like_update_service'++describe Storages::ProjectStorages::UpdateService, type: :model do+ it_behaves_like 'BaseServices update service' do+ let(:factory) { :project_storage }+ end+end