Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StaleRecordsCleaner to be ORM agnostic #1154

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ gemfile:

matrix:
fast_finish: true
# Run Danger only once
include:
- rvm: 2.5
gemfile: gemfiles/rails_5_2.gemfile
script: bundle exec danger
exclude:
- gemfile: gemfiles/rails_5_0.gemfile
rvm: 2.1
Expand Down
57 changes: 57 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CHANGELOG_FILE = 'NEWS.md'
GITHUB_REPO = 'https://github.com/doorkeeper-gem/doorkeeper'

def changelog_changed?
git.modified_files.include?(CHANGELOG_FILE) || git.added_files.include?(CHANGELOG_FILE)
end

def changelog_entry_example
pr_number = github.pr_json['number']
pr_url = github.pr_json['html_url']
pr_title = github.pr_title
.sub(/[?.!,;]?$/, '')
.capitalize

"- [##{pr_number}](#{pr_url}): #{pr_title}."
end

# --------------------------------------------------------------------------------------------------------------------
# Has any changes happened inside the actual library code?
# --------------------------------------------------------------------------------------------------------------------
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_spec_changes = !git.modified_files.grep(/spec/).empty?

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to lib, but didn't write any tests?
# --------------------------------------------------------------------------------------------------------------------
if has_app_changes && !has_spec_changes
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
end

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to specs, but no library code has changed?
# --------------------------------------------------------------------------------------------------------------------
if !has_app_changes && has_spec_changes
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
end

# Mainly to encourage writing up some reasoning about the PR, rather than
# just leaving a title
if github.pr_body.length < 10
fail "Please provide a summary in the Pull Request description"
end

# --------------------------------------------------------------------------------------------------------------------
# Have you updated CHANGELOG.md?
# --------------------------------------------------------------------------------------------------------------------
# Add a CHANGELOG entry for app changes
if has_app_changes && !changelog_changed?
markdown <<-MARKDOWN
Here's an example of a #{CHANGELOG_FILE} entry:
```markdown
#{changelog_entry_example}
```
MARKDOWN

