helpers.rb 519 字节
Newer Older
N
Nihad Abbasov 已提交
1 2 3 4 5 6
module Gitlab
  module APIHelpers
    def current_user
      @current_user ||= User.find_by_authentication_token(params[:private_token])
    end

N
Nihad Abbasov 已提交
7
    def user_project
N
Nihad Abbasov 已提交
8 9 10 11 12 13 14
      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
N
Nihad Abbasov 已提交
15 16
    end

N
Nihad Abbasov 已提交
17
    def authenticate!
N
Nihad Abbasov 已提交
18
      error!({'message' => '401 Unauthorized'}, 401) unless current_user
N
Nihad Abbasov 已提交
19 20 21
    end
  end
end