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

64 lines
1.4 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
class Profiles::KeysController < Profiles::ApplicationController
skip_before_action :authenticate_user!, only: [:get_keys]
2014-09-02 18:07:02 +05:30
def index
2015-04-26 12:48:37 +05:30
@keys = current_user.keys
2016-06-02 11:05:42 +05:30
@key = Key.new
2014-09-02 18:07:02 +05:30
end
def show
@key = current_user.keys.find(params[:id])
end
2016-06-02 11:05:42 +05:30
# Back-compat: We need to support this URL since git-annex webapp points to it
2014-09-02 18:07:02 +05:30
def new
2016-06-02 11:05:42 +05:30
redirect_to profile_keys_path
2014-09-02 18:07:02 +05:30
end
def create
@key = current_user.keys.new(key_params)
if @key.save
redirect_to profile_key_path(@key)
else
2016-06-02 11:05:42 +05:30
@keys = current_user.keys.select(&:persisted?)
render :index
2014-09-02 18:07:02 +05:30
end
end
def destroy
@key = current_user.keys.find(params[:id])
@key.destroy
respond_to do |format|
format.html { redirect_to profile_keys_url }
2016-06-02 11:05:42 +05:30
format.js { head :ok }
2014-09-02 18:07:02 +05:30
end
end
# Get all keys of a user(params[:username]) in a text format
# Helpful for sysadmins to put in respective servers
def get_keys
if params[:username].present?
begin
user = User.find_by_username(params[:username])
if user.present?
render text: user.all_ssh_keys.join("\n"), content_type: "text/plain"
else
render_404 and return
end
rescue => e
render text: e.message
end
else
render_404 and return
end
end
private
def key_params
params.require(:key).permit(:title, :key)
end
end