2020-08-13 23:38:32 +08:00
|
|
|
class Ci::BaseController < ApplicationController
|
2020-09-18 15:46:36 +08:00
|
|
|
include Ci::DbConnectable
|
|
|
|
|
|
2020-08-13 23:38:32 +08:00
|
|
|
before_action :require_login
|
2020-10-19 09:27:59 +08:00
|
|
|
before_action :connect_to_ci_database, if: -> { current_user && !current_user.is_a?(AnonymousUser) && !current_user.devops_uninit? }
|
2020-08-20 18:37:53 +08:00
|
|
|
|
|
|
|
|
def load_repo
|
|
|
|
|
namespace = params[:owner]
|
|
|
|
|
id = params[:repo] || params[:id]
|
|
|
|
|
|
2020-09-18 15:26:14 +08:00
|
|
|
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id)
|
2020-08-20 18:37:53 +08:00
|
|
|
end
|
2020-09-10 16:01:24 +08:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def authorize_access_project!
|
|
|
|
|
unless @project.manager?(current_user)
|
|
|
|
|
return render_forbidden
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-10-16 11:57:20 +08:00
|
|
|
def authenticate_manager!
|
|
|
|
|
unless @project.manager?(current_user)
|
2020-09-10 16:01:24 +08:00
|
|
|
return render_forbidden
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authenticate_admin!
|
|
|
|
|
return render_forbidden unless current_user.admin?
|
|
|
|
|
end
|
|
|
|
|
|
2020-10-16 11:57:20 +08:00
|
|
|
def authorize_owner!
|
2020-09-10 16:01:24 +08:00
|
|
|
unless @project.owner?(current_user)
|
|
|
|
|
return render_forbidden
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_cloud_account
|
|
|
|
|
@cloud_account ||= current_user.ci_cloud_account
|
2020-09-27 15:30:44 +08:00
|
|
|
@cloud_account.blank? ? nil : @cloud_account
|
2020-09-10 16:01:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def load_ci_user
|
2020-09-27 11:30:37 +08:00
|
|
|
@ci_user ||= Ci::User.find_by(user_login: params[:owner])
|
|
|
|
|
@ci_user.blank? ? raise("未找到相关的记录") : @ci_user
|
2020-09-10 16:01:24 +08:00
|
|
|
end
|
|
|
|
|
|
2020-08-13 23:38:32 +08:00
|
|
|
end
|