2023-02-08 16:56:01 +08:00
|
|
|
|
class Api::V1::IssuesController < Api::V1::BaseController
|
2023-09-04 17:58:17 +08:00
|
|
|
|
before_action :require_login, except: [:index, :show, :test_cases]
|
2023-09-04 18:06:42 +08:00
|
|
|
|
before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy, :test_cases]
|
2023-02-20 16:47:19 +08:00
|
|
|
|
before_action :require_operate_above, only: [:batch_update, :batch_destroy]
|
2023-02-08 16:56:01 +08:00
|
|
|
|
|
|
|
|
|
|
def index
|
2023-02-22 14:42:52 +08:00
|
|
|
|
IssueTag.init_data(@project.id) unless $redis_cache.hget("project_init_issue_tags", @project.id)
|
2023-02-22 13:56:02 +08:00
|
|
|
|
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
2023-02-22 14:42:52 +08:00
|
|
|
|
@total_issues_count = @object_result[:total_issues_count]
|
2023-02-22 13:56:02 +08:00
|
|
|
|
@opened_issues_count = @object_result[:opened_issues_count]
|
|
|
|
|
|
@closed_issues_count = @object_result[:closed_issues_count]
|
2023-03-03 18:43:18 +08:00
|
|
|
|
if params[:only_name].present?
|
2023-04-12 16:12:52 +08:00
|
|
|
|
@issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
2023-03-03 18:43:18 +08:00
|
|
|
|
else
|
|
|
|
|
|
@issues = kaminari_paginate(@object_result[:data])
|
|
|
|
|
|
end
|
2023-02-08 16:56:01 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2023-09-04 17:58:17 +08:00
|
|
|
|
def test_cases
|
2023-09-04 18:11:37 +08:00
|
|
|
|
test_cases = @project.issues.where("test_case is not null")
|
2023-09-04 17:58:17 +08:00
|
|
|
|
test_cases = test_cases.where('test_case LIKE ?', "%#{params[:keyword]}%") if params[:keyword].present?
|
|
|
|
|
|
@test_cases = kaminary_select_paginate(test_cases.select(:test_case).distinct)
|
2023-09-04 18:10:08 +08:00
|
|
|
|
render_ok(count: @test_cases.total_count, data: @test_cases.as_json(only: %i[id test_case]))
|
2023-09-04 17:58:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2023-02-10 11:38:51 +08:00
|
|
|
|
def create
|
|
|
|
|
|
@object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
before_action :load_issue, only: [:show, :update, :destroy]
|
2023-02-24 10:24:57 +08:00
|
|
|
|
before_action :check_issue_operate_permission, only: [:update, :destroy]
|
2023-02-10 11:38:51 +08:00
|
|
|
|
|
|
|
|
|
|
def show
|
2023-02-20 16:47:19 +08:00
|
|
|
|
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
|
2024-08-15 16:04:35 +08:00
|
|
|
|
|
2024-08-16 14:49:48 +08:00
|
|
|
|
# @ratings =
|
|
|
|
|
|
# if @project.manager?(current_user)
|
|
|
|
|
|
# @issue.ratings
|
|
|
|
|
|
# else
|
|
|
|
|
|
# @issue.ratings.where(rater_id: current_user)
|
|
|
|
|
|
# end
|
2023-02-10 11:38:51 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
2023-02-14 23:19:17 +08:00
|
|
|
|
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
2023-02-15 09:48:56 +08:00
|
|
|
|
if @object_result
|
|
|
|
|
|
render_ok
|
|
|
|
|
|
else
|
|
|
|
|
|
render_error("删除疑修失败!")
|
|
|
|
|
|
end
|
2023-02-14 23:19:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
before_action :load_issues, only: [:batch_update, :batch_destroy]
|
|
|
|
|
|
|
|
|
|
|
|
def batch_update
|
|
|
|
|
|
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
2023-02-15 09:48:56 +08:00
|
|
|
|
if @object_result
|
|
|
|
|
|
render_ok
|
|
|
|
|
|
else
|
|
|
|
|
|
render_error("批量更新疑修失败!")
|
|
|
|
|
|
end
|
2023-02-14 23:19:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def batch_destroy
|
|
|
|
|
|
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
2023-02-15 09:48:56 +08:00
|
|
|
|
if @object_result
|
|
|
|
|
|
render_ok
|
|
|
|
|
|
else
|
|
|
|
|
|
render_error("批量删除疑修失败!")
|
|
|
|
|
|
end
|
2023-02-10 11:38:51 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2023-02-23 15:24:30 +08:00
|
|
|
|
private
|
2023-02-17 16:11:39 +08:00
|
|
|
|
|
|
|
|
|
|
def load_issue
|
2023-02-27 15:04:18 +08:00
|
|
|
|
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
|
2023-02-17 16:11:39 +08:00
|
|
|
|
if @issue.blank?
|
|
|
|
|
|
render_not_found("疑修不存在!")
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def load_issues
|
|
|
|
|
|
return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array)
|
|
|
|
|
|
params[:ids].each do |id|
|
|
|
|
|
|
@issue = Issue.find_by_id(id)
|
|
|
|
|
|
if @issue.blank?
|
|
|
|
|
|
return render_not_found("ID为#{id}的疑修不存在!")
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
@issues = Issue.where(id: params[:ids])
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2023-02-20 16:47:19 +08:00
|
|
|
|
def check_issue_operate_permission
|
2023-02-22 09:55:05 +08:00
|
|
|
|
return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user
|
2023-02-23 15:24:30 +08:00
|
|
|
|
end
|
2023-02-08 16:56:01 +08:00
|
|
|
|
|
|
|
|
|
|
def query_params
|
|
|
|
|
|
params.permit(
|
2023-08-29 11:35:46 +08:00
|
|
|
|
:only_name,
|
2023-02-08 16:56:01 +08:00
|
|
|
|
:category,
|
|
|
|
|
|
:participant_category,
|
|
|
|
|
|
:keyword, :author_id,
|
|
|
|
|
|
:milestone_id, :assigner_id,
|
|
|
|
|
|
:status_id,
|
2023-09-04 17:58:17 +08:00
|
|
|
|
:test_case,
|
2023-03-13 15:37:45 +08:00
|
|
|
|
:begin_date, :end_date,
|
2023-02-08 16:56:01 +08:00
|
|
|
|
:sort_by, :sort_direction,
|
2023-02-22 15:56:44 +08:00
|
|
|
|
:issue_tag_ids)
|
2023-02-08 16:56:01 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2023-02-10 11:38:51 +08:00
|
|
|
|
def issue_params
|
|
|
|
|
|
params.permit(
|
|
|
|
|
|
:status_id, :priority_id, :milestone_id,
|
|
|
|
|
|
:branch_name, :start_date, :due_date,
|
|
|
|
|
|
:subject, :description,
|
2023-09-04 17:58:17 +08:00
|
|
|
|
:test_case,
|
|
|
|
|
|
:issue_tag_ids => [],
|
2023-02-10 11:38:51 +08:00
|
|
|
|
:assigner_ids => [],
|
2023-02-15 09:48:56 +08:00
|
|
|
|
:attachment_ids => [],
|
|
|
|
|
|
:receivers_login => [])
|
2023-02-10 11:38:51 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2023-02-14 23:19:17 +08:00
|
|
|
|
def batch_issue_params
|
|
|
|
|
|
params.permit(
|
|
|
|
|
|
:status_id, :priority_id, :milestone_id,
|
|
|
|
|
|
:issue_tag_ids => [],
|
|
|
|
|
|
:assigner_ids => [])
|
|
|
|
|
|
end
|
2023-02-08 16:56:01 +08:00
|
|
|
|
end
|