BigW Consortium Gitlab

gpg_keys_controller.rb 957 Bytes
Newer Older
1
class Profiles::GpgKeysController < Profiles::ApplicationController
2 3
  before_action :set_gpg_key, only: [:destroy, :revoke]

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  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
21
    @gpg_key.destroy
22 23 24 25 26 27 28

    respond_to do |format|
      format.html { redirect_to profile_gpg_keys_url, status: 302 }
      format.js { head :ok }
    end
  end

29
  def revoke
30
    @gpg_key.revoke
31 32 33 34 35 36 37

    respond_to do |format|
      format.html { redirect_to profile_gpg_keys_url, status: 302 }
      format.js { head :ok }
    end
  end

38 39 40 41 42
  private

  def gpg_key_params
    params.require(:gpg_key).permit(:key)
  end
43 44 45 46

  def set_gpg_key
    @gpg_key = current_user.gpg_keys.find(params[:id])
  end
47
end