Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- `app/javascript/packs/public.js`:
  Upstream removed an unused function in code that has
  been refactored a bit. Removed that function in the corresponding
  places.
This commit is contained in:
Thibaut Girka
2020-01-20 18:31:11 +01:00
35 changed files with 165 additions and 202 deletions

View File

@ -109,21 +109,7 @@ module Admin
end
def filter_params
params.permit(
:local,
:remote,
:by_domain,
:active,
:pending,
:disabled,
:silenced,
:suspended,
:username,
:display_name,
:email,
:ip,
:staff
)
params.slice(*AccountFilter::KEYS).permit(*AccountFilter::KEYS)
end
end
end

View File

@ -48,7 +48,7 @@ module Admin
end
def filter_params
params.slice(:local, :remote, :by_domain, :shortcode, :page).permit(:local, :remote, :by_domain, :shortcode, :page)
params.slice(:page, *CustomEmojiFilter::KEYS).permit(:page, *CustomEmojiFilter::KEYS)
end
def action_from_button

View File

@ -62,7 +62,7 @@ module Admin
end
def filter_params
params.permit(:limited, :by_domain)
params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
end
end
end

View File

@ -47,7 +47,7 @@ module Admin
end
def filter_params
params.permit(:available, :expired)
params.slice(*InviteFilter::KEYS).permit(*InviteFilter::KEYS)
end
end
end

View File

@ -52,12 +52,7 @@ module Admin
end
def filter_params
params.permit(
:account_id,
:resolved,
:target_account_id,
:by_target_domain
)
params.slice(*ReportFilter::KEYS).permit(*ReportFilter::KEYS)
end
def set_report

View File

@ -73,7 +73,7 @@ module Admin
end
def filter_params
params.slice(:directory, :reviewed, :unreviewed, :pending_review, :page, :popular, :active, :name).permit(:directory, :reviewed, :unreviewed, :pending_review, :page, :popular, :active, :name)
params.slice(:page, *TagFilter::KEYS).permit(:page, *TagFilter::KEYS)
end
def tag_params

View File

@ -86,7 +86,7 @@ class RelationshipsController < ApplicationController
end
def current_params
params.slice(:page, :status, :relationship, :by_domain, :activity, :order).permit(:page, :status, :relationship, :by_domain, :activity, :order)
params.slice(:page, *RelationshipFilter::KEYS).permit(:page, *RelationshipFilter::KEYS)
end
def action_from_button

View File

@ -1,15 +1,15 @@
# frozen_string_literal: true
module Admin::FilterHelper
ACCOUNT_FILTERS = %i(local remote by_domain active pending silenced suspended username display_name email ip staff).freeze
REPORT_FILTERS = %i(resolved account_id target_account_id by_target_domain).freeze
INVITE_FILTER = %i(available expired).freeze
CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze
TAGS_FILTERS = %i(directory reviewed unreviewed pending_review popular active name).freeze
INSTANCES_FILTERS = %i(limited by_domain).freeze
FOLLOWERS_FILTERS = %i(relationship status by_domain activity order).freeze
FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS + INSTANCES_FILTERS + FOLLOWERS_FILTERS
FILTERS = [
AccountFilter::KEYS,
CustomEmojiFilter::KEYS,
ReportFilter::KEYS,
TagFilter::KEYS,
InstanceFilter::KEYS,
InviteFilter::KEYS,
RelationshipFilter::KEYS,
].flatten.freeze
def filter_link_to(text, link_to_params, link_class_params = link_to_params)
new_url = filtered_url_for(link_to_params)

View File

