diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account_identity_proof.rb | 46 | ||||
-rw-r--r-- | app/models/concerns/account_associations.rb | 3 | ||||
-rw-r--r-- | app/models/form/account_batch.rb | 60 | ||||
-rw-r--r-- | app/models/poll.rb | 4 | ||||
-rw-r--r-- | app/models/report.rb | 11 | ||||
-rw-r--r-- | app/models/status.rb | 12 |
6 files changed, 133 insertions, 3 deletions
diff --git a/app/models/account_identity_proof.rb b/app/models/account_identity_proof.rb new file mode 100644 index 000000000..e7a3f97e5 --- /dev/null +++ b/app/models/account_identity_proof.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true +# == Schema Information +# +# Table name: account_identity_proofs +# +# id :bigint(8) not null, primary key +# account_id :bigint(8) +# provider :string default(""), not null +# provider_username :string default(""), not null +# token :text default(""), not null +# verified :boolean default(FALSE), not null +# live :boolean default(FALSE), not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class AccountIdentityProof < ApplicationRecord + belongs_to :account + + validates :provider, inclusion: { in: ProofProvider::SUPPORTED_PROVIDERS } + validates :provider_username, format: { with: /\A[a-z0-9_]+\z/i }, length: { minimum: 2, maximum: 15 } + validates :provider_username, uniqueness: { scope: [:account_id, :provider] } + validates :token, format: { with: /\A[a-f0-9]+\z/ }, length: { maximum: 66 } + + validate :validate_with_provider, if: :token_changed? + + scope :active, -> { where(verified: true, live: true) } + + after_create_commit :queue_worker + + delegate :refresh!, :on_success_path, :badge, to: :provider_instance + + private + + def provider_instance + @provider_instance ||= ProofProvider.find(provider, self) + end + + def queue_worker + provider_instance.worker_class.perform_async(id) + end + + def validate_with_provider + provider_instance.validate! + end +end diff --git a/app/models/concerns/account_associations.rb b/app/models/concerns/account_associations.rb index 1b22f750c..ecccaf35e 100644 --- a/app/models/concerns/account_associations.rb +++ b/app/models/concerns/account_associations.rb @@ -7,6 +7,9 @@ module AccountAssociations # Local users has_one :user, inverse_of: :account, dependent: :destroy + # Identity proofs + has_many :identity_proofs, class_name: 'AccountIdentityProof', dependent: :destroy, inverse_of: :account + # Timelines has_many :stream_entries, inverse_of: :account, dependent: :destroy has_many :statuses, inverse_of: :account, dependent: :destroy diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb new file mode 100644 index 000000000..60eaaf0e2 --- /dev/null +++ b/app/models/form/account_batch.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +class Form::AccountBatch + include ActiveModel::Model + + attr_accessor :account_ids, :action, :current_account + + def save + case action + when 'unfollow' + unfollow! + when 'remove_from_followers' + remove_from_followers! + when 'block_domains' + block_domains! + end + end + + private + + def unfollow! + accounts.find_each do |target_account| + UnfollowService.new.call(current_account, target_account) + end + end + + def remove_from_followers! + current_account.passive_relationships.where(account_id: account_ids).find_each do |follow| + reject_follow!(follow) + end + end + + def block_domains! + AfterAccountDomainBlockWorker.push_bulk(account_domains) do |domain| + [current_account.id, domain] + end + end + + def account_domains + accounts.pluck(Arel.sql('distinct domain')).compact + end + + def accounts + Account.where(id: account_ids) + end + + def reject_follow!(follow) + follow.destroy + + return unless follow.account.activitypub? + + json = ActiveModelSerializers::SerializableResource.new( + follow, + serializer: ActivityPub::RejectFollowSerializer, + adapter: ActivityPub::Adapter + ).to_json + + ActivityPub::DeliveryWorker.perform_async(json, current_account.id, follow.account.inbox_url) + end +end diff --git a/app/models/poll.rb b/app/models/poll.rb index 6df230337..8f72c7b11 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -60,6 +60,10 @@ class Poll < ApplicationRecord !local? end + def emojis + @emojis ||= CustomEmoji.from_text(options.join(' '), account.domain) + end + class Option < ActiveModelSerializers::Model attributes :id, :title, :votes_count, :poll diff --git a/app/models/report.rb b/app/models/report.rb index 2804020f5..86c303798 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -13,6 +13,7 @@ # action_taken_by_account_id :bigint(8) # target_account_id :bigint(8) not null # assigned_account_id :bigint(8) +# uri :string # class Report < ApplicationRecord @@ -28,6 +29,12 @@ class Report < ApplicationRecord validates :comment, length: { maximum: 1000 } + def local? + false # Force uri_for to use uri attribute + end + + before_validation :set_uri, only: :create + def object_type :flag end @@ -89,4 +96,8 @@ class Report < ApplicationRecord Admin::ActionLog.from("(#{sql}) AS admin_action_logs") end + + def set_uri + self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local? + end end diff --git a/app/models/status.rb b/app/models/status.rb index f576489b4..c049401e8 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -73,7 +73,9 @@ class Status < ApplicationRecord validates_with StatusLengthValidator validates_with DisallowedHashtagsValidator validates :reblog, uniqueness: { scope: :account }, if: :reblog? - validates_associated :owned_poll + validates :visibility, exclusion: { in: %w(direct limited) }, if: :reblog? + + accepts_nested_attributes_for :owned_poll default_scope { recent } @@ -216,7 +218,11 @@ class Status < ApplicationRecord end def emojis - @emojis ||= CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain) + return @emojis if defined?(@emojis) + fields = [spoiler_text, text] + fields += owned_poll.options unless owned_poll.nil? + @emojis = CustomEmoji.from_text(fields.join(' '), account.domain) + @emojis end def mark_for_mass_destruction! @@ -471,8 +477,8 @@ class Status < ApplicationRecord end def set_visibility + self.visibility = reblog.visibility if reblog? && visibility.nil? self.visibility = (account.locked? ? :private : :public) if visibility.nil? - self.visibility = reblog.visibility if reblog? self.sensitive = false if sensitive.nil? end |