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]
18 render json
: @account, serializer
: REST
::AccountSerializer
22 token
= AppSignUpService
.new
.call(doorkeeper_token
.application
, account_params
)
23 response
= Doorkeeper
::OAuth::TokenResponse.new(token
)
25 headers
.merge!
(response
.headers
)
27 self.response_body
= Oj
.dump(response
.body
)
28 self.status
= response
.status
32 FollowService
.new
.call(current_user
.account
, @account, reblogs
: truthy_param
?(:reblogs))
34 options
= @account.locked
? ? {} : { following_map
: { @account.id
=> { reblogs
: truthy_param
?(:reblogs) } }, requested_map
: { @account.id
=> false } }
36 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships(options
)
40 BlockService
.new
.call(current_user
.account
, @account)
41 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
45 MuteService
.new
.call(current_user
.account
, @account, notifications
: truthy_param
?(:notifications))
46 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
50 UnfollowService
.new
.call(current_user
.account
, @account)
51 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
55 UnblockService
.new
.call(current_user
.account
, @account)
56 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
60 UnmuteService
.new
.call(current_user
.account
, @account)
61 render json
: @account, serializer
: REST
::RelationshipSerializer, relationships
: relationships
67 @account = Account
.find(params
[:id])
70 def relationships(**options
)
71 AccountRelationshipsPresenter
.new([@account.id
], current_user
.account_id
, options
)
74 def check_account_suspension
75 gone
if @account.suspended
?
79 params
.permit(:username, :email, :password, :agreement)
82 def check_enabled_registrations
83 forbidden
if single_user_mode
? || !Setting
.open_registrations