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 01/15] =?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 02/15] =?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 eca32ca62533e6e86ef49debbb80a3afeb165401 Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Fri, 10 Apr 2015 11:44:13 +0800
Subject: [PATCH 03/15] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90?=
=?UTF-8?q?=E5=BA=93=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2=E4=B8=8D=E6=AD=A3?=
=?UTF-8?q?=E7=A1=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/files/_course_file.html.erb | 2 +-
app/views/files/_course_list.html.erb | 4 ++--
app/views/tags/_tag_add.html.erb | 20 ++++++++++----------
app/views/tags/tag_save.js.erb | 10 +++-------
4 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb
index b6f65e9b2..62fdc3082 100644
--- a/app/views/files/_course_file.html.erb
+++ b/app/views/files/_course_file.html.erb
@@ -9,7 +9,7 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_show',:locals => {:course => @course}) %>');
showModal('ajax-modal', '513px');
$('#ajax-modal').siblings().remove();
- $('#ajax-modal').before("")
+ $('#ajax-modal').before("
");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("popbox_polls");
}
diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb
index 3d692a36b..3946b1da1 100644
--- a/app/views/files/_course_list.html.erb
+++ b/app/views/files/_course_list.html.erb
@@ -46,8 +46,8 @@
<%= e.event_description.html_safe %>
From 6b758375f8e3560b3359792f38b1f290ac8f251e Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Fri, 10 Apr 2015 15:01:33 +0800
Subject: [PATCH 05/15] =?UTF-8?q?1=E3=80=81=E6=90=9C=E7=B4=A2=E8=AF=BE?=
=?UTF-8?q?=E7=A8=8B=E6=8A=A5500=202=E3=80=81=E8=AF=BE=E7=A8=8B=E8=AE=A8?=
=?UTF-8?q?=E8=AE=BA=E5=8C=BA=E6=8F=8F=E8=BF=B0=E6=8D=A2=E8=A1=8C=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 10 ++++++++--
app/helpers/courses_helper.rb | 5 +++--
app/views/messages/_form_course.html.erb | 2 +-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index ff937990b..1c2419305 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -1,5 +1,5 @@
class CoursesController < ApplicationController
- layout 'base_courses'
+ # layout 'base_courses'
include CoursesHelper
include ActivitiesHelper
helper :activities
@@ -73,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)
}
@@ -82,7 +83,7 @@ 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
@@ -407,6 +408,10 @@ class CoursesController < ApplicationController
@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
@@ -424,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')
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index f4a5ac193..55f216ab9 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -20,7 +20,7 @@ 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
@@ -152,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
#课程成员数计算
@@ -782,6 +782,7 @@ module CoursesHelper
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?
diff --git a/app/views/messages/_form_course.html.erb b/app/views/messages/_form_course.html.erb
index f4f8126fe..54a62144a 100644
--- a/app/views/messages/_form_course.html.erb
+++ b/app/views/messages/_form_course.html.erb
@@ -44,7 +44,7 @@
<%= f.kindeditor :content, :editor_id => 'message_content_editor',
:owner_id => @message.nil? ? 0: @message.id,
:owner_type => OwnerTypeHelper::MESSAGE,
- :width => '91%',
+ :width => '90%',
:height => 300,
:class => 'talk_text fl',
:input_html => { :id => 'message_content',
From 596bc213ca18ce166755b04fd4e440064259a2e0 Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Fri, 10 Apr 2015 15:15:49 +0800
Subject: [PATCH 06/15] =?UTF-8?q?1=E3=80=81=E8=AF=BE=E7=A8=8B=E5=AF=BC?=
=?UTF-8?q?=E8=88=AA=E6=87=92=E7=82=B9=E5=87=BB=E8=AF=BE=E7=A8=8B=E8=B7=B3?=
=?UTF-8?q?=E5=88=B0=E5=8A=A8=E6=80=81=E9=A1=B5=E9=9D=A2=202=E3=80=81?=
=?UTF-8?q?=E5=8F=B3=E4=B8=8A=E8=A7=92=E8=AF=BE=E7=A8=8B=E4=B8=8B=E6=8B=89?=
=?UTF-8?q?=E6=9D=A1=E5=A2=9E=E5=AE=BD=203=E3=80=81=E8=AF=BE=E7=A8=8B?=
=?UTF-8?q?=E9=80=9A=E7=9F=A5=20=E6=88=AA=E8=87=B3=E6=97=B6=E9=97=B4-->?=
=?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/layouts/base_courses.html.erb | 2 +-
app/views/news/_course_news.html.erb | 2 +-
public/stylesheets/public.css | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb
index 9fed77faf..dbcf933ff 100644
--- a/app/views/layouts/base_courses.html.erb
+++ b/app/views/layouts/base_courses.html.erb
@@ -43,7 +43,7 @@
<%=l(:label_courses_management_platform)%>
>
- <%= link_to @course.name, nil %>
+ <%= link_to @course.name, course_path(@course) %>
+
<%= journal.notes.html_safe %>
<%= comment.comments.html_safe %>
+<%= comment.comments.html_safe %>
<%= textAreailizable forum.description%>
diff --git a/app/views/layouts/base_forums.html.erb b/app/views/layouts/base_forums.html.erb index f12b3186d..4d79f50f9 100644 --- a/app/views/layouts/base_forums.html.erb +++ b/app/views/layouts/base_forums.html.erb @@ -53,7 +53,7 @@<%= textAreailizable act.notes %>
@@ -167,7 +167,7 @@ <% end %><%=textAreailizable act, :description %>
<%= desStr %>
@@ -282,7 +282,7 @@ <% end %><%= textAreailizable act,:long_comments %>
@@ -344,7 +344,7 @@ <% end %><%= textAreailizable(act,:content) %>
@@ -385,7 +385,7 @@ <% end %><%= textAreailizable act,:description %>
@@ -559,7 +559,7 @@ <% end %><%= textAreailizable act, :description %>
@@ -633,7 +633,7 @@<%= textAreailizable e.notes %>
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 13/15] =?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 | 79 ++++++++++++++++++++--- config/initializers/delayed_job_config.rb | 2 +- 2 files changed, 70 insertions(+), 11 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 - - # activity = Activity.where(act_id: Issue.where(id: act_ids, project_id: valid_p_ids).map{|x| x.id}).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? || @@ -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 From d99910e8a100f0237536c36ab95e6f3c1774688a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 10 Apr 2015 16:34:57 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=95=99=E8=A8=80=E5=8A=A8=E6=80=81url?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/users_helper.rb | 25 +++++++++++++++++++++++++ app/views/users/show.html.erb | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) 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/views/users/show.html.erb b/app/views/users/show.html.erb index 9b0d3651e..d4c0d4379 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -103,7 +103,8 @@