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