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