A platform for community discussion. Free, open, simple.
FEATURE: display out of date themes on admin dashboard
Osama Sayegh880462a41c09
diff --git a/app/jobs/scheduled/check_out_of_date_themes.rb b/app/jobs/scheduled/check_out_of_date_themes.rbnew file mode 100644index 00000000000..8bd992f6e89--- /dev/null+++ b/app/jobs/scheduled/check_out_of_date_themes.rb@@ -0,0 +1,16 @@+module Jobs+ class CheckOutOfDateThemes < Jobs::Scheduled+ every 1.day++ def execute(args)+ target_themes = RemoteTheme+ .joins("JOIN themes ON themes.remote_theme_id = remote_themes.id")+ .where.not(remote_url: "")++ target_themes.each do |remote|+ remote.update_remote_version+ remote.save!+ end+ end+ end+enddiff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rbindex b64e82dfaca..fffdd0e0360 100644--- a/app/models/admin_dashboard_data.rb+++ b/app/models/admin_dashboard_data.rb@@ -101,7 +101,8 @@ class AdminDashboardData:github_config_check, :s3_config_check, :image_magick_check,:failing_emails_check,:subfolder_ends_in_slash_check,- :pop3_polling_configuration, :email_polling_errored_recently+ :pop3_polling_configuration, :email_polling_errored_recently,+ :out_of_date_themesadd_problem_check dosidekiq_check || queue_size_check@@ -247,4 +248,16 @@ class AdminDashboardDataI18n.t('dashboard.force_https_warning') unless SiteSetting.force_httpsend+ def out_of_date_themes+ old_themes = RemoteTheme.out_of_date_themes+ return unless old_themes.present?++ html = old_themes.map do |name, id|+ "<li><a href=\"/admin/customize/themes/#{id}\">#{CGI.escapeHTML(name)}</a></li>"+ end.join("\n")++ message = I18n.t("dashboard.out_of_date_themes")+ message += "<ul>#{html}</ul>"+ message+ endenddiff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rbindex f817a090a7a..578711a4c59 100644--- a/app/models/remote_theme.rb+++ b/app/models/remote_theme.rb@@ -56,11 +56,18 @@ class RemoteTheme < ActiveRecord::Baseendend+ def self.out_of_date_themes+ self.joins("JOIN themes ON themes.remote_theme_id = remote_themes.id")+ .where.not(remote_url: "")+ .where("commits_behind > 0 OR remote_version <> local_version")+ .pluck("themes.name", "themes.id")+ end+def update_remote_versionimporter = ThemeStore::GitImporter.new(remote_url, private_key: private_key)importer.import!self.updated_at = Time.zone.now- self.remote_version, self.commits_behind = importer.commits_since(remote_version)+ self.remote_version, self.commits_behind = importer.commits_since(local_version)enddef update_from_remote(importer = nil, skip_update: false)diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex ecd2ec798cd..cc10f8c9cb8 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1097,6 +1097,7 @@ en:poll_pop3_timeout: "Connection to the POP3 server is timing out. Incoming email could not be retrieved. Please check your <a href='/admin/site_settings/category/email'>POP3 settings</a> and service provider."poll_pop3_auth_error: "Connection to the POP3 server is failing with an authentication error. Please check your <a href='/admin/site_settings/category/email'>POP3 settings</a>."force_https_warning: "Your website is using SSL. But `<a href='/admin/site_settings/category/all_results?filter=force_https'>force_https</a>` is not yet enabled in your site settings."+ out_of_date_themes: "Updates are available for the following themes:"site_settings:censored_words: "Words that will be automatically replaced with ■■■■"diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rbindex f65de862fd1..1a96b1fe9e1 100644--- a/spec/models/admin_dashboard_data_spec.rb+++ b/spec/models/admin_dashboard_data_spec.rb@@ -336,4 +336,19 @@ describe AdminDashboardData doendend+ describe '#out_of_date_themes' do+ let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }+ let!(:theme) { Theme.create!(remote_theme_id: remote.id, name: "Test< Theme", user_id: -1) }++ it "outputs correctly formatted html" do+ remote.update!(local_version: "old version", remote_version: "new version", commits_behind: 2)+ dashboard_data = described_class.new+ expect(dashboard_data.out_of_date_themes).to eq(+ I18n.t("dashboard.out_of_date_themes") + "<ul><li><a href=\"/admin/customize/themes/#{theme.id}\">Test< Theme</a></li></ul>"+ )++ remote.update!(local_version: "new version", commits_behind: 0)+ expect(dashboard_data.out_of_date_themes).to eq(nil)+ end+ endenddiff --git a/spec/models/remote_theme_spec.rb b/spec/models/remote_theme_spec.rbindex 31f772b94ec..202e170b0a3 100644--- a/spec/models/remote_theme_spec.rb+++ b/spec/models/remote_theme_spec.rb@@ -151,4 +151,17 @@ describe RemoteTheme doexpect(scheme_count).to eq(1)endend++ context ".out_of_date_themes" do+ let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }+ let!(:theme) { Theme.create!(remote_theme_id: remote.id, name: "Test Theme", user_id: -1) }++ it "finds out of date themes" do+ remote.update!(local_version: "old version", remote_version: "new version", commits_behind: 2)+ expect(described_class.out_of_date_themes).to eq([[theme.name, theme.id]])++ remote.update!(local_version: "new version", commits_behind: 0)+ expect(described_class.out_of_date_themes).to eq([])+ end+ endend