diff options
author | Starfall <us@starfall.systems> | 2022-03-22 11:16:06 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-03-22 11:16:06 -0500 |
commit | f37056e6c351a08d09c3986586cc7d27bdea85ab (patch) | |
tree | c28aaff7e0b70ba0fea07d4335777e6676bff60e /app/models/concerns | |
parent | 239d67fc2c0ec82617de50a9831bc1a9efc30ecc (diff) | |
parent | 9ff119eecd1079e52a8a41d7b8d61520c4303c2f (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/account_merging.rb | 7 | ||||
-rw-r--r-- | app/models/concerns/omniauthable.rb | 23 |
2 files changed, 20 insertions, 10 deletions
diff --git a/app/models/concerns/account_merging.rb b/app/models/concerns/account_merging.rb index 119773e6b..8161761fb 100644 --- a/app/models/concerns/account_merging.rb +++ b/app/models/concerns/account_merging.rb @@ -15,7 +15,8 @@ module AccountMerging Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite, Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin, AccountStat, ListAccount, - PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression + PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression, + Appeal ] owned_classes.each do |klass| @@ -47,6 +48,10 @@ module AccountMerging record.update_attribute(:reference_account_id, id) end + Appeal.where(account_warning_id: other_account.id).find_each do |record| + record.update_attribute(:account_warning_id, id) + end + # Some follow relationships have moved, so the cache is stale Rails.cache.delete_matched("followers_hash:#{id}:*") Rails.cache.delete_matched("relationships:#{id}:*") diff --git a/app/models/concerns/omniauthable.rb b/app/models/concerns/omniauthable.rb index 791a94911..a90d5d888 100644 --- a/app/models/concerns/omniauthable.rb +++ b/app/models/concerns/omniauthable.rb @@ -13,7 +13,7 @@ module Omniauthable Devise.omniauth_configs.keys end - def email_verified? + def email_present? email && email !~ TEMP_EMAIL_REGEX end end @@ -40,16 +40,14 @@ module Omniauthable end def create_for_oauth(auth) - # Check if the user exists with provided email if the provider gives us a - # verified email. If no verified email was provided or the user already - # exists, we assign a temporary email and ask the user to verify it on + # Check if the user exists with provided email. If no email was provided, + # we assign a temporary email and ask the user to verify it on # the next step via Auth::SetupController.show strategy = Devise.omniauth_configs[auth.provider.to_sym].strategy assume_verified = strategy&.security&.assume_email_is_verified - email_is_verified = auth.info.verified || auth.info.verified_email || assume_verified + email_is_verified = auth.info.verified || auth.info.verified_email || auth.info.email_verified || assume_verified email = auth.info.verified_email || auth.info.email - email = nil unless email_is_verified user = User.find_by(email: email) if email_is_verified @@ -58,7 +56,7 @@ module Omniauthable user = User.new(user_params_from_auth(email, auth)) user.account.avatar_remote_url = auth.info.image if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image) - user.skip_confirmation! + user.skip_confirmation! if email_is_verified user.save! user end @@ -71,8 +69,8 @@ module Omniauthable agreement: true, external: true, account_attributes: { - username: ensure_unique_username(auth.uid), - display_name: auth.info.full_name || [auth.info.first_name, auth.info.last_name].join(' '), + username: ensure_unique_username(ensure_valid_username(auth.uid)), + display_name: auth.info.full_name || auth.info.name || [auth.info.first_name, auth.info.last_name].join(' '), }, } end @@ -88,5 +86,12 @@ module Omniauthable username end + + def ensure_valid_username(starting_username) + starting_username = starting_username.split('@')[0] + temp_username = starting_username.gsub(/[^a-z0-9_]+/i, '') + validated_username = temp_username.truncate(30, omission: '') + validated_username + end end end |