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
WIP project settings for storages
Wieland Lindenthala3e0231c9466
diff --git a/app/models/project.rb b/app/models/project.rbindex e92be04bca2..5fc42304d1f 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -88,6 +88,9 @@ class Project < ApplicationRecordhas_one :status, class_name: 'Projects::Status', dependent: :destroyhas_many :budgets, dependent: :destroyhas_many :notification_settings, dependent: :destroy+ has_many :projects_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'+ has_many :storages, through: :projects_storages+acts_as_nested_set order_column: :name, dependent: :destroydiff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 4eee276cee7..970a6e5913c 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -407,12 +407,6 @@ Redmine::MenuManager.map :admin_menu do |menu|if: Proc.new { User.current.admin? },caption: :label_setting_plural,parent: :admin_backlogs-- menu.push :storages_settings,- { controller: '/storages/admin/storages', action: :index },- if: Proc.new { User.current.admin? },- caption: :project_module_storages,- icon: 'icon2 icon-hosting'endRedmine::MenuManager.map :project_menu do |menu|@@ -481,8 +475,7 @@ Redmine::MenuManager.map :project_menu do |menu|categories: :label_work_package_category_plural,repository: :label_repository,time_entry_activities: :enumeration_activities,- storage: :label_required_disk_storage,- storages: :'storages.storage'+ storage: :label_required_disk_storage}.each do |key, caption|menu.push :"settings_#{key}",{ controller: "/projects/settings/#{key}", action: 'show' },diff --git a/db/migrate/20220121090847_create_projects_storages.rb b/db/migrate/20220121090847_create_projects_storages.rbnew file mode 100644index 00000000000..35a2705645a--- /dev/null+++ b/db/migrate/20220121090847_create_projects_storages.rb@@ -0,0 +1,15 @@+class CreateProjectsStorages < ActiveRecord::Migration[6.1]+ def change+ create_table :projects_storages do |t|+ t.bigint :project_id, null: false, foreign_key: true+ t.bigint :storage_id, null: false, foreign_key: true+ t.bigint :creator_id, null: false, foreign_key: true++ t.timestamps++ t.index :project_id+ t.index :storage_id+ t.index %i[project_id storage_id], unique: true+ end+ end+enddiff --git a/modules/storages/app/cells/storages/projects_storages_row_cell.rb b/modules/storages/app/cells/storages/projects_storages_row_cell.rbnew file mode 100644index 00000000000..070071cb7d5--- /dev/null+++ b/modules/storages/app/cells/storages/projects_storages_row_cell.rb@@ -0,0 +1,33 @@+module Storages+ class ProjectsStoragesRowCell < ::RowCell+ include ::IconsHelper+ include ::AvatarHelper+ include ::Redmine::I18n++ def name+ model.storage.name+ end++ def provider_type+ model.storage.provider_type+ end++ def creator+ icon = avatar model.creator, size: :mini+ icon + model.creator.name+ end++ def button_links+ [delete_link]+ end++ def delete_link+ link_to '',+ project_settings_projects_storage_path(project_id: model.project, id: model),+ class: 'icon icon-delete',+ data: { confirm: I18n.t(:text_are_you_sure) },+ title: I18n.t(:button_delete),+ method: :delete+ end+ end+enddiff --git a/modules/storages/app/cells/storages/projects_storages_table_cell.rb b/modules/storages/app/cells/storages/projects_storages_table_cell.rbnew file mode 100644index 00000000000..cd7ee97a76c--- /dev/null+++ b/modules/storages/app/cells/storages/projects_storages_table_cell.rb@@ -0,0 +1,43 @@+module Storages+ class ProjectsStoragesTableCell < ::TableCell+ include ::IconsHelper++ class << self+ def row_class+ ::Storages::ProjectsStoragesRowCell+ end+ end++ columns :name, :provider_type, :creator, :created_at++ def initial_sort+ %i[created_at asc]+ end++ def sortable?+ false+ end++ def inline_create_link+ link_to(new_project_settings_projects_storage_path,+ class: 'wp-inline-create--add-link',+ title: I18n.t('storages.label_new_storage')) do+ op_icon('icon icon-add')+ end+ end++ def empty_row_message+ I18n.t 'storages.no_results'+ end++ def headers+ [+ ['name', { caption: Storages::Storage.human_attribute_name(:name) }],+ ['provider_type', { caption: I18n.t('storages.provider_types.label') }],+ ['creator', { caption: I18n.t('storages.label_creator') }],+ ['created_at', { caption: Storages::ProjectStorage.human_attribute_name(:created_at) }]+ ]+ end++ end+enddiff --git a/modules/storages/app/cells/storages/row_cell.rb b/modules/storages/app/cells/storages/storages_row_cell.rbsimilarity index 95%rename from modules/storages/app/cells/storages/row_cell.rbrename to modules/storages/app/cells/storages/storages_row_cell.rbindex 240d8ded196..4bcef67742e 100644--- a/modules/storages/app/cells/storages/row_cell.rb+++ b/modules/storages/app/cells/storages/storages_row_cell.rb@@ -1,5 +1,5 @@module Storages- class RowCell < ::RowCell+ class StoragesRowCell < ::RowCellinclude ::IconsHelperinclude ::AvatarHelperinclude ::Redmine::I18ndiff --git a/modules/storages/app/cells/storages/table_cell.rb b/modules/storages/app/cells/storages/storages_table_cell.rbsimilarity index 86%rename from modules/storages/app/cells/storages/table_cell.rbrename to modules/storages/app/cells/storages/storages_table_cell.rbindex dfade383dcc..31c444234c2 100644--- a/modules/storages/app/cells/storages/table_cell.rb+++ b/modules/storages/app/cells/storages/storages_table_cell.rb@@ -1,6 +1,13 @@module Storages- class TableCell < ::TableCell+ class StoragesTableCell < ::TableCellinclude ::IconsHelper++ class << self+ def row_class+ ::Storages::StoragesRowCell+ end+ end+columns :name, :provider_type, :creator, :created_atdef initial_sortdiff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rbnew file mode 100644index 00000000000..3e7eec6571a--- /dev/null+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -0,0 +1,88 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++class Storages::Admin::ProjectsStoragesController < ApplicationController+ layout 'admin'+ before_action :find_optional_project+ before_action :authorize++ menu_item :settings_projects_storages+++ def index+ @projects_storages = Storages::ProjectStorage.where(project: @project).includes(:storage)++ render '/storages/project_settings/index'+ end++ def new+ @project_storage = Storages::ProjectStorage.new(project: @project)+ @available_storages = Storages::Storage.where.not(storage_id: @project.projects_storages.pluck(:storage_id))++ render '/storages/project_settings/new'+ end++ def create+ combined_params = permitted_project_storage_params+ .to_h+ .reverse_merge(creator_id: User.current.id, project_id: @project.id)++ @project_storage = Storages::ProjectStorage.create combined_params++ redirect_to project_settings_projects_storages_path+ end++ def destroy+ @project_storage = Storages::ProjectStorage.find(params[:id])+ @project_storage.destroy++ redirect_to project_settings_projects_storages_path+ end++ def default_breadcrumb+ # t(:project_module_storages)+ end++ def show_local_breadcrumb+ true+ end++ current_menu_item :index do+ :settings_projects_storages+ end++ private++ def permitted_project_storage_params+ params+ .require(:storages_project_storage)+ .permit('storage_id')+ end+enddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 520a704d4c1..1928c7c25a4 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -31,7 +31,7 @@class Storages::Admin::StoragesController < ApplicationControllerlayout 'admin'before_action :require_admin- menu_item :storages_settings+ menu_item :storages_admin_settingsdef index@storages = Storages::Storage.alldiff --git a/modules/storages/app/controllers/storages/projects/settings_controller.rb b/modules/storages/app/controllers/storages/projects/settings_controller.rbnew file mode 100644index 00000000000..8fd35fd7b04--- /dev/null+++ b/modules/storages/app/controllers/storages/projects/settings_controller.rb@@ -0,0 +1,45 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++class Storages::Projects::SettingsController < Projects::SettingsController+ menu_item :project_settings_storages++ def index+ # tbd+ end++ def create+ # tbd+ end++ def delete+ # tbd+ end+enddiff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rbnew file mode 100644index 00000000000..3e7fe17f319--- /dev/null+++ b/modules/storages/app/models/storages/project_storage.rb@@ -0,0 +1,38 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++class Storages::ProjectStorage < ApplicationRecord+ self.table_name = 'projects_storages'+ belongs_to :project, class_name: 'Project'+ belongs_to :storage, class_name: 'Storages::Storage'+ belongs_to :creator, class_name: 'User'++ validates :project, uniqueness: { scope: :storage }+enddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 121c9fddc3c..2e4f56d915e 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -31,6 +31,8 @@class Storages::Storage < ApplicationRecordhas_many :file_links, class_name: 'Storages::FileLink'belongs_to :creator, class_name: 'User'+ has_many :projects_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'+ has_many :projects, through: :projects_storageshas_secure_token :identifierPROVIDER_TYPES = %w[nextcloud].freezediff --git a/modules/storages/app/views/storages/admin/index.html.erb b/modules/storages/app/views/storages/admin/index.html.erbindex ce7b7c9fdd2..53355b15873 100644--- a/modules/storages/app/views/storages/admin/index.html.erb+++ b/modules/storages/app/views/storages/admin/index.html.erb@@ -12,4 +12,4 @@</li><% end %>-<%= rails_cell ::Storages::TableCell, @storages %>\ No newline at end of file+<%= rails_cell ::Storages::StoragesTableCell, @storages %>\ No newline at end of filediff --git a/modules/storages/app/views/storages/project_settings/index.html.erb b/modules/storages/app/views/storages/project_settings/index.html.erbnew file mode 100644index 00000000000..8aa8519ed78--- /dev/null+++ b/modules/storages/app/views/storages/project_settings/index.html.erb@@ -0,0 +1,15 @@+<% html_title t(:label_administration), t("project_module_storages") %>++<%= toolbar title: t("project_module_storages") do %>+ <li class="toolbar-item">+ <%= link_to new_project_settings_projects_storage_path,+ { class: 'button -alt-highlight',+ aria: { label: t(:'storages.label_new_storage') },+ title: t(:'ifc_models.label_new_storage') } do %>+ <%= op_icon('button--icon icon-add') %>+ <span class="button--text"><%= ::Storages::Storage.model_name.human %></span>+ <% end %>+ </li>+<% end %>++<%= rails_cell ::Storages::ProjectsStoragesTableCell, @projects_storages %>\ No newline at end of filediff --git a/modules/storages/app/views/storages/project_settings/new.html.erb b/modules/storages/app/views/storages/project_settings/new.html.erbnew file mode 100644index 00000000000..11c26e69b5d--- /dev/null+++ b/modules/storages/app/views/storages/project_settings/new.html.erb@@ -0,0 +1,18 @@+<% html_title t(:label_administration), t("project_module_storages") %>+<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>+<%= toolbar title: t("storages.label_new_storage") %>++<%= labelled_tabular_form_for @project_storage, url: project_settings_projects_storages_path do |f| -%>+ <%= error_messages_for_contract @project_storage, @errors %>++ <section class="form--section">+ <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,+ container_class: '-slim' %>+ </div>+ </section>++ <%= styled_button_tag t(:button_create), class: "-highlight -with-icon icon-checkmark" %>+<% end %>diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rbindex e35676948c9..bd42a36a787 100644--- a/modules/storages/config/routes.rb+++ b/modules/storages/config/routes.rb@@ -2,4 +2,10 @@ OpenProject::Application.routes.draw doscope 'admin/settings' doresources :storages, controller: 'storages/admin/storages'end++ scope 'projects/:project_id', as: 'project' do+ namespace 'settings' do+ resources :projects_storages, controller: '/storages/admin/projects_storages', only: %i[index new create destroy]+ end+ endenddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 0d8e424aaf4..31e1c20e9e4 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -35,15 +35,23 @@ module OpenProject::Storages{},dependencies: %i[view_file_links]permission :manage_storage_in_project,- {},- dependencies: %i[select_project_modules]+ { 'storages/admin/projects_storages': %i[index new create destroy] },+ dependencies: %i[]end# Menu extensions+ menu :admin_menu,+ :storages_admin_settings,+ { controller: '/storages/admin/storages', action: :index },+ if: Proc.new { User.current.admin? },+ caption: :project_module_storages,+ icon: 'icon2 icon-hosting'+menu :project_menu,- :storages,- { controller: '/storages/storages', action: 'index' },- caption: :'storages.label_storage'+ :settings_projects_storages,+ { controller: '/storages/admin/projects_storages', action: 'index' },+ caption: :'storages.label_storage',+ parent: :settingsendendend