2022-07-08 10:16:05 +08:00
|
|
|
class SonarTasksController < ApplicationController
|
|
|
|
|
before_action :require_login
|
|
|
|
|
before_action :load_project
|
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
@sonar_task = SonarTask.find_by(project_id: @project.id)
|
2022-07-20 16:19:40 +08:00
|
|
|
tip_exception(-1, "代码未检测,请点击开始检测按钮检测!") if @sonar_task.blank?
|
2022-07-12 15:09:24 +08:00
|
|
|
if @sonar_task.complete_status == 0
|
|
|
|
|
service = Sonar::ApiService.new(@project.id)
|
|
|
|
|
service.task_result(@sonar_task.task_id)
|
|
|
|
|
end
|
2022-07-08 10:16:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
Sonar::ApiService.call(@project.id)
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def type_detail
|
2022-07-08 11:47:11 +08:00
|
|
|
service = Sonar::ApiService.new(@project.id)
|
2022-07-08 12:42:00 +08:00
|
|
|
@data = service.type_detail(params[:task_id], params[:type])
|
2022-07-08 10:16:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def code_source
|
2022-07-08 11:47:11 +08:00
|
|
|
service = Sonar::ApiService.new(@project.id)
|
2022-07-08 12:42:00 +08:00
|
|
|
@data = service.source_code(params[:task_id], params[:component])
|
2022-07-08 13:54:49 +08:00
|
|
|
Rails.logger.info "data=======#{@data}"
|
2022-07-08 10:16:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def authenticate_user!
|
2023-07-07 16:06:27 +08:00
|
|
|
return if @project.member?(current_user) || current_user.admin? || current_user.business? || educoder_auth_teacher?(current_user)
|
2022-07-08 10:16:05 +08:00
|
|
|
render_forbidden('你没有权限操作')
|
|
|
|
|
end
|
2023-06-20 10:07:52 +08:00
|
|
|
|
|
|
|
|
def educoder_auth_teacher?(user)
|
|
|
|
|
user.user_extension&.identity == 'teacher' && user.professional_certification?
|
|
|
|
|
end
|
2022-07-08 10:16:05 +08:00
|
|
|
end
|