debian-mirror-gitlab/app/controllers/profiles/gpg_keys_controller.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class Profiles::GpgKeysController < Profiles::ApplicationController
before_action :set_gpg_key, only: [:destroy, :revoke]
2021-01-03 14:25:43 +05:30
feature_category :users
2017-09-10 17:25:29 +05:30
def index
2018-03-17 18:26:18 +05:30
@gpg_keys = current_user.gpg_keys.with_subkeys
2017-09-10 17:25:29 +05:30
@gpg_key = GpgKey.new
end
def create
2018-03-17 18:26:18 +05:30
@gpg_key = GpgKeys::CreateService.new(current_user, gpg_key_params).execute
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
if @gpg_key.persisted?
2017-09-10 17:25:29 +05:30
redirect_to profile_gpg_keys_path
else
@gpg_keys = current_user.gpg_keys.select(&:persisted?)
render :index
end
end
def destroy
2021-09-30 23:02:18 +05:30
GpgKeys::DestroyService.new(current_user).execute(@gpg_key)
2017-09-10 17:25:29 +05:30
respond_to do |format|
2018-11-18 11:00:15 +05:30
format.html { redirect_to profile_gpg_keys_url, status: :found }
2017-09-10 17:25:29 +05:30
format.js { head :ok }
end
end
def revoke
@gpg_key.revoke
respond_to do |format|
2018-11-18 11:00:15 +05:30
format.html { redirect_to profile_gpg_keys_url, status: :found }
2017-09-10 17:25:29 +05:30
format.js { head :ok }
end
end
private
def gpg_key_params
params.require(:gpg_key).permit(:key)
end
def set_gpg_key
@gpg_key = current_user.gpg_keys.find(params[:id])
end
end