diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index b184392a0..596c8d9e9 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -1,7 +1,7 @@ -class Api::V1::Issues::JournalsController < Api::V1::IssuesController +class Api::V1::Issues::JournalsController < Api::V1::BaseController before_action :require_login, except: [:index, :children_journals] - before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy] - before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy] + before_action :require_public_and_member_above + before_action :load_issue before_action :load_journal, only: [:children_journals, :update, :destroy] before_action :check_journal_operate_permission, only: [:update, :destroy] @@ -41,6 +41,13 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController params.permit(:notes, :parent_id, :reply_id, :attachment_ids => []) end + def load_issue + @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) + if @issue.blank? + render_not_found("疑修不存在!") + end + end + def load_journal @journal = Journal.find_by_id(params[:id]) return render_not_found("评论不存在!") unless @journal.present? diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index d0fc0be4a..fba207c5c 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -11,6 +11,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening + @milestones = milestones.order("#{sort_by} #{sort_direction}") if params[:only_name] @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 7f2b5ee4d..acf92e834 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -57,10 +57,10 @@ class Api::V1::IssuesController < Api::V1::BaseController end end - protected + private def load_issue - @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) + @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) if @issue.blank? render_not_found("疑修不存在!") end @@ -79,9 +79,7 @@ class Api::V1::IssuesController < Api::V1::BaseController def check_issue_operate_permission return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user - end - - private + end def query_params params.permit( diff --git a/app/models/issue_tags_relate.rb b/app/models/issue_tags_relate.rb index df9fd81ae..8bd1486d7 100644 --- a/app/models/issue_tags_relate.rb +++ b/app/models/issue_tags_relate.rb @@ -15,5 +15,15 @@ class IssueTagsRelate < ApplicationRecord belongs_to :issue - belongs_to :issue_tag, counter_cache: :issues_count + belongs_to :issue_tag + + after_create :increment_issue_tags_counter_cache + + def increment_issue_tags_counter_cache + if self.issue.issue_classify == "Issue" + IssueTag.increment_counter :issues_count, issue_tag_id + else + IssueTag.increment_counter :pull_requests_count, issue_tag_id + end + end end diff --git a/app/services/api/v1/issues/milestones/detail_issues_service.rb b/app/services/api/v1/issues/milestones/detail_issues_service.rb index c6b250a58..a6fc5815d 100644 --- a/app/services/api/v1/issues/milestones/detail_issues_service.rb +++ b/app/services/api/v1/issues/milestones/detail_issues_service.rb @@ -16,7 +16,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService @author_id = params[:author_id] @assigner_id = params[:assigner_id] @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(",") : [] - @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 8d9861f24..6a04c56ac 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -2,6 +2,7 @@ json.total_issues_count @total_issues_count json.opened_count @opened_issues_count json.closed_count @closed_issues_count json.total_count @issues.total_count +json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder index 43daf1a4a..8fef8b1f6 100644 --- a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder @@ -1,6 +1,6 @@ json.(tag,:id, :name, :description, :color) -json.issues_count tag.issue_issues.size -json.pull_requests_count tag.pull_request_issues.size +json.issues_count tag.issues_count +json.pull_requests_count tag.pull_requests_count json.project do if tag.project.present? json.partial! "api/v1/projects/simple_detail", project: tag.project diff --git a/config/routes/api.rb b/config/routes/api.rb index 6c9b3dcdf..5c82d3367 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,7 +25,7 @@ defaults format: :json do end end - resources :issues, except: [:new, :edit] do + resources :issues, param: :index, except: [:new, :edit] do collection do patch :batch_update delete :batch_destroy diff --git a/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb b/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb new file mode 100644 index 000000000..161328746 --- /dev/null +++ b/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb @@ -0,0 +1,5 @@ +class AddSomeColumnsToIssueUpgrade < ActiveRecord::Migration[5.2] + def change + add_column :issue_tags, :pull_requests_count, :integer, default: 0 + end +end diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 1fbe5df24..6d016a653 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -29,9 +29,13 @@ namespace :upgrade_issue_generate_data do puts "____________fix start________________" IssuePriority.init_data IssueStatus.init_data + IssueTag.order(created_at: :desc).find_each do |it| + it.update_column(:issues_count, it.issue_issues.size) + it.update_column(:pull_requests_count, it.pull_request_issues.size) + end IssueTag.where(user_id: nil).destroy_all count = 0 - Project.order(created_at: :desc).find_each do |project| + Project.order(created_on: :desc).find_each do |project| count += 1 IssueTag.init_data(project.id) end