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
[#48373] Implement Rails controller methods with UI for project storages
Andreas Pfohl81d13db5a2c3
diff --git a/modules/storages/app/contracts/storages/last_project_folders/base_contract.rb b/modules/storages/app/contracts/storages/last_project_folders/base_contract.rbnew file mode 100644index 00000000000..c3aed54856e--- /dev/null+++ b/modules/storages/app/contracts/storages/last_project_folders/base_contract.rb@@ -0,0 +1,40 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class BaseContract < ::ModelContract+ include ActiveModel::Validations++ attribute :projects_storage+ validates_presence_of :projects_storage+ attribute :mode+ validates :mode, presence: true, inclusion: { in: Storages::ProjectStorage.project_folder_modes.keys }+ attribute :origin_folder_id+ validates_presence_of :origin_folder_id+ end+enddiff --git a/modules/storages/app/contracts/storages/last_project_folders/create_contract.rb b/modules/storages/app/contracts/storages/last_project_folders/create_contract.rbnew file mode 100644index 00000000000..6eaa5a3e083--- /dev/null+++ b/modules/storages/app/contracts/storages/last_project_folders/create_contract.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class CreateContract < ::Storages::LastProjectFolders::BaseContract+ end+enddiff --git a/modules/storages/app/contracts/storages/last_project_folders/delete_contract.rb b/modules/storages/app/contracts/storages/last_project_folders/delete_contract.rbnew file mode 100644index 00000000000..e5f2414e65b--- /dev/null+++ b/modules/storages/app/contracts/storages/last_project_folders/delete_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.+#++++module Storages::LastProjectFolders+ class DeleteContract < ::DeleteContract+ delete_permission(:manage_storages_in_project)+ end+enddiff --git a/modules/storages/app/contracts/storages/last_project_folders/update_contract.rb b/modules/storages/app/contracts/storages/last_project_folders/update_contract.rbnew file mode 100644index 00000000000..3231c009d21--- /dev/null+++ b/modules/storages/app/contracts/storages/last_project_folders/update_contract.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class UpdateContract < ::Storages::LastProjectFolders::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 5877b200fee..4b0883877b1 100644--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -108,6 +108,8 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# @project_storage is used in the view in order to render the form for a new object@project_storage = @object+ @last_project_folders = Storages::LastProjectFolder.where(projects_storage: @project_storage).index_by(&:mode)+render '/storages/project_settings/edit'end@@ -139,7 +141,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerStorages::ProjectStorages::DeleteService.new(user: current_user, model: @object).call- .on_failure { |service_result| flash[:error] = service_result.errors.full_messages }+ .on_failure { |service_result| flash[:error] = service_result.all_errors.full_messages }# Redirect the user to the URL of Projects -> Settings -> File Storagesredirect_to project_settings_projects_storages_pathdiff --git a/modules/storages/app/services/storages/last_project_folders/create_service.rb b/modules/storages/app/services/storages/last_project_folders/create_service.rbnew file mode 100644index 00000000000..05c5cf6a46c--- /dev/null+++ b/modules/storages/app/services/storages/last_project_folders/create_service.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class CreateService < ::BaseServices::Create+ end+enddiff --git a/modules/storages/app/services/storages/last_project_folders/delete_service.rb b/modules/storages/app/services/storages/last_project_folders/delete_service.rbnew file mode 100644index 00000000000..0aa8093a00d--- /dev/null+++ b/modules/storages/app/services/storages/last_project_folders/delete_service.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class DeleteService < ::BaseServices::Delete+ end+enddiff --git a/modules/storages/app/services/storages/last_project_folders/set_attributes_service.rb b/modules/storages/app/services/storages/last_project_folders/set_attributes_service.rbnew file mode 100644index 00000000000..764ac5f6431--- /dev/null+++ b/modules/storages/app/services/storages/last_project_folders/set_attributes_service.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class SetAttributesService < ::BaseServices::SetAttributes+ end+enddiff --git a/modules/storages/app/services/storages/last_project_folders/update_service.rb b/modules/storages/app/services/storages/last_project_folders/update_service.rbnew file mode 100644index 00000000000..a56c620f1d1--- /dev/null+++ b/modules/storages/app/services/storages/last_project_folders/update_service.rb@@ -0,0 +1,32 @@+#-- 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.+#++++module Storages::LastProjectFolders+ class UpdateService < ::BaseServices::Update+ end+enddiff --git a/modules/storages/app/services/storages/project_storages/create_service.rb b/modules/storages/app/services/storages/project_storages/create_service.rbindex a0c31240397..cf0d5f14c18 100644--- a/modules/storages/app/services/storages/project_storages/create_service.rb+++ b/modules/storages/app/services/storages/project_storages/create_service.rb@@ -29,5 +29,23 @@# See: ../storages/create_service.rb for comments on servicesmodule Storages::ProjectStoragesclass CreateService < ::BaseServices::Create+ protected++ def after_perform(service_call)+ super(service_call)++ project_storage = service_call.result++ last_project_folder_result = ::Storages::LastProjectFolders::CreateService.new(user:)+ .call({+ projects_storage_id: project_storage.id,+ origin_folder_id: project_storage.project_folder_id,+ mode: project_storage.project_folder_mode+ })++ service_call.add_dependent!(last_project_folder_result)++ service_call+ endendenddiff --git a/modules/storages/app/views/storages/project_settings/_form.html.erb b/modules/storages/app/views/storages/project_settings/_form.html.erbindex 61094fe1434..fd03f691e96 100644--- a/modules/storages/app/views/storages/project_settings/_form.html.erb+++ b/modules/storages/app/views/storages/project_settings/_form.html.erb@@ -117,6 +117,19 @@ See COPYRIGHT and LICENSE files for more details.<%= t(:"storages.instructions.no_specific_folder") %></span>+ <div class="form--field-container">+ <%= f.label :project_folder_mode, class: "form--label-with-radio-button" do %>+ <%= f.radio_button :project_folder_mode,+ 'automatic',+ no_label: true,+ data: { action: 'project-storage-form#updateDisplay' }%>+ <%= t(:"storages.label_automatic_folder") %>+ <% end %>+ </div>+ <span class="form--field-instructions -xwide -with-bottom-spacing">+ <%= t(:"storages.instructions.automatic_folder") %>+ </span>+<div class="form--field-container"><%= f.label :project_folder_mode, class: "form--label-with-radio-button" do %><%= f.radio_button :project_folder_mode,diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 2612a98cada..df5ad80f93f 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -67,6 +67,7 @@ en:host: "Please add the host address of your storage including the https://. It should not be longer than 255 characters."no_storage_set_up: "There are no file storages set up yet."no_specific_folder: "By default, each user will start at their own home folder when they upload a file."+ automatic_folder: "This will automatically create a root folder for this project and manage the access permissions for each project member."empty_project_folder_validation: "Selecting a folder is mandatory to proceed."existing_manual_folder: >You can designate an existing folder as the root folder for this project. The permissions are however not automatically managed, the@@ -105,6 +106,7 @@ en:label_new_storage: "New storage"label_existing_manual_folder: "Existing folder with manually managed permissions"label_no_specific_folder: "No specific folder"+ label_automatic_folder: "New folder with automatically managed permissions"label_no_selected_folder: "No selected folder"label_storage: "Storage"label_storages: "Storages"