Commit eda00156 authored by Alexis Reigel's avatar Alexis Reigel

fetch gpg signature badges by ajax

parent c4c44c6a
...@@ -64,6 +64,7 @@ import initSettingsPanels from './settings_panels'; ...@@ -64,6 +64,7 @@ import initSettingsPanels from './settings_panels';
import initExperimentalFlags from './experimental_flags'; import initExperimentalFlags from './experimental_flags';
import OAuthRememberMe from './oauth_remember_me'; import OAuthRememberMe from './oauth_remember_me';
import PerformanceBar from './performance_bar'; import PerformanceBar from './performance_bar';
import GpgBadges from './gpg_badges';
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -300,6 +301,9 @@ import PerformanceBar from './performance_bar'; ...@@ -300,6 +301,9 @@ import PerformanceBar from './performance_bar';
}).bindEvents(); }).bindEvents();
break; break;
case 'projects:commits:show': case 'projects:commits:show':
shortcut_handler = new ShortcutsNavigation();
GpgBadges.fetch();
break;
case 'projects:activity': case 'projects:activity':
shortcut_handler = new ShortcutsNavigation(); shortcut_handler = new ShortcutsNavigation();
break; break;
......
export default class GpgBadges {
static fetch() {
const form = $('.commits-search-form');
$.get({
url: form.data('signatures-path'),
data: form.serialize(),
}).done((response) => {
const badges = $('.js-loading-gpg-badge');
response.signatures.forEach((signature) => {
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
});
});
}
}
...@@ -6,18 +6,9 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -6,18 +6,9 @@ class Projects::CommitsController < Projects::ApplicationController
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :assign_ref_vars before_action :assign_ref_vars
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :set_commits
def show def show
@limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i
search = params[:search]
@commits =
if search.present?
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset)
else
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
@note_counts = project.notes.where(commit_id: @commits.map(&:id)) @note_counts = project.notes.where(commit_id: @commits.map(&:id))
.group(:commit_id).count .group(:commit_id).count
...@@ -37,4 +28,33 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -37,4 +28,33 @@ class Projects::CommitsController < Projects::ApplicationController
end end
end end
end end
def signatures
respond_to do |format|
format.json do
render json: {
signatures: @commits.select(&:has_signature?).map do |commit|
{
commit_sha: commit.sha,
html: view_to_html_string('projects/commit/_signature', signature: commit.signature)
}
end
}
end
end
end
private
def set_commits
@limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i
search = params[:search]
@commits =
if search.present?
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset)
else
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
end
end end
...@@ -113,6 +113,10 @@ module CommitsHelper ...@@ -113,6 +113,10 @@ module CommitsHelper
commit_action_link('cherry-pick', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip) commit_action_link('cherry-pick', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip)
end end
def commit_signature_badge_classes(additional_classes)
%w(btn status-box gpg-status-box) + Array(additional_classes)
end
protected protected
# Private: Returns a link to a person. If the person has a matching user and # Private: Returns a link to a person. If the person has a matching user and
......
...@@ -237,9 +237,11 @@ class Commit ...@@ -237,9 +237,11 @@ class Commit
def signature def signature
return @signature if defined?(@signature) return @signature if defined?(@signature)
@signature = Gitlab::Gpg::Commit.new(self).signature @signature = gpg_commit.signature
end end
delegate :has_signature?, to: :gpg_commit
def revert_branch_name def revert_branch_name
"revert-#{short_id}" "revert-#{short_id}"
end end
...@@ -388,4 +390,8 @@ class Commit ...@@ -388,4 +390,8 @@ class Commit
def merged_merge_request_no_cache(user) def merged_merge_request_no_cache(user)
MergeRequestsFinder.new(user, project_id: project.id).find_by(merge_commit_sha: id) if merge_commit? MergeRequestsFinder.new(user, project_id: project.id).find_by(merge_commit_sha: id) if merge_commit?
end end
def gpg_commit
@gpg_commit ||= Gitlab::Gpg::Commit.new(self)
end
end end
- if commit.has_signature?
%button{ class: commit_signature_badge_classes('js-loading-gpg-badge'), data: { toggle: 'tooltip', placement: 'auto top', title: 'GPG signature (loading...)', 'commit-sha' => commit.sha } }
%i.fa.fa-spinner.fa-spin
- css_classes = %w(btn status-box gpg-status-box) + css_classes - css_classes = commit_signature_badge_classes(css_classes)
- title = capture do - title = capture do
.gpg-popover-status .gpg-popover-status
......
...@@ -39,7 +39,12 @@ ...@@ -39,7 +39,12 @@
.commit-actions.hidden-xs .commit-actions.hidden-xs
- if commit.status(ref) - if commit.status(ref)
= render_commit_status(commit, ref: ref) = render_commit_status(commit, ref: ref)
- if request.xhr?
= render partial: 'projects/commit/signature', object: commit.signature = render partial: 'projects/commit/signature', object: commit.signature
- else
= render partial: 'projects/commit/ajax_signature', locals: { commit: commit }
= link_to commit.short_id, project_commit_path(project, commit), class: "commit-sha btn btn-transparent" = link_to commit.short_id, project_commit_path(project, commit), class: "commit-sha btn btn-transparent"
= clipboard_button(text: commit.id, title: _("Copy commit SHA to clipboard")) = clipboard_button(text: commit.id, title: _("Copy commit SHA to clipboard"))
= link_to_browse_code(project, commit) = link_to_browse_code(project, commit)
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
= link_to _("Create merge request"), create_mr_path(@repository.root_ref, @ref), class: 'btn btn-success' = link_to _("Create merge request"), create_mr_path(@repository.root_ref, @ref), class: 'btn btn-success'
.control .control
= form_tag(project_commits_path(@project, @id), method: :get, class: 'commits-search-form') do = form_tag(project_commits_path(@project, @id), method: :get, class: 'commits-search-form', data: { 'signatures-path' => namespace_project_signatures_path }) do
= search_field_tag :search, params[:search], { placeholder: _('Filter by commit message'), id: 'commits-search', class: 'form-control search-text-input input-short', spellcheck: false } = search_field_tag :search, params[:search], { placeholder: _('Filter by commit message'), id: 'commits-search', class: 'form-control search-text-input input-short', spellcheck: false }
.control .control
= link_to project_commits_path(@project, @ref, rss_url_options), title: _("Commits feed"), class: 'btn' do = link_to project_commits_path(@project, @ref, rss_url_options), title: _("Commits feed"), class: 'btn' do
......
...@@ -76,6 +76,8 @@ scope format: false do ...@@ -76,6 +76,8 @@ scope format: false do
get '/tree/*id', to: 'tree#show', as: :tree get '/tree/*id', to: 'tree#show', as: :tree
get '/raw/*id', to: 'raw#show', as: :raw get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame get '/blame/*id', to: 'blame#show', as: :blame
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits get '/commits/*id', to: 'commits#show', as: :commits
post '/create_dir/*id', to: 'tree#create_dir', as: :create_dir post '/create_dir/*id', to: 'tree#create_dir', as: :create_dir
......
...@@ -204,7 +204,7 @@ describe 'Commits' do ...@@ -204,7 +204,7 @@ describe 'Commits' do
end end
end end
describe 'GPG signed commits' do describe 'GPG signed commits', :js do
it 'changes from unverified to verified when the user changes his email to match the gpg key' do it 'changes from unverified to verified when the user changes his email to match the gpg key' do
user = create :user, email: 'unrelated.user@example.org' user = create :user, email: 'unrelated.user@example.org'
project.team << [user, :master] project.team << [user, :master]
...@@ -262,7 +262,7 @@ describe 'Commits' do ...@@ -262,7 +262,7 @@ describe 'Commits' do
end end
end end
it 'shows popover badges', :js do it 'shows popover badges' do
gpg_user = create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard' gpg_user = create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard'
Sidekiq::Testing.inline! do Sidekiq::Testing.inline! do
create :gpg_key, key: GpgHelpers::User1.public_key, user: gpg_user create :gpg_key, key: GpgHelpers::User1.public_key, user: gpg_user
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment