2012-06-27 04:32:56 -07:00
|
|
|
module Gitlab
|
|
|
|
module APIHelpers
|
|
|
|
def current_user
|
|
|
|
@current_user ||= User.find_by_authentication_token(params[:private_token])
|
|
|
|
end
|
|
|
|
|
2012-07-06 06:08:17 -07:00
|
|
|
def user_project
|
2012-07-25 05:24:28 -07:00
|
|
|
if @project ||= current_user.projects.find_by_id(params[:id]) ||
|
|
|
|
current_user.projects.find_by_code(params[:id])
|
|
|
|
else
|
|
|
|
error!({'message' => '404 Not found'}, 404)
|
|
|
|
end
|
|
|
|
|
|
|
|
@project
|
2012-07-06 06:08:17 -07:00
|
|
|
end
|
|
|
|
|
2012-09-03 04:46:29 -07:00
|
|
|
def paginate(object)
|
|
|
|
object.page(params[:page]).per(params[:per_page].to_i)
|
|
|
|
end
|
|
|
|
|
2012-06-27 04:32:56 -07:00
|
|
|
def authenticate!
|
2012-06-29 03:52:20 -07:00
|
|
|
error!({'message' => '401 Unauthorized'}, 401) unless current_user
|
2012-06-27 04:32:56 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|