From 32264fb4a6fc5f09de1d9559718bcc5b66e4772c Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 3 Mar 2015 09:11:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BF=AE=E6=94=B9=E4=B8=BA=E7=94=A8=E6=88=B7=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 2 +- app/services/courses_service.rb | 42 ++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 8b167980d..6d68d549a 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -213,7 +213,7 @@ module Mobile present :status, 0 end - desc '课程动态' + desc '用户课程动态' params do requires :token, type: String end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 1f5ca7894..7e80f415c 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -333,24 +333,38 @@ class CoursesService end def course_dynamic(params,current_user) - course = Course.find(params[:id]) - if current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course))) - raise '403' + + @user = User.find(params[:id]) + if !current_user.admin? && !@user.active? + raise '404' + return end - count,is_teacher = get_course_anonymous_evaluation current_user,course - if is_teacher - student_commit_number = count + if current_user == @user || current_user.admin? + membership = @user.coursememberships.all else - need_anonymous_comments_count = count + membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user)) end - news_count = course.news.count - message_count = course.journals_for_messages.count + membership.sort! {|older, newer| newer.created_on <=> older.created_on } result = [] - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count} - #{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count} + membership.each do |mp| + course = mp.course + unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course))) + count,is_teacher = get_course_anonymous_evaluation current_user,course + if is_teacher + student_commit_number = count + else + need_anonymous_comments_count = count + end + news_count = course.news.count + message_count = course.journals_for_messages.count + + result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count} + result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count} + result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number} + result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count} + #{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count} + end + end result end