Commit 46ad09bf70400eeebab5495ee6a5ded4da86012e

Authored by GitLab
1 parent 5101ff7b

code refactor as per standards

app/controllers/profiles/keys_controller.rb
@@ -34,14 +34,17 @@ class Profiles::KeysController < ApplicationController @@ -34,14 +34,17 @@ class Profiles::KeysController < ApplicationController
34 end 34 end
35 end 35 end
36 36
37 - #get all keys of a user(params[:username]) in a text format  
38 - #helpful for sysadmins to put in respective servers 37 + # Get all keys of a user(params[:username]) in a text format
  38 + # Helpful for sysadmins to put in respective servers
39 def get_keys 39 def get_keys
40 if params[:username].present? 40 if params[:username].present?
41 begin 41 begin
42 user = User.find_by_username(params[:username]) 42 user = User.find_by_username(params[:username])
43 - user.present? ? (render :text => user.all_ssh_keys.join('\n')) :  
44 - (render_404 and return) 43 + if user.present?
  44 + render text: user.all_ssh_keys.join('\n')
  45 + else
  46 + render_404 and return
  47 + end
45 rescue => e 48 rescue => e
46 render text: e.message 49 render text: e.message
47 end 50 end
app/models/user.rb
@@ -437,6 +437,6 @@ class User < ActiveRecord::Base @@ -437,6 +437,6 @@ class User < ActiveRecord::Base
437 end 437 end
438 438
439 def all_ssh_keys 439 def all_ssh_keys
440 - keys.collect{|x| x.key}.join("\n") 440 + keys.map(&:key)
441 end 441 end
442 end 442 end
config/routes.rb
@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do @@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do
12 API::API.logger Rails.logger 12 API::API.logger Rails.logger
13 mount API::API => '/api' 13 mount API::API => '/api'
14 14
15 - #get all keys of user 15 + # Get all keys of user
16 get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ } 16 get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ }
17 17
18 constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } 18 constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }