BigW Consortium Gitlab

Commit 7b4d29f4 by Alexis Reigel

add profile gpg key page to manage gpg keys

parent ab4120de
class Profiles::GpgKeysController < Profiles::ApplicationController
def index
@gpg_keys = current_user.gpg_keys
@gpg_key = GpgKey.new
end
def create
@gpg_key = current_user.gpg_keys.new(gpg_key_params)
if @gpg_key.save
redirect_to profile_gpg_keys_path
else
@gpg_keys = current_user.gpg_keys.select(&:persisted?)
render :index
end
end
def destroy
@gpp_key = current_user.gpg_keys.find(params[:id])
@gpp_key.destroy
respond_to do |format|
format.html { redirect_to profile_gpg_keys_url, status: 302 }
format.js { head :ok }
end
end
private
def gpg_key_params
params.require(:gpg_key).permit(:key)
end
end
...@@ -76,6 +76,7 @@ class User < ActiveRecord::Base ...@@ -76,6 +76,7 @@ class User < ActiveRecord::Base
where(type.not_eq('DeployKey').or(type.eq(nil))) where(type.not_eq('DeployKey').or(type.eq(nil)))
end, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent end, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :deploy_keys, -> { where(type: 'DeployKey') }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :deploy_keys, -> { where(type: 'DeployKey') }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :gpg_keys, dependent: :destroy
has_many :emails, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :emails, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :personal_access_tokens, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :personal_access_tokens, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
......
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
= link_to profile_keys_path, title: 'SSH Keys' do = link_to profile_keys_path, title: 'SSH Keys' do
%span %span
SSH Keys SSH Keys
= nav_link(controller: :gpg_keys) do
= link_to profile_gpg_keys_path, title: 'GPG Keys' do
%span
GPG Keys
= nav_link(controller: :preferences) do = nav_link(controller: :preferences) do
= link_to profile_preferences_path, title: 'Preferences' do = link_to profile_preferences_path, title: 'Preferences' do
%span %span
......
%div
= form_for [:profile, @gpg_key], html: { class: 'js-requires-input' } do |f|
= form_errors(@gpg_key)
.form-group
= f.label :key, class: 'label-light'
= f.text_area :key, class: "form-control", rows: 8, required: true, placeholder: "Don't paste the private part of the GPG key. Paste the public part which begins with '-----BEGIN PGP PUBLIC KEY BLOCK-----'."
.prepend-top-default
= f.submit 'Add key', class: "btn btn-create"
%li.key-list-item
.pull-left.append-right-10
= icon 'key', class: "settings-list-icon hidden-xs"
.key-list-item-info
= key.emails.join(' ')
.description
= key.fingerprint
.pull-right
%span.key-created-at
created #{time_ago_with_tooltip(key.created_at)}
= link_to profile_gpg_key_path(key), data: { confirm: 'Are you sure?' }, method: :delete, class: "btn btn-transparent prepend-left-10" do
%span.sr-only Remove
= icon('trash')
- is_admin = local_assigns.fetch(:admin, false)
- if @gpg_keys.any?
%ul.well-list
= render partial: 'profiles/gpg_keys/key', collection: @gpg_keys, locals: { is_admin: is_admin }
- else
%p.settings-message.text-center
- if is_admin
There are no GPG keys associated with this account.
- else
There are no GPG keys with access to your account.
- page_title "GPG Keys"
= render 'profiles/head'
.row.prepend-top-default
.col-lg-3.profile-settings-sidebar
%h4.prepend-top-0
= page_title
%p
GPG keys allow you to verify signed commits.
.col-lg-9
%h5.prepend-top-0
Add an GPG key
= render 'form'
%hr
%h5
Your GPG keys (#{@gpg_keys.count})
.append-bottom-default
= render 'key_table'
...@@ -23,6 +23,7 @@ resource :profile, only: [:show, :update] do ...@@ -23,6 +23,7 @@ resource :profile, only: [:show, :update] do
end end
resource :preferences, only: [:show, :update] resource :preferences, only: [:show, :update]
resources :keys, only: [:index, :show, :create, :destroy] resources :keys, only: [:index, :show, :create, :destroy]
resources :gpg_keys, only: [:index, :create, :destroy]
resources :emails, only: [:index, :create, :destroy] resources :emails, only: [:index, :create, :destroy]
resources :chat_names, only: [:index, :new, :create, :destroy] do resources :chat_names, only: [:index, :new, :create, :destroy] do
collection do collection do
......
require 'rails_helper'
feature 'Profile > GPG Keys', :gpg do
let(:user) { create(:user) }
before do
login_as(user)
end
describe 'User adds a key' do
before do
visit profile_gpg_keys_path
end
scenario 'saves the new key' do
fill_in('Key', with: attributes_for(:gpg_key)[:key])
click_button('Add key')
expect(page).to have_content('mail@koffeinfrei.org lex@panter.ch')
expect(page).to have_content('4F4840A503964251CF7D7F5DC728AF10972E97C0')
end
end
scenario 'User sees their keys' do
create(:gpg_key, user: user)
visit profile_gpg_keys_path
expect(page).to have_content('mail@koffeinfrei.org lex@panter.ch')
expect(page).to have_content('4F4840A503964251CF7D7F5DC728AF10972E97C0')
end
scenario 'User removes a key via the key index' do
create(:gpg_key, user: user)
visit profile_gpg_keys_path
click_link('Remove')
expect(page).to have_content('Your GPG keys (0)')
end
end
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