Skip to content

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

Merge branch 'dev' into implementation/55968-implement-project-removal-with-warning-dialog-before-removing-the-project

Judith Roth07b467f8a8fc
diff --cc modules/storages/app/components/storages/project_storages/projects/row_component.rb
index 8e4a4ab7679,feb10977115..4560b2eca8e
--- a/modules/storages/app/components/storages/project_storages/projects/row_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/row_component.rb
@@@ -29,11 -29,9 +29,11 @@@
# Purpose: Defines how to format the components within a table row of Projects
# associated with a Storage
module Storages::ProjectStorages::Projects
- class RowComponent < Projects::RowComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class RowComponent < Projects::RowComponent
+ include OpTurbo::Streamable
+
def project_folder_type
- project_folder_mode = table.project_folder_modes_per_project[project.id]
+ project_folder_mode = table.project_storages[project.id].project_folder_mode
I18n.t("project_storages.project_folder_mode.#{project_folder_mode}")
end
diff --cc modules/storages/app/components/storages/project_storages/projects/table_component.rb
index 7fffb53bc76,6781c3525f8..b598ba7fbfd
--- a/modules/storages/app/components/storages/project_storages/projects/table_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/table_component.rb
@@@ -31,10 -31,10 +31,10 @@@
# See also: row_component.rb, which contains a method
# for every "column" defined below.
module Storages::ProjectStorages::Projects
- class TableComponent < Projects::TableComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class TableComponent < Projects::TableComponent
include OpTurbo::Streamable
- options :project_folder_modes_per_project
+ options :storage
def columns
@columns ||= query
diff --cc modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
index 616f4d1eb89,aacdecce734..c1636835181
--- a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
@@@ -38,34 -39,41 +39,50 @@@ class Storages::Admin::Storages::Projec
before_action :require_admin
before_action :find_model_object
+ before_action :load_project_storage, only: %i(destroy destroy_confirmation_dialog)
- before_action :storage_projects_query,
- :project_folder_modes_per_project,
- only: :index
++ before_action :storage_projects_query, only: :index
+ before_action :initialize_project_storage, only: :new
+ before_action :find_projects_to_activate_for_storage, only: :create
+
menu_item :external_file_storages
- def index
- @project_query = ProjectQuery.new(
- name: "project-storage-mappings-#{@storage.id}"
- ) do |query|
- query.where(:storages, "=", [@storage.id])
- query.select(:name)
- query.order("lft" => "asc")
- end
+ def index; end
+
+ def new
+ respond_with_dialog Storages::Admin::Storages::AddProjectsModalComponent.new(project_storage: @project_storage)
end
- def new; end
- def create; end
+ def create
+ create_service = ::Storages::ProjectStorages::BulkCreateService
+ .new(user: current_user, projects: @projects, storage: @storage,
+ project_folder_mode: params.to_unsafe_h[:storages_project_storage][:project_folder_mode],
+ include_sub_projects: include_sub_projects?)
+ .call
+
+ create_service.on_success { update_project_list_via_turbo_stream(url_for_action: :index) }
+
+ create_service.on_failure do
+ update_flash_message_via_turbo_stream(
+ message: join_flash_messages(create_service.errors),
+ full: true, dismiss_scheme: :hide, scheme: :danger
+ )
+ end
+
+ respond_with_turbo_streams(status: create_service.success? ? :ok : :unprocessable_entity)
+ end
- def destroy; end
+ def destroy_confirmation_dialog
+ respond_with_dialog Storages::ProjectStorages::DestroyConfirmationDialogComponent.new(
+ storage: @storage,
+ project_storage: @project_storage
+ )
+ end
+
+ def destroy
+ @project_storage.destroy
+ redirect_to admin_settings_storage_project_storages_path(@storage)
+ end
private
@@@ -77,4 -81,58 +94,51 @@@
super
@storage = @object
end
+
+ def find_projects_to_activate_for_storage
+ if (project_ids = params.to_unsafe_h[:storages_project_storage][:project_ids]).present?
+ @projects = Project.find(project_ids)
+ else
+ initialize_project_storage
+ @project_storage.errors.add(:project_ids, :blank)
+ component = Storages::Admin::Storages::AddProjectsFormModalComponent.new(project_storage: @project_storage)
+ update_via_turbo_stream(component:, status: :bad_request)
+ respond_with_turbo_streams
+ end
+ rescue ActiveRecord::RecordNotFound
+ update_flash_message_via_turbo_stream message: t(:notice_project_not_found), full: true, dismiss_scheme: :hide,
+ scheme: :danger
+ update_project_list_via_turbo_stream
+
+ respond_with_turbo_streams
+ end
+
+ def update_project_list_via_turbo_stream(url_for_action: action_name)
+ update_via_turbo_stream(
+ component: Storages::ProjectStorages::Projects::TableComponent.new(
+ query: storage_projects_query,
- project_folder_modes_per_project:,
++ storage: @storage,
+ params: { url_for_action: }
+ )
+ )
+ end
+
+ def storage_projects_query
+ @storage_projects_query = ProjectQuery.new(name: "storage-projects-#{@storage.id}") do |query|
+ query.where(:storages, "=", [@storage.id])
+ query.select(:name)
+ query.order("lft" => "asc")
+ end
+ end
+
- def project_folder_modes_per_project
- @project_folder_modes_per_project ||= Storages::ProjectStorage
- .where(storage_id: @storage.id)
- .pluck(:project_id, :project_folder_mode)
- .to_h
- end
-
+ def initialize_project_storage
+ @project_storage = ::Storages::ProjectStorages::SetAttributesService
+ .new(user: current_user, model: ::Storages::ProjectStorage.new, contract_class: EmptyContract)
+ .call(storage: @storage)
+ .result
+ end
+
+ def include_sub_projects?
+ ActiveRecord::Type::Boolean.new.cast(params.to_unsafe_h[:storages_project_storage][:include_sub_projects])
+ end
end
diff --cc modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
index 3f2343c2fd3,60e1e996cf2..63c09852b77
--- a/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
@@@ -52,9 -46,11 +46,11 @@@ See COPYRIGHT and LICENSE files for mor
%>
<%=
- render(Storages::ProjectStorages::Projects::TableComponent.new(
- query: @project_query,
- storage: @storage,
- params:)
+ render(
+ Storages::ProjectStorages::Projects::TableComponent.new(
+ query: @storage_projects_query,
- project_folder_modes_per_project: @project_folder_modes_per_project,
++ storage: @storage,
+ params:
+ )
)
%>