-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1727 from doorkeeper-gem/fixes/allow-null-app-secret
Allow to set null secret value for Applications if it's public
- Loading branch information
Showing
10 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators" | ||
require "rails/generators/active_record" | ||
|
||
module Doorkeeper | ||
# Generates migration with which drops NOT NULL constraint and allows not | ||
# to bloat the database with redundant secret value. | ||
# | ||
class RemoveApplicationSecretNotNullConstraint < ::Rails::Generators::Base | ||
include ::Rails::Generators::Migration | ||
source_root File.expand_path("templates", __dir__) | ||
desc "Removes NOT NULL constraint for OAuth2 applications." | ||
|
||
def enable_polymorphic_resource_owner | ||
migration_template( | ||
"remove_applications_secret_not_null_constraint.rb.erb", | ||
"db/migrate/remove_applications_secret_not_null_constraint.rb", | ||
migration_version: migration_version, | ||
) | ||
end | ||
|
||
def self.next_migration_number(dirname) | ||
ActiveRecord::Generators::Base.next_migration_number(dirname) | ||
end | ||
|
||
private | ||
|
||
def migration_version | ||
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
lib/generators/doorkeeper/templates/remove_applications_secret_not_null_constraint.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class RemoveApplicationsSecretNotNullConstraint < ActiveRecord::Migration<%= migration_version %> | ||
def change | ||
change_column_null :oauth_applications, :secret, true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
spec/generators/remove_applications_secret_not_null_constraint_generator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "generators/doorkeeper/remove_applications_secret_not_null_constraint_generator" | ||
|
||
RSpec.describe Doorkeeper::RemoveApplicationSecretNotNullConstraint do | ||
include GeneratorSpec::TestCase | ||
|
||
tests described_class | ||
destination ::File.expand_path('tmp/dummy', __dir__) | ||
|
||
describe "after running the generator" do | ||
before do | ||
prepare_destination | ||
end | ||
|
||
it "creates a migration with a version specifier" do | ||
run_generator | ||
|
||
assert_migration "db/migrate/remove_applications_secret_not_null_constraint.rb" do |migration| | ||
assert migration.include?("change_column_null :oauth_applications, :secret") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters