1 # frozen_string_literal: true
3 class Api
::V1::AccountsController < Api
::BaseController
4 before_action
-> { authorize_if_got_token!
:read, :'read:accounts' }, except
: [:create, :follow, :unfollow, :block, :unblock, :mute, :unmute]
5 before_action
-> { doorkeeper_authorize!
:follow, :'write:follows' }, only
: [:follow, :unfollow]
6 before_action
-> { doorkeeper_authorize!
:follow, :'write:mutes' }, only
: [:mute, :unmute]
7 before_action
-> { doorkeeper_authorize!
:follow, :'write:blocks' }, only
: [:block, :unblock]
8 before_action
-> { doorkeeper_authorize!
:write, :'write:accounts' }, only
: [:create]
10 before_action
:require_user!
, except
: [:show, :create]
11 before_action
:set_account, except
: [:create]
12 before_action
:check_account_suspension, only
: [:show]
13 before_action
:check_enabled_registrations, only
: [:create]
15 skip_before_action
:require_authenticated_user!
, only
: :create
20 render json
: @account, serializer
: REST
::AccountSerializer
24 token
= AppSignUpService
.new
.call(doorkeeper_token
.application
, account_params
)
25 response
= Doorkeeper
::OAuth::TokenResponse.new(token
)
27 headers
.merge!
(response
.headers
)
29 self.response_body
= Oj
.dump(response
.body
)
30 self.status
= response
.status
34 FollowService
.new
.call(current_user
.account
, @account, reblogs
: truthy_param
?(:reblogs))
36 options
= @account.locked
? ? {} : { following_map
: { @account.id
=> { reblogs
: truthy_param
?(:reblogs) } }, requested_map
: { @account.id
=> false } }
38 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships(options
)
42 BlockService
.new
.call(current_user
.account
, @account)
43 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
47 MuteService
.new
.call(current_user
.account
, @account, notifications
: truthy_param
?(:notifications))
48 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
52 UnfollowService
.new
.call(current_user
.account
, @account)
53 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
57 UnblockService
.new
.call(current_user
.account
, @account)
58 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
62 UnmuteService
.new
.call(current_user
.account
, @account)
63 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
69 @account = Account
.find(params
[:id])
72 def relationships(**options
)
73 AccountRelationshipsPresenter
.new([@account.id
], current_user
.account_id
, options
)
76 def check_account_suspension
77 gone
if @account.suspended
?
81 params
.permit(:username, :email, :password, :agreement, :locale)
84 def check_enabled_registrations
85 forbidden
if single_user_mode
? || !allowed_registrations
?
88 def allowed_registrations
?
89 Setting
.registrations_mode !
= 'none'