diff --git a/.gitignore b/.gitignore index ba7890841..dbc349c80 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ vendor/cache /config/initializers/gitlab_config.rb 1234567 public/javascripts/wechat/node_modules/ +.ruby-version diff --git a/Gemfile b/Gemfile index d392c6561..a8131fb3f 100644 --- a/Gemfile +++ b/Gemfile @@ -81,7 +81,7 @@ group :assets do gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', :platforms => :ruby + # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c86a36d05..9ffac4e10 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -23,6 +23,7 @@ module Mobile version 'v1', using: :path format :json content_type :json, "application/json;charset=UTF-8" + use ActionDispatch::Session::CookieStore use Mobile::Middleware::ErrorHandler helpers do @@ -34,6 +35,10 @@ module Mobile raise('Unauthorized. 用户认证失败.') unless current_user end + def session + env['rack.session'] + end + def current_user openid = params[:openid] if openid @@ -67,8 +72,7 @@ module Mobile mount Apis::NewComment mount Apis::Praise - #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) - #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? + add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? end end diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 49fdaff8f..661925012 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -9,7 +9,7 @@ module Mobile params do requires :page, type: Integer - requires :openid, type: String + requires :token, type: String end post do authenticate! diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 3a36a9e37..58d4a4f8c 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -97,25 +97,20 @@ module Mobile desc "加入课程" params do - requires :course_password, type: String + requires :token, type: String + requires :invite_code, type: String, desc: '邀请码' end - post ":id" do + post "join" do authenticate! cs = CoursesService.new - status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user) - out = {status: status[:state]} - message = case status[:state] - when 0; "加入成功" - when 1; "密码错误" - when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)" - when 3; "您已经加入了课程" - when 4; "您加入的课程不存在" - when 5; "您还未登录" - else; "未知错误,请稍后再试" - end - out.merge(message: message) + status = cs.join_course({openid: params[:openid], invite_code: params[:invite_code]}, current_user) + { + status: status[:state], + messsge:CoursesService::JoinCourseError.message(status[:state]) + } end + desc "退出课程" params do requires :token, type: String @@ -201,6 +196,7 @@ module Mobile end route_param :id do get do + authenticate! cs = CoursesService.new course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) #course = Course.find(params[:id]) diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index b767bd768..4a6417cb4 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -8,7 +8,8 @@ module Mobile desc "get special issuse" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user issue = Issue.find params[:id] present :data, issue, with: Mobile::Entities::Issue,user: user present :status, 0 diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb index 15a571a82..5f2d01185 100644 --- a/app/api/mobile/apis/journal_for_messages.rb +++ b/app/api/mobile/apis/journal_for_messages.rb @@ -7,7 +7,8 @@ module Mobile desc "get special journal" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user jour = JournalsForMessage.find params[:id] present :data, jour, with: Mobile::Entities::Jours,user: user present :status, 0 diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb index ae2f9a39c..bab82de8d 100644 --- a/app/api/mobile/apis/messages.rb +++ b/app/api/mobile/apis/messages.rb @@ -7,7 +7,8 @@ module Mobile desc "get special topic" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user message = Message.find params[:id] present :data, message, with: Mobile::Entities::Message,user: user present :status, 0 diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 694ec0613..5b7159301 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -11,12 +11,12 @@ module Mobile params do requires :type, type: String requires :content, type: String - requires :openid, type: String + requires :token, type: String end post ':id' do + authenticate! type = params[:type] result = 1 - current_user = UserWechat.find_by_openid(params[:openid]).user if params[:content]!="" && current_user case type when "HomeworkCommon" diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 8bdd460cc..d42177783 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -7,7 +7,8 @@ module Mobile desc "get special news" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user news = News.find params[:id] present :data, news, with: Mobile::Entities::News,user: user present :status, 0 diff --git a/app/api/mobile/apis/praise.rb b/app/api/mobile/apis/praise.rb index 57dbd0729..834d1195b 100644 --- a/app/api/mobile/apis/praise.rb +++ b/app/api/mobile/apis/praise.rb @@ -9,12 +9,13 @@ module Mobile params do requires :type, type: String - requires :openid, type: String + requires :token, type: String end post ':id' do + authenticate! obj_id = params[:id] obj_type = params[:type] - user = UserWechat.find_by_openid(params[:openid]).user + user = current_user pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first if pts.blank? praise_or_cancel(obj_type,obj_id,user,1) diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 6ce3cacbb..b5ee14d19 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -4,6 +4,48 @@ module Mobile class Users < Grape::API resource :users do + desc "查询是否已绑定" + params do + requires :openid, type: String, desc: 'wechat openid' + end + post 'isbind' do + openid = params[:openid] + uw = UserWechat.where(openid: openid).first + raise "还未绑定trustie帐户" unless uw + + user = uw.user + ::ApiKey.delete_all(user_id: user.id) + key = ::ApiKey.create!(user_id: user.id) + present status: 0, token: key.access_token + end + + desc "绑定微信用户" + params do + requires :login, type: String, desc: 'username' + requires :password, type: String, desc: 'password' + end + post 'wxbind' do + openid = session[:wechat_openid] + logger.debug "openid ============== #{openid}" + raise "无法获取到openid,请在微信中打开本页面" unless openid + uw = UserWechat.where(openid: openid).first + raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw + + user, last_login_on = User.try_to_login(params[:login], params[:password]) + raise "用户名或密码错误,请重新输入" unless user + #补全用户信息 + + raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat + + UserWechat.create!( + openid: openid, + user: user + ) + # ws = WechatService.new + # ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) + present status: 0, message: '您已成功绑定Trustie平台' + end + desc "注册用户" params do requires :login, type: String, desc: 'username' diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index a88d509a3..c8377aa0d 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -7,7 +7,8 @@ module Mobile desc "get one homework" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user homework = HomeworkCommon.find params[:id] present :data, homework, with: Mobile::Entities::Whomework,user: user present :status, 0 diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 50812b349..487a75c4d 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -45,6 +45,8 @@ module Mobile course_expose :tea_id course_expose :term course_expose :time + course_expose :invite_code + course_expose :qrcode course_expose :updated_at course_expose :course_student_num expose :teacher, using: Mobile::Entities::User do |c, opt| diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 8c6a839b3..2eb20f0db 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -26,6 +26,8 @@ module Mobile u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id when :realname u.nil? ? "" : get_user_realname(u) + when :name + u.nil? ? "" : u.show_name end end end @@ -57,6 +59,11 @@ module Mobile user_expose :student_num # 活跃值 user_expose :active_count + + user_expose :role_name + + user_expose :name + end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e421b8c69..43b488e96 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -74,7 +74,7 @@ class CoursesController < ApplicationController else @state = 5 #未登录 end - @object_id = params[:object_id] + @object_id = @course.id if @course respond_to do |format| format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} } end @@ -1224,7 +1224,7 @@ class CoursesController < ApplicationController def member_to_xls homeworks, course, members,groups xls_report = StringIO.new book = Spreadsheet::Workbook.new - sheet1 = book.create_worksheet :name => "student" + sheet1 = book.create_worksheet :name => "总成绩" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 #sheet1.row(0).default_format = blue #sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)]) @@ -1268,6 +1268,121 @@ class CoursesController < ApplicationController count_row += 1 end + homeworks.each_with_index do |home, i| + sheet = book.create_worksheet :name => "第#{i+1}次作业" + sheet[0,0] = "课程编号" + sheet[0,1] = course.id + sheet[1,0] = "课程学期" + sheet[1,1] = course.time.to_s+"年"+course.term + sheet[2,0] = "课程名称" + sheet[2,1] = course.name + sheet[3,0] = "教师团队" + sheet[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') + sheet[4,0] = "主讲教师" + sheet[4,1] = course.teacher.show_name + sheet[4,0] = "作业批次" + sheet[4,1] = "第#{i+1}次作业" + sheet[4,0] = "作业名称" + sheet[4,1] = home.name + if home.homework_type == 1 #普通作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0]= j + 1 + sheet[count_row,1] = stu.user.show_name + sheet[count_row,2] = stu.user.login + sheet[count_row,3] = stu.user.user_extensions.student_id + sheet[count_row,4] = stu.name + sheet[count_row,5] = strip_html stu.description + sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,8] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,9] = home.teacher_priority == 1 ? 0 : stu.absence_penalty + sheet[count_row,10] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,11] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,12] = format_time(stu.created_at) + else + sheet[count_row,8] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,9] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,10] = format_time(stu.created_at) + end + count_row += 1 + end + elsif home.homework_type == 2 #编程作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0]= j + 1 + sheet[count_row,1] = stu.user.show_name + sheet[count_row,2] = stu.user.login + sheet[count_row,3] = stu.user.user_extensions.student_id + sheet[count_row,4] = stu.name + sheet[count_row,5] = stu.description + sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + sheet[count_row,8] = stu.system_score.nil? ? l(:label_without_score) : stu.system_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,9] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,10] = home.teacher_priority == 1 ? 0 : stu.absence_penalty + sheet[count_row,11] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,12] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,13] = format_time(stu.created_at) + else + sheet[count_row,9] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,11] = format_time(stu.created_at) + end + count_row += 1 + end + elsif home.homework_type == 3 #分组作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0] = j + 1 + sheet[count_row,1] = get_group_member_names stu + sheet[count_row,2] = stu.name + sheet[count_row,3] = (stu.project_id == 0 || stu.project_id.nil?) ? l(:excel_no_project) : stu.project.name + sheet[count_row,4] = strip_html stu.description + sheet[count_row,5] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,6] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,7] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,8] = home.teacher_priority == 1 ? 0 : stu.absence_penalty + sheet[count_row,9] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,11] = format_time(stu.created_at) + else + sheet[count_row,7] = home.teacher_priority == 1 ? 0 : stu.late_penalty + sheet[count_row,8] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,9] = format_time(stu.created_at) + end + count_row += 1 + end + end + end + =begin group0 = CourseGroup.new(); group0.id = 0; diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index d478b4d63..3a72ba55e 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1209,13 +1209,18 @@ class StudentWorkController < ApplicationController sheet1 = book.create_worksheet :name => "homework" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - if @homework.homework_type == 1 #匿评作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) + if @homework.homework_type == 1 #普通作业 + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end count_row = 1 items.each do |homework| sheet1[count_row,0]=homework.user.id - sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,1] = homework.user.show_name sheet1[count_row,2] = homework.user.login sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail @@ -1223,18 +1228,31 @@ class StudentWorkController < ApplicationController sheet1[count_row,6] = strip_html homework.description sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) - sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) - sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) - sheet1[count_row,11] = format_time(homework.created_at) + if @homework.anonymous_comment ==0 + sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,10] = @homework.teacher_priority == 1 ? 0 : homework.absence_penalty + sheet1[count_row,11] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,12] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,13] = format_time(homework.created_at) + else + sheet1[count_row,9] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,11] = format_time(homework.created_at) + end count_row += 1 end elsif @homework.homework_type == 2 #编程作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end count_row = 1 items.each do |homework| sheet1[count_row,0]=homework.user.id - sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,1] = homework.user.show_name sheet1[count_row,2] = homework.user.login sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail @@ -1243,11 +1261,48 @@ class StudentWorkController < ApplicationController sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : homework.system_score.round(2) - sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) - sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) - sheet1[count_row,12] = format_time(homework.created_at) + if @homework.anonymous_comment ==0 + sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,11] = @homework.teacher_priority == 1 ? 0 : homework.absence_penalty + sheet1[count_row,12] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,13] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,14] = format_time(homework.created_at) + else + sheet1[count_row,10] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,12] = format_time(homework.created_at) + end count_row += 1 end + elsif @homework.homework_type == 3 #分组作业 + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 1 + items.each do |homework| + sheet1[count_row,0] = get_group_member_names homework + sheet1[count_row,1] = homework.name + sheet1[count_row,2] = (homework.project_id == 0 || homework.project_id.nil?) ? l(:excel_no_project) : homework.project.name + sheet1[count_row,3] = strip_html homework.description + sheet1[count_row,4] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) + sheet1[count_row,5] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) + if @homework.anonymous_comment ==0 + sheet1[count_row,6] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,7] = @homework.teacher_priority == 1 ? 0 : homework.absence_penalty + sheet1[count_row,8] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,10] = format_time(homework.created_at) + else + sheet1[count_row,6] = @homework.teacher_priority == 1 ? 0 : homework.late_penalty + sheet1[count_row,7] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,8] = format_time(homework.created_at) + end + count_row += 1 + end end book.write xls_report xls_report.string diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ba1a51343..b7972ff6f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -87,7 +87,10 @@ class UsersController < ApplicationController #展开所有回复 def show_all_replies - @comment = JournalsForMessage.find params[:comment].to_i + case params[:type] + when 'JournalsForMessage' + @comment = JournalsForMessage.find params[:comment].to_i + end end #二级回复 @@ -95,6 +98,7 @@ class UsersController < ApplicationController case params[:type] when 'HomeworkCommon' @reply = JournalsForMessage.find params[:reply_id] + @type = 'HomeworkCommon' if params[:user_activity_id] @user_activity_id = params[:user_activity_id] else @@ -102,6 +106,11 @@ class UsersController < ApplicationController end @is_in_course = params[:is_in_course].to_i @course_activity = params[:course_activity].to_i + when 'JournalsForMessage' + @reply = JournalsForMessage.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @type = 'JournalsForMessage' end respond_to do |format| format.js @@ -3261,7 +3270,11 @@ class UsersController < ApplicationController @journals = obj.comments.reorder("created_on desc") when 'JournalsForMessage' obj = JournalsForMessage.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_on desc") + journals = [] + @journals = get_all_children(journals, obj) + @type = 'JournalsForMessage' + @user_activity_id = params[:div_id].to_i if params[:div_id] + @allow_delete = params[:allow_delete] when 'Issue' obj = Issue.where('id = ?', params[:id].to_i).first @journals = obj.journals.reorder("created_on desc") diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 169a33fce..15d4ab2e1 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -3,10 +3,23 @@ class WechatsController < ActionController::Base wechat_responder include ApplicationHelper - + # ROOT_URL = "#{Setting.protocol}://#{Setting.host_name}/" + ROOT_URL = "http://wechat.trustie.net" # default text responder when no other match on :text do |request, content| - request.reply.text "您的意见已收到,感谢您的反馈!" # Just echo + #邀请码 + begin + uw = user_binded?(request[:FromUserName]) + if !uw + return sendBind() + else + return join_class({invite_code: content}, uw.user) + end + rescue => e + logger.error e.inspect + logger.error e.backtrace.join("\n") + return request.reply.text e + end end # When receive 'help', will trigger this responder @@ -35,7 +48,18 @@ class WechatsController < ActionController::Base # When subscribe user scan scene_id in public account on :scan, with: 'scene_id' do |request, ticket| - request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}" + begin + uw = user_binded?(request[:FromUserName]) + if !uw + return sendBind() + else + return join_class({ticket: ticket}, uw.user) + end + rescue => e + logger.error e.inspect + logger.error e.backtrace.join("\n") + return request.reply.text e + end end # When no any on :scan responder can match subscribe user scaned scene_id @@ -128,6 +152,15 @@ class WechatsController < ActionController::Base default_msg(request) end + on :click, with: 'JOIN_CLASS' do |request, key| + uw = user_binded?(request[:FromUserName]) + unless uw + sendBind(request) + else + request.reply.text "请直接回复6位班级邀请码\n(不区分大小写):" + end + end + def default_msg(request) uw = user_binded?(request[:FromUserName]) if uw && uw.user @@ -145,8 +178,8 @@ class WechatsController < ActionController::Base 您还未绑定确实的用户,请先绑定,谢谢!" } } 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=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" - pic_url = "#{Setting.protocol}://#{Setting.host_name}/images/weixin_pic.jpg" + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login#wechat_redirect" + pic_url = "#{ROOT_URL}/images/weixin_pic.jpg" article.item title: "#{n[:title]}", description: n[:content], pic_url: pic_url, @@ -154,18 +187,53 @@ class WechatsController < ActionController::Base end end + def join_class(params, user) + course = nil + course = Course.where(qrcode: params[:ticket]) if params[:ticket] + course = Course.where(invite_code: params[:invite_code]) if params[:invite_code] + raise "课程不存在" if course.blank? + + cs = CoursesService.new + status = cs.join_course(course.invite_code, user) + logger.info status + if status[:state] != 0 + raise CoursesService::JoinCourseError.message(status[:state]) + end + + course = status[:course] + 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" + pic_url = "#{ROOT_URL}/images/wechat/class.jpg" + article.item title: "#{n[:title]}", + description: n[:content], + pic_url: pic_url, + url: url + end + + end + ### controller method module Controllers - def get_open_id + def get_bind begin - code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) raise "无法获取到微信openid" unless openid - render :json => {status:0, openid: openid} + + uw = UserWechat.where(openid: openid).first + raise "还未绑定trustie帐户" unless uw + logger.debug "get_bind ============= #{uw}" + + user = uw.user + ::ApiKey.delete_all(user_id: user.id) + key = ::ApiKey.create!(user_id: user.id) + + render :json =>{status: 0, token: key.access_token} rescue Exception=>e - render :json => {status: -1, msg: e.message} + render :json => {status: -1, message: e.message} end end @@ -175,7 +243,7 @@ class WechatsController < ActionController::Base code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) - raise "无法获取到openid" unless openid + raise "无法获取到openid,请在微信中打开本页面" unless openid raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid) user, last_login_on = User.try_to_login(params[:username], params[:password]) @@ -206,19 +274,26 @@ class WechatsController < ActionController::Base def user_activities session[:wechat_code] = params[:code] if params[:code] - code = params[:code] || session[:wechat_code] - openid = get_openid_from_code(code) - @wechat_user = user_binded?(openid) - unless @wechat_user - redirect_to login_wechat_path - return + @path = '/'+(params[:state] || '') + open_id = get_openid_from_code(params[:code]) rescue + unless open_id + render 'wechats/open_wechat', layout: nil and return + end + if params[:state] == 'myclass' + @course_id = params[:id]; end + session[:wechat_openid] = open_id + if params[:code] + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return + end render 'wechats/user_activities', layout: nil end + private def get_openid_from_code(code) + return 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg' if code =='only-for-test' openid = session[:wechat_openid] unless openid diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 22b7f1f52..668269a26 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -54,15 +54,16 @@ class WordsController < ApplicationController :reply_id => reply_user_id, :notes => content, :is_readed => false} - @jfm = add_reply_adapter options + @activity = params[:activity_id].nil? ? JournalsForMessage.find(parent_id) : JournalsForMessage.find(params[:activity_id].to_i) + @jfm = add_reply_adapter(@activity, options) @save_succ = true if @jfm.errors.empty? if @save_succ - update_course_activity('JournalsForMessage',parent_id) - update_user_activity('JournalsForMessage',parent_id) - update_forge_activity('JournalsForMessage',parent_id) - update_org_activity('JournalsForMessage',parent_id) - update_principal_activity('JournalsForMessage',parent_id) - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + update_course_activity('JournalsForMessage',@activity.id) + update_user_activity('JournalsForMessage',@activity.id) + update_forge_activity('JournalsForMessage',@activity.id) + update_org_activity('JournalsForMessage',@activity.id) + update_principal_activity('JournalsForMessage',@activity.id) + @activity.update_attribute(:updated_on,Time.now) end respond_to do |format| # format.html { @@ -76,8 +77,6 @@ class WordsController < ApplicationController format.js { #@reply_type = params[:reply_type] @user_activity_id = params[:user_activity_id] - @activity = JournalsForMessage.find(parent_id) - @is_activity = params[:is_activity] if params[:is_activity] } end @@ -92,13 +91,14 @@ class WordsController < ApplicationController elsif @journal_destroyed.jour_type == "Course" @course = Course.find @journal_destroyed.jour_id @jours_count = @course.journals_for_messages.where('m_parent_id IS NULL').count + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id] elsif @journal_destroyed.jour_type == "Principal" @user = User.find(@journal_destroyed.jour_id) @jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count @is_user = true @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @is_activity = params[:is_activity].to_i if params[:is_activity] - @activity = @journal_destroyed.parent if @journal_destroyed.parent + @activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id] unless @activity redirect_to feedback_path(@user) return @@ -374,28 +374,44 @@ class WordsController < ApplicationController obj end - def add_reply_adapter options + def add_reply_adapter obj, options #modify by nwb #添加对课程留言的支持 #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 - obj = obj_distinguish_url_origin || User.find_by_id(2) - if obj.kind_of? User - obj.add_jour(nil, nil, nil, options) - elsif obj.kind_of? Project - Project.add_new_jour(nil, nil, obj.id, options) - elsif obj.kind_of? Course - Course.add_new_jour(nil, nil, obj.id, options) - elsif obj.kind_of? Bid - obj.add_jour(nil, nil, nil, options) - elsif obj.kind_of? Contest - obj.add_jour(nil, nil, obj.id, options) #new added - elsif obj.kind_of? Softapplication - obj.add_jour(nil, nil, obj.id, options) #new added - elsif obj.kind_of? HomeworkAttach - obj.add_jour(nil, nil, obj.id, options) #new added - else - raise "create reply obj unknow type.#{obj.class}" + case obj.jour_type + when 'Principal' + obj.jour.add_jour(nil, nil, nil, options) + when 'Project' + Project.add_new_jour(nil, nil, obj.jour_id, options) + when 'Course' + Course.add_new_jour(nil, nil, obj.jour_id, options) + when 'Bid' + obj.jour.add_jour(nil, nil, nil, options) + when 'Contest' + obj.jour.add_jour(nil, nil, obj.jour_id, options) + when 'Softapplication' + obj.jour.add_jour(nil, nil, obj.jour_id, options) + when 'HomeworkAttach' + obj.jour.add_jour(nil, nil, obj.jour_id, options) end + # obj = obj_distinguish_url_origin || User.find_by_id(2) + # if obj.kind_of? User + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Project + # Project.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Course + # Course.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Bid + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Contest + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? Softapplication + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? HomeworkAttach + # obj.add_jour(nil, nil, obj.id, options) #new added + # else + # raise "create reply obj unknow type.#{obj.class}" + # end end #######end of message end diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index fb1231287..e993b120f 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -489,4 +489,26 @@ module ApiHelper self.update_attribute(:praise_num, self.praise_num.to_i - num) end + + class Errors + def self.define_error(arr) + @errors = {} + arr.each_with_index { |item, index| + if index %2 == 1 + @errors[arr[index-1]] = item + end + } + if arr.count % 2== 1 + @default_error = arr.last + else + @default_error = "未知错误" + end + + end + + def self.message(msg_id) + @errors[msg_id] || @default_error + end + end + end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 46fdb02f3..ee2e2d74a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3127,6 +3127,26 @@ def get_reply_parents parents_rely, comment parents_rely end +#获取回复的所有父节点(不包括根节点) +def get_reply_parents_no_root parents_rely, comment + if !comment.parent.nil? && !comment.parent.parent.nil? + parents_rely << comment.parent + get_reply_parents_no_root parents_rely, comment.parent + end + parents_rely +end + +#获取留言的所有子节点 +def get_all_children result, jour + if jour.kind_of? JournalsForMessage + jour.children.each do |jour_child| + result << jour_child + get_all_children result, jour_child + end + end + result.sort! { |a,b| b.created_on <=> a.created_on } +end + #将有置顶属性的提到数组前面 def sort_by_sticky topics tmpTopics = [] @@ -3283,3 +3303,20 @@ def get_hw_index(hw,is_teacher) index = hw_ids.index(hw.id) return index end + +def get_group_member_names work + result = "" + unless work.nil? + work.student_work_projects.each do |member| + user = User.where(:id => member.user_id).first + unless user.nil? + if result != "" + result += "、#{user.show_name}" + else + result += user.show_name + end + end + end + end + result +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index c10652c6f..47d343e8f 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -270,13 +270,22 @@ module CoursesHelper # ===================================================================================== # return people list + def searchPeopleByName(course, role_name) + course.members.select{|m| + m.roles.any?{|r|r.name == role_name} + } + end + def searchTeacherAndAssistant project - #searchPeopleByRoles(project, TeacherRoles) - members = [] - project.members.includes(:user).each do |m| - members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) - end - members + searchPeopleByName(project, 'Manager').concat( + searchPeopleByName(project, 'Teacher') + ).concat( + searchPeopleByName(project, 'TeachingAsistant') + ) + end + + def searchStudent project + searchPeopleByName(project, 'Student') end def TeacherAndAssistantCount course @@ -293,19 +302,6 @@ module CoursesHelper members end - def searchStudent project - #searchPeopleByRoles(project, StudentRoles) - members = [] - project.members.each do |m| - if m && m.user && m.user.allowed_to?(:as_student,project) - members << m - end - end - members - end - - - def searchStudent_by_name project, name #searchPeopleByRoles(project, StudentRoles) members = [] diff --git a/app/models/course.rb b/app/models/course.rb index e3a845b11..195e7cf9f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,3 +1,5 @@ +#coding=utf-8 + require 'elasticsearch/model' class Course < ActiveRecord::Base include Redmine::SafeAttributes @@ -65,7 +67,7 @@ class Course < ActiveRecord::Base acts_as_attachable :view_permission => :view_course_files, :delete_permission => :manage_files - validates_presence_of :password, :term,:name + validates_presence_of :term,:name validates_format_of :class_period, :with =>/^[1-9]\d*$/ validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ validates_length_of :description, :maximum => 10000 @@ -405,6 +407,7 @@ class Course < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) end + #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 #def name # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) @@ -422,12 +425,14 @@ class Course < ActiveRecord::Base # __elasticsearch__.delete_document # end def create_course_ealasticsearch_index + return if Rails.env.development? if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引 self.__elasticsearch__.index_document end end def update_course_ealasticsearch_index + return if Rails.env.development? if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin self.__elasticsearch__.update_document @@ -444,6 +449,7 @@ class Course < ActiveRecord::Base end def delete_course_ealasticsearch_index + return if Rails.env.development? begin self.__elasticsearch__.delete_document rescue => e @@ -451,6 +457,31 @@ class Course < ActiveRecord::Base end end + # 生成邀请码 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_invite_code + code = invite_code + if !invite_code || invite_code.size <5 + self.invite_code = CODES.sample(5).join + return generate_invite_code if Course.where(invite_code: invite_code).present? + save! && reload + code = invite_code + end + code + end + + + def generate_qrcode + ticket = self.qrcode + if !ticket || ticket.size < 10 + response = Wechat.api.qrcode_create_scene(invite_code) + logger.debug "response = #{response}" + self.qrcode = response['ticket'] + save! && reload + ticket = qrcode + end + ticket + end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 2c8387349..41fb18b61 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -68,7 +68,6 @@ class CoursesService if current_user.nil? || !(current_user.admin? || c.is_public == 1 || (c.is_public == 0 && current_user.member_of_course?(c))) raise '403' end - @teachers= searchTeacherAndAssistant(c) #@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1' case params[:role] when '1' @@ -87,7 +86,11 @@ class CoursesService gender = m.user.user_extensions.gender.nil? ? 0 : m.user.user_extensions.gender work_unit = get_user_work_unit m.user location = get_user_location m.user - users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} + users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, + :work_unit => work_unit, :mail => m.user.mail, :location => location, + role_name: m.roles.first.name, + name: m.user.show_name, + :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} end users end @@ -162,6 +165,9 @@ class CoursesService #显示课程 def show_course(params,current_user) course = Course.find(params[:id]) + course.generate_invite_code + course.generate_qrcode + if course.school work_unit = course.school.name else @@ -193,7 +199,7 @@ class CoursesService @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.send(:safe_attributes=, params[:course], current_user) #@course.safe_attributes(current_user,params[:course]) - @course.password = params[:course][:password] + #@course.password = params[:course][:password] @course.tea_id = current_user.id @course.term = params[:term] @course.time = params[:time] @@ -252,7 +258,7 @@ class CoursesService def edit_course(params,course,current_user) course.send(:safe_attributes=, params[:course], current_user) #course.safe_attributes = params[:course] - course.password = params[:course][:password] + #course.password = params[:course][:password] course.time = params[:time] course.term = params[:term] course.end_time = params[:end_time] @@ -300,23 +306,27 @@ class CoursesService @state end + class JoinCourseError < Errors + define_error [ + 0, '加入成功', + 1, '密码错误', + 2, '课程已过期 请联系课程管理员重启课程。', + 3, '您已经加入了课程', + 4, '您加入的课程不存在', + 5, '您还未登录', + 6, '申请成功,请等待审核完毕', + 7, '您已经发送过申请了,请耐心等待', + 8, '您已经是该课程的教师了', + 9, '您已经是该课程的教辅了', + 10, '您已经是该课程的管理员了', + '未知错误,请稍后再试' + ] + end #加入课程 #object_id:课程id #course_password :加入课程的密码 - #@state == 0 加入成功 - #@state == 1 密码错误 - #@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处) - #@state == 3 您已经加入了课程 - #@state == 4 您加入的课程不存在 - #@state == 5 您还未登录 - #@state == 6 申请成功,请等待审核完毕 - #@state == 7 您已经发送过申请了,请耐心等待 - #@state == 8 您已经是该课程的教师了 - #@state == 9 您已经是该课程的教辅了 - #@state == 10 您已经是该课程的管理员了 - #@state 其他 未知错误,请稍后再试 def join_course params,current_user - course = Course.find_by_id params[:object_id] + course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code] @state = 10 if course @@ -326,7 +336,7 @@ class CoursesService if current_user.member_of_course?(course) #如果已经是成员 member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] roleName = member.roles[0].name if member - if params[:course_password] == course.password + if params[:invite_code].present? #如果加入角色为学生 并且当前是学生 if params[:role] == "10" && roleName == "Student" @state = 3 @@ -352,19 +362,19 @@ class CoursesService elsif params[:role] == "10" && roleName != "Student" member.role_ids = [params[:role]] member.save - StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 end else @state = 1 end else - if params[:course_password] == course.password + 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 => params[:object_id]) + StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 else #如果已经发送过消息了,那么就要给个提示 diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index 9617b7f76..7d8aaed86 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -87,11 +87,7 @@
<%= string %>
+ <% end %> + <% end %> +<%= comment.notes.html_safe %>
+ <% else %> + <%= comment.content_detail.html_safe %> + <% end %> +