From 78d0ec35a55cff97ebbbf3761e28554bc634b175 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 6 Jan 2022 16:50:18 +0000 Subject: [PATCH] DEV: Deprecate OAuth2Authenticator and OAuth2UserInfo (#15427) These have been superseded by ManagedAuthenticator and UserAssociatedAccount. For more information, see https://meta.discourse.org/t/106695 --- app/models/oauth2_user_info.rb | 3 +++ lib/auth/oauth2_authenticator.rb | 1 + lib/discourse.rb | 2 +- spec/services/user_anonymizer_spec.rb | 2 -- spec/services/user_merger_spec.rb | 2 -- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/oauth2_user_info.rb b/app/models/oauth2_user_info.rb index 285eb7a5c7a..f58d82f9614 100644 --- a/app/models/oauth2_user_info.rb +++ b/app/models/oauth2_user_info.rb @@ -3,6 +3,9 @@ class Oauth2UserInfo < ActiveRecord::Base belongs_to :user + after_initialize do + Discourse.deprecate("Oauth2UserInfo is deprecated. Use `ManagedAuthenticator` and `UserAssociatedAccount` instead. For more information, see https://meta.discourse.org/t/106695", drop_from: '2.9.0', output_in_test: true) + end end # == Schema Information diff --git a/lib/auth/oauth2_authenticator.rb b/lib/auth/oauth2_authenticator.rb index 58365344f00..78880319a6d 100644 --- a/lib/auth/oauth2_authenticator.rb +++ b/lib/auth/oauth2_authenticator.rb @@ -8,6 +8,7 @@ class Auth::OAuth2Authenticator < Auth::Authenticator # only option at the moment is :trusted def initialize(name, opts = {}) + Discourse.deprecate("OAuth2Authenticator is deprecated. Use `ManagedAuthenticator` and `UserAssociatedAccount` instead. For more information, see https://meta.discourse.org/t/106695", drop_from: '2.9.0', output_in_test: true) @name = name @opts = opts end diff --git a/lib/discourse.rb b/lib/discourse.rb index 303b94293bf..f1b10278f12 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -876,7 +876,7 @@ module Discourse digest = Digest::MD5.hexdigest(warning) redis_key = "deprecate-notice-#{digest}" - if !Discourse.redis.without_namespace.get(redis_key) + if Rails.logger && !Discourse.redis.without_namespace.get(redis_key) Rails.logger.warn(warning) begin Discourse.redis.without_namespace.setex(redis_key, 3600, "x") diff --git a/spec/services/user_anonymizer_spec.rb b/spec/services/user_anonymizer_spec.rb index 0ed06e82da5..8a98e7ac32a 100644 --- a/spec/services/user_anonymizer_spec.rb +++ b/spec/services/user_anonymizer_spec.rb @@ -203,12 +203,10 @@ describe UserAnonymizer do it "removes external auth associations" do user.user_associated_accounts = [UserAssociatedAccount.create(user_id: user.id, provider_uid: "example", provider_name: "facebook")] user.single_sign_on_record = SingleSignOnRecord.create(user_id: user.id, external_id: "example", last_payload: "looks good") - user.oauth2_user_infos = [Oauth2UserInfo.create(user_id: user.id, uid: "example", provider: "example")] make_anonymous user.reload expect(user.user_associated_accounts).to be_empty expect(user.single_sign_on_record).to eq(nil) - expect(user.oauth2_user_infos).to be_empty end it "removes api key" do diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb index a063d4e892e..604d795c4b8 100644 --- a/spec/services/user_merger_spec.rb +++ b/spec/services/user_merger_spec.rb @@ -999,13 +999,11 @@ describe UserMerger do it "deletes external auth infos of source user" do UserAssociatedAccount.create(user_id: source_user.id, provider_name: "facebook", provider_uid: "1234") - Oauth2UserInfo.create(user_id: source_user.id, uid: "example", provider: "example") SingleSignOnRecord.create(user_id: source_user.id, external_id: "example", last_payload: "looks good") merge_users! expect(UserAssociatedAccount.where(user_id: source_user.id).count).to eq(0) - expect(Oauth2UserInfo.where(user_id: source_user.id).count).to eq(0) expect(SingleSignOnRecord.where(user_id: source_user.id).count).to eq(0) end