From 8c841b95b66ff522ec77a760b63bb423a336e50b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 15:23:37 +0800 Subject: [PATCH 1/9] modify competition apig --- app/controllers/competitions/competition_teams_controller.rb | 4 ++-- app/models/searchable/dependents/challenge_tag.rb | 2 +- app/models/searchable/dependents/stage.rb | 2 +- app/models/searchable/dependents/user.rb | 4 ++-- app/views/competitions/competition_staffs/show.json.jbuilder | 1 + app/views/competitions/competition_teams/index.json.jbuilder | 3 +++ 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index b4861c4d3..e03810b61 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -54,13 +54,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController end @count = teams.count - @teams = paginate(teams.includes(:user, users: :user_extension)) + @teams = paginate(teams.includes(:user, users: { user_extension: :school })) end def user_competition_teams teams = current_competition.competition_teams teams = teams.joins(:team_members).where(team_members: { user_id: current_user.id }) - @teams = teams.includes(:user, users: :user_extension).to_a + @teams = teams.includes(:user, users: { user_extension: :school }).to_a @count = @teams.size end diff --git a/app/models/searchable/dependents/challenge_tag.rb b/app/models/searchable/dependents/challenge_tag.rb index fdec79d1b..51ef804dd 100644 --- a/app/models/searchable/dependents/challenge_tag.rb +++ b/app/models/searchable/dependents/challenge_tag.rb @@ -10,7 +10,7 @@ module Searchable::Dependents::ChallengeTag def check_searchable_dependents if new_record? || name_previously_changed? - challenge.shixun.reindex(:searchable_challenge_data) + challenge.shixun.reindex end end end \ No newline at end of file diff --git a/app/models/searchable/dependents/stage.rb b/app/models/searchable/dependents/stage.rb index 262ddd36f..d4207fec8 100644 --- a/app/models/searchable/dependents/stage.rb +++ b/app/models/searchable/dependents/stage.rb @@ -9,7 +9,7 @@ module Searchable::Dependents::Stage def check_searchable_dependents if name_previously_changed? || description_previously_changed? - subject.reindex(:searchable_stages_data) + subject.reindex end end end \ No newline at end of file diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb index 761704d06..103131ed6 100644 --- a/app/models/searchable/dependents/user.rb +++ b/app/models/searchable/dependents/user.rb @@ -10,13 +10,13 @@ module Searchable::Dependents::User def check_searchable_dependents if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed? # reindex shixun - created_shixuns.each{ |shixun| shixun.reindex(:searchable_user_data) } + created_shixuns.each{ |shixun| shixun.reindex } # reindex course manage_courses.each(&:reindex) # reindex subject - created_subjects.each { |subject| subject.reindex(:searchable_user_data) } + created_subjects.each { |subject| subject.reindex } end end end \ No newline at end of file diff --git a/app/views/competitions/competition_staffs/show.json.jbuilder b/app/views/competitions/competition_staffs/show.json.jbuilder index 2cba22d2f..c490aaf5f 100644 --- a/app/views/competitions/competition_staffs/show.json.jbuilder +++ b/app/views/competitions/competition_staffs/show.json.jbuilder @@ -1,5 +1,6 @@ competition = current_competition +json.personal competition.personal? json.enroll_ended competition.enroll_ended? json.enrolled competition.enrolled?(current_user) diff --git a/app/views/competitions/competition_teams/index.json.jbuilder b/app/views/competitions/competition_teams/index.json.jbuilder index 86bb86a1c..b641b28e6 100644 --- a/app/views/competitions/competition_teams/index.json.jbuilder +++ b/app/views/competitions/competition_teams/index.json.jbuilder @@ -17,6 +17,9 @@ json.competition_teams do json.partial! 'users/user_simple', user: member.user json.user_id member.user_id json.role member.en_role + json.identity member.user.identity + json.school_name member.user.school_name + json.student_id member.user.student_id end end end From f6a5a0ebbca775e8f6d72ac8d4f65c7b9aea6b21 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:27:07 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=AF=95=E5=8D=B7=EF=BC=8C=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E7=9A=84=E7=8A=B6=E6=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 12 ++++++++---- app/models/poll.rb | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index aba0a00bc..8286a96e2 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,8 +127,10 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - return Exercise::UNPUBLISHED if user.nil? - if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] @@ -139,9 +141,11 @@ class Exercise < ApplicationRecord else status = Exercise::UNPUBLISHED end - else - status = exercise_status #当为老师的时候,则为试卷的总状态 + else + status = exercise_status #当为老师的时候,则为试卷的总状态 + end end + status end diff --git a/app/models/poll.rb b/app/models/poll.rb index e6a363f1d..5fda30609 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -100,19 +100,25 @@ class Poll < ApplicationRecord end def get_poll_status(user) - if user.student_of_course?(course) - ex_time = get_poll_times(user_id,false) - pb_time = ex_time[:publish_time] - ed_time = ex_time[:end_time] - if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - status = 2 - elsif ed_time.present? && ed_time <= Time.now - status = 3 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) + ex_time = get_poll_times(user_id,false) + pb_time = ex_time[:publish_time] + ed_time = ex_time[:end_time] + if course.end_time.present? && course.end_time <= Time.now + status = 4 + elsif pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + status = 2 + elsif ed_time.present? && ed_time <= Time.now + status = 3 + else + status = 1 + end else - status = 1 + status = polls_status end - else - status = polls_status end status end From e8e02abbbb28aff0583078ddc7f47b83fe0e1dcb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:29:59 +0800 Subject: [PATCH 3/9] fixbug --- app/models/exercise.rb | 2 +- app/models/poll.rb | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 8286a96e2..61c5c8eab 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,7 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - if course.end_time.present? && course.end_time <= Time.now + if course.end_date.present? && course.end_date <= Time.now status = 4 else if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 diff --git a/app/models/poll.rb b/app/models/poll.rb index 5fda30609..a9b4c2984 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -99,17 +99,15 @@ class Poll < ApplicationRecord end end - def get_poll_status(user) - if course.end_time.present? && course.end_time <= Time.now + def get_poll_status(user)s + if course.end_date.present? && course.end_date <= Time.now status = 4 else if user.present? && user.student_of_course?(course) ex_time = get_poll_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] - if course.end_time.present? && course.end_time <= Time.now - status = 4 - elsif pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now status = 2 elsif ed_time.present? && ed_time <= Time.now status = 3 From a94728a6c434662767c15b474b3cd3363fc4f48e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:31:19 +0800 Subject: [PATCH 4/9] fixbug --- app/models/poll.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index a9b4c2984..52b814bb3 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -99,7 +99,7 @@ class Poll < ApplicationRecord end end - def get_poll_status(user)s + def get_poll_status(user) if course.end_date.present? && course.end_date <= Time.now status = 4 else From 4303995003e44804998bb1fe1d05a6b8c1d8a225 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:33:47 +0800 Subject: [PATCH 5/9] fixbug --- app/models/exercise.rb | 3 +-- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 61c5c8eab..825f7cd9f 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,7 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - if course.end_date.present? && course.end_date <= Time.now + if course.is_end status = 4 else if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 @@ -145,7 +145,6 @@ class Exercise < ApplicationRecord status = exercise_status #当为老师的时候,则为试卷的总状态 end end - status end diff --git a/app/models/poll.rb b/app/models/poll.rb index 52b814bb3..7f0d2fd94 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -100,7 +100,7 @@ class Poll < ApplicationRecord end def get_poll_status(user) - if course.end_date.present? && course.end_date <= Time.now + if course.is_end status = 4 else if user.present? && user.student_of_course?(course) From de0aa8bcddf77952cc6e5b4d9c02569582e378fc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:38:00 +0800 Subject: [PATCH 6/9] fixbug --- app/controllers/polls_controller.rb | 6 +++--- app/views/polls/common_header.json.jbuilder | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 3fc17c661..9811cfa5a 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -205,15 +205,15 @@ class PollsController < ApplicationController @is_teacher_or = 1 @user_poll_answer = 3 #教师页面 end - poll_status = @poll.get_poll_status(current_user) + @poll_status = @poll.get_poll_status(current_user) poll_id_array = [@poll.id] @poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的 @poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的 if (@poll_publish_count == 0) && (@poll_unpublish_count == 0) #即表示没有分班 - if poll_status == 1 + if @poll_status == 1 @poll_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候 - elsif poll_status == 2 + elsif @poll_status == 2 @poll_publish_count = 1 #试卷未发布,且课堂没有分班的时候 end end diff --git a/app/views/polls/common_header.json.jbuilder b/app/views/polls/common_header.json.jbuilder index 39c4ef811..b0a3d7374 100644 --- a/app/views/polls/common_header.json.jbuilder +++ b/app/views/polls/common_header.json.jbuilder @@ -1,5 +1,6 @@ json.course_is_end @course.is_end # true表示已结束,false表示未结束 -json.extract! @poll, :id,:polls_name,:polls_description,:polls_status,:show_result +json.extract! @poll, :id,:polls_name,:polls_description,:show_result +json.polls_status @poll_status json.user_permission do json.is_teacher_or @is_teacher_or From 66bef13e5c3317fd0cb0ae71830e4394d5ad2978 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:45:26 +0800 Subject: [PATCH 7/9] fixbug --- app/controllers/exercises_controller.rb | 4 ++++ app/controllers/polls_controller.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f26e97849..03c943f8d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -667,6 +667,7 @@ class ExercisesController < ApplicationController #立即发布的弹窗内容 def publish_modal + ActiveRecord::Base.transaction do begin exercise_ids = params[:check_ids] @@ -685,6 +686,9 @@ class ExercisesController < ApplicationController #首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。 def publish + tip_exception("缺少截止时间参数") if params[:end_time].blank? + tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Exercise.where(id: params[:check_ids]) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 9811cfa5a..f5003a0c7 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -244,6 +244,9 @@ class PollsController < ApplicationController end #首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。 def publish + tip_exception("缺少截止时间参数") if params[:end_time].blank? + tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Poll.where(id: params[:check_ids]) From 44561b8a5196e6c93c1c0cbc3c442291fdd413cb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 16:01:42 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E8=AF=95=E7=94=A8=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E4=BB=A5=E4=B8=8D=E7=94=A8=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 875050642..6a7599f28 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -184,14 +184,13 @@ class ApplicationController < ActionController::Base end # 系统全局认证 - # def check_auth - if !current_user.profile_completed? - info_url = '/account/profile' - tip_exception(402, info_url) - elsif current_user.certification != 1 + if 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) end end From 02b0851e38de2b652ef2c850f117b27e229ad4aa Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 16:05:24 +0800 Subject: [PATCH 9/9] competition module update api modify --- .../competitions/competition_modules_controller.rb | 12 +++++++++++- app/models/searchable/dependents/user.rb | 4 ++-- .../competition_modules/show.json.jbuilder | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/competitions/competition_modules_controller.rb b/app/controllers/competitions/competition_modules_controller.rb index da9873c43..c4692af70 100644 --- a/app/controllers/competitions/competition_modules_controller.rb +++ b/app/controllers/competitions/competition_modules_controller.rb @@ -15,7 +15,17 @@ class Competitions::CompetitionModulesController < Competitions::BaseController md = current_module.competition_module_md_content || current_module.build_competition_module_md_content md.name = params[:md_name] md.content = params[:md_content] - md.save! + + ActiveRecord::Base.transaction do + md.save! + + attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i) + old_attachment_ids = md.attachments.pluck(:id) + + destroy_ids = old_attachment_ids - attachment_ids + md.attachments.where(id: destroy_ids).delete_all + Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md) + end render_ok end diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb index 103131ed6..f6dcaa430 100644 --- a/app/models/searchable/dependents/user.rb +++ b/app/models/searchable/dependents/user.rb @@ -10,13 +10,13 @@ module Searchable::Dependents::User def check_searchable_dependents if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed? # reindex shixun - created_shixuns.each{ |shixun| shixun.reindex } + created_shixuns.each(&:reindex) # reindex course manage_courses.each(&:reindex) # reindex subject - created_subjects.each { |subject| subject.reindex } + created_subjects.each(&:reindex) end end end \ No newline at end of file diff --git a/app/views/competitions/competition_modules/show.json.jbuilder b/app/views/competitions/competition_modules/show.json.jbuilder index d47742cf0..69cdcc544 100644 --- a/app/views/competitions/competition_modules/show.json.jbuilder +++ b/app/views/competitions/competition_modules/show.json.jbuilder @@ -5,4 +5,7 @@ if md.present? json.md_name md.name json.md_content md.content json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S') + json.attachments do + json.array! md.attachments, partial: 'attachments/attachment_simple', as: :attachment + end end \ No newline at end of file