Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
mastodon
Commits
824d1b88
Unverified
Commit
824d1b88
authored
4 years ago
by
Takeshi Umeda
Committed by
GitHub
4 years ago
Browse files
Options
Download
Plain Diff
Merge branch 'master' into feature-circles
parents
6358072b
c747883d
Changes
905
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
app/controllers/activitypub/outboxes_controller.rb
+22
-7
app/controllers/activitypub/outboxes_controller.rb
app/controllers/activitypub/replies_controller.rb
+1
-1
app/controllers/activitypub/replies_controller.rb
app/controllers/admin/accounts_controller.rb
+27
-11
app/controllers/admin/accounts_controller.rb
app/controllers/admin/announcements_controller.rb
+1
-1
app/controllers/admin/announcements_controller.rb
app/controllers/admin/domain_blocks_controller.rb
+5
-4
app/controllers/admin/domain_blocks_controller.rb
app/controllers/admin/email_domain_blocks_controller.rb
+1
-1
app/controllers/admin/email_domain_blocks_controller.rb
app/controllers/admin/instances_controller.rb
+5
-39
app/controllers/admin/instances_controller.rb
app/controllers/admin/ip_blocks_controller.rb
+56
-0
app/controllers/admin/ip_blocks_controller.rb
app/controllers/admin/statuses_controller.rb
+1
-1
app/controllers/admin/statuses_controller.rb
app/controllers/api/base_controller.rb
+5
-4
app/controllers/api/base_controller.rb
app/controllers/api/v1/accounts/featured_tags_controller.rb
+22
-0
app/controllers/api/v1/accounts/featured_tags_controller.rb
app/controllers/api/v1/accounts/follower_accounts_controller.rb
+1
-1
...ntrollers/api/v1/accounts/follower_accounts_controller.rb
app/controllers/api/v1/accounts/following_accounts_controller.rb
+1
-1
...trollers/api/v1/accounts/following_accounts_controller.rb
app/controllers/api/v1/accounts/identity_proofs_controller.rb
+1
-1
...controllers/api/v1/accounts/identity_proofs_controller.rb
app/controllers/api/v1/accounts/lists_controller.rb
+1
-1
app/controllers/api/v1/accounts/lists_controller.rb
app/controllers/api/v1/accounts/relationships_controller.rb
+1
-1
app/controllers/api/v1/accounts/relationships_controller.rb
app/controllers/api/v1/accounts/statuses_controller.rb
+8
-17
app/controllers/api/v1/accounts/statuses_controller.rb
app/controllers/api/v1/accounts_controller.rb
+4
-10
app/controllers/api/v1/accounts_controller.rb
app/controllers/api/v1/admin/accounts_controller.rb
+17
-2
app/controllers/api/v1/admin/accounts_controller.rb
app/controllers/api/v1/admin/reports_controller.rb
+1
-1
app/controllers/api/v1/admin/reports_controller.rb
with
181 additions
and
104 deletions
+181
-104
app/controllers/activitypub/outboxes_controller.rb
+
22
-
7
View file @
824d1b88
...
...
@@ -20,9 +20,9 @@ class ActivityPub::OutboxesController < ActivityPub::BaseController
def
outbox_presenter
if
page_requested?
ActivityPub
::
CollectionPresenter
.
new
(
id:
account_
outbox_url
(
@account
,
page_params
),
id:
outbox_url
(
page_params
),
type: :ordered
,
part_of:
account_
outbox_url
(
@account
)
,
part_of:
outbox_url
,
prev:
prev_page
,
next:
next_page
,
items:
@statuses
...
...
@@ -32,12 +32,20 @@ class ActivityPub::OutboxesController < ActivityPub::BaseController
id:
account_outbox_url
(
@account
),
type: :ordered
,
size:
@account
.
statuses_count
,
first:
account_
outbox_url
(
@account
,
page:
true
),
last:
account_
outbox_url
(
@account
,
page:
true
,
min_id:
0
)
first:
outbox_url
(
page:
true
),
last:
outbox_url
(
page:
true
,
min_id:
0
)
)
end
end
def
outbox_url
(
**
kwargs
)
if
params
[
:account_username
].
present?
account_outbox_url
(
@account
,
**
kwargs
)
else
instance_actor_outbox_url
(
**
kwargs
)
end
end
def
next_page
account_outbox_url
(
@account
,
page:
true
,
max_id:
@statuses
.
last
.
id
)
if
@statuses
.
size
==
LIMIT
end
...
...
@@ -49,9 +57,12 @@ class ActivityPub::OutboxesController < ActivityPub::BaseController
def
set_statuses
return
unless
page_requested?
@statuses
=
@account
.
statuses
.
permitted_for
(
@account
,
signed_request_account
)
@statuses
=
@statuses
.
paginate_by_id
(
LIMIT
,
params_slice
(
:max_id
,
:min_id
,
:since_id
))
@statuses
=
cache_collection
(
@statuses
,
Status
)
@statuses
=
cache_collection_paginated_by_id
(
@account
.
statuses
.
permitted_for
(
@account
,
signed_request_account
),
Status
,
LIMIT
,
params_slice
(
:max_id
,
:min_id
,
:since_id
)
)
end
def
page_requested?
...
...
@@ -61,4 +72,8 @@ class ActivityPub::OutboxesController < ActivityPub::BaseController
def
page_params
{
page:
true
,
max_id:
params
[
:max_id
],
min_id:
params
[
:min_id
]
}.
compact
end
def
set_account
@account
=
params
[
:account_username
].
present?
?
Account
.
find_local!
(
username_param
)
:
Account
.
representative
end
end
This diff is collapsed.
Click to expand it.
app/controllers/activitypub/replies_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -31,7 +31,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController
end
def
set_replies
@replies
=
only_other_accounts?
?
Status
.
where
.
not
(
account_id:
@account
.
id
)
:
@account
.
statuses
@replies
=
only_other_accounts?
?
Status
.
where
.
not
(
account_id:
@account
.
id
)
.
joins
(
:account
).
merge
(
Account
.
without_suspended
)
:
@account
.
statuses
@replies
=
@replies
.
where
(
in_reply_to_id:
@status
.
id
,
visibility:
[
:public
,
:unlisted
])
@replies
=
@replies
.
paginate_by_min_id
(
DESCENDANTS_LIMIT
,
params
[
:min_id
])
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/admin/accounts_controller.rb
+
27
-
11
View file @
824d1b88
...
...
@@ -2,7 +2,7 @@
module
Admin
class
AccountsController
<
BaseController
before_action
:set_account
,
only:
[
:show
,
:redownload
,
:remove_avatar
,
:remove_header
,
:enable
,
:unsilence
,
:unsuspend
,
:memorialize
,
:approve
,
:reject
]
before_action
:set_account
,
except:
[
:index
]
before_action
:require_remote_account!
,
only:
[
:redownload
]
before_action
:require_local_account!
,
only:
[
:enable
,
:memorialize
,
:approve
,
:reject
]
...
...
@@ -14,49 +14,65 @@ module Admin
def
show
authorize
@account
,
:show?
@deletion_request
=
@account
.
deletion_request
@account_moderation_note
=
current_account
.
account_moderation_notes
.
new
(
target_account:
@account
)
@moderation_notes
=
@account
.
targeted_moderation_notes
.
latest
@warnings
=
@account
.
targeted_account_warnings
.
latest
.
custom
@domain_block
=
DomainBlock
.
rule_for
(
@account
.
domain
)
end
def
memorialize
authorize
@account
,
:memorialize?
@account
.
memorialize!
log_action
:memorialize
,
@account
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.memorialized_msg'
,
username:
@account
.
acct
)
end
def
enable
authorize
@account
.
user
,
:enable?
@account
.
user
.
enable!
log_action
:enable
,
@account
.
user
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.enabled_msg'
,
username:
@account
.
acct
)
end
def
approve
authorize
@account
.
user
,
:approve?
@account
.
user
.
approve!
redirect_to
admin_pending_accounts_path
redirect_to
admin_pending_accounts_path
,
notice:
I18n
.
t
(
'admin.accounts.approved_msg'
,
username:
@account
.
acct
)
end
def
reject
authorize
@account
.
user
,
:reject?
SuspendAccountService
.
new
.
call
(
@account
,
reserve_email:
false
,
reserve_username:
false
)
redirect_to
admin_pending_accounts_path
DeleteAccountService
.
new
.
call
(
@account
,
reserve_email:
false
,
reserve_username:
false
)
redirect_to
admin_pending_accounts_path
,
notice:
I18n
.
t
(
'admin.accounts.rejected_msg'
,
username:
@account
.
acct
)
end
def
destroy
authorize
@account
,
:destroy?
Admin
::
AccountDeletionWorker
.
perform_async
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
),
notice:
I18n
.
t
(
'admin.accounts.destroyed_msg'
,
username:
@account
.
acct
)
end
def
unsensitive
authorize
@account
,
:unsensitive?
@account
.
unsensitize!
log_action
:unsensitive
,
@account
redirect_to
admin_account_path
(
@account
.
id
)
end
def
unsilence
authorize
@account
,
:unsilence?
@account
.
unsilence!
log_action
:unsilence
,
@account
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.unsilenced_msg'
,
username:
@account
.
acct
)
end
def
unsuspend
authorize
@account
,
:unsuspend?
@account
.
unsuspend!
Admin
::
UnsuspensionWorker
.
perform_async
(
@account
.
id
)
log_action
:unsuspend
,
@account
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.unsuspended_msg'
,
username:
@account
.
acct
)
end
def
redownload
...
...
@@ -65,7 +81,7 @@ module Admin
@account
.
update!
(
last_webfingered_at:
nil
)
ResolveAccountService
.
new
.
call
(
@account
)
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.redownloaded_msg'
,
username:
@account
.
acct
)
end
def
remove_avatar
...
...
@@ -76,7 +92,7 @@ module Admin
log_action
:remove_avatar
,
@account
.
user
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.removed_avatar_msg'
,
username:
@account
.
acct
)
end
def
remove_header
...
...
@@ -87,7 +103,7 @@ module Admin
log_action
:remove_header
,
@account
.
user
redirect_to
admin_account_path
(
@account
.
id
)
redirect_to
admin_account_path
(
@account
.
id
)
,
notice:
I18n
.
t
(
'admin.accounts.removed_header_msg'
,
username:
@account
.
acct
)
end
private
...
...
This diff is collapsed.
Click to expand it.
app/controllers/admin/announcements_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -71,7 +71,7 @@ class Admin::AnnouncementsController < Admin::BaseController
private
def
set_announcements
@announcements
=
AnnouncementFilter
.
new
(
filter_params
).
results
.
page
(
params
[
:page
])
@announcements
=
AnnouncementFilter
.
new
(
filter_params
).
results
.
reverse_chronological
.
page
(
params
[
:page
])
end
def
set_announcement
...
...
This diff is collapsed.
Click to expand it.
app/controllers/admin/domain_blocks_controller.rb
+
5
-
4
View file @
824d1b88
...
...
@@ -29,6 +29,7 @@ module Admin
@domain_block
=
existing_domain_block
@domain_block
.
update
(
resource_params
)
end
if
@domain_block
.
save
DomainBlockWorker
.
perform_async
(
@domain_block
.
id
)
log_action
:create
,
@domain_block
...
...
@@ -40,7 +41,7 @@ module Admin
end
def
update
authorize
:domain_block
,
:
cre
ate?
authorize
:domain_block
,
:
upd
ate?
@domain_block
.
update
(
update_params
)
...
...
@@ -48,7 +49,7 @@ module Admin
if
@domain_block
.
save
DomainBlockWorker
.
perform_async
(
@domain_block
.
id
,
severity_changed
)
log_action
:
cre
ate
,
@domain_block
log_action
:
upd
ate
,
@domain_block
redirect_to
admin_instances_path
(
limited:
'1'
),
notice:
I18n
.
t
(
'admin.domain_blocks.created_msg'
)
else
render
:edit
...
...
@@ -73,11 +74,11 @@ module Admin
end
def
update_params
params
.
require
(
:domain_block
).
permit
(
:severity
,
:reject_media
,
:reject_reports
,
:private_comment
,
:public_comment
)
params
.
require
(
:domain_block
).
permit
(
:severity
,
:reject_media
,
:reject_reports
,
:private_comment
,
:public_comment
,
:obfuscate
)
end
def
resource_params
params
.
require
(
:domain_block
).
permit
(
:domain
,
:severity
,
:reject_media
,
:reject_reports
,
:private_comment
,
:public_comment
)
params
.
require
(
:domain_block
).
permit
(
:domain
,
:severity
,
:reject_media
,
:reject_reports
,
:private_comment
,
:public_comment
,
:obfuscate
)
end
end
end
This diff is collapsed.
Click to expand it.
app/controllers/admin/email_domain_blocks_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -27,7 +27,7 @@ module Admin
ips
=
[]
Resolv
::
DNS
.
open
do
|
dns
|
dns
.
timeouts
=
1
dns
.
timeouts
=
5
hostnames
=
dns
.
getresources
(
@email_domain_block
.
domain
,
Resolv
::
DNS
::
Resource
::
IN
::
MX
).
to_a
.
map
{
|
e
|
e
.
exchange
.
to_s
}
...
...
This diff is collapsed.
Click to expand it.
app/controllers/admin/instances_controller.rb
+
5
-
39
View file @
824d1b88
...
...
@@ -2,65 +2,31 @@
module
Admin
class
InstancesController
<
BaseController
before_action
:set_domain_block
,
only: :show
before_action
:set_domain_allow
,
only: :show
before_action
:set_instances
,
only: :index
before_action
:set_instance
,
only: :show
def
index
authorize
:instance
,
:index?
@instances
=
ordered_instances
end
def
show
authorize
:instance
,
:show?
@following_count
=
Follow
.
where
(
account:
Account
.
where
(
domain:
params
[
:id
])).
count
@followers_count
=
Follow
.
where
(
target_account:
Account
.
where
(
domain:
params
[
:id
])).
count
@reports_count
=
Report
.
where
(
target_account:
Account
.
where
(
domain:
params
[
:id
])).
count
@blocks_count
=
Block
.
where
(
target_account:
Account
.
where
(
domain:
params
[
:id
])).
count
@available
=
DeliveryFailureTracker
.
available?
(
params
[
:id
])
@media_storage
=
MediaAttachment
.
where
(
account:
Account
.
where
(
domain:
params
[
:id
])).
sum
(
:file_file_size
)
@private_comment
=
@domain_block
&
.
private_comment
@public_comment
=
@domain_block
&
.
public_comment
end
private
def
set_domain_block
@domain_block
=
DomainBlock
.
rule_for
(
params
[
:id
])
end
def
set_domain_allow
@domain_allow
=
DomainAllow
.
rule_for
(
params
[
:id
])
end
def
set_instance
resource
=
Account
.
by_domain_accounts
.
find_by
(
domain:
params
[
:id
])
resource
||=
@domain_block
resource
||=
@domain_allow
@instance
=
Instance
.
find
(
params
[
:id
])
end
if
resource
@instance
=
Instance
.
new
(
resource
)
else
not_found
end
def
set_instances
@instances
=
filtered_instances
.
page
(
params
[
:page
])
end
def
filtered_instances
InstanceFilter
.
new
(
whitelist_mode?
?
{
allowed:
true
}
:
filter_params
).
results
end
def
paginated_instances
filtered_instances
.
page
(
params
[
:page
])
end
helper_method
:paginated_instances
def
ordered_instances
paginated_instances
.
map
{
|
resource
|
Instance
.
new
(
resource
)
}
end
def
filter_params
params
.
slice
(
*
InstanceFilter
::
KEYS
).
permit
(
*
InstanceFilter
::
KEYS
)
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/admin/ip_blocks_controller.rb
0 → 100644
+
56
-
0
View file @
824d1b88
# frozen_string_literal: true
module
Admin
class
IpBlocksController
<
BaseController
def
index
authorize
:ip_block
,
:index?
@ip_blocks
=
IpBlock
.
page
(
params
[
:page
])
@form
=
Form
::
IpBlockBatch
.
new
end
def
new
authorize
:ip_block
,
:create?
@ip_block
=
IpBlock
.
new
(
ip:
''
,
severity: :no_access
,
expires_in:
1
.
year
)
end
def
create
authorize
:ip_block
,
:create?
@ip_block
=
IpBlock
.
new
(
resource_params
)
if
@ip_block
.
save
log_action
:create
,
@ip_block
redirect_to
admin_ip_blocks_path
,
notice:
I18n
.
t
(
'admin.ip_blocks.created_msg'
)
else
render
:new
end
end
def
batch
@form
=
Form
::
IpBlockBatch
.
new
(
form_ip_block_batch_params
.
merge
(
current_account:
current_account
,
action:
action_from_button
))
@form
.
save
rescue
ActionController
::
ParameterMissing
flash
[
:alert
]
=
I18n
.
t
(
'admin.ip_blocks.no_ip_block_selected'
)
rescue
Mastodon
::
NotPermittedError
flash
[
:alert
]
=
I18n
.
t
(
'admin.custom_emojis.not_permitted'
)
ensure
redirect_to
admin_ip_blocks_path
end
private
def
resource_params
params
.
require
(
:ip_block
).
permit
(
:ip
,
:severity
,
:comment
,
:expires_in
)
end
def
action_from_button
'delete'
if
params
[
:delete
]
end
def
form_ip_block_batch_params
params
.
require
(
:form_ip_block_batch
).
permit
(
ip_block_ids:
[])
end
end
end
This diff is collapsed.
Click to expand it.
app/controllers/admin/statuses_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -14,7 +14,7 @@ module Admin
@statuses
=
@account
.
statuses
.
where
(
visibility:
[
:public
,
:unlisted
])
if
params
[
:media
]
account_media_status_ids
=
@account
.
media_attachments
.
attached
.
reorder
(
nil
).
select
(
:status_id
).
distinct
account_media_status_ids
=
@account
.
media_attachments
.
attached
.
reorder
(
nil
).
select
(
:status_id
).
group
(
:status_id
)
@statuses
.
merge!
(
Status
.
where
(
id:
account_media_status_ids
))
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/base_controller.rb
+
5
-
4
View file @
824d1b88
...
...
@@ -40,7 +40,7 @@ class Api::BaseController < ApplicationController
render
json:
{
error:
'This action is not allowed'
},
status:
403
end
rescue_from
Mastodon
::
RaceConditionError
do
rescue_from
Mastodon
::
RaceConditionError
,
Seahorse
::
Client
::
NetworkingError
,
Stoplight
::
Error
::
RedLight
do
render
json:
{
error:
'There was a temporary problem serving your request, please try again'
},
status:
503
end
...
...
@@ -71,6 +71,7 @@ class Api::BaseController < ApplicationController
def
limit_param
(
default_limit
)
return
default_limit
unless
params
[
:limit
]
[
params
[
:limit
].
to_i
.
abs
,
default_limit
*
2
].
min
end
...
...
@@ -95,14 +96,14 @@ class Api::BaseController < ApplicationController
def
require_user!
if
!
current_user
render
json:
{
error:
'This method requires an authenticated user'
},
status:
422
elsif
current_user
.
disabled?
render
json:
{
error:
'Your login is currently disabled'
},
status:
403
elsif
!
current_user
.
confirmed?
render
json:
{
error:
'Your login is missing a confirmed e-mail address'
},
status:
403
elsif
!
current_user
.
approved?
render
json:
{
error:
'Your login is currently pending approval'
},
status:
403
elsif
!
current_user
.
functional?
render
json:
{
error:
'Your login is currently disabled'
},
status:
403
else
set_user_activity
update_user_sign_in
end
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/featured_tags_controller.rb
0 → 100644
+
22
-
0
View file @
824d1b88
# frozen_string_literal: true
class
Api::V1::Accounts::FeaturedTagsController
<
Api
::
BaseController
before_action
:set_account
before_action
:set_featured_tags
respond_to
:json
def
index
render
json:
@featured_tags
,
each_serializer:
REST
::
FeaturedTagSerializer
end
private
def
set_account
@account
=
Account
.
find
(
params
[
:account_id
])
end
def
set_featured_tags
@featured_tags
=
@account
.
suspended?
?
[]
:
@account
.
featured_tags
end
end
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/follower_accounts_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -25,7 +25,7 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController
end
def
hide_results?
(
@account
.
hides_followers?
&&
current_account
&
.
id
!=
@account
.
id
)
||
(
current_account
&&
@account
.
blocking?
(
current_account
))
@account
.
suspended?
||
(
@account
.
hides_followers?
&&
current_account
&
.
id
!=
@account
.
id
)
||
(
current_account
&&
@account
.
blocking?
(
current_account
))
end
def
default_accounts
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/following_accounts_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -25,7 +25,7 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController
end
def
hide_results?
(
@account
.
hides_following?
&&
current_account
&
.
id
!=
@account
.
id
)
||
(
current_account
&&
@account
.
blocking?
(
current_account
))
@account
.
suspended?
||
(
@account
.
hides_following?
&&
current_account
&
.
id
!=
@account
.
id
)
||
(
current_account
&&
@account
.
blocking?
(
current_account
))
end
def
default_accounts
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/identity_proofs_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -5,7 +5,7 @@ class Api::V1::Accounts::IdentityProofsController < Api::BaseController
before_action
:set_account
def
index
@proofs
=
@account
.
identity_proofs
.
active
@proofs
=
@account
.
suspended?
?
[]
:
@account
.
identity_proofs
.
active
render
json:
@proofs
,
each_serializer:
REST
::
IdentityProofSerializer
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/lists_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -6,7 +6,7 @@ class Api::V1::Accounts::ListsController < Api::BaseController
before_action
:set_account
def
index
@lists
=
@account
.
lists
.
where
(
account:
current_account
)
@lists
=
@account
.
suspended?
?
[]
:
@account
.
lists
.
where
(
account:
current_account
)
render
json:
@lists
,
each_serializer:
REST
::
ListSerializer
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/relationships_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -5,7 +5,7 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController
before_action
:require_user!
def
index
accounts
=
Account
.
where
(
id:
account_ids
).
select
(
'id'
)
accounts
=
Account
.
without_suspended
.
where
(
id:
account_ids
).
select
(
'id'
)
# .where doesn't guarantee that our results are in the same order
# we requested them, so return the "right" order to the requestor.
@accounts
=
accounts
.
index_by
(
&
:id
).
values_at
(
*
account_ids
).
compact
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts/statuses_controller.rb
+
8
-
17
View file @
824d1b88
...
...
@@ -18,14 +18,10 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
end
def
load_statuses
cached_account_statuses
@account
.
suspended?
?
[]
:
cached_account_statuses
end
def
cached_account_statuses
cache_collection
account_statuses
,
Status
end
def
account_statuses
statuses
=
truthy_param?
(
:pinned
)
?
pinned_scope
:
permitted_account_statuses
statuses
.
merge!
(
only_media_scope
)
if
truthy_param?
(
:only_media
)
...
...
@@ -33,7 +29,12 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
statuses
.
merge!
(
no_reblogs_scope
)
if
truthy_param?
(
:exclude_reblogs
)
statuses
.
merge!
(
hashtag_scope
)
if
params
[
:tagged
].
present?
statuses
.
paginate_by_id
(
limit_param
(
DEFAULT_STATUSES_LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
))
cache_collection_paginated_by_id
(
statuses
,
Status
,
limit_param
(
DEFAULT_STATUSES_LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
)
)
end
def
permitted_account_statuses
...
...
@@ -41,17 +42,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
end
def
only_media_scope
Status
.
where
(
id:
account_media_status_ids
)
end
def
account_media_status_ids
# `SELECT DISTINCT id, updated_at` is too slow, so pluck ids at first, and then select id, updated_at with ids.
# Also, Avoid getting slow by not narrowing down by `statuses.account_id`.
# When narrowing down by `statuses.account_id`, `index_statuses_20180106` will be used
# and the table will be joined by `Merge Semi Join`, so the query will be slow.
@account
.
statuses
.
joins
(
:media_attachments
).
merge
(
@account
.
media_attachments
).
permitted_for
(
@account
,
current_account
)
.
paginate_by_max_id
(
limit_param
(
DEFAULT_STATUSES_LIMIT
),
params
[
:max_id
],
params
[
:since_id
])
.
reorder
(
id: :desc
).
distinct
(
:id
).
pluck
(
:id
)
Status
.
joins
(
:media_attachments
).
merge
(
@account
.
media_attachments
.
reorder
(
nil
)).
group
(
:id
)
end
def
pinned_scope
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/accounts_controller.rb
+
4
-
10
View file @
824d1b88
...
...
@@ -9,7 +9,6 @@ class Api::V1::AccountsController < Api::BaseController
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
...
...
@@ -21,7 +20,7 @@ class Api::V1::AccountsController < Api::BaseController
end
def
create
token
=
AppSignUpService
.
new
.
call
(
doorkeeper_token
.
application
,
account_params
)
token
=
AppSignUpService
.
new
.
call
(
doorkeeper_token
.
application
,
request
.
remote_ip
,
account_params
)
response
=
Doorkeeper
::
OAuth
::
TokenResponse
.
new
(
token
)
headers
.
merge!
(
response
.
headers
)
...
...
@@ -31,9 +30,8 @@ class Api::V1::AccountsController < Api::BaseController
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
}
}
follow
=
FollowService
.
new
.
call
(
current_user
.
account
,
@account
,
reblogs:
params
.
key?
(
:reblogs
)
?
truthy_param?
(
:reblogs
)
:
nil
,
notify:
params
.
key?
(
:notify
)
?
truthy_param?
(
:notify
)
:
nil
,
with_rate_limit:
true
)
options
=
@account
.
locked?
||
current_user
.
account
.
silenced?
?
{}
:
{
following_map:
{
@account
.
id
=>
{
reblogs:
follow
.
show_reblogs?
,
notify:
follow
.
notify?
}
},
requested_map:
{
@account
.
id
=>
false
}
}
render
json:
@account
,
serializer:
REST
::
RelationshipSerializer
,
relationships:
relationships
(
options
)
end
...
...
@@ -44,7 +42,7 @@ class Api::V1::AccountsController < Api::BaseController
end
def
mute
MuteService
.
new
.
call
(
current_user
.
account
,
@account
,
notifications:
truthy_param?
(
:notifications
))
MuteService
.
new
.
call
(
current_user
.
account
,
@account
,
notifications:
truthy_param?
(
:notifications
)
,
duration:
(
params
[
:duration
]
||
0
)
)
render
json:
@account
,
serializer:
REST
::
RelationshipSerializer
,
relationships:
relationships
end
...
...
@@ -73,10 +71,6 @@ class Api::V1::AccountsController < Api::BaseController
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
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/admin/accounts_controller.rb
+
17
-
2
View file @
824d1b88
...
...
@@ -22,6 +22,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController
active
pending
disabled
sensitized
silenced
suspended
username
...
...
@@ -58,7 +59,20 @@ class Api::V1::Admin::AccountsController < Api::BaseController
def
reject
authorize
@account
.
user
,
:reject?
SuspendAccountService
.
new
.
call
(
@account
,
reserve_email:
false
,
reserve_username:
false
)
DeleteAccountService
.
new
.
call
(
@account
,
reserve_email:
false
,
reserve_username:
false
)
render
json:
@account
,
serializer:
REST
::
Admin
::
AccountSerializer
end
def
destroy
authorize
@account
,
:destroy?
Admin
::
AccountDeletionWorker
.
perform_async
(
@account
.
id
)
render
json:
@account
,
serializer:
REST
::
Admin
::
AccountSerializer
end
def
unsensitive
authorize
@account
,
:unsensitive?
@account
.
unsensitize!
log_action
:unsensitive
,
@account
render
json:
@account
,
serializer:
REST
::
Admin
::
AccountSerializer
end
...
...
@@ -72,6 +86,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController
def
unsuspend
authorize
@account
,
:unsuspend?
@account
.
unsuspend!
Admin
::
UnsuspensionWorker
.
perform_async
(
@account
.
id
)
log_action
:unsuspend
,
@account
render
json:
@account
,
serializer:
REST
::
Admin
::
AccountSerializer
end
...
...
@@ -79,7 +94,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController
private
def
set_accounts
@accounts
=
filtered_accounts
.
order
(
id: :desc
).
includes
(
user:
[
:invite_request
,
:invite
]).
paginate_by_id
(
limit_param
(
LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
))
@accounts
=
filtered_accounts
.
order
(
id: :desc
).
includes
(
user:
[
:invite_request
,
:invite
]).
to_a_
paginate
d
_by_id
(
limit_param
(
LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
))
end
def
set_account
...
...
This diff is collapsed.
Click to expand it.
app/controllers/api/v1/admin/reports_controller.rb
+
1
-
1
View file @
824d1b88
...
...
@@ -63,7 +63,7 @@ class Api::V1::Admin::ReportsController < Api::BaseController
private
def
set_reports
@reports
=
filtered_reports
.
order
(
id: :desc
).
with_accounts
.
paginate_by_id
(
limit_param
(
LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
))
@reports
=
filtered_reports
.
order
(
id: :desc
).
with_accounts
.
to_a_
paginate
d
_by_id
(
limit_param
(
LIMIT
),
params_slice
(
:max_id
,
:since_id
,
:min_id
))
end
def
set_report
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
6
…
46
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment