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
Adding host to storages. And adding more specs
Wieland Lindenthal2b2cc24c9268
diff --git a/db/migrate/20220113144323_create_storage.rb b/db/migrate/20220113144323_create_storage.rbindex 4b3223da2ba..fbd00faf958 100644--- a/db/migrate/20220113144323_create_storage.rb+++ b/db/migrate/20220113144323_create_storage.rb@@ -1,8 +1,9 @@class CreateStorage < ActiveRecord::Migration[6.1]def changecreate_table :storages do |t|- t.string :provider_type- t.string :name+ t.string :provider_type, null: false+ t.string :name, null: false, index: { unique: true }+ t.string :host, null: false, index: { unique: true }t.references :creator, null: false, index: true, foreign_key: { to_table: :users }t.timestampsdiff --git a/modules/storages/app/cells/storages/storages_row_cell.rb b/modules/storages/app/cells/storages/storages_row_cell.rbindex 4bcef67742e..515edc2e905 100644--- a/modules/storages/app/cells/storages/storages_row_cell.rb+++ b/modules/storages/app/cells/storages/storages_row_cell.rb@@ -5,7 +5,11 @@ module Storagesinclude ::Redmine::I18ndef name- model.name+ link_to model.name, storage_path(model)+ end++ def host+ model.hostenddef provider_type@@ -25,7 +29,7 @@ module Storageslink_to '',storage_path(model),class: 'icon icon-delete',- data: { confirm: I18n.t(:text_are_you_sure) },+ data: { confirm: I18n.t('storages.delete_warning.storage') },title: I18n.t(:button_delete),method: :deleteenddiff --git a/modules/storages/app/cells/storages/storages_table_cell.rb b/modules/storages/app/cells/storages/storages_table_cell.rbindex 31c444234c2..634b1648d9a 100644--- a/modules/storages/app/cells/storages/storages_table_cell.rb+++ b/modules/storages/app/cells/storages/storages_table_cell.rb@@ -8,7 +8,7 @@ module Storagesendend- columns :name, :provider_type, :creator, :created_at+ columns :name, :provider_type, :host, :creator, :created_atdef initial_sort%i[created_at asc]@@ -34,6 +34,7 @@ module Storages[['name', { caption: Storages::Storage.human_attribute_name(:name) }],['provider_type', { caption: I18n.t('storages.provider_types.label') }],+ ['host', { caption: I18n.t('storages.label_host') }],['creator', { caption: I18n.t('storages.label_creator') }],['created_at', { caption: Storages::Storage.human_attribute_name(:created_at) }]]diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex cd4a1a419b0..8d65c49d80b 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -95,6 +95,6 @@ class Storages::Admin::StoragesController < ApplicationControllerdef permitted_storage_paramsparams.require(:storages_storage)- .permit('name', 'provider_type')+ .permit('name', 'provider_type', 'host')endenddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex c73a9bb1cbe..f43a0943d9c 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -36,5 +36,9 @@ class Storages::Storage < ApplicationRecordPROVIDER_TYPES = %w[nextcloud].freeze+ validates_uniqueness_of :host+ validates_url :host+ validates_length_of :host, minimum: 1, maximum: 255validates_uniqueness_of :name+ validates_length_of :name, minimum: 1, maximum: 255enddiff --git a/modules/storages/app/views/storages/admin/_form.html.erb b/modules/storages/app/views/storages/admin/_form.html.erbindex d999e620106..2d5e877a0af 100644--- a/modules/storages/app/views/storages/admin/_form.html.erb+++ b/modules/storages/app/views/storages/admin/_form.html.erb@@ -42,5 +42,12 @@ See COPYRIGHT and LICENSE files for more details.<%= t('storages.instructions.name') %></span></div>+ <div class="form--field -required">+ <%= f.text_field :host, type: :url, required: true, pattern: ".{1,255}", placeholder: "https://my-file-storage.com", container_class: '-wide' %>+ <span class="form--field-instructions">+ <%= t('storages.instructions.host') %>+ </span>+ </div>+</section>diff --git a/modules/storages/app/views/storages/admin/edit.html.erb b/modules/storages/app/views/storages/admin/edit.html.erbindex cdc38b91ba8..303492a0824 100644--- a/modules/storages/app/views/storages/admin/edit.html.erb+++ b/modules/storages/app/views/storages/admin/edit.html.erb@@ -1,6 +1,6 @@-<% html_title t(:label_administration), t("project_module_storages") %>+<% html_title t(:label_administration), t("project_module_storages"), t('label_edit_x', x: @object.name) %><% local_assigns[:additional_breadcrumb] = @object.name %>-<%= toolbar title: @object.name %>+<%= toolbar title: t('label_edit_x', x: @object.name) %><%= labelled_tabular_form_for @object, url: storage_path(@object) do |f| -%><%= error_messages_for_contract @object, @errors %>diff --git a/modules/storages/app/views/storages/admin/index.html.erb b/modules/storages/app/views/storages/admin/index.html.erbindex 53355b15873..a1f7d51a423 100644--- a/modules/storages/app/views/storages/admin/index.html.erb+++ b/modules/storages/app/views/storages/admin/index.html.erb@@ -4,8 +4,8 @@<li class="toolbar-item"><%= link_to new_storage_path,{ class: 'button -alt-highlight',- aria: { label: t(:'storages.label_new_storage') },- title: t(:'ifc_models.label_new_storage') } do %>+ aria: { label: t('storages.label_new_storage') },+ title: t('storages.label_new_storage') } do %><%= op_icon('button--icon icon-add') %><span class="button--text"><%= ::Storages::Storage.model_name.human %></span><% end %>diff --git a/modules/storages/app/views/storages/admin/new.html.erb b/modules/storages/app/views/storages/admin/new.html.erbindex a6d5d3c2a1b..3754527376a 100644--- a/modules/storages/app/views/storages/admin/new.html.erb+++ b/modules/storages/app/views/storages/admin/new.html.erb@@ -1,4 +1,4 @@-<% html_title t(:label_administration), t("project_module_storages") %>+<% html_title t(:label_administration), t("project_module_storages"), t('storages.label_new_storage') %><% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %><%= toolbar title: t("storages.label_new_storage") %>diff --git a/modules/storages/app/views/storages/admin/show.html.erb b/modules/storages/app/views/storages/admin/show.html.erbindex 7a5f4e85abd..f3889c8eda2 100644--- a/modules/storages/app/views/storages/admin/show.html.erb+++ b/modules/storages/app/views/storages/admin/show.html.erb@@ -41,7 +41,7 @@ See COPYRIGHT and LICENSE files for more details.<li class="toolbar-item"><%= link_to storage_path(@object),method: :delete,- data: { confirm: I18n.t(:text_are_you_sure) },+ data: { confirm: I18n.t('storages.delete_warning.storage') },class: 'button -danger' do %><%= op_icon('button--icon icon-delete') %><span class="button--text"><%= t(:button_delete) %></span>@@ -63,16 +63,22 @@ See COPYRIGHT and LICENSE files for more details.<span><%= t(:"storages.provider_types.#{@object.provider_type}") %></span></div></div>+ <div class="attributes-key-value--key"><%= t(:'storages.label_host') %></div>+ <div class="attributes-key-value--value-container">+ <div class="attributes-key-value--value -text">+ <span><%= link_to @object.host, @object.host %></span>+ </div>+ </div><div class="attributes-key-value--key"><%= t(:'storages.label_creator') %></div><div class="attributes-key-value--value-container"><div class="attributes-key-value--value -text"><span><%= @object.creator.name %></span></div></div>- <div class="attributes-key-value--key"><%= t(:'storages.label_created_at') %></div>+ <div class="attributes-key-value--key"><%= Storages::ProjectStorage.human_attribute_name(:created_at) %></div><div class="attributes-key-value--value-container"><div class="attributes-key-value--value -text">- <span><%= @object.created_at %></span>+ <span><%= format_time(@object.created_at) %></span></div></div></div>diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 3d740c1abb6..6714f0f5df0 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -21,13 +21,20 @@ en:new: "Enable a file storage for this project"instructions:name: "Please use a short name. It will get used as a tab title in the work package view."+ host: "The URL of your storage instance. The URL should not be more than 255 characters long."no_storage_set_up: "There are no file storages set up, yet."setting_up_additional_storages: "For setting up additional file storages, please visit"all_available_storages_already_added: "All available storages are already added to the project."+ delete_warning:+ storage: >+ Are you sure you want to delete this storage? This will also delete the storage from all projects where it is used.+ Further, it will also delete all links from work packages to files that are stored in that storage.label_creator: "Creator"label_file_link: "File link"label_file_links: "File links"label_name: "Name"+ label_host: "Host"+ label_provider_type: "Provider type"label_new_storage: "New storage"label_storage: "Storage"label_storages: "Storages"diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rbnew file mode 100644index 00000000000..05afd2e65ba--- /dev/null+++ b/modules/storages/spec/features/admin_storages_spec.rb@@ -0,0 +1,100 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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_relative '../spec_helper'++describe 'Admin storages', type: :feature, js: true do+ let(:admin) do+ create(:admin)+ end++ before do+ login_as admin+ end++ it 'creates, edits and deletes storages' do+ visit storages_path+ expect(page).to have_title('File storages')+ expect(page.find('.title-container')).to have_text('File storages')+ expect(page).to have_text('No storage setup, yet.')++ page.find('.toolbar .button--icon.icon-add').click++ expect(page).to have_title('New storage')+ expect(page.find('.title-container')).to have_text('New storage')+ expect(page).to have_select 'storages_storage[provider_type]', selected: 'Nextcloud'+ expect(page).to have_field('storages_storage[name]', with: 'Nextcloud')++ page.find('#storages_storage_name').set("NC 1")+ page.find('#storages_storage_host').set("https://example.com")+ page.find('button[type=submit]').click++ created_storage = Storages::Storage.find_by(name: 'NC 1')+ expect(page).to have_title("Nc 1")+ expect(page.find('.title-container')).to have_text('NC 1')+ expect(page).to have_text(admin.name)+ expect(page).to have_text('https://example.com')+ expect(page).to have_text(created_storage.created_at.localtime.strftime("%m/%d/%Y %I:%M %p"))++ page.find('.button--icon.icon-edit').click++ expect(page).to have_title("Edit: NC 1")+ expect(page.find('.title-container')).to have_text('Edit: NC 1')+ page.find('#storages_storage_name').set("Other NC")+ page.find('#storages_storage_host').set("https://other.example.com")+ page.find('button[type=submit]').click++ expect(page).to have_title("Other Nc")+ expect(page.find('.title-container')).to have_text('Other NC')+ expect(page).to have_text('https://other.example.com')++ page.find("ul.op-breadcrumb li", text: "File storages").click++ expect(page).to have_title "File storages"+ expect(page.find('.title-container')).to have_text('File storages')+ expect(page).to have_text('Other NC')+ expect(page).to have_text('https://other.example.com')+ expect(page).to have_text(admin.name)++ page.find("a", text: 'Other NC').click++ expect(page).to have_current_path storage_path(created_storage)++ page.find('.button--icon.icon-delete').click++ alert_text = page.driver.browser.switch_to.alert.text+ expect(alert_text).to eq 'Are you sure'++ page.driver.browser.switch_to.alert.accept++ expect(page).to have_current_path(storages_path)+ expect(page).to_not have_text("Other NC")+ end+enddiff --git a/modules/storages/spec/models/storage_spec.rb b/modules/storages/spec/models/storage_spec.rbnew file mode 100644index 00000000000..5e437eba0ba--- /dev/null+++ b/modules/storages/spec/models/storage_spec.rb@@ -0,0 +1,95 @@+#-- 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.+#++++require_relative '../spec_helper'++describe ::Storages::Storage, type: :model do+ let(:test_default_creator) { create(:user) }+ let(:test_default_attributes) do+ { name: "NC 1",+ provider_type: 'nextcloud',+ host: 'https://example.com',+ creator: test_default_creator }+ end++ describe '#create' do+ it "creates an instance" do+ storage = described_class.create test_default_attributes+ expect(storage).to be_valid+ end++ it "should fail the validation if name is empty string" do+ expect(described_class.create(test_default_attributes.merge({ name: "" }))).to be_invalid+ end++ it "should fail the validation if name is nil" do+ expect(described_class.create(test_default_attributes.merge({ name: nil }))).to be_invalid+ end++ it "should fail the validation if host is empty string" do+ expect(described_class.create(test_default_attributes.merge({ host: '' }))).to be_invalid+ end++ it "should fail the validation if host is nil" do+ expect(described_class.create(test_default_attributes.merge({ host: nil }))).to be_invalid+ end++ context "having already one instance" do+ let(:old_storage) { described_class.create test_default_attributes }++ before do+ old_storage+ end++ it "should fail the validation if name is not unique" do+ expect(described_class.create(test_default_attributes.merge({ host: 'https://example2.com' }))).to be_invalid+ end++ it "should fail the validation if host is not unique" do+ expect(described_class.create(test_default_attributes.merge({ name: 'NC 2' }))).to be_invalid+ end+ end+ end++ describe '#destroy' do+ let(:project) { create(project) }+ let(:storage) { described_class.create(test_default_attributes) }+ let(:project_storage) { Storages::ProjectStorage.create(project: project, storage: storage) }+ let(:work_package) { create(:work_package, project: project) }+ let(:file_link) { FileLink.create(container: work_package, storage: storage) }++ before do+ storage.destroy+ end++ it "should destroy all associated ProjectStorage and FileLink records" do+ expect(Storages::ProjectStorage.count).to be 0+ expect(Storages::FileLink.count).to be 0+ end+ end+enddiff --git a/modules/storages/spec/spec_helper.rb b/modules/storages/spec/spec_helper.rbnew file mode 100644index 00000000000..f54b5abead8--- /dev/null+++ b/modules/storages/spec/spec_helper.rb@@ -0,0 +1,32 @@+#-- 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.+#++++# -- load spec_helper from OpenProject core+require 'spec_helper'++Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }diff --git a/modules/storages/spec/support/pages/storage_tab.rb b/modules/storages/spec/support/pages/storage_tab.rbindex 92e3517b85a..49d3d3b05ab 100644--- a/modules/storages/spec/support/pages/storage_tab.rb+++ b/modules/storages/spec/support/pages/storage_tab.rb@@ -30,13 +30,13 @@ require 'support/pages/page'module Pagesclass StorageTab < ::Pages::Page- # attr_reader :project- #- # def initialize(project)- # super()- #- # @project = project- # end+ attr_reader :project++ def initialize(project)+ super()++ @project = project+ end## def path# project_team_planner_path(project)@@ -122,5 +122,5 @@ module Pages# query: name,# results_selector: 'body'# end- # end+ endend