| @@ -38,7 +38,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController | |||
| end | |||
| def journal_params | |||
| params.permit(:notes, :parent_id, :reply_id, :attachment_ids => []) | |||
| params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => []) | |||
| end | |||
| def load_issue | |||
| @@ -54,7 +54,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController | |||
| end | |||
| def check_journal_operate_permission | |||
| return render_forbidden("您没有操作权限!") unless current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user) | |||
| return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user || @journal.parent_journal&.user == current_user | |||
| end | |||
| end | |||
| @@ -73,8 +73,8 @@ class Issue < ApplicationRecord | |||
| has_many :issue_participants, dependent: :destroy | |||
| has_many :participants, through: :issue_participants | |||
| has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant | |||
| has_many :show_assigners, -> {order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner | |||
| has_many :show_issue_tags, -> {order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag | |||
| has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner | |||
| has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag | |||
| has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized | |||
| has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized | |||
| @@ -55,6 +55,7 @@ class Api::V1::Issues::CreateService < ApplicationService | |||
| @created_issue.attachments = @attachments unless attachment_ids.blank? | |||
| @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? | |||
| @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? | |||
| @created_issue.save! | |||
| project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 | |||
| @@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService | |||
| include Api::V1::Issues::Concerns::Checkable | |||
| include Api::V1::Issues::Concerns::Loadable | |||
| attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids | |||
| attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids, :receivers_login | |||
| attr_accessor :created_journal | |||
| validates :notes, :issue, :current_user, presence: true | |||
| @@ -14,6 +14,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService | |||
| @parent_id = params[:parent_id] | |||
| @reply_id = params[:reply_id] | |||
| @attachment_ids = params[:attachment_ids] | |||
| @receivers_login = params[:receivers_login] | |||
| @current_user = current_user | |||
| end | |||
| @@ -24,15 +25,22 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService | |||
| check_parent_journal(parent_id) if parent_id.present? | |||
| check_parent_journal(reply_id) if reply_id.present? | |||
| check_attachments(attachment_ids) unless attachment_ids.blank? | |||
| check_atme_receivers(receivers_login) unless receivers_login.blank? | |||
| load_attachments(attachment_ids) unless attachment_ids.blank? | |||
| load_atme_receivers(receivers_login) unless receivers_login.blank? | |||
| try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") | |||
| @created_journal = @issue.journals.new(journal_attributes) | |||
| build_comment_participants | |||
| build_atme_participants if @atme_receivers.present? | |||
| @created_journal.attachments = @attachments unless attachment_ids.blank? | |||
| @created_journal.save! | |||
| # @信息发送 | |||
| AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? | |||
| unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") | |||
| @created_journal | |||
| @@ -56,4 +64,10 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService | |||
| def build_comment_participants | |||
| @issue.issue_participants.new({participant_type: "commented", participant_id: current_user.id}) unless @issue.issue_participants.exists?(participant_type: "commented", participant_id: current_user.id) | |||
| end | |||
| def build_atme_participants | |||
| atme_receivers.each do |receiver| | |||
| @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) | |||
| end | |||
| end | |||
| end | |||
| @@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService | |||
| include Api::V1::Issues::Concerns::Checkable | |||
| include Api::V1::Issues::Concerns::Loadable | |||
| attr_reader :issue, :journal, :current_user, :notes, :attachment_ids | |||
| attr_reader :issue, :journal, :current_user, :notes, :attachment_ids, :receivers_login | |||
| attr_accessor :updated_journal | |||
| validates :notes, :issue, :journal, :current_user, presence: true | |||
| @@ -13,6 +13,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService | |||
| @journal = journal | |||
| @notes = params[:notes] | |||
| @attachment_ids = params[:attachment_ids] | |||
| @receivers_login = params[:receivers_login] | |||
| @current_user = current_user | |||
| end | |||
| @@ -20,18 +21,35 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService | |||
| raise Error, errors.full_messages.join(", ") unless valid? | |||
| ActiveRecord::Base.transaction do | |||
| check_attachments(attachment_ids) unless attachment_ids.blank? | |||
| check_atme_receivers(receivers_login) unless receivers_login.blank? | |||
| load_attachments(attachment_ids) unless attachment_ids.blank? | |||
| load_atme_receivers(receivers_login) unless receivers_login.blank? | |||
| try_lock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") | |||
| @updated_journal = @journal | |||
| @updated_journal.notes = notes | |||
| build_atme_participants if @atme_receivers.present? | |||
| @updated_journal.attachments = @attachments unless attachment_ids.blank? | |||
| @updated_journal.save! | |||
| # @信息发送 | |||
| AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? | |||
| unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") | |||
| @updated_journal | |||
| end | |||
| end | |||
| private | |||
| def build_atme_participants | |||
| atme_receivers.each do |receiver| | |||
| @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) | |||
| end | |||
| end | |||
| end | |||
| @@ -56,8 +56,8 @@ class Api::V1::Issues::ListService < ApplicationService | |||
| issues = issues.where(author_id: author_id) if author_id.present? | |||
| # issue_tag_ids | |||
| issues = issues.joins(:issue_tags).ransack(issue_tags_id_in_all: issue_tag_ids).result unless issue_tag_ids.blank? | |||
| issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank? | |||
| # milestone_id | |||
| issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? | |||
| @@ -58,6 +58,7 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||
| @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? | |||
| @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? | |||
| @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? | |||
| @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? | |||
| @updated_issue.updated_on = Time.now | |||
| @updated_issue.save! | |||