FEATURE: display out of date themes on admin dashboard
* FEATURE: disaply out of date themes on admin dashboard * Update copy
This commit is contained in:
parent
864e279aaf
commit
880462a41c
|
@ -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
|
||||
end
|
|
@ -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_themes
|
||||
|
||||
add_problem_check do
|
||||
sidekiq_check || queue_size_check
|
||||
|
@ -247,4 +248,16 @@ class AdminDashboardData
|
|||
I18n.t('dashboard.force_https_warning') unless SiteSetting.force_https
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,11 +56,18 @@ class RemoteTheme < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
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_version
|
||||
importer = 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)
|
||||
end
|
||||
|
||||
def update_from_remote(importer = nil, skip_update: false)
|
||||
|
|
|
@ -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 ■■■■"
|
||||
|
|
|
@ -336,4 +336,19 @@ describe AdminDashboardData do
|
|||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,4 +151,17 @@ describe RemoteTheme do
|
|||
expect(scheme_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue