mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-16 17:55:56 +08:00
Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
@@ -194,7 +194,7 @@ module ProjectOperable
|
||||
if owner.is_a?(User)
|
||||
managers.exists?(user_id: user.id)
|
||||
elsif owner.is_a?(Organization)
|
||||
managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || owner.is_only_admin?(user.id)
|
||||
managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_only_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0)
|
||||
else
|
||||
false
|
||||
end
|
||||
@@ -205,7 +205,7 @@ module ProjectOperable
|
||||
if owner.is_a?(User)
|
||||
developers.exists?(user_id: user.id)
|
||||
elsif owner.is_a?(Organization)
|
||||
developers.exists?(user_id: user.id) || owner.is_only_write?(user.id)
|
||||
developers.exists?(user_id: user.id) || (owner.is_only_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0)
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
@@ -1,45 +1,158 @@
|
||||
module Watchable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :watchers, as: :watchable, dependent: :destroy
|
||||
has_many :watcher_users, through: :watchers, source: :user, validate: false
|
||||
|
||||
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
|
||||
scope :following, -> (user_id) { watched_by(user_id) }
|
||||
end
|
||||
|
||||
def watched?(watchable)
|
||||
watchable.watchers.exists?(user: self)
|
||||
end
|
||||
|
||||
def watch!(watchable)
|
||||
watchable.watchers.create!(user: self, created_at: Time.current)
|
||||
end
|
||||
|
||||
def unwatch!(watchable)
|
||||
obj = watchable.watchers.find_by(user: self)
|
||||
obj.destroy! if obj.present?
|
||||
end
|
||||
|
||||
# 我正在关注的、我追随的
|
||||
def following
|
||||
User.following(self.id)
|
||||
end
|
||||
|
||||
def following_count
|
||||
following.size
|
||||
end
|
||||
|
||||
# 关注我的、我的粉丝、我的追随者
|
||||
def followers
|
||||
watcher_users
|
||||
end
|
||||
|
||||
def followers_count
|
||||
followers.size
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
module Watchable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :watchers, as: :watchable, dependent: :destroy
|
||||
has_many :watcher_users, through: :watchers, source: :user, validate: false
|
||||
|
||||
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
|
||||
scope :following, -> (user_id) { watched_by(user_id) }
|
||||
end
|
||||
|
||||
def watched?(watchable)
|
||||
watchable.watchers.exists?(user: self)
|
||||
end
|
||||
|
||||
def watch!(watchable)
|
||||
watchable.watchers.create!(user: self, created_at: Time.current)
|
||||
end
|
||||
|
||||
def unwatch!(watchable)
|
||||
obj = watchable.watchers.find_by(user: self)
|
||||
obj.destroy! if obj.present?
|
||||
end
|
||||
|
||||
# 我正在关注的、我追随的
|
||||
def following
|
||||
User.following(self.id)
|
||||
end
|
||||
|
||||
def following_count
|
||||
following.size
|
||||
end
|
||||
|
||||
def contribution_perc(project)
|
||||
@project = project
|
||||
@user = self
|
||||
|
||||
def cal_perc(count_user, count_all)
|
||||
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
|
||||
end
|
||||
|
||||
if @project['use_blockchain'] == true or @project['use_blockchain'] == 1
|
||||
balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id})
|
||||
balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"]
|
||||
score = cal_perc(balance_user, balance_all)
|
||||
else
|
||||
# 获取所有行为对应的项目内记录总数和个人记录数
|
||||
features = {
|
||||
"requirement" => {},
|
||||
"development" => {},
|
||||
"review" => {}
|
||||
}
|
||||
|
||||
# 1. issue创建
|
||||
issues = Issue.where(project_id: @project.id, issue_classify: 'issue')
|
||||
issue_all = issues.count
|
||||
issue_user = issues.where(author_id: @user.id).count
|
||||
features["requirement"] = features["requirement"].merge({"issue" => {"all" => issue_all, "perc" => cal_perc(issue_user, issue_all)}})
|
||||
# 2. 里程碑创建
|
||||
milestones = Version.where(project_id: @project.id)
|
||||
milestone_all = milestones.count
|
||||
milestone_user = milestones.where(user_id: @user.id).count
|
||||
features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => cal_perc(milestone_user, milestone_all)}})
|
||||
# 3. issue评论
|
||||
issue_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{@project.id} and journalized_type='Issue' and issues.issue_classify='issue'")
|
||||
issue_comment_all = issue_comments.count
|
||||
issue_comment_user = issue_comments.where("journals.user_id=#{@user.id}").count
|
||||
features["requirement"] = features["requirement"].merge({"issue_comment" => {"all" => issue_comment_all, "perc" => cal_perc(issue_comment_user, issue_comment_all)}})
|
||||
# 4. 合并请求
|
||||
prs = PullRequest.where(project_id: @project.id)
|
||||
pr_all = prs.count
|
||||
pr_user = prs.where(user_id: @user.id).count
|
||||
features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => cal_perc(pr_user, pr_all)}})
|
||||
# 5. pr评论
|
||||
pr_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{@project.id} and journalized_type='Issue' and issues.issue_classify='pull_request'")
|
||||
pr_comment_all = pr_comments.count
|
||||
pr_comment_user = pr_comments.where("journals.user_id=#{@user.id}").count
|
||||
features["review"] = features["review"].merge({"pr_comment" => {"all" => pr_comment_all, "perc" => cal_perc(pr_comment_user, pr_comment_all)}})
|
||||
# 6. 代码行评论
|
||||
line_comments = Journal.joins("INNER JOIN pull_requests on journals.journalized_id=pull_requests.id").where("pull_requests.project_id=#{@project.id} and journalized_type='PullRequest'")
|
||||
line_comment_all = line_comments.count
|
||||
line_comment_user = line_comments.where("journals.user_id=#{@user.id}").count
|
||||
features["review"] = features["review"].merge({"line_comment" => {"all" => line_comment_all, "perc" => cal_perc(line_comment_user, line_comment_all)}})
|
||||
# 7. 代码行、commit贡献统计
|
||||
code_contributions = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: nil})
|
||||
commit_all = code_contributions["commit_count"]
|
||||
addition_all = code_contributions["additions"]
|
||||
deletion_all = code_contributions["deletions"]
|
||||
|
||||
commit_user = 0
|
||||
addition_user = 0
|
||||
deletion_user = 0
|
||||
code_contributions["authors"].each do |author|
|
||||
if author["name"] == @user.login
|
||||
commit_user = author["commits"]
|
||||
addition_user = author["additions"]
|
||||
deletion_user = author["deletions"]
|
||||
end
|
||||
end
|
||||
|
||||
features["development"] = features["development"].merge({"commit" => {"all" => commit_all, "perc" => cal_perc(commit_user, commit_all)}})
|
||||
features["development"] = features["development"].merge({"addition" => {"all" => addition_all, "perc" => cal_perc(addition_user, addition_all)}})
|
||||
features["development"] = features["development"].merge({"deletion" => {"all" => deletion_all, "perc" => cal_perc(deletion_user, deletion_all)}})
|
||||
|
||||
def cal_weight(features)
|
||||
weights = {} # 计算每一项的权重
|
||||
categories = []
|
||||
features.each do |key, _|
|
||||
categories << key
|
||||
weights[key] = Hash.new
|
||||
end
|
||||
count_all = 0
|
||||
counts = {}
|
||||
categories.each do |category|
|
||||
count_1 = 0
|
||||
features[category].each do |_, value|
|
||||
count_1 += value["all"]
|
||||
end
|
||||
count_all += count_1
|
||||
counts[category] = count_1
|
||||
features[category].each do |key, value|
|
||||
weight = cal_perc(value["all"], count_1)
|
||||
weights[category] = weights[category].merge({key => weight})
|
||||
end
|
||||
end
|
||||
categories.each do |category|
|
||||
weight = cal_perc(counts[category], count_all)
|
||||
weights[category] = weights[category].merge({"category_weight" => weight})
|
||||
end
|
||||
return weights
|
||||
end
|
||||
|
||||
weights_categories = cal_weight(features)
|
||||
score = 0.0
|
||||
features.each do |category, value_1|
|
||||
category_score = 0.0
|
||||
value_1.each do |action, value_2|
|
||||
category_score += weights_categories[category][action] * value_2["perc"]
|
||||
end
|
||||
score += weights_categories[category]["category_weight"] * category_score.round(4)
|
||||
end
|
||||
end
|
||||
score
|
||||
(score * 100).round(1).to_s + "%"
|
||||
end
|
||||
|
||||
# 关注我的、我的粉丝、我的追随者
|
||||
def followers
|
||||
watcher_users
|
||||
end
|
||||
|
||||
def followers_count
|
||||
followers.size
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,12 +69,26 @@ 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, dependent: :destroy
|
||||
has_many :assigners, through: :issue_assigners
|
||||
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, -> {joins(:issue_assigners).distinct}, through: :issue_assigners, source: :assigner
|
||||
has_many :show_issue_tags, -> {joins(:issue_tags_relates).distinct}, 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
|
||||
has_many :pull_attached_issues, dependent: :destroy
|
||||
has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request
|
||||
|
||||
scope :issue_includes, ->{includes(:user)}
|
||||
scope :issue_many_includes, ->{includes(journals: :user)}
|
||||
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
|
||||
scope :issue_pull_request, ->{where(issue_classify: "pull_request")}
|
||||
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
||||
scope :closed, ->{where(status_id: 5)}
|
||||
scope :opened, ->{where.not(status_id: 5)}
|
||||
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||
after_save :change_versions_count, :send_update_message_to_notice_system
|
||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
|
||||
|
||||
20
app/models/issue_assigner.rb
Normal file
20
app/models/issue_assigner.rb
Normal file
@@ -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
|
||||
9
app/models/issue_participant.rb
Normal file
9
app/models/issue_participant.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class IssueParticipant < ApplicationRecord
|
||||
|
||||
belongs_to :issue
|
||||
belongs_to :participant, class_name: "User"
|
||||
|
||||
enum participant_type: {"authored": 0, "assigned": 1, "commented": 2, "edited": 3, "atme": 4}
|
||||
|
||||
|
||||
end
|
||||
@@ -15,4 +15,21 @@
|
||||
|
||||
class IssuePriority < ApplicationRecord
|
||||
has_many :issues
|
||||
|
||||
def self.init_data
|
||||
map = {
|
||||
"1" => "低",
|
||||
"2" => "正常",
|
||||
"3" => "高",
|
||||
"4" => "紧急"
|
||||
}
|
||||
IssuePriority.order(id: :asc).each do |prty|
|
||||
if map["#{prty.id}"] == prty.name
|
||||
IssuePriority.find_or_create_by(id: prty.id, name: prty.name)
|
||||
else
|
||||
Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)}
|
||||
prty.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,10 +20,28 @@ class IssueStatus < ApplicationRecord
|
||||
ADD = 1
|
||||
SOLVING = 2
|
||||
SOLVED = 3
|
||||
FEEDBACK = 4
|
||||
# FEEDBACK = 4
|
||||
CLOSED = 5
|
||||
REJECTED = 6
|
||||
|
||||
has_many :issues
|
||||
belongs_to :project, optional: true
|
||||
|
||||
def self.init_data
|
||||
map = {
|
||||
"1" => "新增",
|
||||
"2" => "正在解决",
|
||||
"3" => "已解决",
|
||||
"5" => "关闭",
|
||||
"6" => "拒绝"
|
||||
}
|
||||
IssueStatus.order(id: :asc).each do |stat|
|
||||
if map["#{stat.id}"] == stat.name
|
||||
IssueStatus.find_or_create_by(id: stat.id, name: stat.name)
|
||||
else
|
||||
Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)}
|
||||
stat.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,6 +23,34 @@ class IssueTag < ApplicationRecord
|
||||
|
||||
has_many :issue_tags_relates, dependent: :destroy
|
||||
has_many :issues, through: :issue_tags_relates
|
||||
has_many :issue_issues, -> {where(issue_classify: [nil,"issue"])}, source: :issue, through: :issue_tags_relates
|
||||
has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates
|
||||
belongs_to :project, optional: true, counter_cache: true
|
||||
belongs_to :user, optional: true
|
||||
|
||||
def self.init_data(project_id)
|
||||
data = [
|
||||
["缺陷", "表示项目存在问题", "#d92d4c"],
|
||||
["功能", "表示新功能申请", "#ee955a"],
|
||||
["疑问", "表示存在的问题", "#2d6ddc"],
|
||||
["支持", "表示特定功能或特定需求", "#019549"],
|
||||
["任务", "表示需要分配的任务", "#c1a30d"],
|
||||
["协助", "表示需要社区用户协助", "#2a0dc1"],
|
||||
["搁置", "表示此问题暂时不会继续处理", "#892794"],
|
||||
["文档", "表示文档材料补充", "#9ed600"],
|
||||
["测试", "表示需要测试的需求", "#2897b9"],
|
||||
["重复", "表示已存在类似的疑修", "#bb5332"]
|
||||
]
|
||||
data.each do |item|
|
||||
next if IssueTag.exists?(project_id: project_id, name: item[0])
|
||||
IssueTag.create!(project_id: project_id, name: item[0], description: item[1], color: item[2])
|
||||
end
|
||||
$redis_cache.hset("project_init_issue_tags", project_id, 1)
|
||||
end
|
||||
|
||||
def reset_counter_field
|
||||
self.update_column(:issues_count, issue_issues.size)
|
||||
self.update_column(:pull_requests_count, pull_request_issues.size)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,5 +15,29 @@
|
||||
|
||||
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
|
||||
after_destroy :decrement_issue_tags_counter_cache
|
||||
|
||||
def increment_issue_tags_counter_cache
|
||||
Rails.logger.info "11111"
|
||||
Rails.logger.info self.issue.issue_classify
|
||||
|
||||
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
|
||||
|
||||
def decrement_issue_tags_counter_cache
|
||||
Rails.logger.info "2222222"
|
||||
Rails.logger.info self.issue.issue_classify
|
||||
if self.issue.issue_classify == "issue"
|
||||
IssueTag.decrement_counter :issues_count, issue_tag_id
|
||||
else
|
||||
IssueTag.decrement_counter :pull_requests_count, issue_tag_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,9 +40,12 @@ class Journal < ApplicationRecord
|
||||
belongs_to :journalized, polymorphic: true
|
||||
belongs_to :review, optional: true
|
||||
belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true
|
||||
belongs_to :parent_journal, class_name: 'Journal', foreign_key: :parent_id, optional: true, counter_cache: :comments_count
|
||||
belongs_to :reply_journal, class_name: 'Journal', foreign_key: :reply_id, optional: true
|
||||
has_many :journal_details, :dependent => :delete_all
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id
|
||||
has_many :first_ten_children_journals, -> { order(created_on: :asc).limit(10)}, class_name: 'Journal', foreign_key: :parent_id
|
||||
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id, dependent: :destroy
|
||||
|
||||
scope :journal_includes, ->{includes(:user, :journal_details, :attachments)}
|
||||
scope :parent_journals, ->{where(parent_id: nil)}
|
||||
@@ -54,6 +57,81 @@ class Journal < ApplicationRecord
|
||||
self.notes.blank? && self.journal_details.present?
|
||||
end
|
||||
|
||||
def operate_content
|
||||
content = ""
|
||||
detail = self.journal_details.take
|
||||
case detail.property
|
||||
when 'issue'
|
||||
return "创建了<b>疑修</b>"
|
||||
when 'attachment'
|
||||
old_value = Attachment.where(id: detail.old_value.split(",")).pluck(:filename).join("、")
|
||||
new_value = Attachment.where(id: detail.value.split(",")).pluck(:filename).join("、")
|
||||
if old_value.nil? || old_value.blank?
|
||||
content += "添加了<b>#{new_value}</b>附件"
|
||||
else
|
||||
new_value = "无" if new_value.blank?
|
||||
content += "将附件由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
when 'issue_tag'
|
||||
old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、")
|
||||
new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、")
|
||||
if old_value.nil? || old_value.blank?
|
||||
content += "添加了<b>#{new_value}</b>标记"
|
||||
else
|
||||
new_value = "无" if new_value.blank?
|
||||
content += "将标记由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
when 'assigner'
|
||||
old_value = User.where(id: detail.old_value.split(",")).pluck(:nickname).join("、")
|
||||
new_value = User.where(id: detail.value.split(",")).pluck(:nickname).join("、")
|
||||
if old_value.nil? || old_value.blank?
|
||||
content += "添加负责人<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "无" if new_value.blank?
|
||||
content += "将负责人由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
when 'attr'
|
||||
content = "将"
|
||||
case detail.prop_key
|
||||
when 'subject'
|
||||
return "修改了<b>标题</b>"
|
||||
when 'description'
|
||||
return "修改了<b>描述</b>"
|
||||
when 'status_id'
|
||||
old_value = IssueStatus.find_by_id(detail.old_value)&.name
|
||||
new_value = IssueStatus.find_by_id(detail.value)&.name
|
||||
content += "状态"
|
||||
when 'priority_id'
|
||||
old_value = IssuePriority.find_by_id(detail.old_value)&.name
|
||||
new_value = IssuePriority.find_by_id(detail.value)&.name
|
||||
content += "优先级"
|
||||
when 'fixed_version_id'
|
||||
old_value = Version.find_by_id(detail.old_value)&.name
|
||||
new_value = Version.find_by_id(detail.value)&.name
|
||||
content += "里程碑"
|
||||
when 'branch_name'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
content += "关联分支"
|
||||
when 'start_date'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
content += "开始日期"
|
||||
when 'due_date'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
content += "结束日期"
|
||||
end
|
||||
if old_value.nil? || old_value.blank?
|
||||
content += "设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "无" if new_value.blank?
|
||||
content += "由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def journal_content
|
||||
send_details = []
|
||||
if self.is_journal_detail?
|
||||
|
||||
@@ -26,7 +26,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}")
|
||||
@@ -52,7 +52,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{baseurl}', base_url)
|
||||
content.gsub!('{title}', issue&.subject)
|
||||
content.gsub!('{id}', issue&.id.to_s)
|
||||
content.gsub!('{id}', issue&.project_issues_index.to_s)
|
||||
content.gsub!('{platform}', PLATFORM)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
|
||||
@@ -20,7 +20,7 @@ class MessageTemplate::IssueAssignerExpire < MessageTemplate
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueAssignerExpire.get_message_content [ERROR] #{e}")
|
||||
|
||||
@@ -20,7 +20,7 @@ class MessageTemplate::IssueAtme < MessageTemplate
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{nickname}', operator&.real_name).gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}")
|
||||
|
||||
@@ -27,20 +27,20 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
change_count = change_params.keys.size
|
||||
# 疑修负责人修改
|
||||
if change_params[:assigned_to_id].present?
|
||||
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||
assigner1 = User.where(id: change_params[:assigned_to_id][0])
|
||||
assigner2 = User.where(id: change_params[:assigned_to_id][1])
|
||||
if change_count > 1
|
||||
content.sub!('{ifassigner}', '<br/>')
|
||||
else
|
||||
content.sub!('{ifassigner}', '')
|
||||
end
|
||||
content.sub!('{endassigner}', '')
|
||||
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员')
|
||||
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员')
|
||||
content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '未指派成员')
|
||||
content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '未指派成员')
|
||||
else
|
||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||
end
|
||||
@@ -205,20 +205,20 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||
content.gsub!('{identifier}', project&.identifier)
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{title}', issue&.subject)
|
||||
content.gsub!('{id}', issue&.id.to_s)
|
||||
content.gsub!('{id}', issue&.project_issues_index.to_s)
|
||||
change_count = change_params.keys.size
|
||||
# 疑修负责人修改
|
||||
if change_params[:assigned_to_id].present?
|
||||
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||
assigner1 = User.where(id: change_params[:assigned_to_id][0])
|
||||
assigner2 = User.where(id: change_params[:assigned_to_id][1])
|
||||
if change_count > 1
|
||||
content.sub!('{ifassigner}', '<br/>')
|
||||
else
|
||||
content.sub!('{ifassigner}', '')
|
||||
end
|
||||
content.sub!('{endassigner}', '')
|
||||
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员')
|
||||
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员')
|
||||
content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '未指派成员')
|
||||
content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '未指派成员')
|
||||
else
|
||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ class MessageTemplate::IssueExpire < MessageTemplate
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
@@ -53,7 +53,7 @@ class MessageTemplate::IssueExpire < MessageTemplate
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{baseurl}', base_url)
|
||||
content.gsub!('{title}', issue&.subject)
|
||||
content.gsub!('{id}', issue&.id.to_s)
|
||||
content.gsub!('{id}', issue&.project_issues_index.to_s)
|
||||
content.gsub!('{platform}', PLATFORM)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
|
||||
@@ -27,7 +27,7 @@ class MessageTemplate::ProjectIssue < MessageTemplate
|
||||
receivers = managers + followers
|
||||
return '', '', '' if receivers.blank?
|
||||
content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s)
|
||||
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
@@ -54,7 +54,7 @@ class MessageTemplate::ProjectIssue < MessageTemplate
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{login2}', owner&.login)
|
||||
content.gsub!('{identifier}', project&.identifier)
|
||||
content.gsub!('{id}', issue&.id.to_s)
|
||||
content.gsub!('{id}', issue&.project_issues_index.to_s)
|
||||
content.gsub!('{title}', issue&.subject)
|
||||
content.gsub!('{platform}', PLATFORM)
|
||||
|
||||
|
||||
@@ -195,6 +195,14 @@ class Organization < Owner
|
||||
prohibit_gitea_user_login!
|
||||
end
|
||||
|
||||
def teams_count
|
||||
teams.count
|
||||
end
|
||||
|
||||
def organization_users_count
|
||||
organization_users.count
|
||||
end
|
||||
|
||||
def real_name
|
||||
name = lastname + firstname
|
||||
name = name.blank? ? (nickname.blank? ? login : nickname) : name
|
||||
|
||||
@@ -69,6 +69,8 @@ class Owner < ApplicationRecord
|
||||
has_many :applied_transfer_projects, dependent: :destroy
|
||||
|
||||
scope :like, lambda { |keywords|
|
||||
# 表情处理
|
||||
keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search "
|
||||
where(sql, :search => "%#{keywords.strip}%") unless keywords.blank?
|
||||
}
|
||||
|
||||
@@ -240,6 +240,8 @@ class Project < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search_project(search)
|
||||
# 表情处理
|
||||
search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
ransack(name_or_identifier_cont: search)
|
||||
end
|
||||
# 创建者
|
||||
@@ -421,4 +423,19 @@ class Project < ApplicationRecord
|
||||
raise("项目名称包含敏感词汇,请重新输入") if name && !HarmoniousDictionary.clean?(name)
|
||||
raise("项目描述包含敏感词汇,请重新输入") if description && !HarmoniousDictionary.clean?(description)
|
||||
end
|
||||
|
||||
def get_last_project_issues_index
|
||||
last_issue = self.issues.issue_issue.last
|
||||
deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i
|
||||
|
||||
last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0
|
||||
end
|
||||
|
||||
def incre_project_issue_cache_delete_count(count=1)
|
||||
$redis_cache.hincrby("issue_cache_delete_count", self.id, count)
|
||||
end
|
||||
|
||||
def del_project_issue_cache_delete_count
|
||||
$redis_cache.hdel("issue_cache_delete_count", self.id)
|
||||
end
|
||||
end
|
||||
|
||||
23
app/models/pull_attached_issue.rb
Normal file
23
app/models/pull_attached_issue.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: pull_attached_issues
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# pull_request_id :integer
|
||||
# issue_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# fixed :boolean default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_pull_attached_issues_on_issue_id (issue_id)
|
||||
# index_pull_attached_issues_on_pull_request_id (pull_request_id)
|
||||
#
|
||||
|
||||
class PullAttachedIssue < ApplicationRecord
|
||||
|
||||
belongs_to :pull_request
|
||||
belongs_to :issue
|
||||
|
||||
end
|
||||
@@ -44,6 +44,8 @@ class PullRequest < ApplicationRecord
|
||||
has_many :pull_requests_reviewers, dependent: :destroy
|
||||
has_many :reviewers, through: :pull_requests_reviewers
|
||||
has_many :mark_files, dependent: :destroy
|
||||
has_many :pull_attached_issues, dependent: :destroy
|
||||
has_many :attached_issues, through: :pull_attached_issues, source: :issue
|
||||
|
||||
scope :merged_and_closed, ->{where.not(status: 0)}
|
||||
scope :opening, -> {where(status: 0)}
|
||||
|
||||
@@ -30,6 +30,10 @@ class Site < ApplicationRecord
|
||||
self.common.where(key: 'notice').present?
|
||||
end
|
||||
|
||||
def self.has_blockchain?
|
||||
self.common.where(key: 'blockchain').present?
|
||||
end
|
||||
|
||||
private
|
||||
def self.set_add_menu!
|
||||
adds= [
|
||||
|
||||
@@ -178,9 +178,15 @@ class User < Owner
|
||||
has_many :user_trace_tasks, dependent: :destroy
|
||||
|
||||
has_many :feedbacks, dependent: :destroy
|
||||
has_many :issue_assigners, foreign_key: :assigner_id
|
||||
has_many :assigned_issues, through: :issue_assigners, source: :issue
|
||||
has_many :issue_participants, foreign_key: :participant_id
|
||||
has_many :participant_issues, through: :issue_participants, source: :issue
|
||||
# Groups and active users
|
||||
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
||||
scope :like, lambda { |keywords|
|
||||
# 表情处理
|
||||
keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
|
||||
where(sql, :search => "%#{keywords.strip}%") unless keywords.blank?
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ class Version < ApplicationRecord
|
||||
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
||||
belongs_to :user, optional: true
|
||||
|
||||
has_many :opened_issues, -> {where(issue_classify: "issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
|
||||
has_many :closed_issues, -> {where(issue_classify: "issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
|
||||
|
||||
scope :version_includes, ->{includes(:issues, :user)}
|
||||
scope :closed, ->{where(status: 'closed')}
|
||||
scope :opening, ->{where(status: 'open')}
|
||||
@@ -43,6 +46,11 @@ class Version < ApplicationRecord
|
||||
after_create :send_create_message_to_notice_system
|
||||
after_save :send_update_message_to_notice_system
|
||||
|
||||
def issue_percent
|
||||
issues_total_count = opened_issues.size + closed_issues.size
|
||||
issues_total_count.zero? ? 0.0 : closed_issues.size.to_f / issues_total_count
|
||||
end
|
||||
|
||||
def version_user
|
||||
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id)
|
||||
end
|
||||
@@ -53,6 +61,6 @@ class Version < ApplicationRecord
|
||||
end
|
||||
|
||||
def send_update_message_to_notice_system
|
||||
SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.percent == 1.0
|
||||
SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.issue_percent == 1.0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user