diff --git a/.gitignore b/.gitignore
index 2b9fa95fe..73b76dc34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,6 @@
public/api_doc/
/.metadata
vendor/cache
+/files
+/public/images/avatars
+/public/files
diff --git a/Gemfile b/Gemfile
index 48c5adc0e..976184793 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'
@@ -23,7 +24,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'
@@ -32,7 +33,7 @@ group :development do
if RUBY_VERSION >= '2.0.0'
gem 'pry-byebug'
else
- gem 'pry-debugger'
+ # gem 'pry-debugger'
end
gem 'pry-stack_explorer'
gem 'better_errors', '~> 1.1.0'
@@ -58,8 +59,6 @@ group :test do
#end
end
- # gem 'rspec-rails' , '2.13.1'
- # gem 'guard-rspec','2.5.0'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb
index 8f7f0342f..4724b0bc0 100644
--- a/app/api/mobile/api.rb
+++ b/app/api/mobile/api.rb
@@ -41,7 +41,7 @@ module Mobile
mount Apis::Comments
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
- #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
+ #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
end
end
diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb
index fbec9a3b0..9e4cb1bc6 100644
--- a/app/api/mobile/apis/auth.rb
+++ b/app/api/mobile/apis/auth.rb
@@ -26,7 +26,7 @@ module Mobile
present :data, {token: key.access_token, user: api_user}, using: Entities::Auth
present :status, 0
else
- raise 'Unauthorized.'
+ raise "无效的用户名或密码"
end
end
diff --git a/app/api/mobile/apis/comments.rb b/app/api/mobile/apis/comments.rb
index 2e84fe5a9..edc7bcf54 100644
--- a/app/api/mobile/apis/comments.rb
+++ b/app/api/mobile/apis/comments.rb
@@ -80,7 +80,7 @@ module Mobile
end
post do
cs_params = {
- memo: {:subject => params[:subject],:content => '该贴来自手机App意见反馈'},
+ memo: {:subject => '该贴来自手机App意见反馈' ,:content => params[:subject]},
}
cs = CommentService.new
memo,message = cs.create_feedback cs_params, current_user
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 6d68d549a..08c7adf10 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -80,6 +80,10 @@ module Mobile
class_period: params[:class_period]
}
course = ::Course.find(params[:course_id])
+ # 如果没有传密码过来,那就把原来的密码给上,不然会不更新
+ if params[:password].nil? || params[:password].blank?
+ cs_params[:course][:password] = course[:password]
+ end
cs.edit_course_authorize(current_user,course)
course = cs.edit_course(cs_params, course,current_user)
present :data, course, with: Mobile::Entities::Course
diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb
index b6d1db25c..063cfafae 100644
--- a/app/api/mobile/apis/users.rb
+++ b/app/api/mobile/apis/users.rb
@@ -14,7 +14,7 @@ module Mobile
us = UsersService.new
user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true)
- raise "register failed #{user.errors.full_messages}" if user.new_record?
+ raise "该邮箱已经被注册过了" if user.new_record?
present :data, user, with: Mobile::Entities::User
present :status, 0
diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb
index 4c91738c1..520f73384 100644
--- a/app/api/mobile/entities/course.rb
+++ b/app/api/mobile/entities/course.rb
@@ -58,6 +58,7 @@ module Mobile
end
course_expose :current_user_is_member
course_expose :current_user_is_teacher
+ course_expose :work_unit
end
end
end
diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb
index 1f52ae841..9112e7ec5 100644
--- a/app/api/mobile/entities/user.rb
+++ b/app/api/mobile/entities/user.rb
@@ -15,13 +15,13 @@ module Mobile
when :img_url
url_to_avatar(u)
when :gender
- u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
+ u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
when :work_unit
get_user_work_unit u
when :location
get_user_location u
when :brief_introduction
- u.user_extensions.brief_introduction
+ u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
end
end
end
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/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 23b080d94..d880ebe35 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController
accept_api_auth :show, :download, :upload
require 'iconv'
include AttachmentsHelper
-
+ include ApplicationHelper
def show
respond_to do |format|
@@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController
def download
# modify by nwb
# 下载添加权限设置
- candown = false
- if @attachment.container.class.to_s != "HomeworkAttach" && (@attachment.container.has_attribute?(:project) || @attachment.container.has_attribute?(:project_id)) && @attachment.container.project
- project = @attachment.container.project
- candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
- elsif @attachment.container.is_a?(Project)
- project = @attachment.container
- candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
- elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
- @attachment.container.board.project
- project = @attachment.container.board.project
- candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
- elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course
- course = @attachment.container.course
- candown = User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
- elsif @attachment.container.is_a?(Course)
- course = @attachment.container
- candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
- elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
- @attachment.container.board.course
- course = @attachment.container.board.course
- candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
- elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3
- candown = true
- elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first
- course = @attachment.container.courses.first
- candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1)
- else
-
- candown = @attachment.is_public == 1
- end
+ candown = attachment_candown @attachment
if candown || User.current.admin? || User.current.id == @attachment.author_id
@attachment.increment_download
if stale?(:etag => @attachment.digest)
@@ -108,7 +79,7 @@ class AttachmentsController < ApplicationController
end
rescue => e
- redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
+ redirect_to "http: //" + (Setting.host_name.to_s) +"/file_not_found.html"
end
#更新资源文件类型
@@ -349,6 +320,46 @@ class AttachmentsController < ApplicationController
end
end
+ def add_exist_file_to_projects
+ file = Attachment.find(params[:file_id])
+ projects = params[:projects][:project]
+ @message = ""
+ projects.each do |project|
+ c = Project.find(project);
+ if project_contains_attachment?(c,file)
+ if @message && @message == ""
+ @message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
+ next
+ else
+ @message += "
" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
+ next
+ end
+ end
+ attach_copied_obj = file.copy
+ attach_copied_obj.tag_list.add(file.tag_list) # tag关联
+ attach_copied_obj.container = c
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 4
+ end
+ @obj = c
+ @save_flag = attach_copied_obj.save
+ @save_message = attach_copied_obj.errors.full_messages
+ update_quotes attach_copied_obj
+ end
+ respond_to do |format|
+ format.js
+ end
+ rescue NoMethodError
+ @save_flag = false
+ @save_message = [] << l(:label_course_empty_select)
+ respond_to do |format|
+ format.js
+ end
+ end
+
def add_exist_file_to_courses
file = Attachment.find(params[:file_id])
courses = params[:courses][:course]
diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index a22012390..d38846ea0 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -15,7 +15,7 @@ class BidsController < ApplicationController
before_filter :can_show_contest,only: []
#Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
- :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
+ :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
@@ -48,7 +48,7 @@ class BidsController < ApplicationController
format.js
end
end
-
+
def index
@project_type = params[:project_type]
@@ -57,8 +57,8 @@ class BidsController < ApplicationController
@offset, @limit = api_offset_and_limit({:limit => 10})
if @project_type == '1'
@bids = Bid.visible.where('reward_type = ?', 3)
- # elsif
- # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
+ # elsif
+ # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
else
@bids = Bid.visible.where('reward_type = ?', 1)
end
@@ -71,33 +71,33 @@ class BidsController < ApplicationController
#added by nie
if params[:bid_sort_type].present?
case params[:bid_sort_type]
- when '0'
- unless @offset == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.offset(@offset).limit(limit).all.reverse
- end
- @s_state = 0
- when '1'
- unless @offset == 0
- @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
- end
- @s_state = 1
- when '2'
- unless @offset == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- end
- @s_state = 0
+ when '0'
+ unless @offset == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.offset(@offset).limit(limit).all.reverse
+ end
+ @s_state = 0
+ when '1'
+ unless @offset == 0
+ @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
+ end
+ @s_state = 1
+ when '2'
+ unless @offset == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ end
+ @s_state = 0
end
else
unless @offset == 0
@@ -109,7 +109,7 @@ class BidsController < ApplicationController
end
@s_state = 1
end
- #end
+ #end
end
#huang
def contest
@@ -130,33 +130,33 @@ class BidsController < ApplicationController
#added by nie
if params[:contest_sort_type].present?
case params[:contest_sort_type]
- when '0'
- unless @offset == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.offset(@offset).limit(limit).all.reverse
- end
- @s_state = 0
- when '1'
- unless @offset == 0
- @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
- end
- @s_state = 1
- when '2'
- unless @offset == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- limit = @limit if limit == 0
- @bids = @bids.offset(@offset).limit(@limit).all.reverse
- end
- @s_state = 0
+ when '0'
+ unless @offset == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.offset(@offset).limit(limit).all.reverse
+ end
+ @s_state = 0
+ when '1'
+ unless @offset == 0
+ @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
+ end
+ @s_state = 1
+ when '2'
+ unless @offset == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ else
+ limit = @bid_count % @limit
+ limit = @limit if limit == 0
+ @bids = @bids.offset(@offset).limit(@limit).all.reverse
+ end
+ @s_state = 0
end
else
unless @offset == 0
@@ -168,7 +168,7 @@ class BidsController < ApplicationController
end
@s_state = 1
end
- #end
+ #end
end
def fork
@@ -176,11 +176,12 @@ class BidsController < ApplicationController
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
if membership.project.project_type == 1
- @courses << membership.project
+ @courses << membership.project
end
end
end
+ #将某个企业外包需求选为作业,目前此功能已放弃
def create_fork
@homework = Bid.new
@homework.name = params[:bid][:name]
@@ -215,6 +216,7 @@ class BidsController < ApplicationController
end
end
+ #有两个路由链接到此方法:/bids/:id /calls/:id但是貌似这两个路由都不能访问。。方法作用有待确认
def show
@user = @bid.author
@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@@ -229,12 +231,12 @@ class BidsController < ApplicationController
layout_file = ''
case @bid.reward_type
when 3
- html_title(l(:label_question_student))
- layout_file = 'base_homework'
- when 1
- layout_file = 'base_bids'
- else
- layout_file = 'base_contest'
+ html_title(l(:label_question_student))
+ layout_file = 'base_homework'
+ when 1
+ layout_file = 'base_bids'
+ else
+ layout_file = 'base_contest'
end
format.html {
render :layout => layout_file
@@ -242,7 +244,7 @@ class BidsController < ApplicationController
format.api
end
end
-
+
def join_in_contest
if @bid.reward_type == 2 && params[:course_password] == @bid.password
JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id)
@@ -250,53 +252,44 @@ class BidsController < ApplicationController
else
@state = 1
end
-
respond_to do |format|
- # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
- # TO_DO
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
-
+
def unjoin_in_contest
-
joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id)
-
joined.each do |join|
join.delete
end
-
respond_to do |format|
- # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
-
- def new_join
- # added by fq
+ def new_join
end
-
+
# added by bai 增加了参与者和竞赛设置
def show_participator
render :layout => 'base_contest'
-
end
-
+
+ #配置竞赛
def settings
- if @bid.author.id == User.current.id
- if @bid.reward_type == 2
- @contest = Bid.find_by_reward_type(@bid.reward_type)
- render :layout => 'base_contest'
- end
- else
- render_403 :message => :notice_not_contest_setting_authorized
- end
+ if @bid.author.id == User.current.id
+ if @bid.reward_type == 2
+ @contest = Bid.find_by_reward_type(@bid.reward_type)
+ render :layout => 'base_contest'
+ end
+ else
+ render_403 :message => :notice_not_contest_setting_authorized
+ end
end
#end
- # 显示课程
+ # 显示课程作业,但是好像已经废弃
def show_course
bids = Bid.where('parent_id = ?', @bid.id)
@courses = []
@@ -311,12 +304,12 @@ class BidsController < ApplicationController
}
elsif @bid.reward_type == 1
format.html {
- render :layout => 'base_bids'
- }
+ render :layout => 'base_bids'
+ }
else
- format.html {
- render :layout => 'base_contest'
- }
+ format.html {
+ render :layout => 'base_contest'
+ }
end
format.api
@@ -337,12 +330,12 @@ class BidsController < ApplicationController
}
elsif @bid.reward_type == 1
format.html {
- render :layout => 'base_bids'
- }
+ render :layout => 'base_bids'
+ }
else
- format.html {
- render :layout => 'base_contest'
- }
+ format.html {
+ render :layout => 'base_contest'
+ }
end
format.api
@@ -365,12 +358,12 @@ class BidsController < ApplicationController
}
elsif @bid.reward_type == 1
format.html {
- render :layout => 'base_bids'
- }
+ render :layout => 'base_bids'
+ }
else
- format.html {
- render :layout => 'base_contest'
- }
+ format.html {
+ render :layout => 'base_contest'
+ }
end
format.api
@@ -459,9 +452,7 @@ class BidsController < ApplicationController
def show_courseEx
if (User.current.logged? && (User.current.member_of_course?(@bid.courses.first) || User.current.admin?))
- # flash[:notice] = ""
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
-
@user = @bid.author
@bidding_project = @bid.biding_projects.all
@@ -499,7 +490,7 @@ class BidsController < ApplicationController
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1
- WHERE table1.t_score IS NULL")
+ WHERE table1.t_score IS NULL OR table1.t_score = 0")
@not_batch_homework = true
@cur_type = 1
else
@@ -569,12 +560,12 @@ class BidsController < ApplicationController
}
elsif @bid.reward_type == 1
format.html {
- render :layout => 'base_bids'
- }
+ render :layout => 'base_bids'
+ }
else
- format.html {
- render :layout => 'base_contest'
- }
+ format.html {
+ render :layout => 'base_contest'
+ }
end
format.api
end
@@ -586,19 +577,19 @@ class BidsController < ApplicationController
bid_message = params[:bid_for_save][:bid_message]
if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0
if BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
-
+
# added by bai type ==1 需求,type==2 竞赛, type==3 作业
if @bid.reward_type == 1
flash.now[:notice] = l(:label_bidding_succeed)
-
+
elsif @bid.reward_type == 2
flash.now[:notice] = l(:label_bidding_contest_succeed)
-
+
else @bid.reward_type == 3
- flash.now[:notice] = l(:label_bidding_homework_succeed)
+ flash.now[:notice] = l(:label_bidding_homework_succeed)
end
# end
-
+
end
else
if @bid.reward_type == 3
@@ -609,11 +600,11 @@ class BidsController < ApplicationController
end
@bidding_project = @bid.biding_projects
respond_to do |format|
- # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
- # format.html
+ # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
+ # format.html
format.html { redirect_to :back }
format.js
- #format.api { render_api_ok }
+ #format.api { render_api_ok }
end
end
@@ -647,7 +638,7 @@ class BidsController < ApplicationController
@bid.set_commit(@feedback_count)
respond_to do |format|
format.js
- #format.api { render_api_ok }
+ #format.api { render_api_ok }
end
end
@@ -674,9 +665,9 @@ class BidsController < ApplicationController
# @message_count = a_message.count
respond_to do |format|
- # format.html
+ # format.html
format.js
- #format.api { render_api_ok }
+ #format.api { render_api_ok }
end
end
@@ -689,7 +680,7 @@ class BidsController < ApplicationController
respond_to do |format|
format.html { redirect_to :back }
format.js
- #format.api { render_api_ok }
+ #format.api { render_api_ok }
end
end
@@ -698,11 +689,11 @@ class BidsController < ApplicationController
def new
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
- user = @jour.user
- text = @jour.notes
+ user = @jour.user
+ text = @jour.notes
else
- user = @bid.author
- text = @bid.description
+ user = @bid.author
+ text = @bid.description
end
# Replaces pre blocks with [...]
text = text.to_s.strip.gsub(%r{
((.|\s)*?)}m, '[...]') @@ -711,7 +702,7 @@ class BidsController < ApplicationController @id = user.id rescue ActiveRecord::RecordNotFound render_404 - end + end ##新建需求 def new_bid @@ -743,15 +734,15 @@ class BidsController < ApplicationController end end -# added by bai - def update_contest + # added by bai + def update_contest @bid = Bid.find(params[:id]) @bid.name = params[:bid][:name] @bid.description = params[:bid][:description] @bid.reward_type = 2 @bid.budget = params[:bid][:budget] @bid.deadline = params[:bid][:deadline] - @bid.password = params[:bid][:password] + @bid.password = params[:bid][:password] @bid.author_id = User.current.id @bid.commit = 0 if @bid.save @@ -825,31 +816,31 @@ class BidsController < ApplicationController @course = Course.find_by_id(params[:course_id]) @course_id = @course.id #respond_to do |format| - # format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'} - # format.api { render_validation_errors(@bid) } - #end + # format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'} + # format.api { render_validation_errors(@bid) } + #end render file: 'courses/new_homework', layout: 'base_courses' end end # modify by nwb\ # 编辑作业 - def edit - @bid = Bid.find(params[:bid_id]) - if (User.current.admin?||User.current.allowed_to?(:as_teacher,@bid.courses.first)) - @course_id = params[:course_id] - respond_to do |format| - format.html { - @course = Course.find(params[:course_id]) - @user= User.find(User.current.id) - render :layout => 'base_courses' - } - end + def edit + @bid = Bid.find(params[:bid_id]) + if (User.current.admin?||User.current.allowed_to?(:as_teacher,@bid.courses.first)) + @course_id = params[:course_id] + respond_to do |format| + format.html { + @course = Course.find(params[:course_id]) + @user= User.find(User.current.id) + render :layout => 'base_courses' + } + end else render_403 end end - + def update @bid = Bid.find(params[:id]) @course = @bid.courses.first#Project.find(params[:course_id]) @@ -858,7 +849,7 @@ class BidsController < ApplicationController @bid.is_evaluation = params[:bid][:is_evaluation] @bid.proportion = params[:bid][:proportion] @bid.evaluation_num = params[:bid][:evaluation_num] - @bid.open_anonymous_evaluation = params[:bid][:open_anonymous_evaluation] + params[:bid][:open_anonymous_evaluation] ? @bid.open_anonymous_evaluation = 1 : @bid.open_anonymous_evaluation = 0 @bid.reward_type = 3 @bid.deadline = params[:bid][:deadline] @bid.budget = 0 @@ -881,38 +872,38 @@ class BidsController < ApplicationController find_bid render :layout => 'base_homework' end - + def add_homework if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id) # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) - + if hadcommittedhomework(User.current.id, @bid.id) == true - @homework_flag = l(:label_bidding_homework_committed) + @homework_flag = l(:label_bidding_homework_committed) else - @homework = HomeworkAttach.new - @homework.safe_attributes = params[:homeworkattach] - @homework.bid_id = @bid.id - @homework.user_id = User.current.id - @homework.save_attachments(params[:attachments]) - - render_attachment_warning_if_needed(@homework) - - @homework_flag = if @homework.save - l(:label_bidding_homework_succeed) - else - l(:label_bidding_homework_failed) - end - - if @homework.attachments.empty? - @homework.delete - #flash[:error] = l(:no_attachmens_allowed) - @homework_flag = l(:no_attachmens_allowed) - # else - end - end + @homework = HomeworkAttach.new + @homework.safe_attributes = params[:homeworkattach] + @homework.bid_id = @bid.id + @homework.user_id = User.current.id + @homework.save_attachments(params[:attachments]) + + render_attachment_warning_if_needed(@homework) + + @homework_flag = if @homework.save + l(:label_bidding_homework_succeed) + else + l(:label_bidding_homework_failed) + end + + if @homework.attachments.empty? + @homework.delete + #flash[:error] = l(:no_attachmens_allowed) + @homework_flag = l(:no_attachmens_allowed) + # else + end + end end - + @homework_list = @bid.homeworks respond_to do |format| format.html{ @@ -931,7 +922,7 @@ class BidsController < ApplicationController @member = [] @course.memberships.each do |member| unless (member.roles && Role.where('id = ? ', 3)).empty? - @member.push member + @member.push member end end if @bid.homework_type = 1 @@ -958,7 +949,7 @@ class BidsController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -970,7 +961,7 @@ class BidsController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -999,7 +990,7 @@ class BidsController < ApplicationController def manage end - + # 启动匿评 def start_anonymous_comment @bid = Bid.find(params[:id]) @@ -1031,7 +1022,7 @@ class BidsController < ApplicationController end end - def stop_anonymous_comment + def stop_anonymous_comment @bid = Bid.find(params[:id]) @bid.update_column('comment_status', 2) @@ -1039,16 +1030,17 @@ class BidsController < ApplicationController respond_to do |format| format.js end - end + end def alert_anonymous_comment @bid = Bid.find params[:id] @course = @bid.courses.first + @cur_size = 0 + @totle_size = 0 if @bid.comment_status == 0 @totle_size = searchStudent(@course).size @cur_size = @bid.homeworks.size elsif @bid.comment_status == 1 - @totle_size = 0 @bid.homeworks.map { |homework| @totle_size += homework.homework_evaluations.count} @cur_size = 0 @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.is_teacher_score = 0").count} @@ -1060,7 +1052,7 @@ class BidsController < ApplicationController end private - + def get_assigned_homeworks(homeworks, n, index) homeworks += homeworks homeworks[index + 1 .. index + n] diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index f797c7a2f..bdbbb8e37 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -66,15 +66,28 @@ class BoardsController < ApplicationController 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" @topic_count = @board.topics.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @topics = @board.topics. - reorder("#{Message.table_name}.sticky DESC"). - includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - order(sort_clause). - preload(:author, {:last_reply => :author}). - all + if @project + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @topics = @board.topics. + reorder("#{Message.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + preload(:author, {:last_reply => :author}). + all + elsif @course + board_topics = @board.topics. + reorder("#{Message.table_name}.sticky DESC"). + includes(:last_reply). + # limit(@topic_pages.per_page). + # offset(@topic_pages.offset). + order(sort_clause). + preload(:author, {:last_reply => :author}). + all + @topics = paginateHelper board_topics,10 + end + @message = Message.new(:board => @board) #modify by nwb if @project diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 9f61306ab..d226000c0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -17,6 +17,7 @@ class CommentsController < ApplicationController default_search_scope :news + include ApplicationHelper model_object News before_filter :find_model_object before_filter :find_project_from_association @@ -26,9 +27,13 @@ class CommentsController < ApplicationController raise Unauthorized unless @news.commentable? @comment = Comment.new - @comment.safe_attributes = params[:comment] + @project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] @comment.author = User.current if @news.comments << @comment + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@comment.id,OwnerTypeHelper::COMMENT + end flash[:notice] = l(:label_comment_added) end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f9ad609cc..8710b624e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,6 +1,7 @@ class CoursesController < ApplicationController - layout 'base_courses' + # layout 'base_courses' include CoursesHelper + include ActivitiesHelper helper :activities helper :members helper :words @@ -30,66 +31,33 @@ class CoursesController < ApplicationController def join if User.current.logged? cs = CoursesService.new - join = cs.join_course params,User.current + user = User.current + join = cs.join_course params,user @state = join[:state] course = join[:course] - #course = Course.find_by_id params[:object_id] - #if course - # if course_endTime_timeout? course - # @state = 2 - # else - # if User.current.member_of_course?(course) - # @state = 3 - # else - # if params[:course_password] == course.password - # members = [] - # members << Member.new(:role_ids => [10], :user_id => User.current.id) - # course.members << members - # StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) - # @state = 0 - # else - # @state = 1 - # end - # end - # end - #else - # @state = 4 - #end else @state = 5 #未登录 end respond_to do |format| - format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => course, :object_id => params[:object_id]} } + format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :object_id => params[:object_id]} } end rescue Exception => e @state = 4 #已经加入了课程 respond_to do |format| - # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => nil, :object_id => nil} } end end def unjoin if User.current.logged? - # - # @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id) - # @member.first.destroy - # - # joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) - # joined.each do |join| - # join.delete - # end cs = CoursesService.new cs.exit_course params,User.current end - respond_to do |format| - # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } end end - def join_private_courses respond_to do |format| @@ -105,6 +73,7 @@ class CoursesController < ApplicationController if @course.errors.full_messages.count <= 0 respond_to do |format| format.html { + # render :layout => 'base_courses' flash[:notice] = l(:notice_successful_update) redirect_to settings_course_url(@course) } @@ -114,41 +83,11 @@ class CoursesController < ApplicationController respond_to do |format| format.html { settings - render :action => 'settings' + redirect_to settings_course_url(@course) } format.api { render_validation_errors(@course) } end end - #@course.safe_attributes = params[:course] - #@course.time = params[:time] - #@course.term = params[:term] - #@course.class_period = params[:class_period] - #if @course.save - # if params[:course][:is_public] == '0' - # course_status = CourseStatus.find_by_course_id(@course.id) - # course_status.destroy if course_status - # elsif params[:course][:is_public] == '1' - # course_status = CourseStatus.find_by_course_id(@course.id) - # course_status.destroy if course_status - # course_status = CourseStatus.create(:course_id => @course.id, :grade => 0) - # end - # - # respond_to do |format| - # format.html { - # flash[:notice] = l(:notice_successful_update) - # redirect_to settings_course_url(@course) - # } - # format.api { render_api_ok } - # end - #else - # respond_to do |format| - # format.html { - # settings - # render :action => 'settings' - # } - # format.api { render_validation_errors(@course) } - # end - #end end def new_join @@ -160,7 +99,6 @@ class CoursesController < ApplicationController def search courses_all = Course.all_course name = params[:name] - #(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank? if name.blank? @courses = [] @courses_all = [] @@ -242,22 +180,19 @@ class CoursesController < ApplicationController def searchmembers @subPage_title = l :label_student_list - @render_file = 'member_list' - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' - @is_remote = true + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' + # @is_remote = true @score_sort_by = "desc" q = "#{params[:name].strip}" - #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:incourse] - @results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q) - + results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q) elsif params[:ingroup] @group = CourseGroup.find(params[:search_group_id]) - @results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q) + results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q) end @is_remote = true - @result_count = @results.count - @results = paginateHelper @results, 10 + @result_count = results.count + @results = paginateHelper results, 10 @search_name = q end @@ -269,7 +204,7 @@ class CoursesController < ApplicationController group.course_id = @course.id group.save end - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @is_remote = true @course_groups = @course.course_groups @@ -303,17 +238,26 @@ class CoursesController < ApplicationController valid_attr = params[:valid] valid_value = params[:value] - - faker = CourseGroup.new + group_id = params[:group_id] + # faker = CourseGroup.new if valid_attr.eql?('name') - faker.name = valid_value - faker.course_id = params[:course_id] - faker.valid? - req[:valid] = faker.errors[:name].blank? - req[:message] = faker.errors[:name] + course = Course.find params[:course_id] + group_names = course.course_groups.map{|group| group.name unless group.id.to_s == group_id}.select{|group| !group.nil?} + if group_names.include?(valid_value) + req[:valid] = false + req[:message] = l(:modal_valid_unpassing) + else + req[:valid] = true + req[:message] = l(:modal_valid_passing) + end + # faker.name = valid_value + # faker.course_id = params[:course_id] + # faker.valid? + # req[:valid] = faker.errors[:name].blank? + # req[:message] = faker.errors[:name] end - req[:message] = l(:modal_valid_passing) if req[:message].blank? + # req[:message] = l(:modal_valid_passing) if req[:message].blank? render :json => req end def join_group @@ -341,35 +285,28 @@ class CoursesController < ApplicationController end def searchgroupmembers @subPage_title = l :label_student_list - @render_file = 'member_list' + @render_file = 'new_member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true @score_sort_by = "desc" if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) - @results = student_homework_score(@group.id,0, 0,"desc") @results = paginateHelper @results, 10 - - else page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) @results = student_homework_score(0,page_from, 10,"desc") @results = paginateHelper_for_members @results, 10 end - - - end - def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) - @render_file = 'member_list' + @render_file = 'new_member_list' @score_sort_by = "desc" - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @role = params[:role].nil? ? '2':params[:role] @is_remote = true @course_groups = @course.course_groups if @course.course_groups @@ -383,25 +320,20 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @all_members = student_homework_score(0,page, 10,"desc") - + # @all_members = @course.members @members = paginateHelper_for_members @all_members, 10 - - end - respond_to do |format| if params[:page] + format.html {render :layout => 'base_courses'} format.js else format.html {render :layout => 'base_courses'} end end - - # render :layout => 'base_courses' else render_403 end - end def export_course_member_excel @@ -415,20 +347,9 @@ class CoursesController < ApplicationController end def member_score_sort - - # @teachers= searchTeacherAndAssistant(@course) @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' - # @role = params[:role] - # @course_groups = @course.course_groups if @course.course_groups - # @show_serch = params[:role] == '2' @subPage_title = l :label_student_list - @render_file = 'member_list' - # @results = params[:result] if params[:result] - # unless @result.nil? - # @results = @result.reverse - # - # end - # @results = paginateHelper @results@score_sort_by = "desc" + @render_file = 'new_member_list' @is_remote = true @score_sort_by = params[:sort_by] if params[:sort_by] @search_name = params[:search_name] if params[:search_name] @@ -436,7 +357,6 @@ class CoursesController < ApplicationController if !@search_name.nil? if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name) @result_count = @results.count @results = paginateHelper @results, 10 @@ -450,7 +370,6 @@ class CoursesController < ApplicationController if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @results = student_homework_score(0,page, 10,@score_sort_by) - @results = paginateHelper_for_members @results, 10 else @group = CourseGroup.find(group_id) @@ -458,32 +377,25 @@ class CoursesController < ApplicationController @results = paginateHelper @results, 10 end end - end # 显示每个学生的作业评分详情 def show_member_score - @member_score = Member.find(params[:member_id]) if params[:member_id] respond_to do |format| format.html {render :layout => 'course_base'} format.js - end - end def handle_course courses, activities course_activity_count_array=activities.values() - course_array=[] i=0; courses.each do |course| course_array[i]=course i=i+1 end - courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array) - return courses end @@ -493,6 +405,13 @@ class CoursesController < ApplicationController @issue_category ||= IssueCategory.new @member ||= @course.members.new @trackers = Tracker.sorted.all + + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort + respond_to do |format| + format.html { render :layout => 'base_courses' } + format.api { render_validation_errors(@course) } + end else render_403 end @@ -510,6 +429,7 @@ class CoursesController < ApplicationController else respond_to do |format| format.html { + # render :layout => 'base_courses' flash[:notice] = l(:notice_successful_create) if params[:continue] redirect_to new_course_url(attrs, :course => '0') @@ -522,57 +442,6 @@ class CoursesController < ApplicationController format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } end end - #if User.current.user_extensions.identity - # @course = Course.new - # @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s - # @course.safe_attributes = params[:course] - # @course.tea_id = User.current.id - # # added by bai - # @course.term = params[:term] - # @course.time = params[:time] - # #@course.school_id = params[:occupation] - # @course.school_id = User.current.user_extensions.school_id - # @course.setup_time = params[:setup_time] - # @course.endup_time = params[:endup_time] - # @course.class_period = params[:class_period] - #end - # - #@issue_custom_fields = IssueCustomField.sorted.all - #@trackers = Tracker.sorted.all - # - #if @course.save - # #unless User.current.admin? - # r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - # m = Member.new(:user => User.current, :roles => [r]) - # m.project_id = -1 - # course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) - # #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) - # if params[:course][:is_public] == '1' - # course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) - # end - # @course.members << m - # @course.course_infos << course - # #end - # respond_to do |format| - # format.html { - # flash[:notice] = l(:notice_successful_create) - # if params[:continue] - # redirect_to new_course_url(attrs, :course => '0') - # elsif params[:course_continue] - # redirect_to new_course_url(:course => '1') - # else - # redirect_to settings_course_url(@course, :course_type => 1) - # end - # } - # format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } - # end - # else - # #@course.destroy - # respond_to do |format| - # format.html { render :action => 'new', :layout => 'base' } #Added by young - # format.api { render_validation_errors(@course) } - # end - # end end def course @@ -590,54 +459,28 @@ class CoursesController < ApplicationController @course_count = @courses_all.count @course_pages = Paginator.new @course_count, per_page_option, params['page'] - - #gcm activity count - @course_activity_count=Hash.new - #count initialize @courses_all.each do |course| @course_activity_count[course.id]=0 end - - #@course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcm end - - case params[:course_sort_type] when '0' @courses = @courses_all.order("created_on desc") @s_type = 0 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - when '1' @courses = @courses_all.order("course_ac_para desc") @s_type = 1 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - when '2' @courses = @courses_all.order("watchers_count desc") @s_type = 2 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - #gcm when '3' - - #gcm @course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcmend - @courses=handle_course @courses_all,@course_activity_count @s_type = 3 @courses = @courses[@course_pages.offset, @course_pages.per_page] @@ -645,11 +488,7 @@ class CoursesController < ApplicationController @s_type = 0 @courses = @courses_all.order("created_on desc") @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - end respond_to do |format| @@ -657,9 +496,6 @@ class CoursesController < ApplicationController render :layout => 'base' } format.api { - # @offset, @limit = api_offset_and_limit - # @course_count = Course.visible.count - # @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all } format.atom { courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all @@ -668,20 +504,16 @@ class CoursesController < ApplicationController end end - def new @course_type = params[:course_type] ||= params[:course] @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all - @course = Course.new @course.safe_attributes = params[:course] month = Time.now.month - - render :layout => 'base' + render :layout => 'new_base' end - def desc_sort_course_by_avtivity(activity_count, courses) return courses if activity_count.size<2 (activity_count.size-2).downto(0) do |i| @@ -758,22 +590,11 @@ class CoursesController < ApplicationController def homework if @course.is_public != 0 || User.current.member_of_course?(@course) || User.current.admin? - @offset, @limit = api_offset_and_limit({:limit => 10}) - @bids = @course.homeworks.order('deadline ASC') - @bids = @bids.like(params[:name]) if params[:name].present? - @bid_count = @bids.count - @bid_pages = Paginator.new @bid_count, @limit, params['page'] - - @offset ||= @bid_pages.reverse_offset - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - if limit == 0 - limit = 10 - end - @bids = @bids.offset(@offset).limit(limit).all.reverse - end + bids = @course.homeworks.order('created_on DESC') + bids = bids.like(params[:name]) if params[:name].present? + @bids = paginateHelper bids,10 + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) render :layout => 'base_courses' else render_403 @@ -785,6 +606,7 @@ class CoursesController < ApplicationController @homework = Bid.new @homework.safe_attributes = params[:bid] @homework.open_anonymous_evaluation = 1 + @homework.deadline = (Time.now + 3600 * 24).strftime('%Y-%m-%d') if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) render :layout => 'base_courses' else @@ -848,52 +670,65 @@ class CoursesController < ApplicationController end def show - - # try to redirect to the requested menu item if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) return end - @users_by_role = @course.users_by_role 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 - - @key = User.current.rss_key #新增内容 @days = Setting.activity_days_default.to_i - if params[:from] begin; @date_to = params[:from].to_date + 1; rescue; end end - has = { "show_course_files" => true, "show_course_news" => true, "show_course_messages" => true, + #"show_course_journals_for_messages" => true, "show_bids" => true, - "show_course_journals_for_messages" => true, - "show_homeworks" => true + "show_homeworks" => true, + #"show_polls" => true } @date_to ||= Date.today + 1 - # @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date - #@date_from = @date_to - @days-1.years @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 # 无新动态时,显示老动态 @@ -904,23 +739,17 @@ class CoursesController < ApplicationController events = @activity.events(:is_public => 1) end end - - @offset, @limit = api_offset_and_limit({:limit => 10}) - @events_count = events.count - @events_pages = Paginator.new @events_count, @limit, params['page'] - @offset ||= @events_pages.offset - events = events.slice(@offset,@limit) - - @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' - # 这写变量发现没有用而且拖慢速度 - #@teachers= searchTeacherAndAssistant(@course) - #@canShowRealName = isCourseTeacher(User.current.id,@course) - 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 @@ -947,10 +776,6 @@ class CoursesController < ApplicationController offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) page = 1 + offset / @limit end - - #@feedback_count = @jours.count - #@feedback_pages = Paginator.new @feedback_count, @limit, page - #@offset ||= @feedback_pages.offset @jour = paginateHelper @jours,10 @state = false respond_to do |format| @@ -990,7 +815,6 @@ class CoursesController < ApplicationController end private - def allow_join course if course_endTime_timeout? course respond_to do |format| @@ -1021,38 +845,38 @@ class CoursesController < ApplicationController if groupid == 0 if nums == 0 sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id -AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id -AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{nums}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{nums}" end else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id - and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) - GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} -and members.course_group_id = #{groupid} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) + GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} + and members.course_group_id = #{groupid} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" end sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) @@ -1068,7 +892,7 @@ GROUP BY members.user_id ORDER BY score #{score_sort_by}" #当加入,退出分班时查询分班的学生 def search_group_members group @subPage_title = l :label_student_list - @render_file = 'member_list' + @render_file = 'new_member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true @score_sort_by = "desc" 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 28156ac0c..1ca3e2fcf 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,13 +23,14 @@ class FilesController < ApplicationController before_filter :auth_login1, :only => [:index] before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project] helper :sort include SortHelper include FilesHelper helper :project_score include CoursesHelper + include ApplicationHelper def show_attachments obj @attachments = [] @@ -41,8 +42,8 @@ class FilesController < ApplicationController @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset - @curse_attachments_all = @all_attachments[@offset, @limit] - @curse_attachments = paginateHelper @all_attachments,10 + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 end def search @@ -78,6 +79,39 @@ class FilesController < ApplicationController end end + def search_project + sort = "" + @sort = "" + @order = "" + @is_remote = true + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] + end + sort = "#{@sort} #{@order}" + end + + begin + q = "%#{params[:name].strip}%" + #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + if params[:insite] + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@project + @searched_attach = paginateHelper @result,10 + else + @result = find_project_attache q,@project,sort + @result = visable_attachemnts @result + @searched_attach = paginateHelper @result,10 + end + + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url + end + end + def find_course_attache keywords,course,sort = "" if sort == "" sort = "created_on DESC" @@ -87,6 +121,26 @@ class FilesController < ApplicationController #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") end + def find_project_attache keywords,project,sort = "" + if sort == "" + sort = "created_on DESC" + end + ids = "" + len = 0 + count = project.versions.count + project.versions.each do |version| + len = len + 1 + if len != count + ids += version.id.to_s + ',' + else + ids += version.id.to_s + end + end + resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%"). + reorder(sort) + #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") + end + def find_public_attache keywords,sort = "" # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。 @@ -132,17 +186,27 @@ class FilesController < ApplicationController attribute = "downloads" when "created_on" attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" end - - if order_by.count == 1 - sort += "#{Attachment.table_name}.#{attribute} asc " if attribute - elsif order_by.count == 2 - sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " if attribute && order_by[1] - end - if sort_type != params[:sort].split(",").last - sort += "," + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end end end + else + sort = "#{Attachment.table_name}.created_on desc" end @containers = [ Project.includes(:attachments).find(@project.id)] @@ -184,6 +248,8 @@ class FilesController < ApplicationController attribute = "created_on" when "quotes" attribute = "quotes" + else + attribute = "created_on" end @sort = order_by[0] @order = order_by[1] @@ -199,6 +265,8 @@ class FilesController < ApplicationController end end end + else + sort = "#{Attachment.table_name}.created_on desc" end @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] @@ -215,6 +283,11 @@ class FilesController < ApplicationController @can_quote = attachment_candown @file end + def quote_resource_show_project + @file = Attachment.find(params[:id]) + @can_quote = attachment_candown @file + end + def new @versions = @project.versions.sort @course_tag = @project.project_type @@ -241,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 @@ -270,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/forums_controller.rb b/app/controllers/forums_controller.rb index 64157ea42..253e1d28d 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,11 @@ class ForumsController < ApplicationController respond_to do |format| if @memo.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@memo.id,OwnerTypeHelper::MEMO + end + #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 +168,15 @@ 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 + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM + end + #end respond_to do |format| format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index ba7e92467..c90d078e2 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -22,6 +22,7 @@ class HomeworkAttachController < ApplicationController #获取未批作业列表 def get_not_batch_homework @not_batch_homework = true + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" get_not_batch_homework_list sort,direction, @bid.id @cur_page = params[:page] || 1 @@ -39,6 +40,7 @@ class HomeworkAttachController < ApplicationController #获取已评作业列表 def get_batch_homeworks + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" @is_batch_homeworks = true if sort == 't_socre' @@ -49,11 +51,12 @@ class HomeworkAttachController < ApplicationController order_by = "created_at #{direction}" end all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NOT NULL") + all_homework_list = search_homework_member(all_homework_list,@search_name.to_s.downcase) if @search_name @cur_page = params[:page] || 1 @cur_type = 2 @homework_list = paginateHelper all_homework_list,10 @@ -72,6 +75,7 @@ class HomeworkAttachController < ApplicationController #获取所有作业列表 def get_homeworks @is_all_homeworks = true + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" if sort == 't_socre' order_by = "t_score #{direction}" @@ -85,6 +89,8 @@ class HomeworkAttachController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}") + + all_homework_list = search_homework_member(all_homework_list,@search_name.to_s.downcase) if @search_name @cur_page = params[:page] || 1 @cur_type = 3 @homework_list = paginateHelper all_homework_list,10 @@ -477,7 +483,7 @@ class HomeworkAttachController < ApplicationController get_not_batch_homework_list params[:cur_sort] || "s_socre",params[:cur_direction] || "desc",@homework.bid_id elsif @cur_type == "2" #老师已批列表 @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "3" #全部作业列表 @@ -538,6 +544,14 @@ class HomeworkAttachController < ApplicationController end private + #根据条件过滤作业结果 + def search_homework_member homeworks,name + select_homework = homeworks.select{ |homework| + homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name) + } + select_homework + end + #验证是否显示课程 def can_show_course @first_page = FirstPage.find_by_page_type('project') @@ -596,7 +610,8 @@ class HomeworkAttachController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{bid_id} ORDER BY #{order_by}) AS table1 - WHERE table1.t_score IS NULL") + WHERE table1.t_score IS NULL OR table1.t_score = 0 ") + @all_homework_list = search_homework_member(@all_homework_list,@search_name.to_s.downcase) if @search_name @homework_list = paginateHelper @all_homework_list,10 end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index aaaa4484d..fc243741a 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -133,6 +133,9 @@ class MembersController < ApplicationController elsif @course course_info = [] if params[:membership] + @create_member_error_messages = "角色不能留空" unless params[:membership][:role_ids] + @create_member_error_messages = "用户不能留空" unless params[:membership][:user_ids] + if params[:membership][:user_ids] attrs = params[:membership].dup user_ids = attrs.delete(:user_ids) @@ -140,7 +143,7 @@ class MembersController < ApplicationController member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) role = Role.find_by_id(params[:membership][:role_ids]) # 这里的判断只能通过角色名,可以弄成常量 - if role.name == "学生" || role.name == "Student" + if role && (role.name == "学生" || role.name == "Student") StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id) end members << member @@ -159,6 +162,11 @@ class MembersController < ApplicationController end @course.members << members @course.course_infos << course_info + + @roles = Role.givable.all[3..5] + members = @course.member_principals.includes(:roles, :principal).all.sort + else + @create_member_error_messages = l(:label_user_role_null) end respond_to do |format| format.html { redirect_to_settings_in_courses } @@ -242,6 +250,9 @@ class MembersController < ApplicationController end end end + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort + @member = @course.members.new end saved = @member.save @@ -304,7 +315,8 @@ class MembersController < ApplicationController joined.each do |join| join.delete end - + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort end respond_to do |format| format.html { redirect_to_settings_in_courses } 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/messages_controller.rb b/app/controllers/messages_controller.rb index d2a253c2a..436418430 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -44,18 +44,35 @@ class MessagesController < ApplicationController end @reply_count = @topic.children.count - @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - @replies = @topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC"). - limit(@reply_pages.per_page). - offset(@reply_pages.offset). - all + # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + # @replies = @topic.children. + # includes(:author, :attachments, {:board => :project}). + # reorder("#{Message.table_name}.created_on DESC"). + # limit(@reply_pages.per_page). + # offset(@reply_pages.offset). + # all @reply = Message.new(:subject => "RE: #{@message.subject}") if @course + messages_replies = @topic.children. + includes(:author, :attachments, {:board => :project}). + reorder("#{Message.table_name}.created_on DESC"). + #limit(@reply_pages.per_page). + #offset(@reply_pages.offset). + all + @replies = paginateHelper messages_replies,10 + @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_courses"#by young else + @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + @replies = @topic.children. + includes(:author, :attachments, {:board => :project}). + reorder("#{Message.table_name}.created_on DESC"). + limit(@reply_pages.per_page). + offset(@reply_pages.offset). + all + + @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_projects"#by young end end @@ -69,6 +86,11 @@ class MessagesController < ApplicationController if request.post? @message.save_attachments(params[:attachments]) if @message.save + # 更新kindeditor上传的图片资源所有者 + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE + end call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) render_attachment_warning_if_needed(@message) redirect_to board_message_url(@board, @message) @@ -76,6 +98,13 @@ class MessagesController < ApplicationController layout_file = @project ? 'base_projects' : 'base_courses' render :action => 'new', :layout => layout_file end + else + respond_to do |format| + format.html { + layout_file = @project ? 'base_projects' : 'base_courses' + render :layout => layout_file + } + end end end @@ -93,6 +122,10 @@ class MessagesController < ApplicationController @topic.children << @reply #@topic.update_attribute(:updated_on, Time.now) if !@reply.new_record? + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE + end call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) @@ -159,16 +192,7 @@ class MessagesController < ApplicationController @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " @temp = Message.new - #@temp.content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}> " - @content << @message.content.to_s.strip.gsub(%r{
((.|\s)*?)}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" - @content_html = textilizable(@content) - @temp.content = @content_html - #@content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}
((.|\s)*?)}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "\n\n
" << @content - #@temp = Message.new - #@temp.content = @content - + @temp.content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}".html_safe end def preview diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index b44e8a348..d41491349 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -17,6 +17,7 @@ class NewsController < ApplicationController layout 'base_projects'# by young + include ApplicationHelper before_filter :authorize1, :only => [:show] default_search_scope :news model_object News @@ -70,13 +71,13 @@ class NewsController < ApplicationController scope = @course ? @course.news.course_visible : News.course_visible @news_count = scope.count - @news_pages = Paginator.new @news_count, @limit, params['page'] - @offset ||= @news_pages.offset - @newss = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC", - :offset => @offset, - :limit => @limit) - + #@news_pages = Paginator.new @news_count, @limit, params['page'] + #@offset ||= scope_page.offset + scope_order = scope.all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + # :offset => @offset, + # :limit => @limit) + @newss = paginateHelper scope_order,10 respond_to do |format| format.html { @news = News.new @@ -136,6 +137,10 @@ class NewsController < ApplicationController @news.safe_attributes = params[:news] @news.save_attachments(params[:attachments]) if @news.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS + end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) redirect_to course_news_index_url(@course) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e9a27cf44..8ed9fcfef 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -336,11 +336,11 @@ 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 - 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/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/settings_controller.rb b/app/controllers/settings_controller.rb index c60d1bd8f..93e0e9c4b 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -29,6 +29,9 @@ class SettingsController < ApplicationController end def edit + hidden_non_project = Setting.find_by_name("hidden_non_project") + @text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project) + @notifiables = Redmine::Notifiable.all if request.post? && params[:settings] && params[:settings].is_a?(Hash) settings = (params[:settings] || {}).dup.symbolize_keys @@ -70,4 +73,20 @@ class SettingsController < ApplicationController rescue Redmine::PluginNotFound render_404 end + + #隐藏/显示非项目信息 + def hidden_non_project + @notifiable = Setting.find_by_name("hidden_non_project") + if @notifiable + @notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1 + @notifiable.save + else + @notifiable = Setting.new() + @notifiable.name = "hidden_non_project" + @notifiable.value = 0 + @notifiable.save + end + + redirect_to settings_url + end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 5bd5fb0e3..e26901320 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -73,7 +73,7 @@ class TagsController < ApplicationController @issues_results, @bids_results, @forums_results, - @attachments_results, + @attachments_results, @contests_results, @courses_results, @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) @@ -109,7 +109,7 @@ class TagsController < ApplicationController @issues_results, @bids_results, @forums_results, - @attachments_results, + @attachments_results, @contests_results, @courses_results, @open_source_projects_results= refresh_results(@obj_id,@show_flag) @@ -248,6 +248,8 @@ class TagsController < ApplicationController @obj = OpenSourceProject.find_by_id(@obj_id) when '9' @obj = Course.find_by_id(@obj_id) + when '10' + @obj = Attachment.find_by_id(@obj_id) else @obj = nil end @@ -315,6 +317,14 @@ class TagsController < ApplicationController when '8' @obj = OpenSourceProject.find_by_id(obj_id) @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) + when '10' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) when '9' then @obj = Course.find_by_id(obj_id) @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) @@ -380,7 +390,9 @@ class TagsController < ApplicationController when '8' return 'OpenSourceProject' when '9' - return 'Course' + return 'Course' + when '10' + return 'Attachment' else render_error :message => e.message return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4db471ab4..2a10af260 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -438,13 +438,84 @@ class UsersController < ApplicationController # Description 所有动态 where_condition = nil; # where_condition = "act_type <> 'JournalsForMessage'" + user_ids = [] if @user == User.current watcher = User.watched_by(@user) watcher.push(User.current) - activity = Activity.where(where_condition).where('user_id in (?)', watcher).order('id desc') + user_ids = watcher.map{|x| x.id} else - activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc') + user_ids << @user.id end + activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc') + + permission = !User.current.admin? + if permission + #Issue + act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id} + project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids = [] + ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + #Bid + act_ids = activity.where(act_type: 'Bid').select('act_id').map{|x| x.act_id} + course_ids = HomeworkForCourse.where(bid_id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: course_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << HomeworkForCourse.where(bid_id: act_ids, course_id: c_ids).map{|x| x.id} + + #Journal + act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id} + project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id} + + #News + act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id} + project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id} + + #Message + act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id} + board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id} + project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id} + + project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id} + + logger.debug "filter ids #{ids}" + + activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty? + end + # activity = activity.reject { |e| # e.act.nil? || # (!User.current.admin? && !e.act.nil? @@ -454,14 +525,11 @@ class UsersController < ApplicationController # (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) # } + # + @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page) - # @activity = @activity.reject { |e| - # ((e.act_type=="Issue") && ( !e.act.visible?(User.current))) || - # ((e.act_type == "Journal") && (!e.act.project.visible?(User.current))) || - # ((e.act_type == "Bid") && ((!User.current.member_of_course?(e.act.courses.first) || !User.current.admin?))) - # } @state = 0 end @@ -553,7 +621,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 +688,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/words_controller.rb b/app/controllers/words_controller.rb index 2fc4fef9a..680a13963 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -1,7 +1,7 @@ # encoding: utf-8 #####leave message fq class WordsController < ApplicationController - + include ApplicationHelper before_filter :find_user, :only => [:new, :create, :destroy, :more, :back] def create if params[:new_form][:user_message].size>0 @@ -209,6 +209,10 @@ class WordsController < ApplicationController message = params[:new_form][:course_message] feedback = Course.add_new_jour(user, message, params[:id]) if(feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end redirect_to course_feedback_url(params[:id]), notice: l(:label_feedback_success) else flash[:error] = feedback.errors.full_messages[0] diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 6c5385115..df354f107 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -5,24 +5,48 @@ 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 + begin + send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => params[:filename], :type => detect_content_type(params[:file]) + rescue => e + render file: 'public/no_file_found.html' + end + end + #一个作业下所有文件打包下载,只有admin和课程老师有权限 def assort if params[:obj_class] == "Bid" bid = Bid.find params[:obj_id] + render_403 if User.current.allowed_to?(:as_teacher,bid.courses.first) file_count = 0 bid.homeworks.map { |homework| file_count += homework.attachments.count} if file_count > 0 zipfile = zip_bid bid else render file: 'public/no_file_found.html' + return end else logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!" end - send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile) if zipfile + # if zipfile + # if zipfile.length > 1 + # @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)} + # else + # send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file]) + # return + # end + # end + + respond_to do |format| + format.json { + render json: zipfile.to_json + } + end #rescue Exception => e # render file: 'public/no_file_found.html' end @@ -34,9 +58,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 @@ -66,68 +90,145 @@ 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 - zipping "#{Time.now.to_i}_#{bid.name}.zip", bid_homework_path, OUTPUT_FOLDER + + homework_id = bid.id + user_id = bid.author_id + + + 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(homeattach) + def zip_homework_by_user(homework_attach) homeworks_attach_path = [] not_exist_file = [] # 需要将所有homework.attachments遍历加入zip - # 并且返回zip路径 - homeattach.attachments.each do |attach| + + + 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 - 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 = 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 zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) - # 输入待打包的文件列表,已经打包文件定位到ouput_path - ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') - input_filename = files_paths + 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 + + out_file + end + + + def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) 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)) - Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| - input_filename.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 - + files_paths.each do |filename| + 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 + + # 合理分配文件打包 + # 如果小于 pack_attachment_max_size, 则返回单个文件 + # 反之则切分为多个文件组返回 + def split_pack_files(files, pack_attachment_max_size) + max_size = 0 + last_files = [] + ret_files = [] + files.each_with_index do |f,i| + if (max_size += File.size(f)) > pack_attachment_max_size + max_size = 0 + if last_files.empty? #如果单个文件超过大小,也将此文件作为一组 + ret_files << {files: [f], count: 1, index: ret_files.count+1} + last_files.clear + else + ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} + last_files.clear + redo + end + else + last_files << f + end + end + + ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty? + ret_files + end + def detect_content_type(name) content_type = Redmine::MimeType.of(name) content_type.to_s 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/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..095d0ada5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,39 @@ 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 + # owner_type = 2 对应的是forum + # owner_type = 3 对应的是message + # owner_type = 4 对应的是news + # owner_type = 5 对应的是comment + 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是否在给定的列表 @@ -95,6 +128,21 @@ module ApplicationHelper end end + #重载上面方法,增加样式显示 + def link_to_user_header user,canShowRealName=false,options={} + if user.is_a?(User) + if canShowRealName + name = user.show_name + name = user.login if name == "" + else + name = user.login + end + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => options[:class] + else + h(user.to_s) + end + end + # Displays a link to +issue+ with its subject. # Examples: # @@ -256,7 +304,7 @@ module ApplicationHelper onclick = "$('##{id}').slideToggle(); " onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ") onclick << "return false;" - link_to(name, "#", :onclick => onclick) + link_to(name, "javascript:void(0)", :onclick => onclick,:class => options[:class]) end def image_to_function(name, function, html_options = {}) @@ -1622,6 +1670,53 @@ module ApplicationHelper @public_forum = Forum.find(1) end + #获取用户未过期的课程 + def get_user_course user + courses_doing = [] + user.courses.each do |course| + if !course_endTime_timeout?(course) + courses_doing.push course + end + end + courses_doing + end + + + def attachment_candown attachment + candown = false + if attachment.container + if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project + project = attachment.container.project + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif attachment.container.is_a?(Project) + project = attachment.container + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.project + project = attachment.container.board.project + candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course + course = attachment.container.course + candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.is_a?(Course) + course = attachment.container + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.course + course = attachment.container.board.course + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 + candown = true + elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses + course = attachment.container.courses.first + candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) + else + candown = (attachment.is_public == 1 || attachment.is_public == true) + end + end + candown + end + private def wiki_helper @@ -1847,12 +1942,14 @@ module ApplicationHelper def render_dynamic_nav home_link = link_to l(:field_homepage), {:controller => 'welcome', :action => 'index'} - home_link = "
#{@message.content.html_safe}" << home_link << " " + home_link = "" << home_link << " " # bootstrap_render_dynamic_nav content_tag :ul, (home_link.html_safe+bootstrap_render_dynamic_nav) end def bootstrap_render_dynamic_nav + hidden_non_project = Setting.find_by_name("hidden_non_project") + visiable = !(hidden_non_project && hidden_non_project.value == "0") main_course_link = link_to l(:label_course_practice), {:controller => 'welcome', :action => 'index', :host => Setting.course_domain} main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain} @@ -1870,25 +1967,25 @@ module ApplicationHelper #@nav_dispaly_project_label nav_list = Array.new - nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label && @show_course == 1 + nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label && @show_course == 1 && visiable # nav_list.push(course_all_course_link) if @nav_dispaly_course_all_label && @show_course == 1 - nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label && @show_course == 1 + nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label && @show_course == 1 && visiable nav_list.push(main_project_link) if @nav_dispaly_main_project_label - nav_list.push(main_course_link) if @nav_dispaly_main_course_label && @show_course == 1 - nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label && @show_contest == 1 + nav_list.push(main_course_link) if @nav_dispaly_main_course_label && @show_course == 1 && visiable + nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label && @show_contest == 1 && visiable - nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1 + nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1 && visiable # nav_list.push(projects_link) if @nav_dispaly_project_label #nav_list.push(users_link) if @nav_dispaly_user_label # nav_list.push(contest_link) if @nav_dispaly_contest_label && @show_contest == 1 - nav_list.push(bids_link) if @nav_dispaly_bid_label - nav_list.push(forum_link) if @nav_dispaly_forum_label - nav_list.push(stores_link) if @nav_dispaly_store_all_label + nav_list.push(bids_link) if @nav_dispaly_bid_label && visiable + nav_list.push(forum_link) if @nav_dispaly_forum_label && visiable + nav_list.push(stores_link) if @nav_dispaly_store_all_label && visiable content_li = '' nav_list.collect do |nav_item| - content_li << content_tag(:li, nav_item) + content_li << content_tag(:li, nav_item, :class => 'topnav_a fl') end content_li.html_safe end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 50dd79a08..8843b1a76 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -34,6 +34,16 @@ module AttachmentsHelper :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} end end + + def link_to_attachments_course(container, options = {}) + options.assert_valid_keys(:author, :thumbnails) + + if container.attachments.any? + options = {:deletable => container.attachments_deletable?, :author => true}.merge(options) + render :partial => 'attachments/course_file_links', + :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} + end + end def attach_delete(project) if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) @@ -67,6 +77,7 @@ module AttachmentsHelper end end + #判断课程course中是否包含课件attachment,course中引用了attachment也算作包含 def course_contains_attachment? course,attachment course.attachments.each do |att| if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from @@ -75,6 +86,15 @@ module AttachmentsHelper end false end + #判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 + def project_contains_attachment? project,attachment + project.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false + end def get_qute_number attachment if attachment.copy_from diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index bd017757a..5b311acd7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -20,11 +20,45 @@ module CoursesHelper # 返回教师数量,即roles表中定义的Manager def teacherCount project - project.members.count - studentCount(project).to_i + project ? project.members.count - studentCount(project).to_i : 0 # or # searchTeacherAndAssistant(project).count end + #课程模块需要展示的模块 + def course_model + @nav_dispaly_course_all_label = 1 + @nav_dispaly_forum_label = 1 + @nav_dispaly_course_label = nil + @nav_dispaly_store_all_label = 1 + end + + #生成课程老师成员链接 + def course_teacher_link teacher_num + if User.current.member_of_course?(@course) + link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue' + else + content_tag 'span',teacher_num, :class => 'info_foot_num c_blue' + end + end + + #生成课程学生列表连接 + def course_student_link student_num + if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) + link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue' + else + content_tag 'span',student_num, :class => 'info_foot_num c_blue' + end + end + + def course_poll_count + Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status in (2,3)").count + end + + def course_feedback_count + @course.journals_for_messages.where('m_parent_id IS NULL').count + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count @@ -118,7 +152,7 @@ module CoursesHelper # 学生人数计算 # add by nwb def studentCount course - course.student.count.to_s#course.student.count + course ? course.student.count.to_s : 0#course.student.count end #课程成员数计算 @@ -199,10 +233,10 @@ module CoursesHelper #searchPeopleByRoles(project, StudentRoles) mems = [] if name != "" + name = name.to_s.downcase members.each do |m| - - username = m.user[:lastname].to_s + m.user[:firstname].to_s - if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) mems << m end end @@ -598,30 +632,163 @@ module CoursesHelper #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() - days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years + #原来课程动态计算当期时间前(一年+一月)的动态 + # date_to ||= Date.today + 1 + # #date_from = date_to - days-1.years + date_from = @course.created_at.to_date-days #file_count Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| + if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin? activities[attachment.container_id]+=1 + else + activities[attachment.container_id] + end end + #message_count + #Board.where(course_id: @course_ids).each do |board| + # activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + #end + #message_count Board.where(course_id: @course_ids).each do |board| -# activities[board.course_id]+=1 - activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + countmessage = 0 + # 课程人员退出课程后,之前在讨论区回帖不计入课程动态统计 + board.messages.where("updated_on>?", date_from).each do |message| + if message.author.member_of_course?(@course) + countmessage+=1 + end + end + activities[board.course_id]+=countmessage end #news News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| + if news.author.member_of_course?(@course) activities[news.course_id]+=1 + end end + #feedback_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| + countbid=0 + # @bid_ids<?",date_from).each do |bid| + countbid+=1 + end + activities[homework.course_id]+=countbid + end + + #@bid_ids.each do |bid_id| + # activities[] +=Bid.where(id: bid_id ).where("created_on>?",date_from).count + #end + + #poll_count + #Poll.where(polls_group_id: @course_ids, polls_type: Course, polls_status: 2||3).where("published_at>?",date_from).each do |poll| + # activities[poll.polls_group_id]+=1 + #end + #end + + # 动态数 + 1 ( 某某创建了该课程 ) activities.each_pair { |key, value| activities[key] = value + 1 } return activities end + #获取某个课程的动态数 + def course_activity_count course + course_activity_count=Hash.new + course_activity_count[course.id]=0 + count = get_course_activity([course],course_activity_count)[course.id] + count.nil? ? 0 : count + end + + #重启、关闭课程按钮 + def set_course_time course + id = "finish_course_#{course.id}" + linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js) + desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed) + link_to "#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a" + end + + #加入课程、退出课程按钮 + def join_in_course_header(course, user, options=[]) + if user.logged? + joined = course.members.map{|member| member.user_id}.include? user.id + text = joined ? ("".html_safe + l(:label_course_exit_student)) : ("".html_safe + l(:label_course_join_student)) + url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) + method = joined ? 'delete' : 'post' + if joined + link = "#{l(:label_course_join_student)}" + link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) + else + link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a") + "#{l(:label_course_exit_student)}".html_safe + end + else + link = "#{l(:label_course_join_student)}" + + "#{l(:label_course_exit_student)}" + end + link.html_safe + end + + def bid_anonymous_comment bid + if bid.open_anonymous_evaluation == 1 + if bid.homeworks.count >= 2 + case bid.comment_status + when 0 + link = link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' + when 1 + link = link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit' + when 2 + link = "匿评结束".html_safe + end + else + link = "启动匿评".html_safe + end + else + link = "启动匿评".html_safe + end + link + end + + def student_new_homework bid + user_homework = cur_user_homework_for_bid bid + if user_homework && user_homework.empty? + link_to l(:label_commit_homework), new_exercise_book_path(bid),:class => 'fr mr10 work_edit' + else + "作业已交".html_safe + end + end + + def student_anonymous_comment bid + if bid.open_anonymous_evaluation == 1 + case bid.comment_status + when 0 + "未开启匿评".html_safe + when 1 + "正在匿评中".html_safe + when 2 + "匿评已结束".html_safe + end + else + "未启用匿评".html_safe + end + end + + def visable_attachemnts_incourse course + return[] unless course + result = [] + course.attachments.each do |attachment| + if attachment.is_public? || User.current.member_of_course?(course) || User.current.admin? + result << attachment + end + end + result + end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 9eff409ff..3c8ed63d4 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -45,6 +45,7 @@ module FilesHelper File.new(zipfile_name,'w+') end + #带勾选框的课程列表 def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| @@ -55,6 +56,17 @@ module FilesHelper s.html_safe end + #带勾选框的项目列表 + def projects_check_box_tags(name,projects,current_project,attachment) + s = '' + projects.each do |project| + if !project_contains_attachment?(project,attachment) && User.current.allowed_to?(:manage_files, project) + s << "" + end + end + s.html_safe + end + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user,file result = false @@ -66,6 +78,17 @@ module FilesHelper result end + #判断用户是否拥有不包含当前资源的项目,需用户在该项目中有资源管理相关资源 + def has_project? user,file + result = false + user.projects.each do |project| + if !project_contains_attachment?(project,file) && User.current.allowed_to?(:manage_files, project) + return true + end + end + result + end + # 判断指定的资源时候符合类型 def isTypeOk(attachment, type, contentType) result = false @@ -87,66 +110,33 @@ 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 result end - def visable_attachemnts_incourse attachments + def visable_attachemnts_insite attachments,obj result = [] - attachments.each do |attachment| - if attachment.is_public? || (attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id - result << attachment - end - end - result - end - - def visable_attachemnts_insite attachments,course - result = [] - attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id - result << attachment + if obj.is_a?(Course) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == obj.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end end + else if obj.is_a?(Project) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Project" && attachment.container_id == obj.id && User.current.member_of_course?(Project.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end + end end - result end - - def attachment_candown attachment - candown = false - if attachment.container - if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project - project = attachment.container.project - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif attachment.container.is_a?(Project) - project = attachment.container - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.project - project = attachment.container.board.project - candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course - course = attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.is_a?(Course) - course = attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.course - course = attachment.container.board.course - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 - candown = true - elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses - course = attachment.container.courses.first - candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) - else - candown = (attachment.is_public == 1 || attachment.is_public == true) - end - end - candown + result end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index ed18b7ae4..c8e8bd87b 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -44,18 +44,19 @@ module MembersHelper # add by nwb # 课程可添加的成员列表 def render_principals_for_new_course_members(course) - scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) - principal_count = scope.count - principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] - principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all - - s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') + if params[:q] && params[:q] != "" + scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') - links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options| link_to text, autocomplete_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true } - s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') + s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links") end diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb new file mode 100644 index 000000000..98f273bee --- /dev/null +++ b/app/helpers/owner_type_helper.rb @@ -0,0 +1,9 @@ +module OwnerTypeHelper + MEMO = 1 + FORUM = 2 + MESSAGE = 3 + NEWS = 4 + COMMENT = 5 + BID = 6 + JOURNALSFORMESSAGE = 7 +end \ No newline at end of file diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 17b68c3f6..284ee8c43 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -20,6 +20,8 @@ module TagsHelper @obj= Contest.find_by_id(obj_id) when '9' @obj= Course.find_by_id(obj_id) + when '10' + @obj = Attachment.find_by_id(obj_id) else raise Exception, '[TagsHelper] ===> tag type unknow.' end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 58935dd11..af2d5abc4 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -278,4 +278,29 @@ module UsersHelper end } end + + #获取用户留言相关的连接 + def user_jour_feed_back_url active + if active.act_type == "JournalsForMessage" + jour = JournalsForMessage.find active.act_id + if jour + case jour.jour_type + when "Principal" + link_to(l(:label_goto), user_newfeedback_user_path(jour.jour_id)) + when "Project" + link_to(l(:label_goto), project_feedback_path(jour.jour_id)) + when "Bid" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + when "Course" + link_to(l(:label_goto), course_feedback_path(jour.jour_id)) + when "Contest" + link_to(l(:label_goto), show_contest_contest_path(jour.jour_id)) + when "Softapplication" + link_to(l(:label_goto), softapplication_path(jour.jour_id)) + when "HomeworkAttach" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + end + end + end + end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 294d895a5..7995d7e68 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -45,6 +45,26 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + + def watcher_link_with_id(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or objects.first.instance_of?(Contest) or (objects.first.instance_of?(Bid))) + css = options[:class] + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css,:id=>options[:id] + end ############## added by linchun def new_watcher_link(objects, user, options=[]) @@ -135,7 +155,7 @@ module WatchersHelper else text = l(:label_new_join_group) form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, :remote => true, :method => 'post') do - submit_tag text, class: "group_in", style: "width: 43px;height: 21px;" + submit_tag text, class: "group_in", style: "width: 90px;height: 21px;" end end end diff --git a/app/models/bid.rb b/app/models/bid.rb index 10476b4d3..ccd6198bb 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -17,7 +17,8 @@ class Bid < ActiveRecord::Base HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes - + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :course has_many :biding_projects, :dependent => :destroy @@ -47,7 +48,7 @@ class Bid < ActiveRecord::Base validate :validate_user validate :validate_reward_type after_create :act_as_activity - + after_destroy :delete_kindeditor_assets scope :visible, lambda {|*args| nil } @@ -157,5 +158,10 @@ class Bid < ActiveRecord::Base end end - + # Time 2015-04-01 14:19:06 + # Author lizanle + # Description 删除对应课程通知的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::BID + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 539c62e85..bdb642d3c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,8 +17,25 @@ class Comment < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :commented, :polymorphic => true, :counter_cache => true 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 + # Author lizanle + # Description 删除对应评论的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::COMMENT + end end 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/discuss_demo.rb b/app/models/discuss_demo.rb deleted file mode 100644 index 6ed8d15b6..000000000 --- a/app/models/discuss_demo.rb +++ /dev/null @@ -1,4 +0,0 @@ -class DiscussDemo < ActiveRecord::Base - attr_accessible :title, :body - has_many_kindeditor_assets :assets, :dependent => :destroy -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 878937ea7..6db069a09 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,10 +17,10 @@ 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 + after_create :send_mail def reset_counters! self.class.reset_counters!(id) end @@ -33,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) @@ -47,5 +48,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,OwnerTypeHelper::FORUM + end end 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.rb b/app/models/journals_for_message.rb index 23d9c7753..dda45965e 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -4,6 +4,8 @@ class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy safe_attributes "jour_type", # 留言所属类型 "jour_id", # 留言所属类型的id "notes", # 留言内容 @@ -16,7 +18,7 @@ class JournalsForMessage < ActiveRecord::Base "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) "is_comprehensive_evaluation" # 1 教师评论、2 匿评、3 留言 acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC" - + after_destroy :delete_kindeditor_assets belongs_to :project, :foreign_key => 'jour_id', :conditions => "#{self.table_name}.jour_type = 'Project' " @@ -47,6 +49,7 @@ class JournalsForMessage < ActiveRecord::Base acts_as_activity_provider :type => 'course_journals_for_messages', :author_key => :user_id, + :permission => :view_course_journals_for_messages, :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :course } @@ -163,5 +166,10 @@ class JournalsForMessage < ActiveRecord::Base end end - + # Time 2015-04-01 14:15:06 + # Author lizanle + # Description 删除对应课程留言的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,7 + 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 b404ea531..a6acb1635 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} 17:59:59" + date_to = "#{date_to} 17: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查询课程课件更新 @@ -97,11 +122,11 @@ class Mailer < ActionMailer::Base end end # 查询user在课程中发布的通知,项目中发的新闻 - @course_news = News.find_by_sql("select DISTINCT n.* from news n + @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.course_id in (#{course_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") - @project_news = News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] # 查询user在课程及个人中留言 @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where @@ -114,18 +139,18 @@ 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 - end + 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 + # 公共讨论区发帖、回帖添加邮件发送信息 def forum_message_added(memo) @memo = memo redmine_headers 'Memo' => memo.id @@ -134,16 +159,16 @@ 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' - recipients << @forum.creator.mail - end - if @author.mail_notification != 'day' && @author.mail_notification != 'week' - recipients << @author.mail - end + #将帖子创建者邮箱地址加入数组 + recipients << @forum.creator.mail + #回复人邮箱地址加入数组 + 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. @@ -178,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 #如果是直接留言并且留言对象是课程 @@ -195,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 @@ -248,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}") @@ -296,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) @@ -384,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. @@ -422,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 @@ -455,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 @@ -465,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 @@ -486,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 @@ -498,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 @@ -521,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) @@ -535,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 @@ -557,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. @@ -581,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. @@ -732,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(reps) + if u && u.mail_notification == 'all' + r_reps << reps + end + end + r_reps + end + def mail(headers={}) headers.merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, @@ -748,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 052ca03db..191d4f978 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!, :send_mail # 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 @@ -53,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 @@ -113,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 @@ -170,4 +170,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,OwnerTypeHelper::MEMO + 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 85a87132d..669495b45 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,6 +18,8 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :board belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy @@ -62,12 +64,10 @@ class Message < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters! after_update :update_messages_board - after_destroy :reset_counters!,:down_user_score + 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)) @@ -208,5 +208,14 @@ 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 删除对应消息的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE + end end 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 d2547fc02..de3ad35b0 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -18,6 +18,8 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy #added by nwb belongs_to :course belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' @@ -45,11 +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)) } @@ -105,4 +106,15 @@ class News < ActiveRecord::Base end end + # Time 2015-03-31 13:50:54 + # Author lizanle + # Description 删除news后删除对应的资源 + def delete_kindeditor_assets + 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/poll.rb b/app/models/poll.rb index 06f1369c1..943c08b51 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -6,4 +6,23 @@ class Poll < ActiveRecord::Base has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 + # 添加课程的poll动态 +# has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy +# after_create :act_as_activity + +# acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)} ##{o.id}: #{o.name}" }, +# :description => :description, +# :author => :author, +# :url => Proc.new {|o| {:controller => 'poll', :action => 'show', :id => o.id}} + +# acts_as_activity_provider :type => 'polls', +# :permission => :view_course_polls, + #:find_options => {:include => [:course, :author]}, + #:timestamp => "#{self.table_name}.published_at", +# :author_key => :author_id + +# def act_as_activity +# self.acts << Activity.new(:user_id => self.user_id) +# end + end diff --git a/app/models/principal.rb b/app/models/principal.rb index 5aa21768f..dfec5b911 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -42,7 +42,8 @@ class Principal < ActiveRecord::Base where({}) else pattern = "%#{q}%" - sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") + # sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") + sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p)" params = {:p => pattern} if q =~ /^(.+)\s+(.+)$/ a, b = "#{$1}%", "#{$2}%" 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 87dc88976..7b232bf13 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] ] @@ -765,7 +766,7 @@ class User < Principal # * nil with options[:global] set : check if user has at least one role allowed for this action, # or falls back to Non Member / Anonymous permissions depending if the user is logged def allowed_to?(action, context, options={}, &block) - if context && context.is_a?(Project) + if Project === context return false unless context.allows_to?(action) # Admin users are authorized for anything else return true if admin? @@ -778,7 +779,7 @@ class User < Principal (block_given? ? yield(role, self) : true) } #添加课程相关的权限判断 - elsif context && context.is_a?(Course) + elsif Course === context return false unless context.allows_to?(action) # Admin users are authorized for anything else return true if admin? 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 c689d699d..aa216d755 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -161,10 +161,15 @@ class CoursesService #显示课程 def show_course(params,current_user) course = Course.find(params[:id]) + if course.school + work_unit = course.school.name + else + work_unit = get_user_work_unit course.teacher + end unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) raise '403' end - {:course => course,:img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} + {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} end #创建课程 @@ -194,6 +199,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 @@ -239,6 +246,8 @@ class CoursesService course.time = params[:time] course.term = params[:term] 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 if course.save if params[:course][:is_public] == '0' course_status = CourseStatus.find_by_course_id(course.id) @@ -336,7 +345,7 @@ class CoursesService def course_dynamic(params,current_user) @user = User.find(params[:id]) - if !current_user.admin? && !@user.active? + if current_user.nil? && !current_user.admin? && !@user.active? raise '404' return end @@ -369,6 +378,16 @@ class CoursesService unless latest_bid.nil? latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => get_user_language(current_user))} end + + # Time 2015-04-07 14:58:30 + # Author lizanle + # Description 添加课程创建动态 + if(User.find_by_id(CourseInfos.find_by_course_id(course.id).try(:user_id))) + create_user_name = User.find_by_id(CourseInfos.find_by_course_id(course.id).user_id).realname + latest_course_dynamics << {:type => 5,:time => course.created_at,:message =>l(:label_recently,:locale => get_user_language(current_user)) << create_user_name << l(:label_creat,:locale => get_user_language(current_user))} + end + + #每个作业中的最新留言 messages = [] course.homeworks.each do |bid| @@ -415,7 +434,7 @@ class CoursesService many_times = course.homeworks.index(bid) + 1 name = bid.name homework_count = bid.homeworks.count #已提交的作业数量 - student_questions_count = bid.commit.nil? ? 0 : bid.commit + student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = bid.comment_status @@ -435,7 +454,7 @@ class CoursesService many_times = course.homeworks.index(bid) + 1 name = bid.name homework_count = bid.homeworks.count #已提交的作业数量 - student_questions_count = bid.commit.nil? ? 0 : bid.commit + student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = bid.comment_status diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index f9be6f79d..d22c62a5a 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -20,7 +20,7 @@ class HomeworkService many_times = course.homeworks.index(@bid) + 1 name = @bid.name homework_count = @bid.homeworks.count #已提交的作业数量 - student_questions_count = @bid.commit.nil? ? 0 : @bid.commit + student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count description = @bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = @bid.comment_status @@ -282,7 +282,7 @@ class HomeworkService many_times = course.homeworks.index(@bid) + 1 name = @bid.name homework_count = @bid.homeworks.count #已提交的作业数量 - student_questions_count = @bid.commit.nil? ? 0 : @bid.commit + student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count description = @bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = @bid.comment_status diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 39ca37d26..63dd725cd 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 @@ -194,20 +192,22 @@ class UsersService #raise @current_user.errors.full_message #return @current_user else - raise 'wrong password' + raise l(:notice_account_wrong_password,:locale => 'zh') end @current_user end #搜索用户 def search_user params - @status = params[:status] || 1 + status = params[:status] || 1 has = { "show_changesets" => true } - scope = User.logged.status(@status) - @search_by = params[:search_by] ? params[:search_by] : "0" - scope = scope.like(params[:name],@search_by) if params[:name].present? + scope = User.logged.status(status) + watcher = User.watched_by(params[:user_id]) + watcher.push(params[:user_id]) + search_by = params[:search_by] ? params[:search_by] : "0" + scope = scope.where("id not in (?)",watcher).like(params[:name],search_by) if params[:name].present? scope end diff --git a/app/views/applied_project/applied_join_project.js.erb b/app/views/applied_project/applied_join_project.js.erb index 3f4f6aff7..ab5cdd484 100644 --- a/app/views/applied_project/applied_join_project.js.erb +++ b/app/views/applied_project/applied_join_project.js.erb @@ -1,11 +1,11 @@ <% if @status == 0%> - alert("您申请的项目不存在"); + alert("<%= l('project.join.tips.notexist') %>"); <% elsif @status == 1%> - alert("请勿重复申请加入该项目"); + alert("<%= l('project.join.tips.repeat') %>"); <% elsif @status == 2%> - alert("申请成功"); + alert("<%= l('project.join.tips.success') %>"); <% elsif @status == 3%> - alert("您已加入该项目"); + alert("<%= l('project.join.tips.has') %>"); <%else%> - alert("申请失败"); + alert("<%= l('project.join.tips.fail') %>"); <%end%> \ No newline at end of file diff --git a/app/views/attachments/_course_file_links.html.erb b/app/views/attachments/_course_file_links.html.erb new file mode 100644 index 000000000..d32025787 --- /dev/null +++ b/app/views/attachments/_course_file_links.html.erb @@ -0,0 +1,72 @@ + diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index b026fead2..18586e809 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -17,23 +17,7 @@ <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> - <% container.saved_attachments.each_with_index do |attachment, i| %> - - <% end %> <% end %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 6572ee2c9..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 %> @@ -63,6 +63,19 @@ + + +