[74354] Rename storage_id to integration_id (#23049)

* Rename `storage_id` to `integration_id`
This commit is contained in:
Yauheni Suhakou
2026-05-05 16:58:08 +02:00
committed by GitHub
parent 1d67d27472
commit 37620b1a9f
15 changed files with 40 additions and 31 deletions
+5 -4
View File
@@ -74,8 +74,8 @@ class OAuthClientsController < ApplicationController
# rubocop:disable Metrics/AbcSize
def ensure_connection
client_id = params.fetch(:oauth_client_id)
storage_id = params.fetch(:storage_id)
oauth_client = OAuthClient.find_by(client_id:, integration_id: storage_id)
integration_id = params.fetch(:integration_id)
oauth_client = OAuthClient.find_by(client_id:, integration_id:)
return handle_absent_oauth_client unless oauth_client
@@ -89,7 +89,8 @@ class OAuthClientsController < ApplicationController
redirect_to(destination_url)
else
nonce = SecureRandom.uuid
cookies["oauth_state_#{nonce}"] = { value: { href: destination_url, storageId: storage_id }.to_json, expires: 1.hour }
cookies["oauth_state_#{nonce}"] = { value: { href: destination_url, integrationId: integration_id }.to_json,
expires: 1.hour }
redirect_to(configuration.authorization_uri(state: nonce), allow_other_host: true)
end
end
@@ -199,7 +200,7 @@ class OAuthClientsController < ApplicationController
# This must be fixed in #50872.
state_value = MultiJson.load(cookie, symbolize_keys: true)
@oauth_client = OAuthClient.find_by(client_id: params[:oauth_client_id],
integration_id: state_value[:storageId])
integration_id: state_value[:integrationId])
end
@oauth_client = oauth_client_from_cookie.call
@@ -119,7 +119,7 @@ module Storages::ProjectStorages::Members
def ensure_connection_url
oauth_clients_ensure_connection_url(
oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id
integration_id: storage.id
)
end
@@ -36,7 +36,7 @@ module Storages
nonce = SecureRandom.uuid
cookies["oauth_state_#{nonce}"] = {
value: { href: callback_url,
storageId: storage.id }.to_json,
integrationId: storage.id }.to_json,
expires: 1.hour
}
@@ -95,7 +95,7 @@ class Storages::ProjectStoragesController < ApplicationController
def ensure_connection_url
oauth_clients_ensure_connection_url(
oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: request.url
)
end
@@ -44,7 +44,7 @@ module Storages
oauth_clients_ensure_connection_url(
oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: api_static_link
)
else
@@ -50,7 +50,7 @@ RSpec.describe Storages::OpenStorageLinks do
it "returns the 'ensure connections' link" do
expect(subject).to end_with("/oauth_clients/#{oauth_client.client_id}/ensure_connection?" \
"destination_url=%2Fapi%2Fv3%2Fstorages%2F#{storage.id}%2Fopen&" \
"storage_id=#{storage.id}")
"integration_id=#{storage.id}")
end
end
@@ -118,7 +118,7 @@ RSpec.describe "projects/:project_id/project_storages/:id/open", :webmock do
expect(last_response).to have_http_status(:found)
expect(last_response.headers["Location"]).to eq(
"http://test.host/oauth_clients/#{storage.oauth_client.client_id}/ensure_connection?" \
"destination_url=#{destination}&storage_id=#{storage.id}"
"destination_url=#{destination}&integration_id=#{storage.id}"
)
end
end
@@ -93,7 +93,7 @@ RSpec.describe "GET /projects/:project_id/settings/project_storages/:id/oauth_ac
expect(last_response.cookies["oauth_state_#{nonce}"])
.to eq([CGI.escape({ href: "http://#{Setting.host_name}/projects/#{project.id}/settings/project_storages/external_file_storages",
storageId: project_storage.storage_id }.to_json)])
integrationId: project_storage.storage_id }.to_json)])
end
end
@@ -33,7 +33,7 @@ module EnsureConnectionPathHelper
url_helpers = OpenProject::StaticRouting::StaticRouter.new.url_helpers
url_helpers.oauth_clients_ensure_connection_path(
oauth_client_id: project_storage.storage.oauth_client.client_id,
storage_id: project_storage.storage.id,
integration_id: project_storage.storage.id,
destination_url: url_helpers.open_project_storage_url(
project_id: project_storage.project.identifier,
id: project_storage.id
@@ -43,7 +43,7 @@ module Wikis
def login_url
oauth_clients_ensure_connection_url(
oauth_client_id: provider.oauth_client.client_id,
storage_id: provider.id,
integration_id: provider.id,
destination_url: @return_url
)
end
@@ -59,9 +59,17 @@ See COPYRIGHT and LICENSE files for more details.
end
elsif page_link_infos.empty?
box.with_row do
render(Primer::Beta::Blankslate.new(border: false)) do |blankslate|
blankslate.with_heading(tag: :h2).with_content(t(".empty_heading"))
blankslate.with_description { t(".empty_text") }
if user_connected?
render(Primer::Beta::Blankslate.new(border: false)) do |blankslate|
blankslate.with_heading(tag: :h2).with_content(t(".empty_heading"))
blankslate.with_description { t(".empty_text") }
end
else
render(Wikis::OAuthLoginComponent.new(
provider,
return_url: work_package_url(@work_package, tab: :wikis)
)
)
end
end
else
@@ -50,7 +50,7 @@ See COPYRIGHT and LICENSE files for more details.
size: :medium,
href: oauth_clients_ensure_connection_url(
oauth_client_id: @wiki_provider.oauth_client.client_id,
storage_id: @wiki_provider.id,
integration_id: @wiki_provider.id,
destination_url: edit_admin_settings_wiki_provider_url(@wiki_provider)
)
) do |button|
@@ -59,7 +59,7 @@ RSpec.describe Wikis::RelationPageLinksComponent, type: :component do
context "when the provider does not support OAuth" do
let(:provider) { create(:internal_wiki_provider) }
before { subject }
before { render_component }
it { expect(page).to have_text(I18n.t("wikis.relation_page_links_component.empty_heading")) }
it { expect(page).to have_text(I18n.t("wikis.relation_page_links_component.empty_text")) }
@@ -78,7 +78,7 @@ RSpec.describe "OAuthClient callback endpoint" do
refresh_token: "xyzrefreshtoken",
user_id: "g-root"))
allow(rack_oauth2_client).to receive(:authorization_code=)
state_cookie = CGI.escape({ href: redirect_uri, storageId: oauth_client.integration_id }.to_json)
state_cookie = CGI.escape({ href: redirect_uri, integrationId: oauth_client.integration_id }.to_json)
set_cookie "oauth_state_asdf1234=#{state_cookie}"
end
@@ -51,13 +51,13 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when user is logged in" do
before { login_as(user) }
it "responds with 400 when storage_id parameter is absent" do
it "responds with 400 when integration_id parameter is absent" do
get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id)
expect(last_response).to have_http_status(:bad_request)
expect(last_response.body).to eq("Required parameter missing: storage_id")
expect(last_response.body).to eq("Required parameter missing: integration_id")
end
context "when storage_id parameter is present" do
context "when integration_id parameter is present" do
context "when user is not 'connected'" do
let(:nonce) { "57a17c3f-b2ed-446e-9dd8-651ba3aec37d" }
@@ -73,7 +73,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when destination_url parameter is absent" do
it "redirects to storage authorization_uri with oauth_state_* cookie set" do
get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, storage_id: storage.id)
get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, integration_id: storage.id)
oauth_client = storage.oauth_client
expect(last_response).to have_http_status(:found)
@@ -85,7 +85,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
)
expect(last_response.cookies["oauth_state_#{nonce}"])
.to eq(["%7B%22href%22%3A%22http%3A%2F%2F#{CGI.escape(Setting.host_name)}" \
"%2F%22%2C%22storageId%22%3A%22#{storage.id}%22%7D"])
"%2F%22%2C%22integrationId%22%3A%22#{storage.id}%22%7D"])
end
end
@@ -93,7 +93,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when destination_url is the same origin as OP" do
it "redirects to storage authorization_uri with oauth_state_* cookie set" do
get oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: "#{root_url}123")
oauth_client = storage.oauth_client
@@ -106,14 +106,14 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
)
expect(last_response.cookies["oauth_state_#{nonce}"])
.to eq(["%7B%22href%22%3A%22http%3A%2F%2F#{CGI.escape(Setting.host_name)}" \
"%2F123%22%2C%22storageId%22%3A%22#{storage.id}%22%7D"])
"%2F123%22%2C%22integrationId%22%3A%22#{storage.id}%22%7D"])
end
end
context "when destination_url is not the same origin as OP" do
it "redirects to storage authorization_uri with oauth_state_* cookie set" do
get oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: "#{storage.host}index.php")
oauth_client = storage.oauth_client
@@ -126,7 +126,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
)
expect(last_response.cookies["oauth_state_#{nonce}"])
.to eq(["%7B%22href%22%3A%22http%3A%2F%2F#{CGI.escape(Setting.host_name)}" \
"%2F%22%2C%22storageId%22%3A%22#{storage.id}%22%7D"])
"%2F%22%2C%22integrationId%22%3A%22#{storage.id}%22%7D"])
end
end
end
@@ -151,7 +151,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when destination_url parameter is absent" do
it "redirects to root_url" do
get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, storage_id: storage.id)
get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, integration_id: storage.id)
expect(last_response).to have_http_status(:found)
expect(last_response.location).to eq("http://#{Setting.host_name}/")
@@ -163,7 +163,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when destination_url is the same origin as OP" do
it "redirects to destination_url" do
get oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: "#{root_url}123")
storage.oauth_client
@@ -176,7 +176,7 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
context "when destination_url is not the same origin as OP" do
it "redirects to root_url" do
get oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,
storage_id: storage.id,
integration_id: storage.id,
destination_url: "#{storage.host}index.php")
storage.oauth_client