about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-12-16 11:50:35 +0100
committerGitHub <noreply@github.com>2022-12-16 11:50:35 +0100
commit7ca0a71601f92064db64862c8cab46a77d9c3d3d (patch)
tree342c9a8972757d3706903a40e27a6f8e5a43533e /app/models
parent3868ba683d56dbbeecc839fdeaeb7b3d0b18bb9a (diff)
parent0912fb736d435b132779828376cd10cf7ad8e56e (diff)
Merge pull request #2014 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb12
-rw-r--r--app/models/account_filter.rb2
-rw-r--r--app/models/concerns/account_interactions.rb4
-rw-r--r--app/models/media_attachment.rb2
-rw-r--r--app/models/user.rb16
5 files changed, 26 insertions, 10 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 7059c555f..4a7219624 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -339,9 +339,15 @@ class Account < ApplicationRecord
 
   def save_with_optional_media!
     save!
-  rescue ActiveRecord::RecordInvalid
-    self.avatar = nil
-    self.header = nil
+  rescue ActiveRecord::RecordInvalid => e
+    errors = e.record.errors.errors
+    errors.each do |err|
+      if err.attribute == :avatar
+        self.avatar = nil
+      elsif err.attribute == :header
+        self.header = nil
+      end
+    end
 
     save!
   end
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb
index 3a4ac0492..d27bb46fc 100644
--- a/app/models/account_filter.rb
+++ b/app/models/account_filter.rb
@@ -81,7 +81,7 @@ class AccountFilter
     when 'suspended'
       Account.suspended
     when 'disabled'
-      accounts_with_users.merge(User.disabled)
+      accounts_with_users.merge(User.disabled).without_suspended
     when 'silenced'
       Account.silenced
     when 'sensitized'
diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb
index 15c49f2fe..de8bf338f 100644
--- a/app/models/concerns/account_interactions.rb
+++ b/app/models/concerns/account_interactions.rb
@@ -44,6 +44,10 @@ module AccountInteractions
       end
     end
 
+    def requested_by_map(target_account_ids, account_id)
+      follow_mapping(FollowRequest.where(account_id: target_account_ids, target_account_id: account_id), :account_id)
+    end
+
     def endorsed_map(target_account_ids, account_id)
       follow_mapping(AccountPin.where(account_id: account_id, target_account_id: target_account_ids), :target_account_id)
     end
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index f2b34e4cd..4dd3042ab 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -210,6 +210,8 @@ class MediaAttachment < ApplicationRecord
 
   default_scope { order(id: :asc) }
 
+  attr_accessor :skip_download
+
   def local?
     remote_url.blank?
   end
diff --git a/app/models/user.rb b/app/models/user.rb
index 209bfa521..4344da2ff 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -386,6 +386,15 @@ class User < ApplicationRecord
     super
   end
 
+  def revoke_access!
+    Doorkeeper::AccessGrant.by_resource_owner(self).update_all(revoked_at: Time.now.utc)
+
+    Doorkeeper::AccessToken.by_resource_owner(self).in_batches do |batch|
+      batch.update_all(revoked_at: Time.now.utc)
+      Web::PushSubscription.where(access_token_id: batch).delete_all
+    end
+  end
+
   def reset_password!
     # First, change password to something random and deactivate all sessions
     transaction do
@@ -394,12 +403,7 @@ class User < ApplicationRecord
     end
 
     # Then, remove all authorized applications and connected push subscriptions
-    Doorkeeper::AccessGrant.by_resource_owner(self).in_batches.update_all(revoked_at: Time.now.utc)
-
-    Doorkeeper::AccessToken.by_resource_owner(self).in_batches do |batch|
-      batch.update_all(revoked_at: Time.now.utc)
-      Web::PushSubscription.where(access_token_id: batch).delete_all
-    end
+    revoke_access!
 
     # Finally, send a reset password prompt to the user
     send_reset_password_instructions