Merge branch 'master' into for-upstream/optional-notification-muting

This commit is contained in:
Eugen Rochko
2017-11-15 03:36:01 +01:00
committed by GitHub
227 changed files with 4735 additions and 2420 deletions

View File

@@ -3,7 +3,7 @@
#
# Table name: accounts
#
# id :integer not null, primary key
# id :bigint not null, primary key
# username :string default(""), not null
# domain :string
# secret :string default(""), not null
@@ -41,10 +41,11 @@
# shared_inbox_url :string default(""), not null
# followers_url :string default(""), not null
# protocol :integer default("ostatus"), not null
# memorial :boolean default(FALSE), not null
#
class Account < ApplicationRecord
MENTION_RE = /(?:^|[^\/[:word:]])@(([a-z0-9_]+)(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
MENTION_RE = /(?<=^|[^\/[:word:]])@(([a-z0-9_]+)(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
include AccountAvatar
include AccountFinderConcern
@@ -150,6 +151,20 @@ class Account < ApplicationRecord
ResolveRemoteAccountService.new.call(acct)
end
def unsuspend!
transaction do
user&.enable! if local?
update!(suspended: false)
end
end
def memorialize!
transaction do
user&.disable! if local?
update!(memorial: true)
end
end
def keypair
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
end

View File

@@ -6,8 +6,8 @@
# domain :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# id :integer not null, primary key
# account_id :bigint
# id :bigint not null, primary key
#
class AccountDomainBlock < ApplicationRecord

View File

@@ -3,10 +3,10 @@
#
# Table name: account_moderation_notes
#
# id :integer not null, primary key
# id :bigint not null, primary key
# content :text not null
# account_id :integer not null
# target_account_id :integer not null
# account_id :bigint not null
# target_account_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@@ -5,9 +5,9 @@
#
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# id :integer not null, primary key
# target_account_id :integer not null
# account_id :bigint not null
# id :bigint not null, primary key
# target_account_id :bigint not null
#
class Block < ApplicationRecord

View File

@@ -3,7 +3,7 @@
#
# Table name: conversations
#
# id :integer not null, primary key
# id :bigint not null, primary key
# uri :string
# created_at :datetime not null
# updated_at :datetime not null

View File

@@ -3,9 +3,9 @@
#
# Table name: conversation_mutes
#
# conversation_id :integer not null
# account_id :integer not null
# id :integer not null, primary key
# conversation_id :bigint not null
# account_id :bigint not null
# id :bigint not null, primary key
#
class ConversationMute < ApplicationRecord

View File

@@ -3,7 +3,7 @@
#
# Table name: custom_emojis
#
# id :integer not null, primary key
# id :bigint not null, primary key
# shortcode :string default(""), not null
# domain :string
# image_file_name :string
@@ -15,6 +15,7 @@
# disabled :boolean default(FALSE), not null
# uri :string
# image_remote_url :string
# visible_in_picker :boolean default(TRUE), not null
#
class CustomEmoji < ApplicationRecord
@@ -24,6 +25,8 @@ class CustomEmoji < ApplicationRecord
:(#{SHORTCODE_RE_FRAGMENT}):
(?=[^[:alnum:]:]|$)/x
has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }
validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { in: 0..50.kilobytes }

View File

@@ -8,7 +8,7 @@
# updated_at :datetime not null
# severity :integer default("silence")
# reject_media :boolean default(FALSE), not null
# id :integer not null, primary key
# id :bigint not null, primary key
#
class DomainBlock < ApplicationRecord

View File

@@ -3,15 +3,34 @@
#
# Table name: email_domain_blocks
#
# id :integer not null, primary key
# domain :string not null
# id :bigint not null, primary key
# domain :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class EmailDomainBlock < ApplicationRecord
before_validation :normalize_domain
validates :domain, presence: true, uniqueness: true
def self.block?(email)
domain = email.gsub(/.+@([^.]+)/, '\1')
_, domain = email.split('@', 2)
return true if domain.nil?
begin
domain = TagManager.instance.normalize_domain(domain)
rescue Addressable::URI::InvalidURIError
return true
end
where(domain: domain).exists?
end
private
def normalize_domain
self.domain = TagManager.instance.normalize_domain(domain)
end
end

View File

@@ -5,9 +5,9 @@
#
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# id :integer not null, primary key
# status_id :integer not null
# account_id :bigint not null
# id :bigint not null, primary key
# status_id :bigint not null
#
class Favourite < ApplicationRecord

View File

@@ -5,9 +5,9 @@
#
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# id :integer not null, primary key
# target_account_id :integer not null
# account_id :bigint not null
# id :bigint not null, primary key
# target_account_id :bigint not null
#
class Follow < ApplicationRecord

View File

@@ -5,9 +5,9 @@
#
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# id :integer not null, primary key
# target_account_id :integer not null
# account_id :bigint not null
# id :bigint not null, primary key
# target_account_id :bigint not null
#
class FollowRequest < ApplicationRecord
@@ -27,7 +27,5 @@ class FollowRequest < ApplicationRecord
destroy!
end
def reject!
destroy!
end
alias reject! destroy!
end

View File

@@ -11,8 +11,8 @@
# data_content_type :string
# data_file_size :integer
# data_updated_at :datetime
# account_id :integer not null
# id :integer not null, primary key
# account_id :bigint not null
# id :bigint not null, primary key
#
class Import < ApplicationRecord

View File

@@ -3,14 +3,14 @@
#
# Table name: media_attachments
#
# id :integer not null, primary key
# status_id :integer
# id :bigint not null, primary key
# status_id :bigint
# file_file_name :string
# file_content_type :string
# file_file_size :integer
# file_updated_at :datetime
# remote_url :string default(""), not null
# account_id :integer
# account_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# shortcode :string

View File

@@ -3,11 +3,11 @@
#
# Table name: mentions
#
# status_id :integer
# status_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# id :integer not null, primary key
# account_id :bigint
# id :bigint not null, primary key
#
class Mention < ApplicationRecord

View File

@@ -3,13 +3,13 @@
#
# Table name: notifications
#
# id :integer not null, primary key
# account_id :integer
# activity_id :integer
# id :bigint not null, primary key
# account_id :bigint
# activity_id :bigint
# activity_type :string
# created_at :datetime not null
# updated_at :datetime not null
# from_account_id :integer
# from_account_id :bigint
#
class Notification < ApplicationRecord

View File

@@ -3,7 +3,7 @@
#
# Table name: preview_cards
#
# id :integer not null, primary key
# id :bigint not null, primary key
# url :string default(""), not null
# title :string default(""), not null
# description :string default(""), not null

View File

@@ -8,10 +8,10 @@
# action_taken :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# action_taken_by_account_id :integer
# id :integer not null, primary key
# target_account_id :integer not null
# account_id :bigint not null
# action_taken_by_account_id :bigint
# id :bigint not null, primary key
# target_account_id :bigint not null
#
class Report < ApplicationRecord

View File

@@ -3,25 +3,25 @@
#
# Table name: session_activations
#
# id :integer not null, primary key
# user_id :integer not null
# id :bigint not null, primary key
# user_id :bigint not null
# session_id :string not null
# created_at :datetime not null
# updated_at :datetime not null
# user_agent :string default(""), not null
# ip :inet
# access_token_id :integer
# web_push_subscription_id :integer
# access_token_id :bigint
# web_push_subscription_id :bigint
#
# id :integer not null, primary key
# user_id :integer not null
# id :bigint not null, primary key
# user_id :bigint not null
# session_id :string not null
# created_at :datetime not null
# updated_at :datetime not null
# user_agent :string default(""), not null
# ip :inet
# access_token_id :integer
# access_token_id :bigint
#
class SessionActivation < ApplicationRecord

View File

@@ -8,8 +8,8 @@
# thing_type :string
# created_at :datetime
# updated_at :datetime
# id :integer not null, primary key
# thing_id :integer
# id :bigint not null, primary key
# thing_id :bigint
#
class Setting < RailsSettings::Base

View File

@@ -3,7 +3,7 @@
#
# Table name: site_uploads
#
# id :integer not null, primary key
# id :bigint not null, primary key
# var :string default(""), not null
# file_file_name :string
# file_content_type :string

View File

@@ -3,25 +3,25 @@
#
# Table name: statuses
#
# id :integer not null, primary key
# id :bigint not null, primary key
# uri :string
# account_id :integer not null
# account_id :bigint not null
# text :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# in_reply_to_id :integer
# reblog_of_id :integer
# in_reply_to_id :bigint
# reblog_of_id :bigint
# url :string
# sensitive :boolean default(FALSE), not null
# visibility :integer default("public"), not null
# in_reply_to_account_id :integer
# application_id :integer
# in_reply_to_account_id :bigint
# application_id :bigint
# spoiler_text :text default(""), not null
# reply :boolean default(FALSE), not null
# favourites_count :integer default(0), not null
# reblogs_count :integer default(0), not null
# language :string
# conversation_id :integer
# conversation_id :bigint
# local :boolean
#

View File

@@ -3,9 +3,9 @@
#
# Table name: status_pins
#
# id :integer not null, primary key
# account_id :integer not null
# status_id :integer not null
# id :bigint not null, primary key
# account_id :bigint not null
# status_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@@ -3,13 +3,13 @@
#
# Table name: stream_entries
#
# activity_id :integer
# activity_id :bigint
# activity_type :string
# created_at :datetime not null
# updated_at :datetime not null
# hidden :boolean default(FALSE), not null
# account_id :integer
# id :integer not null, primary key
# account_id :bigint
# id :bigint not null, primary key
#
class StreamEntry < ApplicationRecord

View File

@@ -11,8 +11,8 @@
# updated_at :datetime not null
# last_successful_delivery_at :datetime
# domain :string
# account_id :integer not null
# id :integer not null, primary key
# account_id :bigint not null
# id :bigint not null, primary key
#
class Subscription < ApplicationRecord

View File

@@ -3,7 +3,7 @@
#
# Table name: tags
#
# id :integer not null, primary key
# id :bigint not null, primary key
# name :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null

View File

@@ -3,9 +3,8 @@
#
# Table name: users
#
# id :integer not null, primary key
# id :bigint not null, primary key
# email :string default(""), not null
# account_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# encrypted_password :string default(""), not null
@@ -31,10 +30,14 @@
# last_emailed_at :datetime
# otp_backup_codes :string is an Array
# filtered_languages :string default([]), not null, is an Array
# account_id :bigint not null
# disabled :boolean default(FALSE), not null
# moderator :boolean default(FALSE), not null
#
class User < ApplicationRecord
include Settings::Extend
ACTIVE_DURATION = 14.days
devise :registerable, :recoverable,
@@ -51,8 +54,10 @@ class User < ApplicationRecord
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
validates_with BlacklistedEmailValidator, if: :email_changed?
scope :recent, -> { order(id: :desc) }
scope :admins, -> { where(admin: true) }
scope :recent, -> { order(id: :desc) }
scope :admins, -> { where(admin: true) }
scope :moderators, -> { where(moderator: true) }
scope :staff, -> { admins.or(moderators) }
scope :confirmed, -> { where.not(confirmed_at: nil) }
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: false }) }
@@ -72,12 +77,61 @@ class User < ApplicationRecord
confirmed_at.present?
end
def staff?
admin? || moderator?
end
def role
if admin?
'admin'
elsif moderator?
'moderator'
else
'user'
end
end
def disable!
update!(disabled: true,
last_sign_in_at: current_sign_in_at,
current_sign_in_at: nil)
end
def enable!
update!(disabled: false)
end
def confirm!
skip_confirmation!
save!
end
def promote!
if moderator?
update!(moderator: false, admin: true)
elsif !admin?
update!(moderator: true)
end
end
def demote!
if admin?
update!(admin: false, moderator: true)
elsif moderator?
update!(moderator: false)
end
end
def disable_two_factor!
self.otp_required_for_login = false
otp_backup_codes&.clear
save!
end
def active_for_authentication?
super && !disabled?
end
def setting_default_privacy
settings.default_privacy || (account.locked? ? 'private' : 'public')
end

View File

@@ -3,7 +3,7 @@
#
# Table name: web_push_subscriptions
#
# id :integer not null, primary key
# id :bigint not null, primary key
# endpoint :string not null
# key_p256dh :string not null
# key_auth :string not null

View File

@@ -6,8 +6,8 @@
# data :json
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# user_id :integer
# id :bigint not null, primary key
# user_id :bigint
#
class Web::Setting < ApplicationRecord