.circleci
.github
app
chewy
controllers
activitypub
admin
api
v1
accounts
admin
announcements
apps
crypto
featured_tags
instances
lists
polls
push
statuses
timelines
accounts_controller.rb
announcements_controller.rb
apps_controller.rb
blocks_controller.rb
bookmarks_controller.rb
conversations_controller.rb
custom_emojis_controller.rb
directories_controller.rb
domain_blocks_controller.rb
endorsements_controller.rb
favourites_controller.rb
featured_tags_controller.rb
filters_controller.rb
follow_requests_controller.rb
instances_controller.rb
lists_controller.rb
markers_controller.rb
media_controller.rb
mutes_controller.rb
notifications_controller.rb
polls_controller.rb
preferences_controller.rb
reports_controller.rb
scheduled_statuses_controller.rb
statuses_controller.rb
streaming_controller.rb
suggestions_controller.rb
trends_controller.rb
v2
web
base_controller.rb
oembed_controller.rb
proofs_controller.rb
auth
concerns
oauth
settings
well_known
about_controller.rb
account_follow_controller.rb
account_unfollow_controller.rb
accounts_controller.rb
application_controller.rb
authorize_interactions_controller.rb
custom_css_controller.rb
directories_controller.rb
emojis_controller.rb
filters_controller.rb
follower_accounts_controller.rb
following_accounts_controller.rb
home_controller.rb
instance_actors_controller.rb
intents_controller.rb
invites_controller.rb
manifests_controller.rb
media_controller.rb
media_proxy_controller.rb
public_timelines_controller.rb
relationships_controller.rb
remote_follow_controller.rb
remote_interaction_controller.rb
shares_controller.rb
statuses_controller.rb
tags_controller.rb
helpers
javascript
lib
mailers
models
policies
presenters
serializers
services
validators
views
workers
bin
config
db
dist
lib
log
nanobox
public
spec
streaming
vendor
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.js
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.profile
.rspec
.rubocop.yml
.ruby-version
.sass-lint.yml
.slugignore
.yarnclean
AUTHORS.md
Aptfile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
SECURITY.md
Vagrantfile
app.json
babel.config.js
boxfile.yml
config.ru
crowdin.yml
docker-compose.yml
ide-helper.js
package.json
postcss.config.js
priv-config
scalingo.json
yarn.lock
92 lines
3.2 KiB
Ruby
92 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::AccountsController < Api::BaseController
|
|
before_action -> { authorize_if_got_token! :read, :'read:accounts' }, except: [:create, :follow, :unfollow, :block, :unblock, :mute, :unmute]
|
|
before_action -> { doorkeeper_authorize! :follow, :'write:follows' }, only: [:follow, :unfollow]
|
|
before_action -> { doorkeeper_authorize! :follow, :'write:mutes' }, only: [:mute, :unmute]
|
|
before_action -> { doorkeeper_authorize! :follow, :'write:blocks' }, only: [:block, :unblock]
|
|
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]
|
|
|
|
before_action :require_user!, except: [:show, :create]
|
|
before_action :set_account, except: [:create]
|
|
before_action :check_account_suspension, only: [:show]
|
|
before_action :check_enabled_registrations, only: [:create]
|
|
|
|
skip_before_action :require_authenticated_user!, only: :create
|
|
|
|
override_rate_limit_headers :follow, family: :follows
|
|
|
|
def show
|
|
render json: @account, serializer: REST::AccountSerializer
|
|
end
|
|
|
|
def create
|
|
token = AppSignUpService.new.call(doorkeeper_token.application, account_params)
|
|
response = Doorkeeper::OAuth::TokenResponse.new(token)
|
|
|
|
headers.merge!(response.headers)
|
|
|
|
self.response_body = Oj.dump(response.body)
|
|
self.status = response.status
|
|
end
|
|
|
|
def follow
|
|
FollowService.new.call(current_user.account, @account, reblogs: truthy_param?(:reblogs), with_rate_limit: true)
|
|
|
|
options = @account.locked? || current_user.account.silenced? ? {} : { following_map: { @account.id => { reblogs: truthy_param?(:reblogs) } }, requested_map: { @account.id => false } }
|
|
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships(options)
|
|
end
|
|
|
|
def block
|
|
BlockService.new.call(current_user.account, @account)
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
|
end
|
|
|
|
def mute
|
|
MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications))
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
|
end
|
|
|
|
def unfollow
|
|
UnfollowService.new.call(current_user.account, @account)
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
|
end
|
|
|
|
def unblock
|
|
UnblockService.new.call(current_user.account, @account)
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
|
end
|
|
|
|
def unmute
|
|
UnmuteService.new.call(current_user.account, @account)
|
|
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
|
end
|
|
|
|
private
|
|
|
|
def set_account
|
|
@account = Account.find(params[:id])
|
|
end
|
|
|
|
def relationships(**options)
|
|
AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
|
|
end
|
|
|
|
def check_account_suspension
|
|
gone if @account.suspended?
|
|
end
|
|
|
|
def account_params
|
|
params.permit(:username, :email, :password, :agreement, :locale, :reason)
|
|
end
|
|
|
|
def check_enabled_registrations
|
|
forbidden if single_user_mode? || !allowed_registrations?
|
|
end
|
|
|
|
def allowed_registrations?
|
|
Setting.registrations_mode != 'none'
|
|
end
|
|
end
|