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

[#44841] some more fixes and regression tests

Eric Schuberta1ef0dc706c9
diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.yml
index 1f5baf61fa5..f41cb27c6ca 100644
--- a/docs/api/apiv3/openapi-spec.yml
+++ b/docs/api/apiv3/openapi-spec.yml
@@ -864,6 +864,7 @@ tags:
- "$ref": "./tags/memberships.yml"
- "$ref": "./tags/news.yml"
- "$ref": "./tags/notifications.yml"
+ - "$ref": "./tags/oauth.yml"
- "$ref": "./tags/posts.yml"
- "$ref": "./tags/principals.yml"
- "$ref": "./tags/priorities.yml"
diff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rb
index c633aa22cd6..e0ec070aa99 100644
--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb
+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb
@@ -33,7 +33,7 @@ module Storages::Storages
def set_default_attributes(_params)
storage.creator ||= user
- storage.name ||= I18n.t("storages.provider_types.#{storage.provider_type}.default_name")
+ storage.name ||= derive_default_storage_name
end
private
@@ -45,5 +45,14 @@ module Storages::Storages
def storage
model
end
+
+ def derive_default_storage_name
+ prefix = I18n.t("storages.provider_types.#{storage.provider_type}.default_name")
+ last_id = Storages::Storage.where("name like ?", "#{prefix}%").maximum(:id)
+
+ return prefix if last_id.nil?
+
+ "#{prefix} #{last_id + 1}"
+ end
end
end
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index b73052daa8a..ebe5ff57898 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -74,7 +74,7 @@ module API::V3::Storages
@connection_manager =
::OAuthClients::ConnectionManager.new(user: current_user, oauth_client: model.oauth_client)
- super(model, current_user:, embed_links:)
+ super
end
property :id
diff --git a/modules/storages/spec/services/storages/storages/create_service_spec.rb b/modules/storages/spec/services/storages/storages/create_service_spec.rb
index 5572f216e8e..a3b4054a7de 100644
--- a/modules/storages/spec/services/storages/storages/create_service_spec.rb
+++ b/modules/storages/spec/services/storages/storages/create_service_spec.rb
@@ -29,11 +29,11 @@
require 'spec_helper'
require 'services/base_services/behaves_like_create_service'
-describe ::Storages::Storages::CreateService, type: :model do
+describe Storages::Storages::CreateService, type: :model do
it_behaves_like 'BaseServices create service' do
let(:factory) { :storage }
- let!(:user) { create :admin }
+ let!(:user) { create(:admin) }
let(:instance) do
described_class.new(user:,
@@ -58,11 +58,11 @@ describe ::Storages::Storages::CreateService, type: :model do
it "creates an OAuth application (::Doorkeeper::Application)" do
expect(subject).to be_success
- expect(subject.result.oauth_application).to be_a(::Doorkeeper::Application)
+ expect(subject.result.oauth_application).to be_a(Doorkeeper::Application)
expect(subject.result.oauth_application.name).to include call_attributes[:name]
expect(subject.result.oauth_application.redirect_uri).to include call_attributes[:host]
expect(subject.result.oauth_application.owner).to eql user
- expect(subject.dependent_results.first.result.secret).to be_present
+ expect(subject.result.oauth_application.plaintext_secret).to be_present
end
end
end
diff --git a/spec/requests/oauth_clients/oauth_client_credentials_spec.rb b/spec/requests/oauth_clients/oauth_client_credentials_spec.rb
index 641fbb67fe4..d87baaa2f03 100644
--- a/spec/requests/oauth_clients/oauth_client_credentials_spec.rb
+++ b/spec/requests/oauth_clients/oauth_client_credentials_spec.rb
@@ -31,12 +31,11 @@ require 'spec_helper'
describe 'API v3 oauth applications resource', content_type: :json do
include API::V3::Utilities::PathHelper
- let(:current_user) { create(:admin) }
let(:oauth_client_credentials) { create(:oauth_client) }
- before do
- login_as current_user
+ current_user { create(:admin) }
+ before do
get path
end
@@ -46,7 +45,7 @@ describe 'API v3 oauth applications resource', content_type: :json do
it_behaves_like 'successful response'
context 'as non-admin' do
- let(:current_user) { create(:user) }
+ current_user { create(:user) }
it_behaves_like 'unauthorized access'
end
diff --git a/spec/services/oauth_clients/create_service_spec.rb b/spec/services/oauth_clients/create_service_spec.rb
index 4a2aa6036fa..a11d55c12c0 100644
--- a/spec/services/oauth_clients/create_service_spec.rb
+++ b/spec/services/oauth_clients/create_service_spec.rb
@@ -29,8 +29,21 @@
require 'spec_helper'
require 'services/base_services/behaves_like_create_service'
-describe ::OAuthClients::CreateService, type: :model do
+describe OAuthClients::CreateService, type: :model do
it_behaves_like 'BaseServices create service' do
let(:factory) { :oauth_client }
+
+ context 'if another oauth client for the given integration exists' do
+ let(:storage) { create(:storage) }
+ let!(:existing_client) { create(:oauth_client, integration: storage) }
+ let!(:model_instance) { build_stubbed(:oauth_client, integration: storage) }
+ let(:call_attributes) { { name: 'Death Star', integration: storage } }
+
+ it 'overwrites the existing oauth client' do
+ # Test setup still returns success, but `subject` must be initialized
+ expect(subject).to be_success
+ expect(OAuthClient.where(id: existing_client.id)).not_to exist
+ end
+ end
end
end