diff --git a/Gemfile b/Gemfile index 29b2716a9..fb0312d5b 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'ruby-ole' #gem 'email_verifier', path: 'lib/email_verifier' gem 'rufus-scheduler' #gem 'dalli', path: 'lib/dalli-2.7.2' -gem 'rails_kindeditor' +gem 'rails_kindeditor',path:'lib/rails_kindeditor' group :development do gem 'grape-swagger' #gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 64157ea42..c347ba6b8 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,7 +1,7 @@ # added by fq class ForumsController < ApplicationController layout "users_base" - + include ApplicationHelper # GET /forums # GET /forums.json before_filter :find_forum_if_available @@ -63,6 +63,9 @@ class ForumsController < ApplicationController respond_to do |format| if @memo.save + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@memo.id,1 + #end format.html { redirect_to (forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else @@ -163,6 +166,13 @@ class ForumsController < ApplicationController @forum = Forum.new(params[:forum]) @forum.creator_id = User.current.id if @forum.save + # Time 2015-03-24 17:07:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 2 对应的是 forum + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@forum.id,2 + #end respond_to do |format| format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index aaa99e417..54bcc0496 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -59,6 +59,20 @@ class MemosController < ApplicationController @memo.content = @quote + @memo.content respond_to do |format| if @memo.save + # Time 2015-03-24 14:47:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + if !params[:asset_id].nil? + ids = params[:asset_id].split(',') + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = @memo.id + asset.owner_type = 1 + asset.save + end + end + #end format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e9a27cf44..41876e041 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -340,7 +340,7 @@ class ProjectsController < ApplicationController @is_zhuce =false flash[:notice] = l(:notice_email_sent, :value => email) else - flash[:error] = l(:notice_registed_success, :value => email) + flash[:error] = l(:notice_registed_error, :value => email) @is_zhuce = true end respond_to do |format| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..a5cfc2b16 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,35 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # Time 2015-03-24 15:27:29 + # Author lizanle + # Description 从硬盘上删除对应的资源文件 + def delete_kindeditor_assets_from_disk owner_id,owner_type + assets = Kindeditor::Asset.where(["owner_id = ? and owner_type = ?",owner_id,owner_type]) + if !assets.nil? && !assets.blank? + assets.all.each do |asset| + next if asset.nil? + filepath = File.join(Rails.root,"public","files","uploads", + asset[:created_at].to_s.gsub("+0800","").to_datetime.strftime("%Y%m").to_s, + asset[:asset].to_s) + File.delete(filepath) if File.exist?filepath + end + end + end + + # Time 2015-03-24 16:38:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + def update_kindeditor_assets_owner ids,owner_id,owner_type + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = owner_id + asset.owner_type = owner_type + asset.save + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表 diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 9eff409ff..884ebc2eb 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -87,7 +87,10 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + if attachment.is_public? || + (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || + (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| + attachment.author_id == User.current.id result << attachment end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 878937ea7..6843ab678 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,5 +1,7 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' @@ -15,7 +17,7 @@ class Forum < ActiveRecord::Base validates_length_of :name, maximum: 50 #validates_length_of :description, maximum: 255 validates :name, :uniqueness => true - + after_destroy :delete_kindeditor_assets acts_as_taggable scope :by_join_date, order("created_at DESC") #after_create :send_email @@ -47,5 +49,11 @@ class Forum < ActiveRecord::Base ["id = ?", forum_id]) end + # Time 2015-03-26 15:50:54 + # Author lizanle + # Description 删除论坛后删除对应的资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,2 + end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index b404ea531..e1c538fd0 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -125,7 +125,7 @@ class Mailer < ActionMailer::Base end - + # 公共讨论区发帖、回帖添加邮件发送信息 def forum_message_added(memo) @memo = memo redmine_headers 'Memo' => memo.id @@ -134,9 +134,11 @@ class Mailer < ActionMailer::Base @forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id) @issue_author_url = url_for(user_activities_url(@author)) recipients ||= [] - if @forum.author.mail_notification != 'day' && @forum.author.mail_notification != 'week' + #将帖子创建者邮箱地址加入数组 + if @forum.creator.mail_notification != 'day' && @forum.creator.mail_notification != 'week' recipients << @forum.creator.mail end + #回复人邮箱地址加入数组 if @author.mail_notification != 'day' && @author.mail_notification != 'week' recipients << @author.mail end diff --git a/app/models/memo.rb b/app/models/memo.rb index 052ca03db..eb0c86855 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,7 +1,9 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper belongs_to :forum + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => "User", :foreign_key => 'author_id' validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 @@ -42,9 +44,9 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters! #, :sendmail#,:be_user_score -- 公共区发帖暂不计入得分 + after_create :add_author_as_watcher, :reset_counters!, :sendmail # after_update :update_memos_forum - after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分 + after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -170,4 +172,10 @@ class Memo < ActiveRecord::Base update_replay_for_memo(User.current,1) end + # Time 2015-03-26 15:20:24 + # Author lizanle + # Description 从硬盘上删除资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,1 + end end diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 7578965b5..9e086ef1b 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -165,7 +165,7 @@
<%= f.text_field :subject, :required => true, :maxlength => 50%>
- <%= f.text_area :content, :required => true, :id => 'editor02' %> + <%= f.kindeditor :content, :required => true %>
- +(<%= l(:label_memos_max_length) %>)
diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 4b282aa8f..012178ae2 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -1,5 +1,5 @@