修复编辑issue,更新附件时,自动回复提示问题(不同Issue下,重名不显示,同意issue下,会更新创建时的附件)

This commit is contained in:
daiao 2016-09-09 09:16:22 +08:00
parent cdd4dfcf09
commit aa27d7def2
3 changed files with 25 additions and 8 deletions

View File

@ -183,6 +183,7 @@ class IssuesController < ApplicationController
end
end
# 用户发布新issue
def create
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
@ -225,6 +226,7 @@ class IssuesController < ApplicationController
end
def edit
# 修改实例变量的值
return unless update_issue_from_params
respond_to do |format|
@ -233,6 +235,7 @@ class IssuesController < ApplicationController
end
end
# 用户编辑更改issue
def update
if params[:issue_detail]
issue = Issue.find(params[:id])
@ -240,6 +243,7 @@ class IssuesController < ApplicationController
@saved = update_user_issue_detail(issue, params)
return
else
# 修改实例变量的值
return unless update_issue_from_params
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
saved = false
@ -575,6 +579,7 @@ class IssuesController < ApplicationController
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
@time_entry.attributes = params[:time_entry]
# 更新issue状态时journal表产生记录返回@current_journal
@issue.init_journal(User.current)
issue_attributes = params[:issue]

View File

@ -757,6 +757,7 @@ class Issue < ActiveRecord::Base
end
end
# 更新issue时判断更新之前当前是否有自动更新的评论
def init_journal(user, notes = "")
@current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
if new_record?
@ -1454,8 +1455,18 @@ class Issue < ActiveRecord::Base
end
# Callback on file attachment
# 在执行issue模块前 执行:当附件被添加时,产生评论
# 第一次创建issue时@current_journal为nil评论不产生
# 当附件名称重名时,也不产生评论
# 当更新isuue时第一次上传的附件的已经存在则不更新次附件评论
def attachment_added(obj)
if @current_journal && @current_journal.user_id == obj.author_id && JournalDetail.find_all_by_value(obj.filename).count == 0
# 找出该issue评论表中附件重名的个数
jor = Journal.where(:journalized_id => self.id)
jor_ids = jor.empty? ? "(-1)" : "(" + jor.map{|detail| detail.id}.join(",") + ")"
jor_details_count = JournalDetail.where("journal_id in #{jor_ids} and value = '#{obj.filename}'").count
if @current_journal && @current_journal.user_id == obj.author_id && jor_details_count == 0 && self.attachments.find_all_by_filename(obj.filename).count == 0
@current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename)
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160830090214) do
ActiveRecord::Schema.define(:version => 20160907080621) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -157,13 +157,13 @@ ActiveRecord::Schema.define(:version => 20160830090214) do
create_table "attachments", :force => true do |t|
t.integer "container_id"
t.string "container_type", :limit => 30
t.string "filename", :default => "", :null => false
t.string "disk_filename", :default => "", :null => false
t.integer "filesize", :default => 0, :null => false
t.string "filename", :default => "", :null => false
t.string "disk_filename", :default => "", :null => false
t.integer "filesize", :default => 0, :null => false
t.string "content_type", :default => ""
t.string "digest", :limit => 40, :default => "", :null => false
t.integer "downloads", :default => 0, :null => false
t.integer "author_id", :default => 0, :null => false
t.string "digest", :limit => 40, :default => "", :null => false
t.integer "downloads", :default => 0, :null => false
t.integer "author_id", :default => 0, :null => false
t.datetime "created_on"
t.string "description"
t.string "disk_directory"
@ -173,6 +173,7 @@ ActiveRecord::Schema.define(:version => 20160830090214) do
t.integer "quotes"
t.integer "is_publish", :default => 1
t.date "publish_time"
t.boolean "init_file", :default => false
end
add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id"