From 5a876d9df1a76b73b2bb75310f9069241f5cce69 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 10 Apr 2015 10:37:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8D=95=E4=B8=AA=E6=94=B6=E4=BB=B6=E4=BA=BA?= =?UTF-8?q?=E4=BC=9A=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 23 ++++++++++++++++------- app/models/mailer.rb | 4 ++-- app/models/user.rb | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a230688dc..482dc4d45 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -438,13 +438,27 @@ 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') + + #Issue + # act_ids = Activity.where(act_type: 'Issue', user_id: user_ids).select('act_id').map{|x| x.act_id} + # project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + # valid_p_ids = [] + # Project.where(id: project_ids).each do |x| + # x.visible?(User.current) + # valid_p_ids << x.id + # end + + # activity = Activity.where(act_id: Issue.where(id: act_ids, project_id: valid_p_ids).map{|x| x.id}).order('id desc') + # activity = activity.reject { |e| # e.act.nil? || # (!User.current.admin? && !e.act.nil? @@ -457,11 +471,6 @@ class UsersController < ApplicationController @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 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index df23813cd..39c38b269 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 35c29cbcc..59c0ab608 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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? From e6780cc2fba2ceea0cf213ae77d205775e24aa4e Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 10 Apr 2015 10:47:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8A=A0=E5=85=A5delayedjob=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/delayed_job_config.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 config/initializers/delayed_job_config.rb diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb new file mode 100644 index 000000000..8a763c7df --- /dev/null +++ b/config/initializers/delayed_job_config.rb @@ -0,0 +1,9 @@ +Delayed::Worker.destroy_failed_jobs = false +Delayed::Worker.sleep_delay = 3 +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')) From f94184bc8101b4ebfa60aac02eb420574297c780 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 10 Apr 2015 16:27:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=83=A8=E5=88=86=E6=80=A7=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 77 ++++++++++++++++++++--- config/initializers/delayed_job_config.rb | 2 +- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 482dc4d45..2a10af260 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -448,16 +448,73 @@ class UsersController < ApplicationController end activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc') - #Issue - # act_ids = Activity.where(act_type: 'Issue', user_id: user_ids).select('act_id').map{|x| x.act_id} - # project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} - # valid_p_ids = [] - # Project.where(id: project_ids).each do |x| - # x.visible?(User.current) - # valid_p_ids << x.id - # end + 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} - # activity = Activity.where(act_id: Issue.where(id: act_ids, project_id: valid_p_ids).map{|x| x.id}).order('id desc') + #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? || @@ -468,6 +525,8 @@ 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) diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb index 8a763c7df..1a4cf8463 100644 --- a/config/initializers/delayed_job_config.rb +++ b/config/initializers/delayed_job_config.rb @@ -1,5 +1,5 @@ Delayed::Worker.destroy_failed_jobs = false -Delayed::Worker.sleep_delay = 3 +Delayed::Worker.sleep_delay = 10 Delayed::Worker.max_attempts = 1 Delayed::Worker.max_run_time = 5.minutes Delayed::Worker.read_ahead = 10