diff --git a/Gemfile b/Gemfile index 3bea83669..03dbb5785 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'elasticsearch-rails' ### profile -#gem 'oneapm_rpm' +gem 'oneapm_rpm' group :development do gem 'grape-swagger' diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 5908ef866..caabad198 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -193,14 +193,13 @@ module Mobile desc "返回单个课程" params do requires :id, type: Integer - optional :token, type: String + requires :token,type:String end route_param :id do get do - authenticate! + # course = Course.find(params[:id]) cs = CoursesService.new - course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) - #course = Course.find(params[:id]) + course = cs.show_course(params,current_user) present :data, course, with: Mobile::Entities::Course,user: current_user { status: 0} end @@ -393,10 +392,7 @@ module Mobile authenticate! course = Course.find(params[:course_id]) - exercises = course.exercises - exercises.each do |v| - v[:coursename] = course.nil? ? "未知" : course.name - end + exercises = course.exercises.where("exercise_status <> 1").order("created_at desc") present :data,exercises,with:Mobile::Entities::Exercise present :status,0 end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index 16531940f..d5823d5b4 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -8,13 +8,23 @@ module Mobile desc '获取所有课件' params do requires :token, type: String + requires :page, type: Integer end - get do + post do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new # data = current_user.course_attachments data = rs.all_course_attachments current_user + all_count = data.count + data = data.limit(10).offset(page * 10) + count = data.count + present :data, data, with: Mobile::Entities::Attachment,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end @@ -24,14 +34,24 @@ module Mobile desc '获取所有作业' params do requires :token, type: String + requires :page, type: Integer end - get 'homeworks' do + post 'homeworks' do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new homeworks = rs.all_homework_commons current_user + all_count = homeworks.count + homeworks = homeworks.limit(10).offset(page * 10) + count = homeworks.count + present :data, homeworks, with: Mobile::Entities::Homework,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end @@ -39,13 +59,23 @@ module Mobile desc '获取所有测验' params do requires :token, type: String + requires :page, type: Integer end - get 'exercies' do + post 'exercises' do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new exercises = rs.all_exercises current_user + all_count = exercises.count + exercises = exercises.limit(10).offset(page * 10) + count = exercises.count + present :data, exercises, with: Mobile::Entities::Exercise,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index e2ea8d35b..e34bae63f 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -67,7 +67,8 @@ module Mobile openid: openid, user: user ) - + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, Time.now.strftime("%Y-%m-%d")) present :data, user, with: Mobile::Entities::User present :status, 0 end diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 5f1e54b8a..ea305d967 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -208,6 +208,9 @@ class WechatsController < ActionController::Base course = Course.where(invite_code: params[:invite_code]).first if params[:invite_code] raise "班级不存在,请确认您的邀请码是否输入正确,谢谢!" unless course + #取出用户角色类型 + role = 10 + cs = CoursesService.new status = cs.join_course({invite_code: course.invite_code}, user) logger.info status @@ -218,7 +221,7 @@ class WechatsController < ActionController::Base news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!', content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } return request.reply.news(news) do |article, n, index| # article is return object - url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect" + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/class?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect" pic_url = "#{ROOT_URL}/images/wechat/class.jpg" article.item title: "#{n[:title]}", description: n[:content], diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a71208248..603084cd1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2992,7 +2992,7 @@ int main(int argc, char** argv){ unless projects.empty? project_ids = '('+projects.map{|pro|pro.project_id}.join(',')+')' sort_projects = ForgeActivity.find_by_sql("SELECT MAX(updated_at) AS updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} GROUP BY project_id ORDER BY MAX(updated_at) DESC") - + #sort_projects = sort_projects.sort_by{|sp| (!sp.project.project_score.nil? && !sp.project.project_score.commit_time.nil?) ? '' : sp.project.project_score.commit_time} return sort_projects end end @@ -3292,7 +3292,7 @@ def strip_html(text,len=0,endss="...") ss = "" if !text.nil? && text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip - ss = ss.gsub(/ /, ' ') + ss = ss.gsub(/ */, ' ') if len > 0 && ss.length > len ss = ss[0, len] + endss @@ -3306,6 +3306,7 @@ end def message_content content content = (strip_html content).strip + content = content.gsub(/\s+/, " ") if content.gsub(" ", "") == "" content = "[非文本消息]" end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index a55a81e89..39c77de4b 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -187,10 +187,10 @@ class CoursesService else work_unit = get_user_work_unit course.teacher end - unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) - raise '403' - end - {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0} + # unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) + # raise '403' + # end + {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.nil? ? false : current_user.member_of_course?(course),:current_user_is_teacher => current_user.nil? ? false : is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0} end #创建课程 @@ -326,8 +326,8 @@ class CoursesService define_error [ 0, '加入成功', 1, '密码错误', - 2, '课程已过期 请联系课程管理员重启课程。', - 3, '您已经加入了课程', + 2, '班级已过期 请联系班级管理员重启班级。', + 3, '您已经加入了班级', 4, '您的邀请码不正确', 5, '您还未登录', 6, '申请成功,请等待审核完毕', @@ -354,54 +354,27 @@ class CoursesService roleName = member.roles[0].name if member if params[:invite_code].present? #如果加入角色为学生 并且当前是学生 - if params[:role] == "10" && roleName == "Student" + if roleName == "Student" @state = 3 #如果加入的角色为老师,并且当前已经是老师 - elsif params[:role] == "9" && roleName == "Teacher" + elsif roleName == "Teacher" @state = 8 #如果加入的角色教辅并且当前为教辅 - elsif params[:role] == "7" && roleName == "TeachingAsistant" + elsif roleName == "TeachingAsistant" @state = 9 elsif roleName == "Manager" @state = 10 - #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 - elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" ) - #如果已经发送过消息了,那么就要给个提示 - if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0 - @state = 7 - else - Mailer.run.join_course_request(course, User.current, params[:role]) - CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) - @state = 6 - end - #如果加入角色是学生,但是是当前课程的教师或者教辅 - elsif params[:role] == "10" && roleName != "Student" - member.role_ids = [params[:role]] - member.save - StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) - @state = 0 end else @state = 1 end else if params[:invite_code].present? - if params[:role] == "10" || params[:role] == nil members = [] members << Member.new(:role_ids => [10], :user_id => current_user.id) course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 - else - #如果已经发送过消息了,那么就要给个提示 - if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0").count != 0 - @state = 7 - else - Mailer.run.join_course_request(course, User.current, params[:role]) - CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) - @state = 6 - end - end else @state = 1 end @@ -419,7 +392,7 @@ class CoursesService def homework_list params,current_user course = Course.find(params[:id]) if course.is_public != 0 || current_user.member_of_course?(course) - bids = course.homework_commons.page(params[:page] || 1).per(20).order('created_at DESC') + bids = course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).page(params[:page] || 1).per(20).order('created_at DESC') bids = bids.like(params[:name]) if params[:name].present? homeworks = [] bids.each do |bid| @@ -522,7 +495,7 @@ class CoursesService def course_attachments params result = [] course = Course.find(params[:course_id]) - attachments = course.attachments.order("created_on ") + attachments = course.attachments.where("is_publish = 1").order("created_on desc") if !params[:name].nil? && params[:name] != "" attachments.each do |atta| result << atta if atta.filename.include?(params[:name]) diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb index dbdf3d7f3..822757dfe 100644 --- a/app/views/courses/_set_join.js.erb +++ b/app/views/courses/_set_join.js.erb @@ -10,12 +10,12 @@ <% elsif @state == 1 %> alert("密码错误"); <% elsif @state == 2 %> - alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)"); + alert("班级已过期\n请联系班级管理员重启班级。(在配置班级处)"); <% elsif @state == 3 %> - alert("您已经加入了课程"); + alert("您已经加入了班级"); window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" <% elsif @state == 4 %> - alert("您加入的课程不存在"); + alert("您加入的班级不存在"); <% elsif @state == 5 %> alert("您还未登录"); <% elsif @state == 6 %> diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 7b51ef568..f87b483da 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -198,10 +198,8 @@ <%# first_pro = sort_projects.first %> <% first_pro = Project.find sort_projects.first.project_id %> <% commit_time = first_pro.project_score.commit_time %> - <% one_time = first_pro.updated_on %> <% one_forge_time=ForgeActivity.where("project_id=?",first_pro.id).last.updated_at if ForgeActivity.where("project_id=?",first_pro.id).last %> - <% one_time= one_time > one_forge_time ? one_time : one_forge_time %> - # <%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(one_time) ? commit_time : one_time %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新: + # <%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(one_forge_time) ? commit_time : one_forge_time %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新:
<% sort_projects.each_with_index do |pro, i| %> diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 1b9490918..6e325c2f0 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -208,10 +208,8 @@","").gsub("
","").gsub("