diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index bce0ae3c2..3782468d4 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -5,8 +5,8 @@ class ChallengesController < ApplicationController before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, :edit_choose_question, :show_choose_question, :destroy_challenge_choose, :update_choose_question, :destroy, :crud_answer, :answer] - # before_action :allowed, except: [:index, :show, :edit_choose_question, :edit] - + # 权限控制 + before_action :allowed, except: [:index] include ShixunsHelper include ChallengesHelper @@ -299,8 +299,7 @@ class ChallengesController < ApplicationController end def allowed - # 实训为发布前,除实训的管理者外,其他人都不人都不允许访问 - if !current_user.manager_of_shixun?(@shixun) && (@shixun.status < 1 || @shixun.hidden == 1) + unless current_user.manager_of_shixun?(@shixun) raise Educoder::TipException.new(403, "..") end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 253bafa48..93eba89d8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -11,7 +11,7 @@ class CoursesController < ApplicationController render_error(ex.model.errors.full_messages.join(',')) end - before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups] + before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d9588cb5b..5f7c13964 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -518,7 +518,7 @@ class ShixunsController < ApplicationController ActiveRecord::Base.transaction do begin - #cloud_bridge = edu_setting('cloud_bridge') + cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, @@ -622,10 +622,16 @@ class ShixunsController < ApplicationController end def add_collaborators - raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - condition = "%#{params[:search].strip}%".gsub(" ","") - @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'") + user_name = "%#{params[:user_name].strip}%" + school_name = "%#{params[:school_name].strip}%" + if user_name.present? || school_name.present? + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE + '#{school_name}'") + else + @users = User.none + end end def shixun_members_added @@ -667,14 +673,14 @@ class ShixunsController < ApplicationController limit = params[:limit] || 20 if params[:search] search = "%#{params[:search].to_s.strip.downcase}%" - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0 AND c.name like '#{search}' ").map(&:id) else - course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) end @@ -686,7 +692,7 @@ class ShixunsController < ApplicationController # 将实训发送到课程 def send_to_course @course = Course.find(params[:course_id]) - homework = HomeworksService.new.create_homework shixun, @course, nil, current_user + homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user end # 二维码扫描下载 diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 4b954584b..c73fec500 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -164,8 +164,8 @@ class SubjectsController < ApplicationController end def choose_course - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7e7e1070d..8db7e8bfa 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -508,15 +508,14 @@ module ExercisesHelper current_user_group_name = course_group.first.name if course_group.present? end teacher_review = ex_user.subjective_score < 0.0 ? false : true - if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 - # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 - ex_object_score = nil - ex_subject_score = nil - score = nil - else + if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看 ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s + else + ex_object_score = nil + ex_subject_score = nil + score = nil end { @@ -639,6 +638,9 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end + if user_score > q.question_score + user_score = q.question_score + end if ques_type <= 2 answered_content = exercise_answers.pluck(:exercise_choice_id) elsif ques_type == 3 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0c8b97ca7..60409e51d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,11 +3,11 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users,:dependent => :destroy - has_many :exercise_questions,:dependent => :destroy - has_many :exercise_group_settings,:dependent => :destroy + has_many :exercise_users, :dependent => :delete_all + has_many :exercise_questions, :dependent => :delete_all + has_many :exercise_group_settings, :dependent => :delete_all has_many :tidings, as: :container - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all scope :is_exercise_published, -> { where("exercise_status > ? ",1)} scope :unified_setting, -> { where("unified_setting = ?",true) } diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 465fa036b..11558f937 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments, :dependent => :delete_all scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 525251ce6..72dc30c9d 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,9 +1,10 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers, :dependent => :delete_all + has_many :exercise_standard_answers, :dependent => :delete_all scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 5f456e21f..2c9b281c3 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,19 +4,18 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_shixun_challenges,:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_choices, :dependent => :delete_all + has_many :exercise_answers + has_many :exercise_shixun_challenges, :dependent => :delete_all + has_many :exercise_shixun_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 8548e497d..a9550c024 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments, :dependent => :delete_all # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} diff --git a/app/models/poll.rb b/app/models/poll.rb index 1cead3291..f72239ba7 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -4,13 +4,13 @@ class Poll < ApplicationRecord belongs_to :exercise_bank, optional: true # belongs_to :exercise_bank - has_many :poll_questions,dependent: :destroy - has_many :poll_users, :dependent => :destroy + has_many :poll_questions,dependent: :delete_all + has_many :poll_users, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 - has_many :poll_group_settings, :dependent => :destroy - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :poll_group_settings, :dependent => :delete_all + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all - has_many :tidings, as: :container, dependent: :destroy + has_many :tidings, as: :container, dependent: :delete_all scope :publish_or_not, -> { where("polls_status > ? ",1)} scope :only_public, -> {where("is_public = ?",true)} diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 423198bbf..8e2421328 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord # include Redmine::SafeAttributes belongs_to :poll_question - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes, :dependent => :delete_all scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 1fc8e0c16..a0854aa48 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -1,9 +1,9 @@ class PollQuestion < ApplicationRecord belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :dependent => :delete_all attr_accessor :question_answers, :question_other_anser - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)} diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 7a05c2e11..9445862ba 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -6,10 +6,11 @@ json.question_type question.question_type json.question_score question.question_score.round(1).to_s if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 standard_answers_array = question.get_standard_answer_ids - exercise_choices = choices.order("choice_position ASC") ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 if ex_choice_random_boolean - exercise_choices = exercise_choices.order("RAND()") + exercise_choices = choices.order("RAND()") + else + exercise_choices = choices.order("choice_position ASC") end json.question_choices do json.array! exercise_choices.each_with_index.to_a do |a,index| diff --git a/app/views/shixuns/send_to_course.json.jbuilder b/app/views/shixuns/send_to_course.json.jbuilder index dd087d3e2..b2e30f985 100644 --- a/app/views/shixuns/send_to_course.json.jbuilder +++ b/app/views/shixuns/send_to_course.json.jbuilder @@ -1,4 +1,3 @@ json.status 1 json.message "发送成功" -json.url course_homework_commons_path(@course.id, type: 4) -# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4" \ No newline at end of file +json.course_id @course.id \ No newline at end of file