@ -97,15 +97,6 @@ function main() {
delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
delegate(document, '.blocks-table button.icon-button', 'click', function(e) {
e.preventDefault();
const classList = this.firstElementChild.classList;
classList.toggle('fa-chevron-down');
classList.toggle('fa-chevron-up');
this.parentElement.parentElement.nextElementSibling.classList.toggle('hidden');
});
});
delegate(document, '.sidebar__toggle__icon', 'click', () => {

View File

@ -296,7 +296,7 @@ export default class ScrollableList extends PureComponent {
</div>
</div>
);
} else if (isLoading || childrenCount > 0 || hasMore || !emptyMessage) {
} else if (isLoading || childrenCount > 0 || numPending > 0 || hasMore || !emptyMessage) {
scrollableArea = (
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef} onMouseMove={this.handleMouseMove}>
<div role='feed' className='item-list'>

View File

@ -101,15 +101,6 @@ function main() {
delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
delegate(document, '.blocks-table button.icon-button', 'click', function(e) {
e.preventDefault();
const classList = this.firstElementChild.classList;
classList.toggle('fa-chevron-down');
classList.toggle('fa-chevron-up');
this.parentElement.parentElement.nextElementSibling.classList.toggle('hidden');
});
});
delegate(document, '.sidebar__toggle__icon', 'click', () => {

View File

@ -1,6 +1,21 @@
# frozen_string_literal: true
class AccountFilter
KEYS = %i(
local
remote
by_domain
active
pending
silenced
suspended
username
display_name
email
ip
staff
).freeze
attr_reader :params
def initialize(params)
@ -50,7 +65,7 @@ class AccountFilter
when 'email'
accounts_with_users.merge User.matches_email(value)
when 'ip'
valid_ip?(value) ? accounts_with_users.where('users.current_sign_in_ip <<= ?', value) : Account.none
valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value)) : Account.none
when 'staff'
accounts_with_users.merge User.staff
else

View File

@ -1,6 +1,13 @@
# frozen_string_literal: true
class CustomEmojiFilter
KEYS = %i(
local
remote
by_domain
shortcode
).freeze
attr_reader :params
def initialize(params)

View File

@ -1,6 +1,11 @@
# frozen_string_literal: true
class InstanceFilter
KEYS = %i(
limited
by_domain
).freeze
attr_reader :params
def initialize(params)

View File

@ -1,6 +1,11 @@
# frozen_string_literal: true
class InviteFilter
KEYS = %i(
available
expired
).freeze
attr_reader :params
def initialize(params)

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class RelationshipFilter
KEYS = %i(
relationship
status
by_domain
activity
order
).freeze
end

View File

@ -1,6 +1,13 @@
# frozen_string_literal: true
class ReportFilter
KEYS = %i(
resolved
account_id
target_account_id
by_target_domain
).freeze
attr_reader :params
def initialize(params)

View File

@ -1,6 +1,16 @@
# frozen_string_literal: true
class TagFilter
KEYS = %i(
directory
reviewed
unreviewed
pending_review
popular
active
name
).freeze
attr_reader :params
def initialize(params)

View File

@ -93,6 +93,7 @@ class User < ApplicationRecord
scope :inactive, -> { where(arel_table[:current_sign_in_at].lt(ACTIVE_DURATION.ago)) }
scope :active, -> { confirmed.where(arel_table[:current_sign_in_at].gteq(ACTIVE_DURATION.ago)).joins(:account).where(accounts: { suspended_at: nil }) }
scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) }
scope :matches_ip, ->(value) { left_joins(:session_activations).where('users.current_sign_in_ip <<= ?', value).or(left_joins(:session_activations).where('users.last_sign_in_ip <<= ?', value)).or(left_joins(:session_activations).where('session_activations.ip <<= ?', value)) }
scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) }
before_validation :sanitize_languages
@ -290,6 +291,21 @@ class User < ApplicationRecord
setting_display_media == 'hide_all'
end
def recent_ips
@recent_ips ||= begin
arr = []
session_activations.each do |session_activation|
arr << [session_activation.updated_at, session_activation.ip]
end
arr << [current_sign_in_at, current_sign_in_ip] if current_sign_in_ip.present?
arr << [last_sign_in_at, last_sign_in_ip] if last_sign_in_ip.present?
arr.sort_by(&:first).uniq(&:last).reverse!
end
end
protected
def send_devise_notification(notification, *args)

View File

@ -22,7 +22,7 @@
= form_tag admin_accounts_url, method: 'GET', class: 'simple_form' do
.fields-group
- Admin::FilterHelper::ACCOUNT_FILTERS.each do |key|
- AccountFilter::KEYS.each do |key|
- if params[key].present?
= hidden_field_tag key, params[key]

View File

