From 47fda2df2ccd81a2e2b9b8e5465acad8abe1ce5c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 25 Jun 2025 03:52:30 -0400 Subject: [PATCH] Update `OAuth` inflection to match spec (#35160) --- .rubocop/rspec.yml | 1 + app/controllers/oauth/authorizations_controller.rb | 2 +- app/controllers/oauth/authorized_applications_controller.rb | 2 +- app/controllers/oauth/tokens_controller.rb | 2 +- app/controllers/oauth/userinfo_controller.rb | 4 ++-- app/controllers/well_known/oauth_metadata_controller.rb | 6 +++--- app/presenters/oauth_metadata_presenter.rb | 2 +- app/serializers/oauth_metadata_serializer.rb | 2 +- app/serializers/oauth_userinfo_serializer.rb | 2 +- config/initializers/inflections.rb | 1 + .../20160826155805_add_superapp_to_oauth_applications.rb | 2 +- .../20170114203041_add_website_to_oauth_application.rb | 2 +- ...0220227041951_add_last_used_at_to_oauth_access_tokens.rb | 2 +- ...optimize_null_index_oauth_access_tokens_refresh_token.rb | 2 +- ...mize_null_index_oauth_access_tokens_resource_owner_id.rb | 2 +- spec/controllers/oauth/authorizations_controller_spec.rb | 2 +- .../oauth/authorized_applications_controller_spec.rb | 2 +- spec/requests/oauth/userinfo_spec.rb | 2 +- 18 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.rubocop/rspec.yml b/.rubocop/rspec.yml index d2d2f8325d..27f703444e 100644 --- a/.rubocop/rspec.yml +++ b/.rubocop/rspec.yml @@ -23,5 +23,6 @@ RSpec/SpecFilePathFormat: ActivityPub: activitypub DeepL: deepl FetchOEmbedService: fetch_oembed_service + OAuth: oauth OEmbedController: oembed_controller OStatus: ostatus diff --git a/app/controllers/oauth/authorizations_controller.rb b/app/controllers/oauth/authorizations_controller.rb index deafedeaef..7c8bbf46da 100644 --- a/app/controllers/oauth/authorizations_controller.rb +++ b/app/controllers/oauth/authorizations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController +class OAuth::AuthorizationsController < Doorkeeper::AuthorizationsController skip_before_action :authenticate_resource_owner! before_action :store_current_location diff --git a/app/controllers/oauth/authorized_applications_controller.rb b/app/controllers/oauth/authorized_applications_controller.rb index 8b11a519ea..92c9716196 100644 --- a/app/controllers/oauth/authorized_applications_controller.rb +++ b/app/controllers/oauth/authorized_applications_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController +class OAuth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController skip_before_action :authenticate_resource_owner! before_action :store_current_location diff --git a/app/controllers/oauth/tokens_controller.rb b/app/controllers/oauth/tokens_controller.rb index 34087b20bc..78c439384a 100644 --- a/app/controllers/oauth/tokens_controller.rb +++ b/app/controllers/oauth/tokens_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Oauth::TokensController < Doorkeeper::TokensController +class OAuth::TokensController < Doorkeeper::TokensController def revoke unsubscribe_for_token if token.present? && authorized? && token.accessible? diff --git a/app/controllers/oauth/userinfo_controller.rb b/app/controllers/oauth/userinfo_controller.rb index e268b70dcc..204ea15a94 100644 --- a/app/controllers/oauth/userinfo_controller.rb +++ b/app/controllers/oauth/userinfo_controller.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -class Oauth::UserinfoController < Api::BaseController +class OAuth::UserinfoController < Api::BaseController before_action -> { doorkeeper_authorize! :profile }, only: [:show] before_action :require_user! def show @account = current_account - render json: @account, serializer: OauthUserinfoSerializer + render json: @account, serializer: OAuthUserinfoSerializer end end diff --git a/app/controllers/well_known/oauth_metadata_controller.rb b/app/controllers/well_known/oauth_metadata_controller.rb index c80be2d652..0efba1ffdd 100644 --- a/app/controllers/well_known/oauth_metadata_controller.rb +++ b/app/controllers/well_known/oauth_metadata_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module WellKnown - class OauthMetadataController < ActionController::Base # rubocop:disable Rails/ApplicationController + class OAuthMetadataController < ActionController::Base # rubocop:disable Rails/ApplicationController include CacheConcern # Prevent `active_model_serializer`'s `ActionController::Serialization` from calling `current_user` @@ -13,8 +13,8 @@ module WellKnown # new OAuth scopes are added), we don't use expires_in to cache upstream, # instead just caching in the rails cache: render_with_cache( - json: ::OauthMetadataPresenter.new, - serializer: ::OauthMetadataSerializer, + json: ::OAuthMetadataPresenter.new, + serializer: ::OAuthMetadataSerializer, content_type: 'application/json', expires_in: 15.minutes ) diff --git a/app/presenters/oauth_metadata_presenter.rb b/app/presenters/oauth_metadata_presenter.rb index f488a62925..65291369fa 100644 --- a/app/presenters/oauth_metadata_presenter.rb +++ b/app/presenters/oauth_metadata_presenter.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class OauthMetadataPresenter < ActiveModelSerializers::Model +class OAuthMetadataPresenter < ActiveModelSerializers::Model include RoutingHelper attributes :issuer, :authorization_endpoint, :token_endpoint, diff --git a/app/serializers/oauth_metadata_serializer.rb b/app/serializers/oauth_metadata_serializer.rb index 9c5f7365a4..4d9f340c7b 100644 --- a/app/serializers/oauth_metadata_serializer.rb +++ b/app/serializers/oauth_metadata_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class OauthMetadataSerializer < ActiveModel::Serializer +class OAuthMetadataSerializer < ActiveModel::Serializer attributes :issuer, :authorization_endpoint, :token_endpoint, :revocation_endpoint, :userinfo_endpoint, :scopes_supported, :response_types_supported, :response_modes_supported, diff --git a/app/serializers/oauth_userinfo_serializer.rb b/app/serializers/oauth_userinfo_serializer.rb index e2f37ae02e..1385bb27e6 100644 --- a/app/serializers/oauth_userinfo_serializer.rb +++ b/app/serializers/oauth_userinfo_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class OauthUserinfoSerializer < ActiveModel::Serializer +class OAuthUserinfoSerializer < ActiveModel::Serializer include RoutingHelper attributes :iss, :sub, :name, :preferred_username, :profile, :picture diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 2b0563f4d3..d9a8f72663 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -20,6 +20,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'DeepL' inflect.acronym 'DSL' inflect.acronym 'JsonLd' + inflect.acronym 'OAuth' inflect.acronym 'OEmbed' inflect.acronym 'OStatus' inflect.acronym 'PubSubHubbub' diff --git a/db/migrate/20160826155805_add_superapp_to_oauth_applications.rb b/db/migrate/20160826155805_add_superapp_to_oauth_applications.rb index af8bd922fc..3d1ec66e3e 100644 --- a/db/migrate/20160826155805_add_superapp_to_oauth_applications.rb +++ b/db/migrate/20160826155805_add_superapp_to_oauth_applications.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddSuperappToOauthApplications < ActiveRecord::Migration[5.0] +class AddSuperappToOAuthApplications < ActiveRecord::Migration[5.0] def change add_column :oauth_applications, :superapp, :boolean, default: false, null: false end diff --git a/db/migrate/20170114203041_add_website_to_oauth_application.rb b/db/migrate/20170114203041_add_website_to_oauth_application.rb index 5a0f2b7901..baf792fd69 100644 --- a/db/migrate/20170114203041_add_website_to_oauth_application.rb +++ b/db/migrate/20170114203041_add_website_to_oauth_application.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddWebsiteToOauthApplication < ActiveRecord::Migration[5.0] +class AddWebsiteToOAuthApplication < ActiveRecord::Migration[5.0] def change add_column :oauth_applications, :website, :string end diff --git a/db/migrate/20220227041951_add_last_used_at_to_oauth_access_tokens.rb b/db/migrate/20220227041951_add_last_used_at_to_oauth_access_tokens.rb index a5eb732720..311361d833 100644 --- a/db/migrate/20220227041951_add_last_used_at_to_oauth_access_tokens.rb +++ b/db/migrate/20220227041951_add_last_used_at_to_oauth_access_tokens.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddLastUsedAtToOauthAccessTokens < ActiveRecord::Migration[6.1] +class AddLastUsedAtToOAuthAccessTokens < ActiveRecord::Migration[6.1] def change safety_assured do change_table(:oauth_access_tokens, bulk: true) do |t| diff --git a/db/post_migrate/20220310060740_optimize_null_index_oauth_access_tokens_refresh_token.rb b/db/post_migrate/20220310060740_optimize_null_index_oauth_access_tokens_refresh_token.rb index 30ade8e3fa..029bba37c0 100644 --- a/db/post_migrate/20220310060740_optimize_null_index_oauth_access_tokens_refresh_token.rb +++ b/db/post_migrate/20220310060740_optimize_null_index_oauth_access_tokens_refresh_token.rb @@ -2,7 +2,7 @@ require Rails.root.join('lib', 'mastodon', 'migration_helpers') -class OptimizeNullIndexOauthAccessTokensRefreshToken < ActiveRecord::Migration[5.2] +class OptimizeNullIndexOAuthAccessTokensRefreshToken < ActiveRecord::Migration[5.2] include Mastodon::MigrationHelpers disable_ddl_transaction! diff --git a/db/post_migrate/20220310060809_optimize_null_index_oauth_access_tokens_resource_owner_id.rb b/db/post_migrate/20220310060809_optimize_null_index_oauth_access_tokens_resource_owner_id.rb index 787263bf73..5db33ecff0 100644 --- a/db/post_migrate/20220310060809_optimize_null_index_oauth_access_tokens_resource_owner_id.rb +++ b/db/post_migrate/20220310060809_optimize_null_index_oauth_access_tokens_resource_owner_id.rb @@ -2,7 +2,7 @@ require Rails.root.join('lib', 'mastodon', 'migration_helpers') -class OptimizeNullIndexOauthAccessTokensResourceOwnerId < ActiveRecord::Migration[5.2] +class OptimizeNullIndexOAuthAccessTokensResourceOwnerId < ActiveRecord::Migration[5.2] include Mastodon::MigrationHelpers disable_ddl_transaction! diff --git a/spec/controllers/oauth/authorizations_controller_spec.rb b/spec/controllers/oauth/authorizations_controller_spec.rb index cfc80b8650..0ab324dc3d 100644 --- a/spec/controllers/oauth/authorizations_controller_spec.rb +++ b/spec/controllers/oauth/authorizations_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe Oauth::AuthorizationsController do +RSpec.describe OAuth::AuthorizationsController do let(:app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/', scopes: 'read') } describe 'GET #new' do diff --git a/spec/controllers/oauth/authorized_applications_controller_spec.rb b/spec/controllers/oauth/authorized_applications_controller_spec.rb index 60f9602136..ba7ff8f5d1 100644 --- a/spec/controllers/oauth/authorized_applications_controller_spec.rb +++ b/spec/controllers/oauth/authorized_applications_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe Oauth::AuthorizedApplicationsController do +RSpec.describe OAuth::AuthorizedApplicationsController do render_views describe 'GET #index' do diff --git a/spec/requests/oauth/userinfo_spec.rb b/spec/requests/oauth/userinfo_spec.rb index 7d6226cd41..0aa5a21120 100644 --- a/spec/requests/oauth/userinfo_spec.rb +++ b/spec/requests/oauth/userinfo_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'Oauth Userinfo Endpoint' do +RSpec.describe 'OAuth Userinfo Endpoint' do include RoutingHelper let(:user) { Fabricate(:user) }