Skip to content

Commit

Permalink
Add Api::V1::Instances::BaseController base controller class (masto…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and 000hen committed Dec 6, 2023
1 parent 34ef96d commit d66a836
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 34 deletions.
6 changes: 1 addition & 5 deletions app/controllers/api/v1/instances/activity_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# frozen_string_literal: true

class Api::V1::Instances::ActivityController < Api::BaseController
class Api::V1::Instances::ActivityController < Api::V1::Instances::BaseController
before_action :require_enabled_api!

skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?

vary_by ''

def show
cache_even_if_authenticated!
render_with_cache json: :activity, expires_in: 1.day
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/api/v1/instances/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class Api::V1::Instances::BaseController < Api::BaseController
skip_before_action :require_authenticated_user!,
unless: :limited_federation_mode?

vary_by ''
end
4 changes: 1 addition & 3 deletions app/controllers/api/v1/instances/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Api::V1::Instances::DomainBlocksController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?

class Api::V1::Instances::DomainBlocksController < Api::V1::Instances::BaseController
before_action :require_enabled_api!
before_action :set_domain_blocks

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true

class Api::V1::Instances::ExtendedDescriptionsController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?
class Api::V1::Instances::ExtendedDescriptionsController < Api::V1::Instances::BaseController
skip_around_action :set_locale

before_action :set_extended_description

vary_by ''

# Override `current_user` to avoid reading session cookies unless in whitelist mode
def current_user
super if limited_federation_mode?
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/api/v1/instances/languages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true

class Api::V1::Instances::LanguagesController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?
class Api::V1::Instances::LanguagesController < Api::V1::Instances::BaseController
skip_around_action :set_locale

before_action :set_languages

vary_by ''

def show
cache_even_if_authenticated!
render json: @languages, each_serializer: REST::LanguageSerializer
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/api/v1/instances/peers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true

class Api::V1::Instances::PeersController < Api::BaseController
class Api::V1::Instances::PeersController < Api::V1::Instances::BaseController
before_action :require_enabled_api!

skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?
skip_around_action :set_locale

vary_by ''

# Override `current_user` to avoid reading session cookies unless in whitelist mode
def current_user
super if limited_federation_mode?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# frozen_string_literal: true

class Api::V1::Instances::PrivacyPoliciesController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?

class Api::V1::Instances::PrivacyPoliciesController < Api::V1::Instances::BaseController
before_action :set_privacy_policy

vary_by ''

def show
cache_even_if_authenticated!
render json: @privacy_policy, serializer: REST::PrivacyPolicySerializer
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/api/v1/instances/rules_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true

class Api::V1::Instances::RulesController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?
class Api::V1::Instances::RulesController < Api::V1::Instances::BaseController
skip_around_action :set_locale

before_action :set_rules

vary_by ''

# Override `current_user` to avoid reading session cookies unless in whitelist mode
def current_user
super if limited_federation_mode?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# frozen_string_literal: true

class Api::V1::Instances::TranslationLanguagesController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?

class Api::V1::Instances::TranslationLanguagesController < Api::V1::Instances::BaseController
before_action :set_languages

vary_by ''

def show
cache_even_if_authenticated!
render json: @languages
Expand Down

0 comments on commit d66a836

Please sign in to comment.