@ -139,12 +139,12 @@
%time.formatted{ datetime: @account.created_at.iso8601, title: l(@account.created_at) }= l @account.created_at
%td
%tr
%th= t('admin.accounts.most_recent_ip')
%td= @account.user_current_sign_in_ip
%td
- if @account.user_current_sign_in_ip
= table_link_to 'search', t('admin.accounts.search_same_ip'), admin_accounts_path(ip: @account.user_current_sign_in_ip)
- @account.user.recent_ips.each_with_index do |(_, ip), i|
%tr
- if i.zero?
%th{ rowspan: @account.user.recent_ips.size }= t('admin.accounts.most_recent_ip')
%td= ip
%td= table_link_to 'search', t('admin.accounts.search_same_ip'), admin_accounts_path(ip: ip)
%tr
%th= t('admin.accounts.most_recent_activity')

View File

@ -22,7 +22,7 @@
= form_tag admin_custom_emojis_url, method: 'GET', class: 'simple_form' do
.fields-group
- Admin::FilterHelper::CUSTOM_EMOJI_FILTERS.each do |key|
- CustomEmojiFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
- %i(shortcode by_domain).each do |key|
@ -36,7 +36,7 @@
= form_for(@form, url: batch_admin_custom_emojis_path) do |f|
= hidden_field_tag :page, params[:page] || 1
- Admin::FilterHelper::CUSTOM_EMOJI_FILTERS.each do |key|
- CustomEmojiFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
.batch-table

View File

@ -4,7 +4,7 @@
- content_for :heading_actions do
= link_to t('admin.email_domain_blocks.add_new'), new_admin_email_domain_block_path, class: 'button'
- if @email_domain_blocks.count == 0
- if @email_domain_blocks.empty?
%div.muted-hint.center-text=t 'admin.email_domain_blocks.empty'
- else
.table-wrapper

View File

@ -19,9 +19,8 @@
- unless whitelist_mode?
= form_tag admin_instances_url, method: 'GET', class: 'simple_form' do
.fields-group
- Admin::FilterHelper::INSTANCES_FILTERS.each do |key|
- if params[key].present?
= hidden_field_tag key, params[key]
- InstanceFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
- %i(by_domain).each do |key|
.input.string.optional

View File

@ -15,7 +15,7 @@
- if status.proper.media_attachments.first.video?
- video = status.proper.media_attachments.first
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), blurhash: video.blurhash, sensitive: status.proper.sensitive?, visible: false, width: 610, height: 343, inline: true, alt: video.description
- elsif status.media_attachments.first.audio?
- elsif status.proper.media_attachments.first.audio?
- audio = status.proper.media_attachments.first
= react_component :audio, src: audio.file.url(:original), height: 110, alt: audio.description, duration: audio.file.meta.dig(:original, :duration)
- else

View File

@ -10,9 +10,8 @@
= form_tag admin_reports_url, method: 'GET', class: 'simple_form' do
.fields-group
- Admin::FilterHelper::REPORT_FILTERS.each do |key|
- if params[key].present?
= hidden_field_tag key, params[key]
- ReportFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
- %i(by_target_domain).each do |key|
.input.string.optional

View File

@ -25,7 +25,7 @@
= form_tag admin_tags_url, method: 'GET', class: 'simple_form' do
.fields-group
- Admin::FilterHelper::TAGS_FILTERS.each do |key|
- TagFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
- %i(name).each do |key|
@ -40,9 +40,8 @@
= form_for(@form, url: batch_admin_tags_path) do |f|
= hidden_field_tag :page, params[:page] || 1
= hidden_field_tag :name, params[:name] if params[:name].present?
- Admin::FilterHelper::TAGS_FILTERS.each do |key|
- TagFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
.batch-table.optional

View File

@ -4,7 +4,7 @@
- content_for :heading_actions do
= link_to t('filters.new.title'), new_filter_path, class: 'button'
- if @filters.count == 0
- if @filters.empty?
%div.muted-hint.center-text= t 'filters.index.empty'
- else
.table-wrapper

View File

@ -30,10 +30,9 @@
= form_for(@form, url: relationships_path, method: :patch) do |f|
= hidden_field_tag :page, params[:page] || 1
= hidden_field_tag :relationship, params[:relationship]
= hidden_field_tag :status, params[:status]
= hidden_field_tag :activity, params[:activity]
= hidden_field_tag :order, params[:order]
- RelationshipFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?
.batch-table
.batch-table__toolbar

View File

@ -4,7 +4,7 @@
- content_for :heading_actions do
= link_to t('doorkeeper.applications.index.new'), new_settings_application_path, class: 'button'
- if @applications.count == 0
- if @applications.empty?
%div.muted-hint.center-text=t 'doorkeeper.applications.index.empty'
- else
.table-wrapper