From 345fd545bf6d5f161686a09c4583a1e7488fd9c6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 12 Feb 2015 20:31:55 -0800 Subject: [PATCH] Add version check badge to admin area --- app/helpers/version_check_helper.rb | 5 ++++ app/views/admin/dashboard/index.html.haml | 6 ++++- lib/version_check.rb | 30 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/helpers/version_check_helper.rb create mode 100644 lib/version_check.rb diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb new file mode 100644 index 00000000000..63d8eaeb2bd --- /dev/null +++ b/app/helpers/version_check_helper.rb @@ -0,0 +1,5 @@ +module VersionCheckHelper + def version_status_badge + image_tag VersionCheck.new.url + end +end diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index d1c586328a2..6b4ff4b330d 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -56,7 +56,11 @@ %span.light.pull-right = boolean_to_icon Gitlab.config.omniauth.enabled .col-md-4 - %h4 Components + %h4 + Components + .pull-right + = version_status_badge + %hr %p GitLab diff --git a/lib/version_check.rb b/lib/version_check.rb new file mode 100644 index 00000000000..ada5e0db7a9 --- /dev/null +++ b/lib/version_check.rb @@ -0,0 +1,30 @@ +# This class is used to encrypt GitLab version and URL +# with public key when we send it to version.gitlab.com to +# check if it is a new version for update +class VersionCheck + include SimpleEncrypt + + def public_key + public_key_file = Rails.root.join('safe', 'public.pem').to_s + File.read(public_key_file) + end + + def data + { + version: Gitlab::VERSION, + url: Gitlab.config.gitlab.url + } + end + + def encrypt(string) + encrypt_with_public_key(string, public_key) + end + + def url + "#{host}?gitlab_info=#{encrypt(data.to_json)}" + end + + def host + 'http://localhost:9090/check.png' + end +end