From 78b5264511a76e481110236e9c14764d9c1b953a Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Fri, 23 Jun 2017 22:52:43 +0200 Subject: add gpg commit popover badges --- app/helpers/commits_helper.rb | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'app/helpers/commits_helper.rb') diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index d08e346d605..34ba5694288 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -212,4 +212,82 @@ module CommitsHelper [commits, 0] end end + + def commit_gpg_signature_badge(signature) + if signature.valid_signature? + commit_gpg_valid_signature_badge(signature) + else + commit_gpg_invalid_signature_badge(signature) + end + end + + def commit_gpg_valid_signature_badge(signature) + title = capture do + concat content_tag('i', '', class: 'fa fa-check-circle gpg-badge-popover-icon valid', 'aria-hidden' => 'true') + concat 'This commit was signed with a verified signature.' + end + + content = capture do + concat( + content_tag(:div, class: 'gpg-badge-popover-avatar') do + user_avatar(user: signature.gpg_key.user, size: 32) + end + ) + + concat( + content_tag(:div, class: 'gpg-badge-popover-username') do + signature.gpg_key.user.username + end + ) + + concat( + content_tag(:div) do + signature.gpg_key.user.name + end + ) + end + + commit_gpg_signature_badge_with(signature, label: 'Verified', title: title, content: content, css_classes: ['valid']) + end + + def commit_gpg_invalid_signature_badge(signature) + title = capture do + concat content_tag('i', '', class: 'fa fa-question-circle gpg-badge-popover-icon invalid', 'aria-hidden' => 'true') + concat 'This commit was signed with an unverified signature.' + end + commit_gpg_signature_badge_with(signature, label: 'Unverified', title: title, css_classes: ['invalid']) + end + + def commit_gpg_signature_badge_with(signature, label:, title: '', content: '', css_classes: []) + css_classes = %w(btn btn-xs gpg-badge) + css_classes + + content = capture do + concat( + content_tag(:div, class: 'clearfix') do + content + end + ) + + concat "GPG key ID: #{signature.gpg_key_primary_keyid}" + end + + title = capture do + content_tag 'span', class: 'gpg-badge-popover-title' do + title + end + end + + data = { + toggle: 'popover', + html: 'true', + placement: 'auto bottom', + trigger: 'focus', + title: title, + content: content + } + + content_tag :button, class: css_classes, data: data do + label + end + end end -- cgit v1.2.3