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

Move the aliases and base funcionality from the NextcloudStorage to Storage

Marcello Rocha6e9fb8035214
diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rb
index 5900c53eb56..b6093a79332 100644
--- a/modules/storages/app/models/storages/nextcloud_storage.rb
+++ b/modules/storages/app/models/storages/nextcloud_storage.rb
@@ -45,22 +45,6 @@ module Storages
Peripherals::OAuthConfigurations::NextcloudConfiguration.new(self)
end
- def automatically_managed?
- ActiveSupport::Deprecation.warn(
- '`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. ' \
- 'NOTE: The new method name better reflects the actual behavior of the storage. ' \
- "It's not the storage that is automatically managed, rather the Project (Storage) Folder is. " \
- "A storage only has this feature enabled or disabled."
- )
- super
- end
-
- def automatic_management_enabled=(value)
- self.automatically_managed = value
- end
-
- alias automatic_management_enabled automatically_managed
-
def automatic_management_new_record?
if provider_fields_changed?
previous_configuration = provider_fields_change.first
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 14bfb3ad569..cf8d21707dc 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -135,10 +135,30 @@ module Storages
end
end
+ def automatically_managed?
+ ActiveSupport::Deprecation.warn(
+ '`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. ' \
+ 'NOTE: The new method name better reflects the actual behavior of the storage. ' \
+ "It's not the storage that is automatically managed, rather the Project (Storage) Folder is. " \
+ "A storage only has this feature enabled or disabled."
+ )
+ super
+ end
+
def automatic_management_enabled?
!!automatically_managed
end
+ def automatic_management_unspecified?
+ automatically_managed.nil?
+ end
+
+ def automatic_management_enabled=(value)
+ self.automatically_managed = value
+ end
+
+ alias automatic_management_enabled automatically_managed
+
def configured?
configuration_checks.values.all?
end
diff --git a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
index c308a6c039a..eae9c58e41b 100644
--- a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
+++ b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
@@ -181,28 +181,6 @@ RSpec.describe Storages::NextcloudStorage do
end
end
- shared_examples 'a stored boolean attribute' do |attribute|
- it "#{attribute} has a default value of false" do
- expect(storage.public_send(:"#{attribute}?")).to be(false)
- end
-
- ['1', 'true', true].each do |boolean_like|
- context "with truthy value #{boolean_like}" do
- it "sets #{attribute} to true" do
- storage.public_send(:"#{attribute}=", boolean_like)
- expect(storage.public_send(attribute)).to be(true)
- end
- end
- end
-
- it "#{attribute} can be set to true" do
- storage.public_send(:"#{attribute}=", true)
-
- expect(storage.public_send(attribute)).to be(true)
- expect(storage.public_send(:"#{attribute}?")).to be(true)
- end
- end
-
describe '#username' do
it_behaves_like 'a stored attribute with default value', :username, 'OpenProject'
end
@@ -215,30 +193,6 @@ RSpec.describe Storages::NextcloudStorage do
it_behaves_like 'a stored attribute with default value', :group_folder, 'OpenProject'
end
- describe '#automatically_managed' do
- it_behaves_like 'a stored boolean attribute', :automatically_managed
- end
-
- describe '#automatic_management_enabled?' do
- context 'when automatic management enabled is true' do
- let(:storage) { build(:nextcloud_storage, automatic_management_enabled: true) }
-
- it { expect(storage).to be_automatic_management_enabled }
- end
-
- context 'when automatic management enabled is false' do
- let(:storage) { build(:nextcloud_storage, automatic_management_enabled: false) }
-
- it { expect(storage).not_to be_automatic_management_enabled }
- end
-
- context 'when automatic management enabled is nil' do
- let(:storage) { build(:nextcloud_storage, automatic_management_enabled: nil) }
-
- it { expect(storage.automatic_management_enabled?).to be(false) }
- end
- end
-
describe '#automatic_management_new_record?' do
context 'when automatic management has just been specified but not yet persisted' do
let(:storage) { build_stubbed(:nextcloud_storage, provider_fields: {}) }
diff --git a/modules/storages/spec/models/storages/storage_spec.rb b/modules/storages/spec/models/storages/storage_spec.rb
new file mode 100644
index 00000000000..0b55a825b24
--- /dev/null
+++ b/modules/storages/spec/models/storages/storage_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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_module_spec_helper
+
+RSpec.describe Storages::Storage do
+ describe "provider_fields" do
+ let(:storage) { build(:storage, provider_fields: {}) }
+
+ shared_examples 'a stored boolean attribute' do |attribute|
+ it "#{attribute} has a default value of false" do
+ expect(storage.public_send(:"#{attribute}?")).to be(false)
+ end
+
+ ['1', 'true', true].each do |boolean_like|
+ context "with truthy value #{boolean_like}" do
+ it "sets #{attribute} to true" do
+ storage.public_send(:"#{attribute}=", boolean_like)
+ expect(storage.public_send(attribute)).to be(true)
+ end
+ end
+ end
+
+ it "#{attribute} can be set to true" do
+ storage.public_send(:"#{attribute}=", true)
+
+ expect(storage.public_send(attribute)).to be(true)
+ expect(storage.public_send(:"#{attribute}?")).to be(true)
+ end
+ end
+
+ describe '#automatically_managed' do
+ it_behaves_like 'a stored boolean attribute', :automatically_managed
+ end
+
+ describe '#automatic_management_enabled?' do
+ context 'when automatic management enabled is true' do
+ let(:storage) { build(:storage, automatic_management_enabled: true) }
+
+ it { expect(storage).to be_automatic_management_enabled }
+ end
+
+ context 'when automatic management enabled is false' do
+ let(:storage) { build(:storage, automatic_management_enabled: false) }
+
+ it { expect(storage).not_to be_automatic_management_enabled }
+ end
+
+ context 'when automatic management enabled is nil' do
+ let(:storage) { build(:storage, automatic_management_enabled: nil) }
+
+ it { expect(storage.automatic_management_enabled?).to be(false) }
+ end
+ end
+ end
+end