Commit 46ad09bf authored by GitLab's avatar GitLab

code refactor as per standards

parent 5101ff7b
...@@ -34,14 +34,17 @@ class Profiles::KeysController < ApplicationController ...@@ -34,14 +34,17 @@ class Profiles::KeysController < ApplicationController
end end
end end
#get all keys of a user(params[:username]) in a text format # Get all keys of a user(params[:username]) in a text format
#helpful for sysadmins to put in respective servers # Helpful for sysadmins to put in respective servers
def get_keys def get_keys
if params[:username].present? if params[:username].present?
begin begin
user = User.find_by_username(params[:username]) user = User.find_by_username(params[:username])
user.present? ? (render :text => user.all_ssh_keys.join('\n')) : if user.present?
(render_404 and return) render text: user.all_ssh_keys.join('\n')
else
render_404 and return
end
rescue => e rescue => e
render text: e.message render text: e.message
end end
......
...@@ -437,6 +437,6 @@ class User < ActiveRecord::Base ...@@ -437,6 +437,6 @@ class User < ActiveRecord::Base
end end
def all_ssh_keys def all_ssh_keys
keys.collect{|x| x.key}.join("\n") keys.map(&:key)
end end
end end
...@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do ...@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do
API::API.logger Rails.logger API::API.logger Rails.logger
mount API::API => '/api' mount API::API => '/api'
#get all keys of user # Get all keys of user
get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ } get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ }
constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
......
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