|
|
@ -9,16 +9,22 @@ class Api::V1::AccountsController < Api::BaseController
|
|
|
|
before_action -> { doorkeeper_authorize! :follow, :write, :'write:blocks' }, only: [:block, :unblock]
|
|
|
|
before_action -> { doorkeeper_authorize! :follow, :write, :'write:blocks' }, only: [:block, :unblock]
|
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]
|
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]
|
|
|
|
|
|
|
|
|
|
|
|
before_action :require_user!, except: [:show, :create]
|
|
|
|
before_action :require_user!, except: [:index, :show, :create]
|
|
|
|
before_action :set_account, except: [:create]
|
|
|
|
before_action :set_account, except: [:index, :create]
|
|
|
|
before_action :check_account_approval, except: [:create]
|
|
|
|
before_action :set_accounts, only: [:index]
|
|
|
|
before_action :check_account_confirmation, except: [:create]
|
|
|
|
before_action :check_account_approval, except: [:index, :create]
|
|
|
|
|
|
|
|
before_action :check_account_confirmation, except: [:index, :create]
|
|
|
|
before_action :check_enabled_registrations, only: [:create]
|
|
|
|
before_action :check_enabled_registrations, only: [:create]
|
|
|
|
|
|
|
|
before_action :check_accounts_limit, only: [:index]
|
|
|
|
|
|
|
|
|
|
|
|
skip_before_action :require_authenticated_user!, only: :create
|
|
|
|
skip_before_action :require_authenticated_user!, only: :create
|
|
|
|
|
|
|
|
|
|
|
|
override_rate_limit_headers :follow, family: :follows
|
|
|
|
override_rate_limit_headers :follow, family: :follows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
|
|
|
render json: @accounts, each_serializer: REST::AccountSerializer
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
def show
|
|
|
|
cache_if_unauthenticated!
|
|
|
|
cache_if_unauthenticated!
|
|
|
|
render json: @account, serializer: REST::AccountSerializer
|
|
|
|
render json: @account, serializer: REST::AccountSerializer
|
|
|
@ -79,6 +85,10 @@ class Api::V1::AccountsController < Api::BaseController
|
|
|
|
@account = Account.find(params[:id])
|
|
|
|
@account = Account.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_accounts
|
|
|
|
|
|
|
|
@accounts = Account.where(id: account_ids).without_unapproved
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check_account_approval
|
|
|
|
def check_account_approval
|
|
|
|
raise(ActiveRecord::RecordNotFound) if @account.local? && @account.user_pending?
|
|
|
|
raise(ActiveRecord::RecordNotFound) if @account.local? && @account.user_pending?
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -87,10 +97,22 @@ class Api::V1::AccountsController < Api::BaseController
|
|
|
|
raise(ActiveRecord::RecordNotFound) if @account.local? && !@account.user_confirmed?
|
|
|
|
raise(ActiveRecord::RecordNotFound) if @account.local? && !@account.user_confirmed?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_accounts_limit
|
|
|
|
|
|
|
|
raise(Mastodon::ValidationError) if account_ids.size > DEFAULT_ACCOUNTS_LIMIT
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def relationships(**options)
|
|
|
|
def relationships(**options)
|
|
|
|
AccountRelationshipsPresenter.new([@account], current_user.account_id, **options)
|
|
|
|
AccountRelationshipsPresenter.new([@account], current_user.account_id, **options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def account_ids
|
|
|
|
|
|
|
|
Array(accounts_params[:ids]).uniq.map(&:to_i)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def accounts_params
|
|
|
|
|
|
|
|
params.permit(ids: [])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def account_params
|
|
|
|
def account_params
|
|
|
|
params.permit(:username, :email, :password, :agreement, :locale, :reason, :time_zone, :invite_code)
|
|
|
|
params.permit(:username, :email, :password, :agreement, :locale, :reason, :time_zone, :invite_code)
|
|
|
|
end
|
|
|
|
end
|
|
|
|