Merge branch 'guange_dev' into szzh

This commit is contained in:
sw 2015-04-10 16:40:01 +08:00
commit fbe12ca6c3
4 changed files with 88 additions and 11 deletions

View File

@ -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

View File

@ -775,9 +775,9 @@ class Mailer < ActionMailer::Base
end
end
elsif reps.is_a? String
u = User.find_by_mail(r)
u = User.find_by_mail(reps)
if u && u.mail_notification == 'all'
r_reps << r
r_reps << reps
end
end
r_reps

View File

@ -766,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?
@ -779,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?

View File

@ -0,0 +1,9 @@
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 10
Delayed::Worker.max_attempts = 1
Delayed::Worker.max_run_time = 5.minutes
Delayed::Worker.read_ahead = 10
Delayed::Worker.default_queue_name = 'default'
Delayed::Worker.delay_jobs = !Rails.env.test?
Delayed::Worker.raise_signal_exceptions = :term
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))