fail("Please include a changelog entry. \nYou can find it at [#{CHANGELOG_FILE}](#{GITHUB_REPO}/blob/master/#{CHANGELOG_FILE}).")
end
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ User-visible changes worth mentioning.
triggers every time)
- [#1149] Fix for `URIChecker#valid_for_authorization?` false negative when query is blank, but `?` present.
- [#1151] Fix Refresh Token strategy: add proper validation of client credentials both for Public & Private clients.
- [#1152] Fixmigration template: change resource owner data type from integer to references
- [#1152] Fix migration template: change resource owner data type from integer to Rails generic `references`
- [#1154] Refactor `StaleRecordsCleaner` to be ORM agnostic.

## 5.0.0

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class ApplicationController <
Doorkeeper.configuration.base_controller.constantize
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/application_metal_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class ApplicationMetalController < ActionController::Metal
MODULES = [
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class ApplicationsController < Doorkeeper::ApplicationController
layout 'doorkeeper/admin' unless Doorkeeper.configuration.api_only
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/authorizations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class AuthorizationsController < Doorkeeper::ApplicationController
before_action :authenticate_resource_owner!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class AuthorizedApplicationsController < Doorkeeper::ApplicationController
before_action :authenticate_resource_owner!
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/token_info_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class TokenInfoController < Doorkeeper::ApplicationMetalController
def show
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/doorkeeper/tokens_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class TokensController < Doorkeeper::ApplicationMetalController
def create
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/doorkeeper/dashboard_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module DashboardHelper
def doorkeeper_errors_for(object, method)
Expand Down
2 changes: 2 additions & 0 deletions app/validators/redirect_uri_validator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'uri'

class RedirectUriValidator < ActiveModel::EachValidator
Expand Down
45 changes: 23 additions & 22 deletions doorkeeper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)

require 'doorkeeper/version'

Gem::Specification.new do |s|
s.name = 'doorkeeper'
s.version = Doorkeeper.gem_version
s.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
s.email = %w([email protected])
s.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
s.summary = 'OAuth 2 provider for Rails and Grape'
s.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
s.license = 'MIT'
Gem::Specification.new do |gem|
gem.name = 'doorkeeper'
gem.version = Doorkeeper.gem_version
gem.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
gem.email = %w([email protected])
gem.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
gem.summary = 'OAuth 2 provider for Rails and Grape'
gem.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
gem.license = 'MIT'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")
s.require_paths = ['lib']
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- spec/*`.split("\n")
gem.require_paths = ['lib']

s.add_dependency 'railties', '>= 4.2'
s.required_ruby_version = '>= 2.1'
gem.add_dependency 'railties', '>= 4.2'
gem.required_ruby_version = '>= 2.1'

s.add_development_dependency 'capybara', '~> 2.18'
s.add_development_dependency 'coveralls'
s.add_development_dependency 'grape'
s.add_development_dependency 'database_cleaner', '~> 1.6'
s.add_development_dependency 'factory_bot', '~> 4.8'
s.add_development_dependency 'generator_spec', '~> 0.9.3'
s.add_development_dependency 'rake', '>= 11.3.0'
s.add_development_dependency 'rspec-rails'
gem.add_development_dependency 'capybara', '~> 2.18'
gem.add_development_dependency 'coveralls'
gem.add_development_dependency 'danger', '~> 5.0'
gem.add_development_dependency 'grape'
gem.add_development_dependency 'database_cleaner', '~> 1.6'
gem.add_development_dependency 'factory_bot', '~> 4.8'
gem.add_development_dependency 'generator_spec', '~> 0.9.3'
gem.add_development_dependency 'rake', '>= 11.3.0'
gem.add_development_dependency 'rspec-rails'
end
1 change: 1 addition & 0 deletions lib/doorkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
require 'doorkeeper/rails/helpers'

require 'doorkeeper/rake'
require 'doorkeeper/stale_records_cleaner'

require 'doorkeeper/orm/active_record'

Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
class Engine < Rails::Engine
initializer "doorkeeper.params.filter" do |app|
Expand Down
3 changes: 3 additions & 0 deletions lib/doorkeeper/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Errors
class DoorkeeperError < StandardError
Expand Down Expand Up @@ -46,6 +48,7 @@ def initialize(response)

UnableToGenerateToken = Class.new(DoorkeeperError)
TokenGeneratorNotFound = Class.new(DoorkeeperError)
NoOrmCleaner = Class.new(DoorkeeperError)

InvalidToken = Class.new BaseResponseError
TokenExpired = Class.new InvalidToken
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/grape/authorization_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Grape
class AuthorizationDecorator < SimpleDelegator
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/grape/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'doorkeeper/grape/authorization_decorator'

module Doorkeeper
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/helpers/controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Define methods that can be called in any controller that inherits from
# Doorkeeper::ApplicationMetalController or Doorkeeper::ApplicationController
module Doorkeeper
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/access_grant_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module AccessGrantMixin
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/access_token_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module AccessTokenMixin
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/application_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module ApplicationMixin
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/accessible.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Accessible
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/expirable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Expirable
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/orderable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Orderable
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/ownership.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Ownership
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/revocable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Revocable
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/models/concerns/scopes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module Models
module Scopes
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/authorization/code.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
module Authorization
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/authorization/context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
module Authorization
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/authorization/token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
module Authorization
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/authorization/uri_builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rack/utils'

module Doorkeeper
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/authorization_code_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class AuthorizationCodeRequest < BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/base_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/base_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class BaseResponse
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class Client
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client/credentials.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class Client
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client_credentials/creator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ClientCredentialsRequest < BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client_credentials/issuer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ClientCredentialsRequest < BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client_credentials/validation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ClientCredentialsRequest < BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/client_credentials_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ClientCredentialsRequest < BaseRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/code_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class CodeRequest
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/code_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class CodeResponse < BaseResponse
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
Error = Struct.new(:name, :state) do
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/error_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ErrorResponse < BaseResponse
Expand Down
2 changes: 2 additions & 0 deletions lib/doorkeeper/oauth/forbidden_token_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Doorkeeper
module OAuth
class ForbiddenTokenResponse < ErrorResponse
Expand Down
Loading