diff --git a/Gemfile b/Gemfile index 70281fedf..679e0a5b2 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,11 @@ source 'http://ruby.taobao.org' unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' - gem 'rubyzip' - gem 'zip-zip' end +gem 'rubyzip' +gem 'delayed_job_active_record'#, :group => :production +gem 'daemons' gem 'grape', '~> 0.9.0' gem 'grape-entity' gem 'seems_rateable', '~> 1.0.13' diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 2cf404ffb..f8d0f5dd1 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -88,9 +88,7 @@ class AccountController < ApplicationController # create a new token for password recovery token = Token.new(:user => user, :action => "recovery") if token.save - Thread.new do - Mailer.lost_password(token).deliver - end + Mailer.run.lost_password(token) flash[:notice] = l(:notice_account_lost_email_sent) redirect_to signin_url return @@ -228,7 +226,7 @@ class AccountController < ApplicationController user = User.find(params[:user]) if params[:user] token = Token.new(:user => user, :action => "register") if token.save - Mailer.register(token).deliver + Mailer.run.register(token) else yield if block_given? @@ -366,7 +364,7 @@ class AccountController < ApplicationController token = Token.new(:user => user, :action => "register") if user.save and token.save UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) - Mailer.register(token).deliver + Mailer.run.register(token) flash[:notice] = l(:notice_account_register_done) @@ -401,7 +399,7 @@ class AccountController < ApplicationController if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) # Sends an email to the administrators - Mailer.account_activation_request(user).deliver + Mailer.run.account_activation_request(user) account_pending else yield if block_given? diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index f2c0eb056..8e70ed32c 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -13,7 +13,7 @@ class AppliedProjectController < ApplicationController @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) if @applieds.count == 0 appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) - Mailer.applied_project(appliedproject).deliver + Mailer.run.applied_project(appliedproject) @status = 2 else @status = 1 @@ -31,7 +31,7 @@ class AppliedProjectController < ApplicationController @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) if @applieds.count == 0 appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) - Mailer.applied_project(appliedproject).deliver + Mailer.run.applied_project(appliedproject) end #redirect_to project_path(params[:project_id]) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 581005bf7..a243018ba 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,6 +1,7 @@ class CoursesController < ApplicationController layout 'base_courses' include CoursesHelper + include ActivitiesHelper helper :activities helper :members helper :words @@ -680,26 +681,49 @@ class CoursesController < ApplicationController "show_course_files" => true, "show_course_news" => true, "show_course_messages" => true, - "show_bids" => true, "show_course_journals_for_messages" => true, + "show_bids" => true, "show_homeworks" => true } @date_to ||= Date.today + 1 @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) - @author ||= @course.teacher - # 决定显示所用用户或单个用户活动 - @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subprojects => false, - :author => @author) - @activity.scope_select {|t| has["show_#{t}"]} - # modify by nwb - # 添加私密性判断 - if User.current.member_of_course?(@course)|| User.current.admin? - events = @activity.events(@days, @course.created_at) + if @author.nil? + # 显示老师和助教的活动 + # @authors = searchTeacherAndAssistant(@course) + @authors = course_all_member(@course) + events = [] + @authors.each do |author| + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => author.user) + + @activity.scope_select {|t| has["show_#{t}"]} + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events += @activity.events(@days, @course.created_at) + else + events += @activity.events(@days, @course.created_at, :is_public => 1) + end + + end else - events = @activity.events(@days, @course.created_at, :is_public => 1) + # @author = @course.teacher + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => @author) + + @activity.scope_select {|t| has["show_#{t}"]} + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events = @activity.events(@days, @course.created_at) + else + events = @activity.events(@days, @course.created_at, :is_public => 1) + end end + # 无新动态时,显示老动态 if events.count == 0 if User.current.member_of_course?(@course)|| User.current.admin? @@ -708,13 +732,17 @@ class CoursesController < ApplicationController events = @activity.events(:is_public => 1) end end - events = paginateHelper events,10 - @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} - # documents @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) end + + sorted_events = sort_activity_events_course(events); + events = paginateHelper sorted_events,10 + @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} + # documents + + respond_to do |format| format.html{render :layout => 'base_courses'} format.api diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 9bf2ee846..570726320 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -110,7 +110,7 @@ class DocumentsController < ApplicationController render_attachment_warning_if_needed(@document) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end redirect_to document_url(@document) end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b48569f2c..1ca3e2fcf 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -314,7 +314,7 @@ class FilesController < ApplicationController render_attachment_warning_if_needed(container) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end # TODO: 临时用 nyan @@ -343,7 +343,7 @@ class FilesController < ApplicationController attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type]) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end # TODO: 临时用 nyan diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 41876e041..8ed9fcfef 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -336,7 +336,7 @@ class ProjectsController < ApplicationController def send_mail_to_member if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? email = params[:mail] - Mailer.send_invite_in_project(email, @project, User.current).deliver + Mailer.run.send_invite_in_project(email, @project, User.current) @is_zhuce =false flash[:notice] = l(:notice_email_sent, :value => email) else diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6c115fc11..01e470c91 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -131,7 +131,7 @@ update @project_path=@root_path+"htdocs/"+@repository_name @repository_tag=params[:repository][:upassword] || params[:repository][:password] @repo_name=User.current.login.to_s+"_"+params[:repository][:identifier] - logger.info "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+": "+@repository_tag + logger.info "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+": "+@repository_tag logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name attrs = pickup_extra_info if((@repository_tag!="")&¶ms[:repository_scm]=="Git") @@ -147,9 +147,9 @@ update @repository.project = @project if request.post? && @repository.save if(params[:repository_scm]=="Git") - system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag + system "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+" "+@repository_tag system "echo -e '"+@repo_name+"-write:"+ - " "+@repo_name+"' >> "+@root_path+"group.passwd" + " "+@repo_name+"' >> "+@root_path+"htdocs/group.passwd" system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s system "git init --bare "+@project_path system "mv "+@project_path+"/hooks/post-update{.sample,}" @@ -243,8 +243,8 @@ update if(@repository.type=="Repository::Git") logger.info "destory the repository value"+"root path"+@root_path+"repo_name"+@repo_name+ "repository_name"+@repository_name+"user group"+@middle - system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" - system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" + system "sed -i /"+@repo_name+"/{d} "+@root_path+"htdocs/user.passwd" + system "sed -i /"+@middle+"/{d} "+@root_path+"htdocs/group.passwd" system "rm -r "+@root_path+"htdocs/"+@repository_name # if(@sed_user&&@sed_group&&@remove) # else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4db471ab4..a230688dc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -553,7 +553,7 @@ class UsersController < ApplicationController @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] + Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information] respond_to do |format| format.html { @@ -620,9 +620,9 @@ class UsersController < ApplicationController @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) if was_activated - Mailer.account_activated(@user).deliver + Mailer.run.account_activated(@user) elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? - Mailer.account_information(@user, params[:user][:password]).deliver + Mailer.run.account_information(@user, params[:user][:password]) end respond_to do |format| diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 9880a6382..a3bee3c95 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -5,7 +5,7 @@ class ZipdownController < ApplicationController #检查权限 #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" - OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" #统一下载功能 def download @@ -56,9 +56,9 @@ class ZipdownController < ApplicationController if homework != nil unless homework.attachments.empty? zipfile = zip_homework_by_user homework - send_file zipfile, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) + + send_file zipfile.file_path, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) + "_" + (homework.user.lastname.nil? ? "" : homework.user.lastname) + (homework.user.firstname.nil? ? "" : homework.user.firstname) + - "_" + homework.name + ".zip", :type => detect_content_type(zipfile) if(zipfile) + "_" + homework.name + ".zip", :type => detect_content_type(zipfile.file_path) if(zipfile) else render file: 'public/no_file_found.html' end @@ -88,85 +88,116 @@ class ZipdownController < ApplicationController def zip_bid(bid) # Todo: User Access Controll bid_homework_path = [] + digests = [] bid.homeworks.each do |homeattach| unless homeattach.attachments.empty? - bid_homework_path << zip_homework_by_user(homeattach) + out_file = zip_homework_by_user(homeattach) + bid_homework_path << out_file.file_path + digests << out_file.file_digest end end - zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024) - x = 0 + homework_id = bid.id + user_id = bid.author_id - zips.each { |o| - x += 1 - file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER - o[:real_file] = file - o[:file] = File.basename(file) - o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2) + out_file = find_or_pack(homework_id, user_id, digests.sort){ + zipping("#{Time.now.to_i}_#{bid.name}.zip", + bid_homework_path, OUTPUT_FOLDER) + } + + + # zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024) + # x = 0 + # + # + # zips.each { |o| + # x += 1 + # file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER + # o[:real_file] = file + # o[:file] = File.basename(file) + # o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2) + # } + + [{files:[out_file.file_path], count: 1, index: 1, + real_file: out_file.file_path, file: File.basename(out_file.file_path), + size:(out_file.pack_size / 1024.0 / 1024.0).round(2) + }] + end + + def zip_homework_by_user(homework_attach) + homeworks_attach_path = [] + not_exist_file = [] + # 需要将所有homework.attachments遍历加入zip + + + digests = [] + homework_attach.attachments.each do |attach| + if File.exist?(attach.diskfile) + homeworks_attach_path << attach.diskfile + digests << attach.digest + else + not_exist_file << attach.filename + digests << 'not_exist_file' + end + end + + out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){ + zipping("#{homework_attach.user.lastname}#{homework_attach.user.firstname}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", + homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) } end - def zip_homework_by_user(homeattach) - homeworks_attach_path = [] - not_exist_file = [] - # 需要将所有homework.attachments遍历加入zip - # 并且返回zip路径 - homeattach.attachments.each do |attach| - if File.exist?(attach.diskfile) - homeworks_attach_path << attach.diskfile - else - not_exist_file << attach.filename - end + + def find_or_pack(homework_id, user_id, digests) + raise "please given a pack block" unless block_given? + + out_file = ZipPack.packed?(homework_id, user_id, digests.sort) + + unless out_file && out_file.file_valid? + file = yield + + ZipPack.where(homework_id: homework_id, + user_id: user_id).delete_all + + out_file = ZipPack.create(homework_id: homework_id, + user_id: user_id, + file_digest: Trustie::Utils.digest(file), + file_path: file, + pack_size: File.size(file), + file_digests: digests.join(',') + ) + else + out_file.pack_times = out_file.pack_times + 1 + out_file.save end - zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) + + out_file end def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) - # 输入待打包的文件列表,已经打包文件定位到ouput_path - ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') - rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) - - unless is_attachment - #都是zip合并,没必要再费力压缩了 - Zip.default_compression = Zlib::NO_COMPRESSION - else - Zip.default_compression = Zlib::DEFAULT_COMPRESSION - end - Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_paths.each do |filename| - flag = true - index = 1 - rename_file = ic.iconv( (File.basename(filename)) ).to_s - rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment - + rename_file = File.basename(filename) + rename_file = filename_to_real( File.basename(filename)) if is_attachment begin zipfile.add(rename_file, filename) - flag = false rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt') do |os| - os.write l(:label_file_exist) - end + zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} next end end unless not_exist_file.empty? - zipfile.get_output_stream('FILE_LOST.txt') do |os| - os.write l(:label_file_lost) + not_exist_file.join(',').to_s - end + zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s} end end zipfile_name - #rescue Errno => e - # logger.error "[zipdown#zipping] ===> #{e}" - # @error = e end # 合理分配文件打包 diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 8ef2d6095..445a1670e 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -23,7 +23,7 @@ module AccountHelper token = Token.new(:user => user, :action => "register") if user.save and token.save UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) - Mailer.register(token).deliver + Mailer.run.register(token) #flash[:notice] = l(:notice_account_register_done) #render action: 'email_valid', locals: {:mail => user.mail} else @@ -51,7 +51,7 @@ module AccountHelper if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) # Sends an email to the administrators - Mailer.account_activation_request(user).deliver + Mailer.run.account_activation_request(user) #account_pending else yield if block_given? diff --git a/app/helpers/activities_helper.rb b/app/helpers/activities_helper.rb index c15d89e0c..2f48ba87f 100644 --- a/app/helpers/activities_helper.rb +++ b/app/helpers/activities_helper.rb @@ -30,4 +30,16 @@ module ActivitiesHelper end sorted_events end + def sort_activity_events_course(events) + events_by_group = events.group_by(&:event_group) + sorted_events = [] + events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event| + if group_events = events_by_group.delete(event.event_group) + group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i| + sorted_events << e unless e.event_description.nil? + end + end + end + sorted_events + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index f4ba5040e..3adcdb09e 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -632,7 +632,7 @@ module CoursesHelper #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() - + @bid_ids = [] days = Setting.activity_days_default.to_i date_to ||= Date.today + 1 date_from = date_to - days-1.years @@ -653,8 +653,27 @@ module CoursesHelper activities[news.course_id]+=1 end + #feedbackc_count + JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| + activities[jourformess.jour_id]+=1 + end + + #homework_count + #HomeworkForCourse.where(course_id: @course_ids).each do |homework| + # @bid_ids<?",date_from).count + + #end + + #@bid_ids.each do |bid_id| + # activities[] +=Bid.where(id: bid_id ).where("created_on>?",date_from).count + + #end + + + # 动态数 + 1 ( 某某创建了该课程 ) - activities.each_pair { |key, value| activities[key] = value + 1 } + # activities.each_pair { |key, value| activities[key] = value + 1 } return activities end diff --git a/app/models/comment.rb b/app/models/comment.rb index 880bf448c..bdb642d3c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -23,6 +23,13 @@ class Comment < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments safe_attributes 'comments' + after_create :send_mail + + def send_mail + if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') + Mailer.run.news_comment_added(self) + end + end after_destroy :delete_kindeditor_assets # Time 2015-03-31 09:15:06 diff --git a/app/models/comment_observer.rb b/app/models/comment_observer.rb deleted file mode 100644 index a46e53ab9..000000000 --- a/app/models/comment_observer.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class CommentObserver < ActiveRecord::Observer - def after_create(comment) - if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') - ##by senluo - thread3=Thread.new do - Mailer.news_comment_added(comment).deliver - end - end - end -end diff --git a/app/models/document.rb b/app/models/document.rb index 33ffdaa2f..c8e5f8a24 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -24,6 +24,7 @@ class Document < ActiveRecord::Base after_save :be_user_score # user_score after_destroy :down_user_score acts_as_attachable :delete_permission => :delete_documents + after_create :send_mail # 被ForgeActivity虚拟关联 has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # end @@ -87,4 +88,8 @@ class Document < ActiveRecord::Base :project_id => self.project_id) end + def send_mail + Mailer.run.document_added(self) if Setting.notified_events.include?('document_added') + end + end diff --git a/app/models/document_observer.rb b/app/models/document_observer.rb deleted file mode 100644 index 447952c70..000000000 --- a/app/models/document_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class DocumentObserver < ActiveRecord::Observer - def after_create(document) - ##by senluo - thread2=Thread.new do - Mailer.document_added(document).deliver if Setting.notified_events.include?('document_added') - end - end -end diff --git a/app/models/forum.rb b/app/models/forum.rb index 52417f25e..6db069a09 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -20,7 +20,7 @@ class Forum < ActiveRecord::Base after_destroy :delete_kindeditor_assets acts_as_taggable scope :by_join_date, order("created_at DESC") - #after_create :send_email + after_create :send_mail def reset_counters! self.class.reset_counters!(id) end @@ -35,10 +35,9 @@ class Forum < ActiveRecord::Base self.creator == user || user.admin? end - def send_email - Thread.start do - Mailer.forum_add(self).deliver if Setting.notified_events.include?('forum_add') - end + def send_mail + logger.debug "send mail for forum add." + Mailer.run.forum_add(self) if Setting.notified_events.include?('forum_add') end # Updates topic_count, memo_count and last_memo_id attributes for +board_id+ def self.reset_counters!(forum_id) diff --git a/app/models/forum_observer.rb b/app/models/forum_observer.rb deleted file mode 100644 index 6afcac824..000000000 --- a/app/models/forum_observer.rb +++ /dev/null @@ -1,8 +0,0 @@ -class ForumObserver < ActiveRecord::Observer - # def after_create(forum) - # Thread.start do - # Mailer.forum_add(forum).deliver if Setting.notified_events.include?('forum_add') - # end - # - # end -end diff --git a/app/models/issue_observer.rb b/app/models/issue_observer.rb index e404a4a1c..51f64c783 100644 --- a/app/models/issue_observer.rb +++ b/app/models/issue_observer.rb @@ -18,13 +18,11 @@ class IssueObserver < ActiveRecord::Observer def after_create(issue) - Thread.start do # 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送, recipients = issue.recipients - issue.watcher_recipients + issue.watcher_recipients recipients.each do |rec| - Mailer.issue_add(issue,rec).deliver if Setting.notified_events.include?('issue_added') + Mailer.run.issue_add(issue,rec) if Setting.notified_events.include?('issue_added') end - end end end diff --git a/app/models/journal_observer.rb b/app/models/journal_observer.rb index b58464a9b..1fca58f37 100644 --- a/app/models/journal_observer.rb +++ b/app/models/journal_observer.rb @@ -23,14 +23,12 @@ class JournalObserver < ActiveRecord::Observer (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) ) - Thread.start do # 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送, recipients = journal.recipients - journal.watcher_recipients + journal.watcher_recipients recipients.each do |rec| - Mailer.issue_edit(journal,rec).deliver + Mailer.run.issue_edit(journal,rec) end - end end end end diff --git a/app/models/journals_for_message_observer.rb b/app/models/journals_for_message_observer.rb index 0e5f29d03..ee8e28b86 100644 --- a/app/models/journals_for_message_observer.rb +++ b/app/models/journals_for_message_observer.rb @@ -1,9 +1,7 @@ # Added by young class JournalsForMessageObserver < ActiveRecord::Observer def after_create(journals_for_message) - thread1 = Thread.start do - Mailer.journals_for_message_add(User.current, journals_for_message).deliver - end + Mailer.run.journals_for_message_add(User.current, journals_for_message) end end diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 8421fb67d..da1af66a8 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -101,7 +101,7 @@ class MailHandler < ActionMailer::Base end add_user_to_group(@@handler_options[:default_group]) unless @@handler_options[:no_account_notice] - Mailer.account_information(@user, @user.password).deliver + Mailer.run.account_information(@user, @user.password) end else if logger && logger.error diff --git a/app/models/mailer.rb b/app/models/mailer.rb index e1c538fd0..df23813cd 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -27,6 +27,24 @@ class Mailer < ActionMailer::Base { :host => Setting.host_name, :protocol => Setting.protocol } end + + class MailerProxy + def initialize(cls) + @target = cls + end + def method_missing(name, *args, &block) + if Setting.delayjob_enabled && Object.const_defined?('Delayed') + @target.delay.send(name, *args, &block) + else + @target.send(name, *args, &block).deliver + end + end + end + + def self.run + MailerProxy.new(self) + end + # author: alan # 发送邀请未注册用户加入项目邮件 # 功能: 在加入项目的同时自动注册用户 @@ -45,6 +63,12 @@ class Mailer < ActionMailer::Base def send_for_user_activities(user, date_to, days) date_from = date_to - days.days + subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" + @subject = " #{user.show_name} : #{date_to} #{l(:label_day_mail)}" + + date_from = "#{date_from} 23:59:59" + date_to = "#{date_to} 23:59:59" + # 生成token用于直接点击登录 @user = user token = Token.new(:user =>user , :action => 'autologin') @@ -59,10 +83,11 @@ class Mailer < ActionMailer::Base course_ids = courses.map {|course| course.id}.join(",") # 查询user的缺陷,包括发布的,跟踪的以及被指派的缺陷 - @issues = Issue.find_by_sql("select DISTINCT i.* from issues i, watchers w + sql = "select DISTINCT i.* from issues i, watchers w where (i.assigned_to_id = #{user.id} or i.author_id = #{user.id} or (w.watchable_type = 'Issue' and w.watchable_id = i.id and w.user_id = #{user.id})) - and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc") + and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" + @issues = Issue.find_by_sql(sql) # @bids 查询课程作业,包括老师发布的作业,以及user提交作业 # @attachments查询课程课件更新 @@ -114,15 +139,15 @@ class Mailer < ActionMailer::Base @forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc") @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id})) and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc") - if days == 1 - subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" - @subject = " #{user.show_name} : #{date_to - 1.days} #{l(:label_day_mail)}" - else - subject = "[ #{user.show_name} : #{l(:label_week_mail)}]" - @subject = "#{user.show_name} : #{l(:label_week_mail)}" - end - mail :to => user.mail,:subject => subject + + has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news, + @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| + !o.empty? + } + binding.pry if Rails.env.development? + #有内容才发,没有不发 + mail :to => user.mail,:subject => subject if has_content end # 公共讨论区发帖、回帖添加邮件发送信息 @@ -135,17 +160,15 @@ class Mailer < ActionMailer::Base @issue_author_url = url_for(user_activities_url(@author)) recipients ||= [] #将帖子创建者邮箱地址加入数组 - if @forum.creator.mail_notification != 'day' && @forum.creator.mail_notification != 'week' - recipients << @forum.creator.mail - end + recipients << @forum.creator.mail #回复人邮箱地址加入数组 - if @author.mail_notification != 'day' && @author.mail_notification != 'week' - recipients << @author.mail - end + recipients << @author.mail # cc = wiki_content.page.wiki.watcher_recipients - recipients @memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))) - mail :to => recipients,:subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]" + mail :to => recipients, + :subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]", + :filter => true end # Builds a Mail::Message object used to email recipients of the added journals for message. @@ -180,12 +203,8 @@ class Mailer < ActionMailer::Base # 验证用户的收取邮件的方式 recipients ||= [] recipients1 ||= [] - if @mail.mail_notification != 'week' && @mail.mail_notification != 'day' - recipients1 = @mail.mail - end - if journals_for_message.jour.author.mail_notification != 'week' && journals_for_message.jour.author.mail_notification != 'day' - recipients = journals_for_message.jour.author.mail - end + recipients1 = @mail.mail + recipients = journals_for_message.jour.author.mail # modify by nwb #如果是直接留言并且留言对象是课程 @@ -197,25 +216,24 @@ class Mailer < ActionMailer::Base #收件人邮箱 @recipients ||= [] @members.each do |teacher| - if teacher.user.mail_notification != 'week' && teacher.user.mail_notification != 'day' - @recipients << teacher.user.mail - end + @recipients << teacher.user.mail end mail :to => @recipients, - :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " + :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} ", + :filter => true elsif journals_for_message.jour.class.to_s.to_sym == :Bid if !journals_for_message.jour.author.notify_about? journals_for_message return -1 end - mail :to => recipients, :subject => @title + mail :to => recipients, :subject => @title,:filter => true elsif journals_for_message.jour.class.to_s.to_sym == :Contest if !journals_for_message.jour.author.notify_about? journals_for_message return -1 end - mail :to => recipients, :subject => @title + mail :to => recipients, :subject => @title,:filter => true else - mail :to => recipients1, :subject => @title + mail :to => recipients1, :subject => @title,:filter => true end @@ -250,9 +268,9 @@ class Mailer < ActionMailer::Base subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" - mail(:to => recipients, - - :subject => subject) + mail :to => recipients, + :subject => subject, + :filter => true end # issue.attachments.each do |attach| # attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}") @@ -298,9 +316,9 @@ class Mailer < ActionMailer::Base @issue = issue @journal = journal # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") - mail(:to => recipients, - - :subject => s) + mail :to => recipients, + :subject => s, + :filter => true end def self.deliver_mailer(to,cc, subject) @@ -386,7 +404,8 @@ class Mailer < ActionMailer::Base @issue_author_url = url_for(user_activities_url(@author)) @document_url = url_for(:controller => 'documents', :action => 'show', :id => document) mail :to => document.recipients, - :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" + :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}", + :filter => true end # Builds a Mail::Message object used to email recipients of a project when an attachements are added. @@ -424,21 +443,24 @@ class Mailer < ActionMailer::Base @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.name}] #{l(:label_attachment_new)}", + :filter => true elsif container.class.name == 'Project' redmine_headers 'Project' => container.id @attachments = attachments @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.name}] #{l(:label_attachment_new)}", + :filter => true else redmine_headers 'Project' => container.project.identifier @attachments = attachments @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.project.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.project.name}] #{l(:label_attachment_new)}", + :filter => true end end @@ -457,7 +479,8 @@ class Mailer < ActionMailer::Base @news = news @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, - :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}", + :filter => true elsif news.course redmine_headers 'Course' => news.course.id @author = news.author @@ -467,7 +490,8 @@ class Mailer < ActionMailer::Base recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail } @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => recipients, - :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}", + :filter => true end end @@ -488,7 +512,8 @@ class Mailer < ActionMailer::Base @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, :cc => news.watcher_recipients, - :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" + :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}", + :filter => true elsif news.course redmine_headers 'Course' => news.course.id @author = comment.author @@ -500,7 +525,8 @@ class Mailer < ActionMailer::Base recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail } mail :to => recipients, - :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}", + :filter => true end end @@ -523,7 +549,8 @@ class Mailer < ActionMailer::Base @message_url = url_for(message.event_url) mail :to => recipients, :cc => cc, - :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" + :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", + :filter => true elsif message.course redmine_headers 'Course' => message.course.id, 'Topic-Id' => (message.parent_id || message.id) @@ -537,7 +564,8 @@ class Mailer < ActionMailer::Base @message_url = url_for(message.event_url) mail :to => recipients, :cc => cc, - :subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" + :subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", + :filter => true end end @@ -559,7 +587,8 @@ class Mailer < ActionMailer::Base :id => wiki_content.page.title) mail :to => recipients, :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. @@ -583,7 +612,8 @@ class Mailer < ActionMailer::Base :version => wiki_content.version) mail :to => recipients, :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the specified user their account information. @@ -734,6 +764,25 @@ class Mailer < ActionMailer::Base ActionMailer::Base.delivery_method = saved_method end + #过滤掉不是不合规则的收件人 + def filter(reps) + r_reps = [] + if reps.is_a? Array + reps.each do |r| + u = User.find_by_mail(r) + if u && u.mail_notification == 'all' + r_reps << r + end + end + elsif reps.is_a? String + u = User.find_by_mail(r) + if u && u.mail_notification == 'all' + r_reps << r + end + end + r_reps + end + def mail(headers={}) headers.merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, @@ -750,6 +799,11 @@ class Mailer < ActionMailer::Base headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array) end + if headers[:filter] + headers[:to] = filter(headers[:to]) + headers[:cc] = filter(headers[:cc]) + end + if @author && @author.logged? redmine_headers 'Sender' => @author.login end diff --git a/app/models/memo.rb b/app/models/memo.rb index 182ea314e..191d4f978 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -44,7 +44,7 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters!, :sendmail + after_create :add_author_as_watcher, :reset_counters!, :send_mail # after_update :update_memos_forum after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification @@ -55,10 +55,8 @@ class Memo < ActiveRecord::Base # includes(:forum => ).where() # } - def sendmail - thread1=Thread.new do - Mailer.forum_message_added(self).deliver if Setting.notified_events.include?('forum_message_added') - end + def send_mail + Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added') end def cannot_reply_to_locked_topic @@ -115,7 +113,7 @@ class Memo < ActiveRecord::Base def send_notification if Setting.notified_events.include?('message_posted') - Mailer.message_posted(self).deliver + Mailer.run.message_posted(self) end end diff --git a/app/models/memo_observer.rb b/app/models/memo_observer.rb deleted file mode 100644 index 66cabe923..000000000 --- a/app/models/memo_observer.rb +++ /dev/null @@ -1,8 +0,0 @@ -class MemoObserver < ActiveRecord::Observer - def after_create(memo) - - thread1=Thread.new do - Mailer.forum_message_added(memo).deliver if Setting.notified_events.include?('forum_message_added') - end - end -end diff --git a/app/models/message.rb b/app/models/message.rb index dd1dcf92e..669495b45 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -66,10 +66,8 @@ class Message < ActiveRecord::Base after_update :update_messages_board after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - # fq - after_create :act_as_activity,:be_user_score,:act_as_forge_activity + after_create :act_as_activity,:be_user_score,:act_as_forge_activity, :send_mail #before_save :be_user_score - # end scope :visible, lambda {|*args| includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) @@ -210,6 +208,10 @@ class Message < ActiveRecord::Base end end + def send_mail + Mailer.run.message_posted(self) if Setting.notified_events.include?('message_posted') + end + # Time 2015-03-31 09:15:06 # Author lizanle # Description 删除对应消息的图片资源 diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb deleted file mode 100644 index 383301664..000000000 --- a/app/models/message_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class MessageObserver < ActiveRecord::Observer - def after_create(message) - ##by senluo - thread5=Thread.new do - Mailer.message_posted(message).deliver if Setting.notified_events.include?('message_posted') - end - end -end diff --git a/app/models/news.rb b/app/models/news.rb index 116353cf7..de3ad35b0 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -47,12 +47,10 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :add_author_as_watcher - # fq - after_create :act_as_activity,:act_as_forge_activity - # end + after_create :act_as_activity,:act_as_forge_activity,:add_author_as_watcher, :send_mail + after_destroy :delete_kindeditor_assets - + scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) } @@ -115,4 +113,8 @@ class News < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::NEWS end + def send_mail + Mailer.run.news_added(self) if Setting.notified_events.include?('news_added') + end + end diff --git a/app/models/news_observer.rb b/app/models/news_observer.rb deleted file mode 100644 index 8b9bc7b4b..000000000 --- a/app/models/news_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class NewsObserver < ActiveRecord::Observer - def after_create(news) - ##by senluo - thread6=Thread.new do - Mailer.news_added(news).deliver if Setting.notified_events.include?('news_added') - end - end -end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index f087fce2b..181aa89f6 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -159,7 +159,7 @@ class RelativeMemo < ActiveRecord::Base def send_notification if Setting.notified_events.include?('message_posted') - Mailer.message_posted(self).deliver + Mailer.run.message_posted(self) end end diff --git a/app/models/user.rb b/app/models/user.rb index 9abe80779..35c29cbcc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,9 +64,10 @@ class User < Principal }, } + #每日一报、一事一报、不报 MAIL_NOTIFICATION_OPTIONS = [ ['all', :label_user_mail_option_all], - ['week', :label_user_mail_option_week], + #['week', :label_user_mail_option_week], ['day', :label_user_mail_option_day], ['none', :label_user_mail_option_none] ] diff --git a/app/models/wiki_content_observer.rb b/app/models/wiki_content_observer.rb index 187c02288..6e13d1a8a 100644 --- a/app/models/wiki_content_observer.rb +++ b/app/models/wiki_content_observer.rb @@ -17,18 +17,12 @@ class WikiContentObserver < ActiveRecord::Observer def after_create(wiki_content) - ##by senluo - thread7=Thread.new do - Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added') - end + Mailer.run.wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added') end def after_update(wiki_content) if wiki_content.text_changed? - ##by senluo - thread8=Thread.new do - Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated') - end + Mailer.run.wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated') end end end diff --git a/app/models/zip_pack.rb b/app/models/zip_pack.rb new file mode 100644 index 000000000..e2d03f363 --- /dev/null +++ b/app/models/zip_pack.rb @@ -0,0 +1,18 @@ +class ZipPack < ActiveRecord::Base + # attr_accessible :title, :body + + def self.packed?(bid_id, user_id, digests) + zip_pack = ZipPack.where(homework_id: bid_id, user_id: user_id).first + return false unless zip_pack && zip_pack.digests == digests + zip_pack + end + + def file_valid? + return false unless File.exist?(self.file_path) + Trustie::Utils.digest(self.file_path) == self.file_digest + end + + def digests + self.file_digests.split(',').sort + end +end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 7c816ec19..7c1f14104 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -194,6 +194,8 @@ class CoursesService @course.setup_time = params[:setup_time] @course.endup_time = params[:endup_time] @course.class_period = params[:class_period] + params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0 + params[:course][:open_student] ? @course.open_student = 1 : @course.open_student = 0 end @issue_custom_fields = IssueCustomField.sorted.all diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 39ca37d26..80aa34d45 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -95,9 +95,7 @@ class UsersService # create a new token for password recovery token = Token.new(:user => user, :action => "recovery") if token.save - Thread.new do - Mailer.lost_password(token).deliver - end + Mailer.run.lost_password(token) return l(:notice_account_lost_email_sent,:locale => user.language) end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index a59997a62..577cd280f 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -22,8 +22,8 @@ <%= link_to "留言", get_homework_jours_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%> (<%= @jours_count %>) -
  • - <%#= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), class: "tb_all" unless @bid.homeworks.empty? %> +
  • <%= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid, format: :json), + remote: true, class: "tb_all" unless @bid.homeworks.empty? %>
  • <% else %> diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index 3057285a7..68a326fb2 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -1,3 +1,16 @@ + + +

    <%= l(:permission_new_course)%>

    @@ -24,7 +37,8 @@
  • - + + 显示明码
    学生或其他成员申请加入课程时候需要使用该口令,该口令可以由老师在课堂上公布。
  • @@ -35,7 +49,7 @@
  • - + (打钩为公开,不打钩则不公开,若不公开,仅课程成员可见该课程。)
  • diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index c0b2f1eb6..698bf3cea 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -12,12 +12,13 @@
    <%= link_to_user_header(e.event_author,false,:class => 'problem_name c_orange fl') if e.respond_to?(:event_author) %> <%= link_to_user_header("(#{e.event_author})", @canShowRealName,:class => 'problem_name c_orange fl') if @canShowRealName && e.respond_to?(:event_author) %> +   <%= l(:label_new_activity) %>: - <%= link_to "#{eventToLanguageCourse(e.event_type, @course)}: "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) : e.event_url,:class => "problem_tit c_dblue fl fb"%> + <%= link_to "#{eventToLanguageCourse(e.event_type, @course)} "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) : e.event_url,:class => "problem_tit c_dblue fl fb"%>

    <%= e.event_description %>
    - <%= l :label_activity_time %> : <%= format_activity_day(day) %><%= format_time(e.event_datetime, false) %> + <%= l :label_activity_time %> : <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %>

    @@ -25,7 +26,7 @@ <% end%> <% end%> <% end%> - +<% if @obj_pages.next_page.nil? %>
    <%= image_tag(url_to_avatar(@user), :width => "42", :height => "42") %> @@ -43,7 +44,7 @@
    - +<% end%> diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index de2a5a82c..7fc079bcb 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -15,7 +15,8 @@
    -<% curse_attachments.each do |file| %> +<% curse_attachments.sort.reverse.each do |file| %> + <% if file.is_public? || User.current.member_of_course?(course) %>
    <%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %> @@ -50,6 +51,9 @@
    + <% else %> +
    <%= file.filename %>是私有资源
    + <% end %> <% end %>