From 49a327b9515deb6956699c53e9bb584fb06d4432 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 3 Jan 2024 11:42:15 +0000 Subject: [PATCH] Revert "Add admin-warning feature for critical deprecations" Moved into core via https://github.com/discourse/discourse/commit/07caa5bc03eca4146b8441f3a78fa4826981d313 This reverts commit 49e1f6a6bbcee06ae230ff6b3f32cc6be9d49b4a. --- .../services/deprecation-collector.js | 65 +------------------ config/locales/client.en.yml | 4 -- config/settings.yml | 8 --- spec/system/deprecation_collector_spec.rb | 48 ++++---------- 4 files changed, 15 insertions(+), 110 deletions(-) diff --git a/assets/javascripts/discourse/services/deprecation-collector.js b/assets/javascripts/discourse/services/deprecation-collector.js index 1a6d43c..df7c626 100644 --- a/assets/javascripts/discourse/services/deprecation-collector.js +++ b/assets/javascripts/discourse/services/deprecation-collector.js @@ -1,14 +1,11 @@ import { registerDeprecationHandler } from "@ember/debug"; import { cancel } from "@ember/runloop"; import Service, { inject as service } from "@ember/service"; -import { withPluginApi } from "discourse/lib/plugin-api"; import identifySource from "discourse/lib/source-identifier"; -import { escapeExpression } from "discourse/lib/utilities"; import discourseDebounce from "discourse-common/lib/debounce"; import { registerDeprecationHandler as registerDiscourseDeprecationHandler } from "discourse-common/lib/deprecated"; import getURL from "discourse-common/lib/get-url"; import { bind } from "discourse-common/utils/decorators"; -import I18n from "discourse-i18n"; // Deprecation handling APIs don't have any way to unregister handlers, so we set up permenant // handlers and link them up to the application lifecycle using module-local state. @@ -21,20 +18,12 @@ registerDiscourseDeprecationHandler((message, opts) => handler?.(message, opts) ); -const CRITICAL_DEPRECATIONS = [ - /^discourse.modal-controllers$/, - /^(?!discourse\.)/, -]; - export default class DeprecationCollector extends Service { @service router; - @service currentUser; - @service siteSettings; #configById = new Map(); #counts = new Map(); #reportDebounce; - #adminWarned = false; constructor() { super(...arguments); @@ -74,13 +63,10 @@ export default class DeprecationCollector extends Service { return; } - const source = identifySource(); - if (source?.type === "browser-extension") { + if (identifySource()?.type === "browser-extension") { return; } - this.maybeNotifyAdmin(options.id, source); - let count = this.#counts.get(options.id) || 0; count += 1; this.#counts.set(options.id, count); @@ -107,53 +93,4 @@ export default class DeprecationCollector extends Service { navigator.sendBeacon(getURL("/deprecation-collector/log"), body); } - - maybeNotifyAdmin(id, source) { - if (this.#adminWarned) { - return; - } - - if (!this.currentUser?.admin) { - return; - } - - if (!this.siteSettings?.deprecation_collector_warn_critical_deprecations) { - return; - } - - if (CRITICAL_DEPRECATIONS.some((pattern) => pattern.test(id))) { - this.notifyAdmin(id, source); - } - } - - notifyAdmin(id, source) { - this.#adminWarned = true; - - let notice = I18n.t("deprecation_collector.critical_deprecations"); - - if ( - this.siteSettings?.deprecation_collector_critical_deprecations_message - ) { - notice += - " " + - this.siteSettings.deprecation_collector_critical_deprecations_message; - } - - if (source?.type === "theme") { - notice += - " " + - I18n.t("deprecation_collector.theme_source", { - name: escapeExpression(source.name), - path: source.path, - }); - } - - withPluginApi("0.1", (api) => { - api.addGlobalNotice(notice, "critical-deprecation", { - dismissable: true, - dismissDuration: moment.duration(1, "day"), - level: "warn", - }); - }); - } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1cb5820..7fc5377 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4,7 +4,3 @@ en: site_settings: categories: deprecation_collector: "Deprecation Collector" - js: - deprecation_collector: - critical_deprecations: "[Admin Notice] One of your themes or plugins needs updating for compatibility with upcoming Discourse core changes (more info)." - theme_source: "Identified theme: '%{name}'." diff --git a/config/settings.yml b/config/settings.yml index 9b913d6..bef8031 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,11 +1,3 @@ deprecation_collector: deprecation_collector_enabled: default: false - deprecation_collector_warn_critical_deprecations: - default: false - hidden: true - client: true - deprecation_collector_critical_deprecations_message: - default: "" - hidden: true - client: true diff --git a/spec/system/deprecation_collector_spec.rb b/spec/system/deprecation_collector_spec.rb index 3f81961..aa6daf0 100644 --- a/spec/system/deprecation_collector_spec.rb +++ b/spec/system/deprecation_collector_spec.rb @@ -1,23 +1,24 @@ # frozen_string_literal: true describe "Deprecation collector", type: :system do - before { SiteSetting.deprecation_collector_enabled = true } - - let(:test_deprecation_id) { DeprecationCollector::List.first } - let(:logged_deprecations) { [] } - let!(:stub) do - DeprecationCollector - .stubs(:add_to_counter) - .with do |value| - logged_deprecations << value - true - end - end - it "successfully reports deprecations to the server" do + SiteSetting.deprecation_collector_enabled = true + visit("/latest") expect(find("#main-outlet-wrapper")).to be_visible + logged_deprecations = [] + + test_deprecation_id = DeprecationCollector::List.first + + stub = + DeprecationCollector + .stubs(:add_to_counter) + .with do |value| + logged_deprecations << value + true + end + # Trigger some fake deprecations page.execute_script <<~JS const deprecated = require("discourse-common/lib/deprecated").default; @@ -32,25 +33,4 @@ expect(logged_deprecations).to include(test_deprecation_id, "_other_discourse") end end - - it "warns admins about deprecations when enabled" do - sign_in Fabricate(:admin) - - SiteSetting.deprecation_collector_warn_critical_deprecations = true - SiteSetting.deprecation_collector_critical_deprecations_message = - "Discourse core changes will be applied to your site on Jan 15." - - visit("/latest") - - page.execute_script <<~JS - const deprecated = require("discourse-common/lib/deprecated").default; - deprecated("Fake deprecation message", { id: #{test_deprecation_id.to_json} }) - JS - - message = find("#global-notice-critical-deprecation") - expect(message).to have_text( - "One of your themes or plugins needs updating for compatibility with upcoming Discourse core changes", - ) - expect(message).to have_text(SiteSetting.deprecation_collector_critical_deprecations_message) - end end