From 5cf824022a36c4b27789b97d933efda877a9ee89 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 23 Jul 2019 12:12:03 +0800 Subject: [PATCH 01/29] =?UTF-8?q?=E6=8E=88=E6=9D=83=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 33 +++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b0183574d..28fec46af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -186,15 +186,32 @@ class ApplicationController < ActionController::Base # 系统全局认证 def check_auth - if current_user.certification != 1 && current_user.apply_actions.exists?(container_type: 'TrialAuthorization', status: 0) - tip_exception(408, "您的试用申请正在审核中,请耐心等待") - elsif current_user.certification != 1 - day_cer = UserDayCertification.find_by(user_id: current_user.id) - tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - elsif !current_user.profile_completed? - info_url = '/account/profile' - tip_exception(402, info_url) + day_cer = UserDayCertification.find_by(user_id: current_user.id) + # 如果注册超过24小时则需要完善资料及授权 + if (Time.now.to_i - day_cer.try(:created_at).to_i) > 86400 + if !current_user.profile_completed? + info_url = '/account/profile' + tip_exception(402, info_url) + elsif current_user.certification != 1 + if current_user.apply_actions.exists?(container_type: 'TrialAuthorization', status: 0) + tip_exception(408, "您的试用申请正在审核中,请耐心等待") + end + tip_exception(407, "系统未授权") + end end + + + # if current_user.certification != 1 && current_user.apply_actions.exists?(container_type: 'TrialAuthorization', status: 0) + # tip_exception(408, "您的试用申请正在审核中,请耐心等待") + # elsif (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + # if !current_user.profile_completed? + # info_url = '/account/profile' + # tip_exception(402, info_url) + # elsif current_user.certification != 1 + # day_cer = UserDayCertification.find_by(user_id: current_user.id) + # tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + # end + # end end def start_user_session(user) From d1965d5251df19c3d61fe876b1d17411836a435a Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 23 Jul 2019 12:52:15 +0800 Subject: [PATCH 02/29] 407 --- .../react/src/modules/paths/PathDetail/PathDetailIndex.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/paths/PathDetail/PathDetailIndex.js b/public/react/src/modules/paths/PathDetail/PathDetailIndex.js index 6843f678a..bb410c1ce 100644 --- a/public/react/src/modules/paths/PathDetail/PathDetailIndex.js +++ b/public/react/src/modules/paths/PathDetail/PathDetailIndex.js @@ -139,7 +139,9 @@ class PathDetailIndex extends Component{ let pathid=this.props.match.params.pathId; let url="/paths/"+pathid+".json"; axios.get(url).then((result)=>{ - + if (result.data.status == 407) { + return; + } if(result.data.allow_visit===true){ this.setState({ detailInfoList:result.data, @@ -162,6 +164,9 @@ class PathDetailIndex extends Component{ let pathid=this.props.match.params.pathId; let url="/paths/"+pathid+".json"; axios.get(url).then((result)=>{ + if (result.data.status == 407) { + return; + } if(result.data.allow_visit===true){ this.setState({ detailInfoList:result.data, From b85cca3d19ea2fd9bbfbf19d4a47307868fbe163 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 23 Jul 2019 13:05:54 +0800 Subject: [PATCH 03/29] null --- .../react/src/modules/courses/shixunHomework/shixunHomework.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/react/src/modules/courses/shixunHomework/shixunHomework.js b/public/react/src/modules/courses/shixunHomework/shixunHomework.js index 3a4efc17d..78ee31e82 100644 --- a/public/react/src/modules/courses/shixunHomework/shixunHomework.js +++ b/public/react/src/modules/courses/shixunHomework/shixunHomework.js @@ -1137,7 +1137,7 @@ class ShixunHomework extends Component{ `} {/*onChange={this.onCheckBoxChange} value={checkBoxValues}*/} {datas===undefined?"": - { datas.homeworks.map((item, index) => { + { datas.homeworks && datas.homeworks.map((item, index) => { // console.log("ShixunhomeWorkItem") // console.log("++++++++++++++++++++++++++++++++++++++++++") // console.log(JSON.stringify(this.props)) From a30134783d12fc1a3d2783b46bcc9dcc7e2bbd43 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 23 Jul 2019 13:10:22 +0800 Subject: [PATCH 04/29] null --- public/react/src/modules/courses/coursesPublic/Addcourses.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/react/src/modules/courses/coursesPublic/Addcourses.js b/public/react/src/modules/courses/coursesPublic/Addcourses.js index 886ba2a0e..914a82c6d 100644 --- a/public/react/src/modules/courses/coursesPublic/Addcourses.js +++ b/public/react/src/modules/courses/coursesPublic/Addcourses.js @@ -89,6 +89,7 @@ class Addcourses extends Component{ }) }else{ this.setState({ + professor:null, assistant_professor:null, Checkboxteacherchecked:e.target.checked, Checkboxteachingtype:false From f1eb51c1d5b3ad311826554498ba541ede4f424b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Tue, 23 Jul 2019 13:25:17 +0800 Subject: [PATCH 05/29] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/AppConfig.js | 7 ++--- .../courses/coursesPublic/Addcourses.js | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 5721c88a9..8cca8205f 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -18,10 +18,9 @@ function locationurl(list){ } // TODO 开发期多个身份切换 -const debugType ="" -// window.location.search.indexOf('debug=t') != -1 ? 'teacher' : -// window.location.search.indexOf('debug=s') != -1 ? 'student' : 'admin' -// window._debugType = debugType; +const debugType =window.location.search.indexOf('debug=t') != -1 ? 'teacher' : + window.location.search.indexOf('debug=s') != -1 ? 'mfp2guqj3' : 'admin' +window._debugType = debugType; export function initAxiosInterceptors(props) { // TODO 避免重复的请求 https://github.com/axios/axios#cancellation diff --git a/public/react/src/modules/courses/coursesPublic/Addcourses.js b/public/react/src/modules/courses/coursesPublic/Addcourses.js index 914a82c6d..b7d46eac6 100644 --- a/public/react/src/modules/courses/coursesPublic/Addcourses.js +++ b/public/react/src/modules/courses/coursesPublic/Addcourses.js @@ -117,7 +117,7 @@ class Addcourses extends Component{ hidetojoinclass=()=>{ - + let {Addcoursestype}=this.props; // console.log(this.props) this.setState({ invite_code:undefined, @@ -132,11 +132,16 @@ class Addcourses extends Component{ student:null, Addcoursestypes:false }) - this.props.hideAddcoursestype(); + + if(Addcoursestype===true){ + this.props.hideAddcoursestype(); + } + } submitasyn=(course_id)=>{ - let{professor}=this.state; + let{professor,Addcoursestype}=this.state; + if(professor===1){ this.setState({ loadtype:true, @@ -145,13 +150,17 @@ class Addcourses extends Component{ modalSave:(course_id)=>this.submitasyns(course_id), Addcoursestype:false }) - this.props.hideAddcoursestype(); + if(Addcoursestype===true){ + this.props.hideAddcoursestype(); + } }else{ // let{course_id}=this.state; this.setState({ Addcoursestype:false }) - this.props.hideAddcoursestype(); + if(Addcoursestype===true){ + this.props.hideAddcoursestype(); + } window.location.href ="/courses/"+course_id+"/students"; } @@ -161,6 +170,7 @@ class Addcourses extends Component{ } submittojoinclass=()=>{ + let{Addcoursestype}=this.state; this.setState({ isSpin:true }) @@ -207,7 +217,9 @@ class Addcourses extends Component{ message:"提示", description:response.data.message }); - this.props.hideAddcoursestype(); + if(Addcoursestype===true){ + this.props.hideAddcoursestype(); + } // this.props.showNotification(response.data.message); @@ -220,7 +232,9 @@ class Addcourses extends Component{ this.setState({ Addcoursestype:false }) - this.props.hideAddcoursestype(); + if(Addcoursestype===true){ + this.props.hideAddcoursestype(); + } // this.setState({ @@ -318,7 +332,7 @@ class Addcourses extends Component{ keyboard={false} className={"HomeworkModal"} title="加入课堂" - visible={Addcoursestype===undefined?Addcoursestypes:Addcoursestype} + visible={Addcoursestype===undefined||Addcoursestype===false?Addcoursestypes:Addcoursestype} closable={false} footer={null} destroyOnClose={true} From 1a45a9bee848336fc4443fa83fc1d2143c46e70b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 23 Jul 2019 13:47:27 +0800 Subject: [PATCH 06/29] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 542c33652..7a135b031 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -891,7 +891,7 @@ class CoursesController < ApplicationController # end # 创建学生身份 - if params[:student].present? + if params[:student].present? && params[:student].to_i == 1 existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id) if existing_student.present? # 如果在该课堂已经存在学生身份,且邀请码为分班邀请码,则将其直接加入分班 @@ -911,7 +911,7 @@ class CoursesController < ApplicationController end # 创建教师身份 - if params[:professor].present? || params[:assistant_professor].present? + if (params[:professor].present? && params[:professor].to_i == 1) || (params[:assistant_professor].present? && params[:assistant_professor].to_i == 1) teacher_already_exist = current_user.teacher_of_course_non_active? course unless teacher_already_exist existing_course_message = CourseMessage.find_by(course_id: course.id, course_message_id: current_user.id, @@ -920,8 +920,8 @@ class CoursesController < ApplicationController course_message = CourseMessage.new(course_id: course.id, user_id: course.tea_id, status: 0, course_message_id: current_user.id, course_message_type: "JoinCourseRequest", viewed: false) - course_message.content = 2 if params[:professor].present? - course_message.content = 3 if params[:assistant_professor].present? + course_message.content = 2 if params[:professor].present? && params[:professor].to_i == 1 + course_message.content = 3 if params[:assistant_professor].present? && params[:assistant_professor].to_i == 1 course_message.save! From b63d94df24d84d7dbab98b5b040458bb80ddb9d2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 23 Jul 2019 14:10:10 +0800 Subject: [PATCH 07/29] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7a135b031..6042fbc9a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -14,7 +14,7 @@ class CoursesController < ApplicationController before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, - :left_banner, :top_banner, :apply_to_join_course] + :left_banner, :top_banner, :apply_to_join_course, :exit_course] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, From 4e33c981900b8362db616c51fa92e81871fb9dc0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 23 Jul 2019 14:13:26 +0800 Subject: [PATCH 08/29] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 064061058..e8192ae72 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,7 +1,7 @@ class SubjectsController < ApplicationController before_action :require_login, :check_auth, except: [:index] # before_action :check_auth, except: [:index] - before_action :find_subject, except: [:index, :create, :append_to_stage] + before_action :find_subject, except: [:index, :create, :new, :append_to_stage] before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, :search_members, :add_subject_members, :statistics, :shixun_report, :school_report, :up_member_position, :down_member_position] @@ -94,6 +94,10 @@ class SubjectsController < ApplicationController @subject.increment!(:visits) end + def new + normal_status("") + end + def create ActiveRecord::Base.transaction do begin From ed10b2c98145711f0f8216e9af4a238ee7e22729 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 23 Jul 2019 14:34:10 +0800 Subject: [PATCH 09/29] fixbug --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/edit.json.jbuilder | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index bfaf6b736..cfae5429b 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -21,7 +21,7 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 user_answer_b = user_answer.include?(a.id) json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id - json.choice_text "#{(index+65).chr}.#{a.choice_text}" + json.choice_text (edit_type.present? ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}") json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 71a6fcf07..980e6735a 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -16,7 +16,8 @@ json.exercise_questions do exercise_type:1, user_answer:[], shixun_type:0, - ques_position:nil + ques_position:nil, + edit_type:true end end From e4f464a01ee165c270ca7cacc551905705589913 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 23 Jul 2019 14:38:07 +0800 Subject: [PATCH 10/29] fixbug --- app/views/exercise_questions/edit.json.jbuilder | 3 ++- app/views/exercises/edit.json.jbuilder | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/exercise_questions/edit.json.jbuilder b/app/views/exercise_questions/edit.json.jbuilder index 35db720c7..bf9272026 100644 --- a/app/views/exercise_questions/edit.json.jbuilder +++ b/app/views/exercise_questions/edit.json.jbuilder @@ -6,4 +6,5 @@ json.partial! "exercise_questions/exercise_questions", shixun_challenges: @exercise_question_shixun, exercise_type:1, user_answer:[], - ques_position:nil \ No newline at end of file + ques_position:nil, + edit_type:true diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 980e6735a..71a6fcf07 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -16,8 +16,7 @@ json.exercise_questions do exercise_type:1, user_answer:[], shixun_type:0, - ques_position:nil, - edit_type:true + ques_position:nil end end From 4da3f80ae3bd23ae5db09a2dc0479d4219484940 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 23 Jul 2019 14:42:25 +0800 Subject: [PATCH 11/29] =?UTF-8?q?=E5=BC=80=E6=BA=90=E5=88=9B=E6=96=B0?= =?UTF-8?q?=E7=BB=84=E6=8A=A5=E5=90=8D=E5=90=8E=EF=BC=8C=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E8=AF=BE=E5=A0=82=E7=9A=84=E8=B5=9B=E4=BA=8B=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E5=B8=96=E5=AD=90=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/courses/coursesPublic/Addcourses.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/react/src/modules/courses/coursesPublic/Addcourses.js b/public/react/src/modules/courses/coursesPublic/Addcourses.js index 914a82c6d..6826de89c 100644 --- a/public/react/src/modules/courses/coursesPublic/Addcourses.js +++ b/public/react/src/modules/courses/coursesPublic/Addcourses.js @@ -200,6 +200,12 @@ class Addcourses extends Component{ // // modalSave:this.submitasyn, // course_id:response.data.course_id // }) + + // https://www.trustie.net/issues/22365 + if (response.data.course_id == 2704) { + this.props.history.push('/courses/2704/boards/8367/messages/42072') + return; + } if(response.data.course_id!=undefined){ this.submitasyn(response.data.course_id) } From 25147ab31633806e27adce0f3ea89dd50c54acad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 23 Jul 2019 14:42:47 +0800 Subject: [PATCH 12/29] fixubg --- app/views/exercise_questions/edit.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercise_questions/edit.json.jbuilder b/app/views/exercise_questions/edit.json.jbuilder index bf9272026..41bd61487 100644 --- a/app/views/exercise_questions/edit.json.jbuilder +++ b/app/views/exercise_questions/edit.json.jbuilder @@ -7,4 +7,4 @@ json.partial! "exercise_questions/exercise_questions", exercise_type:1, user_answer:[], ques_position:nil, - edit_type:true + edit_type:1 From 9bc2c49bb698b9f1a32f53848e3713dc313020f4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 23 Jul 2019 14:46:27 +0800 Subject: [PATCH 13/29] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise_questions/edit.json.jbuilder | 2 +- app/views/exercise_questions/show.json.jbuilder | 3 ++- app/views/exercises/_user_exercise_info.json.jbuilder | 3 ++- app/views/exercises/blank_exercise.json.jbuilder | 3 ++- app/views/exercises/edit.json.jbuilder | 3 ++- app/views/exercises/show.json.jbuilder | 3 ++- app/views/exercises/start_answer.json.jbuilder | 3 ++- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/views/exercise_questions/edit.json.jbuilder b/app/views/exercise_questions/edit.json.jbuilder index 41bd61487..bf9272026 100644 --- a/app/views/exercise_questions/edit.json.jbuilder +++ b/app/views/exercise_questions/edit.json.jbuilder @@ -7,4 +7,4 @@ json.partial! "exercise_questions/exercise_questions", exercise_type:1, user_answer:[], ques_position:nil, - edit_type:1 + edit_type:true diff --git a/app/views/exercise_questions/show.json.jbuilder b/app/views/exercise_questions/show.json.jbuilder index c27fe21a5..d10e41093 100644 --- a/app/views/exercise_questions/show.json.jbuilder +++ b/app/views/exercise_questions/show.json.jbuilder @@ -6,4 +6,5 @@ json.partial! "exercise_questions/exercise_questions", shixun_challenges: @exercise_question_shixun, exercise_type:1, user_answer:[], - ques_position:nil + ques_position:nil, + edit_type:nil diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index e690f4867..0d21cc593 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -62,7 +62,8 @@ json.exercise_questions do exercise_type: ex_type, user_answer: user_ques_answers[:answered_content], shixun_type: user_ques_answers[:shixun_type], - ques_position: nil + ques_position: nil, + edit_type:nil if user_ques_comments.count > 0 json.question_comments do json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first diff --git a/app/views/exercises/blank_exercise.json.jbuilder b/app/views/exercises/blank_exercise.json.jbuilder index 16b5449fb..a23f8e3b4 100644 --- a/app/views/exercises/blank_exercise.json.jbuilder +++ b/app/views/exercises/blank_exercise.json.jbuilder @@ -12,7 +12,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type:2, user_answer:[], - ques_position:nil + ques_position:nil, + edit_type:nil end end diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 71a6fcf07..587783c7d 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -16,7 +16,8 @@ json.exercise_questions do exercise_type:1, user_answer:[], shixun_type:0, - ques_position:nil + ques_position:nil, + edit_type:nil end end diff --git a/app/views/exercises/show.json.jbuilder b/app/views/exercises/show.json.jbuilder index d92eebeab..afd15e8e7 100644 --- a/app/views/exercises/show.json.jbuilder +++ b/app/views/exercises/show.json.jbuilder @@ -19,7 +19,8 @@ json.exercise_questions do exercise_type:1, user_answer:[], shixun_type:0, - ques_position:nil + ques_position:nil, + edit_type:nil end end diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index 42d611712..53336bf6f 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -59,6 +59,7 @@ json.exercise_questions do choices:question.exercise_choices, exercise_type:3, shixun_type:question_info[:shixun_type], - ques_position: q[:ques_number] + ques_position: q[:ques_number], + edit_type:nil end end \ No newline at end of file From d0105922a611a244940e5d0397455fa3d2c3e97c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 23 Jul 2019 14:56:16 +0800 Subject: [PATCH 14/29] fix bind email --- app/services/users/bind_email_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/users/bind_email_service.rb b/app/services/users/bind_email_service.rb index 1ad9ad6b4..4c8124ffa 100644 --- a/app/services/users/bind_email_service.rb +++ b/app/services/users/bind_email_service.rb @@ -13,7 +13,7 @@ class Users::BindEmailService < ApplicationService raise Error, '该邮箱已被绑定' if User.where.not(id: user.id).exists?(mail: params[:email]) - code = VerificationCode.where(email: params[:email], code: params[:code], code_type: 4).last + code = VerificationCode.where(email: params[:email], code: params[:code], code_type: 5).last raise Error, '验证码无效' unless code&.effective? ActiveRecord::Base.transaction do From 81a948a90e9343a9894dfccf57964d45f0bb06d4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 23 Jul 2019 15:06:33 +0800 Subject: [PATCH 15/29] fixubg --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/edit.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index cfae5429b..b9565535e 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -21,7 +21,7 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 user_answer_b = user_answer.include?(a.id) json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id - json.choice_text (edit_type.present? ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}") + json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}" json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 587783c7d..980e6735a 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -17,7 +17,7 @@ json.exercise_questions do user_answer:[], shixun_type:0, ques_position:nil, - edit_type:nil + edit_type:true end end From 7072612d9087bf3ab7fd0d1a2f93c126e2159eb0 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 23 Jul 2019 15:38:32 +0800 Subject: [PATCH 16/29] library feature api --- app/controllers/libraries_controller.rb | 87 +++++++++++++++++++ app/decorators/library_decorator.rb | 5 ++ app/forms/libraries/save_form.rb | 12 +++ app/libs/util/uuid.rb | 9 ++ app/models/library.rb | 43 +++++++++ app/models/library_apply.rb | 19 ++++ app/models/library_library_tag.rb | 4 + app/models/library_tag.rb | 6 ++ app/services/libraries/agree_apply_service.rb | 32 +++++++ .../libraries/refuse_apply_service.rb | 39 +++++++++ app/services/libraries/save_service.rb | 69 +++++++++++++++ app/services/libraries/submit_service.rb | 32 +++++++ app/views/libraries/index.json.jbuilder | 16 ++++ app/views/libraries/show.json.jbuilder | 46 ++++++++++ .../locales/forms/save_library_form.zh-CN.yml | 12 +++ config/routes.rb | 2 + 16 files changed, 433 insertions(+) create mode 100644 app/controllers/libraries_controller.rb create mode 100644 app/decorators/library_decorator.rb create mode 100644 app/forms/libraries/save_form.rb create mode 100644 app/libs/util/uuid.rb create mode 100644 app/models/library.rb create mode 100644 app/models/library_apply.rb create mode 100644 app/models/library_library_tag.rb create mode 100644 app/models/library_tag.rb create mode 100644 app/services/libraries/agree_apply_service.rb create mode 100644 app/services/libraries/refuse_apply_service.rb create mode 100644 app/services/libraries/save_service.rb create mode 100644 app/services/libraries/submit_service.rb create mode 100644 app/views/libraries/index.json.jbuilder create mode 100644 app/views/libraries/show.json.jbuilder create mode 100644 config/locales/forms/save_library_form.zh-CN.yml diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb new file mode 100644 index 000000000..55894aaa6 --- /dev/null +++ b/app/controllers/libraries_controller.rb @@ -0,0 +1,87 @@ +class LibrariesController < ApplicationController + include PaginateHelper + + before_action :require_login, :check_auth, except: %i[index show] + + helper_method :current_library, :library_manageable? + + def index + libraries = Library.all + + libraries = + if User.current&.logged? && params[:type] == 'mine' + libraries.where(user_id: current_user.id).order(created_at: :desc) + else + libraries.where(status: :published).order(visited_count: :desc) + end + + keyword = params[:keyword].to_s.strip + if keyword.present? + libraries = libraries.where('title LIKE :keyword OR author_name LIKE :keyword OR author_school_name LIKE :keyword', + keyword: "%#{keyword}%") + end + + @count = libraries.count + @libraries = paginate libraries.includes(:library_tags, :praise_tread_cache, user: :user_extension) + + ids = @libraries.map(&:id) + @download_count_map = Attachment.where(container_type: 'Library', container_id: ids) + .group(:container_id).sum(:downloads) + end + + def show + unless current_library.published? || library_manageable?(current_library) + return render_forbidden + end + end + + def create + library = current_user.libraries.new + Libraries::SaveService.call(library, current_user, save_params) + render_ok + rescue Libraries::SaveService::Error => ex + render_error(ex.message) + end + + def update + return render_forbidden unless library_manageable?(current_library) + + Libraries::SaveService.call(current_library, current_user, save_params) + render_ok + rescue Libraries::SaveService::Error => ex + render_error(ex.message) + end + + def destroy + if admin_or_business? + current_library.destroy! + elsif current_library.user_id == current_user&.id + unless current_library.pending? + render_error('只有草稿才能删除') + return + end + + current_library.destroy! + else + render_forbidden + return + end + + render_ok + end + + private + + def current_library + @_current_library ||= Library.find(params[:id]) + end + + def library_manageable?(library) + current_user&.id == library.user_id || admin_or_business? + end + + def save_params + params.permit(:title, :content, :author_name, :author_school_name, + :cover_id, :publish, attachment_ids: [], tag_ids: []) + end +end \ No newline at end of file diff --git a/app/decorators/library_decorator.rb b/app/decorators/library_decorator.rb new file mode 100644 index 000000000..2768ad036 --- /dev/null +++ b/app/decorators/library_decorator.rb @@ -0,0 +1,5 @@ +module LibraryDecorator + extend ApplicationDecorator + + display_time_method :published_at, :created_at, :updated_at +end \ No newline at end of file diff --git a/app/forms/libraries/save_form.rb b/app/forms/libraries/save_form.rb new file mode 100644 index 000000000..89e00cb20 --- /dev/null +++ b/app/forms/libraries/save_form.rb @@ -0,0 +1,12 @@ +class Libraries::SaveForm + include ActiveModel::Model + + attr_accessor :title, :content, :author_name, :author_school_name, :cover_id, + :publish, :attachment_ids, :tag_ids + + validates :title, presence: true, length: { maximum: 255 } + validates :content, presence: true + validates :author_name, presence: true, length: { maximum: 10 } + validates :author_school_name, presence: true, length: { maximum: 50 } + validates :attachment_ids, presence: true +end \ No newline at end of file diff --git a/app/libs/util/uuid.rb b/app/libs/util/uuid.rb new file mode 100644 index 000000000..2f6757139 --- /dev/null +++ b/app/libs/util/uuid.rb @@ -0,0 +1,9 @@ +module Util + module UUID + module_function + + def time_uuid(format: '%Y%m%d%H%M%S', suffix: 8) + "#{Time.zone.now.strftime(format)}#{Random.rand(10**suffix).to_i}" + end + end +end diff --git a/app/models/library.rb b/app/models/library.rb new file mode 100644 index 000000000..894dcdac0 --- /dev/null +++ b/app/models/library.rb @@ -0,0 +1,43 @@ +class Library < ApplicationRecord + include AASM + + belongs_to :user + belongs_to :cover, class_name: 'Attachment', foreign_key: :cover_id, optional: true + + has_many :library_applies, dependent: :delete_all + has_many :library_library_tags, dependent: :delete_all + has_many :library_tags, through: :library_library_tags + + has_many :attachments, as: :container + has_one :praise_tread_cache, foreign_key: :object_id + + validates :uuid, presence: true, uniqueness: true + + aasm(:status) do + state :pending, initiali: true + state :processing + state :refused + state :published + + event :submit do + transitions from: [:pending, :refused], to: :processing + end + + event :refuse do + transitions from: :processing, to: :refused + end + + event :publish do + transitions from: :processing, to: :published + end + end + + def generate_uuid + uuid = Util::UUID.time_uuid + while Library.exists?(uuid: uuid) + uuid = Util::UUID.time_uuid + end + + self.uuid = uuid + end +end \ No newline at end of file diff --git a/app/models/library_apply.rb b/app/models/library_apply.rb new file mode 100644 index 000000000..13e195f34 --- /dev/null +++ b/app/models/library_apply.rb @@ -0,0 +1,19 @@ +class LibraryApply < ApplicationRecord + include AASM + + belongs_to :library + + aasm(:status) do + state :pending, initiali: true + state :refused + state :agreed + + event :refuse do + transitions from: :pending, to: :refused + end + + event :agree do + transitions from: :pending, to: :agreed + end + end +end \ No newline at end of file diff --git a/app/models/library_library_tag.rb b/app/models/library_library_tag.rb new file mode 100644 index 000000000..9527289b0 --- /dev/null +++ b/app/models/library_library_tag.rb @@ -0,0 +1,4 @@ +class LibraryLibraryTag < ApplicationRecord + belongs_to :library + belongs_to :library_tag +end diff --git a/app/models/library_tag.rb b/app/models/library_tag.rb new file mode 100644 index 000000000..79ff4672f --- /dev/null +++ b/app/models/library_tag.rb @@ -0,0 +1,6 @@ +class LibraryTag < ApplicationRecord + has_many :library_library_tags, dependent: :delete_all + has_many :libraries, through: :library_library_tags + + validates :name, presence: true, uniqueness: true +end diff --git a/app/services/libraries/agree_apply_service.rb b/app/services/libraries/agree_apply_service.rb new file mode 100644 index 000000000..d452083b3 --- /dev/null +++ b/app/services/libraries/agree_apply_service.rb @@ -0,0 +1,32 @@ +class Libraries::AgreeApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :library_apply, :library, :user + + def initialize(library_apply, user) + @library_apply = library_apply + @library = library_apply.library + @user = user + end + + def call + raise Error, '该状态下不能进行此操作' unless library_apply.may_agree? + + ActiveRecord::Base.transaction do + library_apply.agree! + library_apply.library.publish! + + # 将消息改为已处理 + Tiding.where(container_id: library.id, container_type: 'Library', tiding_type: 'Apply', status: 0).update_all(status: 1) + notify_library_author! + end + end + + private + + def notify_library_author! + Tiding.create!(user_id: library.user_id, trigger_user_id: 1, + container_id: library.id, container_type: 'Library', + tiding_type: 'System', status: 1) + end +end \ No newline at end of file diff --git a/app/services/libraries/refuse_apply_service.rb b/app/services/libraries/refuse_apply_service.rb new file mode 100644 index 000000000..9b249b6fa --- /dev/null +++ b/app/services/libraries/refuse_apply_service.rb @@ -0,0 +1,39 @@ +class Libraries::RefuseApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :library_apply, :library, :user, :params + + def initialize(library_apply, user, params) + @library_apply = library_apply + @library = library_apply.library + @user = user + @params = params + end + + def call + reason = params[:reason].to_s.strip + raise Error, '原因不能为空' if reason.blank? + raise Error, '该状态下不能进行此操作' unless library_apply.may_refuse? + + ActiveRecord::Base.transaction do + library_apply.reason = reason + library_apply.refused_at = Time.current + library_apply.refuse + library_apply.save! + + library.refuse! + + # 将消息改为已处理 + Tiding.where(container_id: library.id, container_type: 'Library', tiding_type: 'Apply', status: 0).update_all(status: 1) + notify_library_author! + end + end + + private + + def notify_library_author! + Tiding.create!(user_id: library.user_id, trigger_user_id: 1, + container_id: library.id, container_type: 'Library', + tiding_type: 'System', status: 2, extra: library_apply.reason) + end +end \ No newline at end of file diff --git a/app/services/libraries/save_service.rb b/app/services/libraries/save_service.rb new file mode 100644 index 000000000..45cd033dd --- /dev/null +++ b/app/services/libraries/save_service.rb @@ -0,0 +1,69 @@ +class Libraries::SaveService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :library, :user, :params + + def initialize(library, user, params) + @library = library + @user = user + @params = params + end + + def call + Libraries::SaveForm.new(params).validate! + + if library.new_record? + library.user_id = user.id + library.generate_uuid + end + + ActiveRecord::Base.transaction do + library.assign_attributes(library_params) + library.save! + + deal_library_tag! + deal_attachments! + + Libraries::SubmitService.call(library) if with_publish? + end + + library + rescue Libraries::SubmitService::Error => ex + raise Error, ex.message + end + + private + + def deal_library_tag! + new_tag_ids = LibraryTag.where(id: Array.wrap(params[:tag_ids]).compact).pluck(:id) + old_tag_ids = library.library_library_tags.pluck(:library_tag_id) + + # 删除标签 + destroy_ids = old_tag_ids - new_tag_ids + library.library_library_tags.where(library_tag_id: destroy_ids).delete_all + + # 创建标签 + created_ids = new_tag_ids - old_tag_ids + created_ids.each do |id| + library.library_library_tags.create!(library_tag_id: id) + end + end + + def deal_attachments! + attachment_ids = Array.wrap(params[:attachment_ids]).compact.map(&:to_i) + old_attachment_id = library.attachments.pluck(:id) + + destroy_ids = old_attachment_id - attachment_ids + library.attachments.where(id: destroy_ids).delete_all + + Attachment.where(id: attachment_ids, author_id: user.id).update_all(container: library) + end + + def library_params + params.slice(*%i[title content author_name author_school_name cover_id]) + end + + def with_publish? + params[:publish].to_s == 'true' + end +end diff --git a/app/services/libraries/submit_service.rb b/app/services/libraries/submit_service.rb new file mode 100644 index 000000000..ab7af2910 --- /dev/null +++ b/app/services/libraries/submit_service.rb @@ -0,0 +1,32 @@ +class Libraries::SubmitService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :library + + def initialize(library) + @library = library + end + + def call + return if library.processing? || library.published? + + raise Error, '该状态下不能提交审核' unless library.may_submit? + + ActiveRecord::Base.transaction do + library.published_at = Time.current + library.submit + library.save! + + library.library_applies.create! + send_library_apply_notify! + end + end + + private + + def send_library_apply_notify! + Tiding.create!(user_id: 1, trigger_user_id: library.user_id, + container_id: library.id, container_type: 'Library', + tiding_type: 'Apply', status: 0) + end +end \ No newline at end of file diff --git a/app/views/libraries/index.json.jbuilder b/app/views/libraries/index.json.jbuilder new file mode 100644 index 000000000..c58d390b0 --- /dev/null +++ b/app/views/libraries/index.json.jbuilder @@ -0,0 +1,16 @@ +json.count @count +json.libraries do + json.array! @libraries.each do |library| + json.extract! library, :id, :title, :content, :author_name, :author_school_name, :status, :visited_count + + json.cover_url library.cover_id.present? ? download_url(library.cover) : nil + + json.praise_count library.praise_tread_cache&.praise_num || 0 + json.download_count @download_count_map.fetch(library.id, 0) + + json.published_at library.display_published_at + json.created_at library.display_created_at + + json.tags library.library_tags.map(&:name) + end +end \ No newline at end of file diff --git a/app/views/libraries/show.json.jbuilder b/app/views/libraries/show.json.jbuilder new file mode 100644 index 000000000..0f4b6ea17 --- /dev/null +++ b/app/views/libraries/show.json.jbuilder @@ -0,0 +1,46 @@ +library = current_library + +json.extract! library, :id, :uuid, :title, :content, :author_name, :author_school_name, :status, :visited_count + +json.praise_count library.praise_tread_cache&.praise_num || 0 + +json.published_at library.display_published_at +json.created_at library.display_created_at + +# 创建者 +json.creator do + json.partial! 'users/user_simple', user: library.user +end + +# 封面 +if library.cover_id.present? + json.cover do + json.partial! 'attachments/attachment_simple', attachment: library.cover + end +else + json.cover nil +end + +json.attachments library.attachments, partial: 'attachments/attachment_small', as: :attachment + +# 标签 +json.tags do + json.array! library.library_tags.each do |tag| + json.extract! tag, :id, :name + end +end + +# 操作权限 +json.operation do + if current_user&.logged? + manageable = library_manageable?(library) + + json.can_deletable manageable + json.can_editable manageable + json.user_praised PraiseTread.exists?(user_id: current_user&.id) + else + json.can_deletable false + json.can_editable false + json.user_praised false + end +end diff --git a/config/locales/forms/save_library_form.zh-CN.yml b/config/locales/forms/save_library_form.zh-CN.yml new file mode 100644 index 000000000..e28fa2a55 --- /dev/null +++ b/config/locales/forms/save_library_form.zh-CN.yml @@ -0,0 +1,12 @@ +'zh-CN': + activemodel: + attributes: + libraries/save_form: + title: 标题 + content: 描述 + author_name: 作者名称 + author_school_name: 作者单位 + cover_id: 封面 + publish: '' + attachment_ids: 附件 + tag_ids: 标签 diff --git a/config/routes.rb b/config/routes.rb index 9da4d4a7e..16140e99c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -690,6 +690,8 @@ Rails.application.routes.draw do post :win, on: :collection end end + + resources :libraries, only: [:index, :show, :create, :update, :destroy] end #git 认证回调 From 92a9567b0b0322f68eb774f9e2b769d33008f3e2 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 23 Jul 2019 15:40:32 +0800 Subject: [PATCH 17/29] css --- public/compatibility.html | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/public/compatibility.html b/public/compatibility.html index d6df184fc..25ea3f8b9 100644 --- a/public/compatibility.html +++ b/public/compatibility.html @@ -2,7 +2,7 @@ - Educoder + EduCoder @@ -10,7 +10,7 @@ - + @@ -114,12 +114,15 @@ width: 100%; height: 100%; } + .newContainer { + margin-top: 8%; + } .Compatibility { background: #fff; width: 1008px; margin: 0 auto; padding: 16px; - margin-bottom: 220px; + margin-bottom: 168px; } .Compatibility-icon { width: 112px; @@ -180,10 +183,19 @@ margin-top: 32px; text-align: center; } + + @media screen and (max-height: 760px) { + .Compatibility-icon { + margin: 20px auto; + } + .CompatibilityBrowsers { + margin-top: 24px; + } + }
-
你正在使用的浏览器版本过低,将不能正常浏览和使用Educoder。
+
你正在使用的浏览器版本过低,将不能正常浏览和使用EduCoder。
-
+
+
--> +