diff --git a/app/controllers/api/v1/issues/assigners_controller.rb b/app/controllers/api/v1/issues/assigners_controller.rb new file mode 100644 index 000000000..421ae2eda --- /dev/null +++ b/app/controllers/api/v1/issues/assigners_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::Issues::AssignersController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + # 负责人列表 + def index + @assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id}) + @assigners = kaminary_select_paginate(@assigners) + end +end \ No newline at end of file diff --git a/app/models/issue.rb b/app/models/issue.rb index 2a3b95958..069fae40a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -68,6 +68,9 @@ class Issue < ApplicationRecord has_many :issue_tags, through: :issue_tags_relates has_many :issue_times, dependent: :destroy has_many :issue_depends, dependent: :destroy + has_many :issue_assigners + has_many :assigners, through: :issue_assigners + scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} scope :issue_issue, ->{where(issue_classify: [nil,"issue"])} diff --git a/app/models/issue_assigner.rb b/app/models/issue_assigner.rb new file mode 100644 index 000000000..a0836f214 --- /dev/null +++ b/app/models/issue_assigner.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: issue_assigners +# +# id :integer not null, primary key +# issue_id :integer +# assigner_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_issue_assigners_on_assigner_id (assigner_id) +# index_issue_assigners_on_issue_id (issue_id) +# + +class IssueAssigner < ApplicationRecord + belongs_to :issue + belongs_to :assigner, class_name: "User" +end diff --git a/app/models/user.rb b/app/models/user.rb index 4288c4d4c..9162702fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -175,6 +175,8 @@ class User < Owner has_many :system_notifications, through: :system_notification_histories has_one :trace_user, dependent: :destroy has_many :feedbacks, dependent: :destroy + has_many :issue_assigners, foreign_key: :assigner_id + has_many :assigned_issues, through: :issue_assigners, source: :issue # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| diff --git a/app/views/api/v1/issues/assigners/index.json.jbuilder b/app/views/api/v1/issues/assigners/index.json.jbuilder new file mode 100644 index 000000000..fbcf469a6 --- /dev/null +++ b/app/views/api/v1/issues/assigners/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @assigners.total_count +json.assigners @assigners.each do |assigner| + json.partial! 'api/v1/users/simple_user', locals: { user: assigner} +end \ No newline at end of file diff --git a/db/migrate/20230207091507_create_issue_assigners.rb b/db/migrate/20230207091507_create_issue_assigners.rb new file mode 100644 index 000000000..1a25db213 --- /dev/null +++ b/db/migrate/20230207091507_create_issue_assigners.rb @@ -0,0 +1,10 @@ +class CreateIssueAssigners < ActiveRecord::Migration[5.2] + def change + create_table :issue_assigners do |t| + t.references :issue + t.references :assigner, references: :user + + t.timestamps + end + end +end