Commit a2a9ec03 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch...

Merge branch '23746-error-500-when-trying-to-destroy-oauth-application-entry-in-admin-area' into 'master'

Resolve "Error 500 when trying to destroy OAuth application entry in admin area"

See merge request gitlab-org/gitlab!19617
parents b63dee17 9ca20012
---
title: Use cascading deletes for deleting oauth_openid_requests upon deleting an oauth_access_grant
merge_request: 19617
author:
type: fixed
# frozen_string_literal: true
class UpdateOauthOpenIdRequestsForeignKeys < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_foreign_key(:oauth_openid_requests, :oauth_access_grants, column: :access_grant_id, on_delete: :cascade, name: new_foreign_key_name)
remove_foreign_key_if_exists(:oauth_openid_requests, name: existing_foreign_key_name)
end
def down
add_concurrent_foreign_key(:oauth_openid_requests, :oauth_access_grants, column: :access_grant_id, on_delete: false, name: existing_foreign_key_name)
remove_foreign_key_if_exists(:oauth_openid_requests, name: new_foreign_key_name)
end
private
def new_foreign_key_name
concurrent_foreign_key_name(:oauth_openid_requests, :access_grant_id)
end
def existing_foreign_key_name
'fk_oauth_openid_requests_oauth_access_grants_access_grant_id'
end
end
......@@ -4536,7 +4536,7 @@ ActiveRecord::Schema.define(version: 2019_11_25_140458) do
add_foreign_key "notes", "projects", name: "fk_99e097b079", on_delete: :cascade
add_foreign_key "notes", "reviews", name: "fk_2e82291620", on_delete: :nullify
add_foreign_key "notification_settings", "users", name: "fk_0c95e91db7", on_delete: :cascade
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_oauth_openid_requests_oauth_access_grants_access_grant_id"
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_77114b3b09", on_delete: :cascade
add_foreign_key "operations_feature_flag_scopes", "operations_feature_flags", column: "feature_flag_id", on_delete: :cascade
add_foreign_key "operations_feature_flags", "projects", on_delete: :cascade
add_foreign_key "operations_feature_flags_clients", "projects", on_delete: :cascade
......
# frozen_string_literal: true
FactoryBot.define do
factory :oauth_openid_request, class: 'Doorkeeper::OpenidConnect::Request' do
access_grant factory: :oauth_access_grant
sequence(:nonce) { |n| n.to_s }
end
end
# frozen_string_literal: true
require 'spec_helper'
describe OauthAccessGrant do
let(:user) { create(:user) }
let(:application) { create(:oauth_application, owner: user) }
describe '#delete' do
it 'cascades to oauth_openid_requests' do
access_grant = create(:oauth_access_grant, application: application)
create(:oauth_openid_request, access_grant: access_grant)
expect { access_grant.delete }.to change(Doorkeeper::OpenidConnect::Request, :count).by(-1)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment