summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
blob: 4dfe35f49ef54ba742004b7f6cecbb7abaa321cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Gitlab
  module APIHelpers
    def current_user
      @current_user ||= User.find_by_authentication_token(params[:private_token])
    end

    def user_project
      @project ||=  current_user.projects.find_by_id(params[:id]) ||
                    current_user.projects.find_by_code(params[:id])
    end

    def authenticate!
      error!({'message' => '401 Unauthorized'}, 401) unless current_user
    end
  end
end