diff --git a/app/controllers/blob_controller.rb b/app/controllers/blob_controller.rb deleted file mode 100644 index bba1efb5f..000000000 --- a/app/controllers/blob_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -class BlobController < ApplicationController - def new - commit unless @repository.empty? - end - - def create - create_commit(Files::CreateService, success_path: after_create_path, - failure_view: :new, - failure_path: namespace_project_new_blob_path(@project.namespace, @project, @ref)) - end - -end diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb deleted file mode 100644 index 695f264e7..000000000 --- a/app/controllers/challenges_controller.rb +++ /dev/null @@ -1,341 +0,0 @@ -class ChallengesController < ApplicationController - before_action :require_login, :check_auth, except: [:index] - before_action :find_shixun, only: [:new, :create, :index] - skip_before_action :verify_authenticity_token, only: [:create, :update, :create_choose_question, :crud_answer] - 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 :update_allowed, except: [:index] - # 关卡访问的权限控制 - before_action :shixun_access_allowed, only: [:index] - - include ChallengesHelper - - - - - # 新建实践题 - def new - @position = @shixun.challenges.count + 1 - @st = params[:st].to_i - @task_pass_default = PlatformSample.find_by(samples_type: "taskPass").try(:contents) - end - - # params - # challenge:{"subject": "标题", "task_pass": "过关任务", - # "diffculty": "关卡难度", "score": "关卡分数", "st": "关卡类型"} 关卡相关信息 - # challenge_tag: 关卡标签 - # - def create - ActiveRecord::Base.transaction do - begin - @challenge = Challenge.new(challenge_params) - @challenge.position = @shixun.challenges.count + 1 - @challenge.shixun_id = @shixun.id - @challenge.user_id = current_user.id - @challenge.modify_time = Time.now - @challenge.save! - - # 实训是否需要重置, 非实践任务创建第一个阶段调用, 避免不包含实践任务的实训进行模拟实战报错 todo: 新建实训需要重置TPI - # shixun_modify_status_without_publish(@shixun, 1) if @challenge.position != 1 - - tags = params[:challenge_tag] - if tags.present? - tags.each do |tag| - # TODO 创建tag的时候为什么一直报challenge choose必须存在?? - ChallengeTag.create!(name: tag, challenge_id: @challenge.id) - end - end - rescue Exception => e - uid_logger_error("create challenge failed #{e}") - end - end - end - - # 创建选择题 - def create_choose_question - ActiveRecord::Base.transaction do - begin - @challenge_choose = ChallengeChoose.new(chooce_params) - @challenge_choose.position = @challenge.challenge_chooses.count + 1 - @challenge_choose.category = @challenge_choose.standard_answer.length == 1 ? 1 : 2 - @challenge_choose.challenge_id = @challenge.id - - if @challenge_choose.save! - # 创建选项 - params[:question][:cnt].each_with_index do |test, index| - answer = params[:choice][:answer][index] - ChallengeQuestion.create(:option_name => test, - :challenge_choose_id => @challenge_choose.id, - :position => index, :right_key => answer) - end - # 创建单选多选的技能标签 - if params[:challenge_tag].present? - params[:challenge_tag].each do |tag| - ChallengeTag.create(:name => tag, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id) - end - end - @challenge.update_column(:score, @challenge.challenge_chooses.sum(:score)) - end - rescue Exception => e - raise ActiveRecord::Rollback - end - end - end - - # 选择题详情页面 - def show_choose_question - @challenge_choose = ChallengeChoose.find params[:choose_id] - - end - - # 选择题更新页面 - def update_choose_question - @challenge_choose = ChallengeChoose.find(params[:choose_id]) - ActiveRecord::Base.transaction do - if params[:standard_answer] != @challenge_choose.standard_answer - @challenge.update_column(:modify_time, Time.now) - end - @challenge_choose.update_attributes(chooce_params) - @challenge.update_column(:score, @challenge.challenge_chooses.sum(:score)) - # 单选多选题的更新 - category = @challenge_choose.standard_answer.length > 1 ? 2 : 1 - @challenge_choose.update_column(:category, category) - begin - @challenge_choose.challenge_questions.delete_all - params[:question][:cnt].each_with_index do |test, index| - answer = params[:choice][:answer][index] - ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer) - end - @challenge_choose.challenge_tags.delete_all unless @challenge_choose.challenge_tags.blank? - if params[:challenge_tag].present? - params[:challenge_tag].each do |tag| - ChallengeTag.create(:name => tag, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id) - end - end - @challenge_choose = ChallengeChoose.find params[:choose_id] - rescue Exception => e - raise ActiveRecord::Rollback - end - end - end - - # 选择题的编辑 - def edit_choose_question - @challenge_choose = ChallengeChoose.find params[:choose_id] - end - - def destroy_challenge_choose - ActiveRecord::Base.transaction do - @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first - pos = @challenge_choose.position - @challenge.challenge_chooses.where("position > ?", pos).update_all("position = position - 1") - @challenge_choose.destroy - @status = 1 - # 发起重置请求 TODO: 重置实训需要后续做 - # shixun_modify_status_without_publish(@shixun, 1) - end - end - - # 编辑模式 - # tab 0,nil 过关任务, 1 评测设置, 2 参考答案 - def edit - @tab = params[:tab].to_i - @power = @shixun.status == 0 - challenge_num = Challenge.where(:shixun_id => @shixun).count - @position = @challenge.position - @chooses = @challenge.challenge_chooses - if @position < challenge_num - @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first - end - @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => @position - 1).first if @position - 1 > 0 - end - - def index - uid_logger("identifier: #{params}") - - @challenges = @shixun.challenges.fields_for_list - - @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 - @user = current_user - @shixun.increment!(:visits) - end - - - - def show - @tab = params[:tab].nil? ? 1 : params[:tab].to_i - challenge_num = @shixun.challenges_count - @power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布 - @position = @challenge.position - if @position < challenge_num - @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first - end - @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => @position - 1).first if @position - 1 > 0 - end - - # tab 0:过关任务的更新; 1:评测设置的更新; 2:表示参考答案的更新; - def update - begin - ActiveRecord::Base.transaction do - tab = params[:tab].to_i - @challenge.update_attributes!(challenge_params) - if tab == 0 && @challenge.st == 0 - @challenge.challenge_tags.delete_all - if params[:challenge_tag].present? - params[:challenge_tag].each do |input| - ChallengeTag.create!(:name => input, :challenge_id => @challenge.id) - end - end - elsif tab == 1 - path = @challenge.path - exec_path = @challenge.exec_path - test_set = @challenge.test_sets - sets_output = test_set.map(&:output) - sets_input = test_set.map(&:input) - sets_open = test_set.map(&:is_public) - set_score = test_set.map(&:score) - set_match_rule = test_set.map(&:match_rule) - params_hidden = params[:test_set].map{|set| set[:hidden].to_i == 0} - params_output = params[:test_set].map{|set| set[:output] } - params_input = params[:test_set].map{|set| set[:input] } - params_score = params[:test_set].map{|set| set[:score]} - params_test_set = params[:test_set].map{|set| set[:match_rule]} - # 测试集变化则需要更新(输入、 输出、 是否隐藏) - if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || - set_score != params_score || params_test_set != set_match_rule - test_set.delete_all unless test_set.blank? - params[:test_set].each_with_index do |set, index| - # last: 末尾匹配, full: 全完匹配 - logger.info("set: #{set}; match_rule : #{set[:match_rule]}") - match_rule = set[:match_rule] == 'last' ? 'last' : 'full' - TestSet.create!(:challenge_id => @challenge.id, - :input => "#{set[:input]}", - :output => "#{set[:output]}", - :is_public => params_hidden[index], - :score => set[:score], - :match_rule => "#{match_rule}", - :position => (index + 1)) - end - @challenge.update_column(:modify_time, Time.now) - # 测试集的 - @shixun.myshixuns.update_all(:system_tip => 0) - end - if params[:challenge][:show_type].to_i == -1 - @challenge.update_attributes(picture_path: nil, web_route: nil, expect_picture_path: nil, original_picture_path: nil) - end - # 关卡评测执行文件如果被修改,需要修改脚本内容 - logger.info("############shixun_publiced:#{@shixun.public == 0}") - if @shixun.public == 0 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) - end - # TODO: - # if path != params[:challenge][:path] - # shixun_modify_status_without_publish(@shixun, 1) - # end - #Attachment.attach_files(@challenge, params[:attachments]) - end - - end - rescue Exception => e - logger.error("##update_challenges: ##{e.message}") - tip_exception("#{e.message}") - end - - end - - # 参考答案的'增,删,改' - # POST: /shixuns/:id/challenges/:id/crud_answer - # {'challenge_answer': [ - # {'name': 'name', contents: 'contents', score: 10}, - # {...}, - # {...}, ...] - #} - def crud_answer - if @challenge.challenge_answers && params[:challenge_answer].blank? - @challenge.challenge_answers.destroy_all - else - raise '参考答案不能为空' if params[:challenge_answer].empty? - raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100 - ActiveRecord::Base.transaction do - @challenge.challenge_answers.destroy_all if @challenge.challenge_answers - params[:challenge_answer].each_with_index do |answer, index| - # 内容为空不保存 - next if answer[:contents].blank? - ChallengeAnswer.create!(name: answer[:name], contents: answer[:contents], - level: index+1, score: answer[:score], challenge_id: @challenge.id) - end - end - end - end - - # 查看参考答案接口 - def answer - @answers = @challenge.challenge_answers - end - - def index_down - next_challenge = @challenge.next_challenge - position = @challenge.position - @challenge.update_attribute(:position, (position + 1)) - next_challenge.update_attribute(:position, next_challenge.position - 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) - end - - def index_up - position = @challenge.position - last_challenge = @challenge.last_challenge - @challenge.update_attribute(:position, (position - 1)) - last_challenge.update_attribute(:position, last_challenge.position + 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) - end - - def destroy - next_challenges = @shixun.challenges.where("position > #{@challenge.position}") - next_challenges.update_all("position = position - 1") - # Todo: 实训修改后,关卡需要重置 - # shixun_modify_status_without_publish(@shixun, 1) - @challenge.destroy - # 关卡位置被删除,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) - end - - - private - - def find_shixun - @shixun = Shixun.find_by_identifier(params[:shixun_identifier]) - end - - # 通用接口 - def find_challenge - @challenge = Challenge.find params[:id] - @shixun = Shixun.find_by!(identifier: params[:shixun_identifier]) - end - - def challenge_params - tip_exception("评测时间不能超过300秒") if params[:challenge][:exec_time].to_i > 300 - params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average, - :path, :exec_path, :show_type, :original_picture_path, :test_set_score, - :expect_picture_path, :picture_path, :web_route, :answer, :exec_time) - end - - def chooce_params - params.require(:challenge_choose).permit(:subject, :answer, - :standard_answer, :score, :difficult) - end - - def update_allowed - unless current_user.manager_of_shixun?(@shixun) - raise Educoder::TipException.new(403, "..") - end - end - -end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb deleted file mode 100644 index c5d3082ba..000000000 --- a/app/controllers/comments_controller.rb +++ /dev/null @@ -1,75 +0,0 @@ -class CommentsController < ApplicationController - before_action :find_hack - before_action :require_login - - - # 评论 - def create - begin - @discuss = @hack.discusses.new(comment_params) # 管理员回复的能够显示 - @discuss.hidden = false - @discuss.user_id = current_user.id - @discuss.save! - rescue Exception => e - uid_logger_error("create discuss failed : #{e.message}") - render_error("评论异常") - end - end - - # 回复 - def reply - begin - @discuss = @hack.discusses.new(reply_params) - @discuss.hidden = false - @discuss.user_id = current_user.id - @discuss.root_id = params[:comments][:parent_id] - @discuss.save! - rescue Exception => e - uid_logger_error("reply discuss failed : #{e.message}") - render_error("回复评论异常") - end - end - - # 列表 - def index - discusses = - if current_user.admin_or_business? - @hack.discusses.where(root_id: nil) - else - @hack.discusses.where(root_id: nil, hidden: false) - end - @discusses_count = discusses.count - @discusses= paginate discusses - end - - # 删除 - def destroy - @hack.discusses.find_by(id: params[:id]).destroy - render_ok - end - - # 隐藏、取消隐藏 - def hidden - if current_user.admin_or_business? - @discuss = @hack.discusses.where(id: params[:id]).first - @discuss.update_attribute(:hidden, params[:hidden].to_i == 1) - sucess_status - else - Educoder::TipException(403, "..") - end - end - - - private - def find_hack - @hack = Hack.find_by_identifier(params[:hack_identifier]) - end - - def comment_params - params.require(:comments).permit(:content) - end - - def reply_params - params.require(:comments).permit(:content, :parent_id) - end -end diff --git a/app/controllers/compose_projects_controller.rb b/app/controllers/compose_projects_controller.rb deleted file mode 100644 index 4355571c7..000000000 --- a/app/controllers/compose_projects_controller.rb +++ /dev/null @@ -1,38 +0,0 @@ -class ComposeProjectsController < ApplicationController - #未做完 - before_action :require_login - before_action :set_compose - - def create - project_ids = params[:project_ids] - ComposeProject.transaction do - project_ids.each do |p| - project = Project.select(:id, :user_id).find(p) - unless project.blank? || ComposeProject.exists?(user_id: project.user_id, project_id: p, compose_id: @compose.id) - ComposeProject.create!(user_id: project.user_id, project_id: p, compose_id: @compose.id, position: p) - end - end - end - normal_status(0, "添加成功") - end - - def destroy - project_ids = params[:project_ids] - if ComposeProject.where(project_id: project_ids, compose_id: @compose.id).delete_all - normal_status(0, "项目删除成功") - else - normal_status(-1, "项目删除失败") - end - end - - - private - - def set_compose - @compose = Compose.find(params[:compose_id]) - unless @compose.present? - normal_status(-1, "组织不存在") - end - end - -end \ No newline at end of file diff --git a/app/controllers/composes_controller.rb b/app/controllers/composes_controller.rb deleted file mode 100644 index c1a7f524f..000000000 --- a/app/controllers/composes_controller.rb +++ /dev/null @@ -1,99 +0,0 @@ -class ComposesController < ApplicationController - before_action :require_login, except: [:index] - before_action :find_compose, except: [:index, :new,:create] - - def index - @order_type = params[:order] || "created_at" - @search_name = params[:search] - composes = Compose.compose_includes - if @search_name.present? - composes = composes.where("title like ?", "%#{@search_name}%") - end - composes = composes.order("#{@order_type} desc") - @page = params[:page] || 1 - @limit = params[:limit] || 15 - @composes_size = composes.size - @composes = composes.page(@page).per(@limit) - end - - def new - - end - - def create - ActiveRecord::Base.transaction do - begin - @compose = Compose.new(compose_params.merge(user_id: current_user.id)) - if @compose.save - ComposeUser.create!(user_id: current_user.id, compose_id: @compose.id, is_manager: 1) - normal_status(0,"组织创建成功") - else - error_messages = @compose.errors.messages[:title][0] - normal_status(-1,"组织创建失败:#{error_messages}") - end - rescue Exception => e - tip_exception("#{e}") - raise ActiveRecord::Rollback - end - end - end - - def edit - - end - - def update - if @compose.update_attributes(compose_params) - normal_status(0,"组织更新成功") - else - error_messages = @compose.errors.messages[:title][0] - normal_status(-1,"组织更新失败:#{error_messages}") - end - end - - def destroy - if @compose.destroy - normal_status(0,"组织删除成功") - else - normal_status(-1,"组织删除失败,请稍后重试") - end - end - - def show - compose_projects_ids = @compose&.compose_projects&.pluck(:project_id) - search = params[:search] - if compose_projects_ids.size > 0 - compose_projects = Project.where(id: compose_projects_ids) - - if search.present? - compose_projects = compose_projects.where("name like ? ", "%#{search.to_s.strip}%") - end - else - compose_projects = [] - end - - @compose_projects_size = compose_projects.size - - if @compose_projects_size > 0 - @page = params[:page] || 1 - @limit = params[:limit] || 15 - @compose_projects = compose_projects.page(@page).per(@limit) - else - @compose_projects = compose_projects - end - end - - private - - def compose_params - params.require(:compose).permit(:user_id, :title, :description, :show_mode, :compose_mode, :compose_users_count, :compose_projects_count) - end - - def find_compose - @compose = Compose.find(params[:compose_id]) - unless @compose.present? - normal_status(-1, "组织不存在") - end - end - -end \ No newline at end of file diff --git a/app/controllers/course_groups_controller.rb b/app/controllers/course_groups_controller.rb deleted file mode 100644 index d07a1e12c..000000000 --- a/app/controllers/course_groups_controller.rb +++ /dev/null @@ -1,73 +0,0 @@ -class CourseGroupsController < ApplicationController - before_action :require_login, :check_auth - before_action :set_group, except: [:create] - before_action :find_course, only: [:create] - before_action :teacher_allowed, except: [:set_invite_code_halt] - - def create - tip_exception("分班名称不能为空") if params[:name].blank? - if @course.course_groups.where(name: params[:name]).count > 0 - normal_status(-1, "已存在同名分班") - else - course_group = @course.course_groups.create!(name: params[:name], position: @course.course_groups.count + 1) - render :json => {group_id: course_group.id, status: 0, message: "创建成功"} - end - end - - def destroy - ActiveRecord::Base.transaction do - begin - @course.course_groups.where("position > #{@group.position}").update_all("position = position - 1") - # 将该分班的学生转到未分班 - @group.course_members.update_all(course_group_id: 0) - @group.destroy - rescue Exception => e - uid_logger_error(e.message) - tip_exception("删除分班失败") - end - end - end - - # 分班重命名 - def rename_group - tip_exception("名称不能为空") if params[:name].blank? - if @course.course_groups.where(name: params[:name]).count > 0 - normal_status(-1, "已存在同名分班") - else - @group.update_attributes(name: params[:name].strip) - normal_status(0, "更新成功") - end - end - - # 分班的拖动 - def move_category - tip_exception("移动失败") if params[:position].blank? - unless params[:position].to_i == @group.position - if params[:position].to_i < @group.position - @course.course_groups.where("position < #{@group.position} and position >= ?", params[:position]).update_all("position = position + 1") - else - @course.course_groups.where("position > #{@group.position} and position <= ?", params[:position]).update_all("position = position - 1") - end - @group.update_attributes(position: params[:position]) - normal_status(0, "移动成功") - else - normal_status(-1, "位置没有变化") - end - end - - # 邀请码停用/启用 - def set_invite_code_halt - teacher = @course.teachers.find_by(user_id: current_user.id) - tip_exception(403, "无权限") unless current_user.admin_or_business? || - (teacher.present? && (teacher.teacher_course_groups.pluck(:course_group_id).include?(@group.id) || teacher.teacher_course_groups.size == 0)) - @group.update!(invite_code_halt: !@group.invite_code_halt) - normal_status(0, "成功") - end - - private - - def set_group - @group = CourseGroup.find_by!(id: params[:id]) - @course = @group.course - end -end diff --git a/app/controllers/course_modules_controller.rb b/app/controllers/course_modules_controller.rb deleted file mode 100644 index 0bef519fd..000000000 --- a/app/controllers/course_modules_controller.rb +++ /dev/null @@ -1,68 +0,0 @@ -class CourseModulesController < ApplicationController - before_action :require_login, :check_auth - before_action :set_module, except: [:unhidden_modules] - before_action :find_course, only: [:unhidden_modules] - before_action :teacher_or_admin_allowed, except: [:add_second_category] - before_action :teacher_allowed, only: [:add_second_category] - - # 模块置顶 - def sticky_module - # position为1则不做处理,否则该模块的position置为1,position小于当前模块的position加1 - unless @course_module.position == 1 - @course.course_modules.where("position < #{@course_module.position}").update_all("position = position + 1") - @course_module.update_attributes(position: 1) - end - normal_status(0, "置顶成功") - end - - # 模块隐藏 - def hidden_module - tip_exception("请至少保留一个课堂模块") if @course.none_hidden_course_modules.where.not(id: @course_module.id).size == 0 - @course_module.update_attributes(hidden: 1) - normal_status(0, "更新成功") - end - - # 模块重命名 - def rename_module - name = params[:name].strip - tip_exception("名称不能为空") if name.blank? - tip_exception("已存在同名模块") if @course.course_modules.exists?(module_name: name) - @course_module.update_attributes(module_name: name) - - case @course_module.module_type - when 'board' - @course.course_board.update_columns(name: name) - end - normal_status(0, "更新成功") - end - - # 模块的显示 - def unhidden_modules - tip_exception("请选择要显示的模块") if params[:module_ids].blank? - @course.course_modules.where(id: params[:module_ids]).update_all(hidden: 0) - normal_status(0, "更新成功") - end - - # 添加二级目录 - def add_second_category - tip_exception("子目录名称不能为空") if params[:name].blank? - tip_exception("已存在同名子目录") if @course_module.course_second_categories.exists?(name: params[:name].strip) - ActiveRecord::Base.transaction do - begin - category = @course_module.course_second_categories.create!(name: params[:name].strip, category_type: @course_module.module_type, - course_id: @course.id, position: @course_module.course_second_categories.count + 1) - render :json => {category_id: category.id, status: 0, message: "添加成功"} - rescue Exception => e - uid_logger_error(e.message) - tip_exception("添加子目录失败") - end - end - end - - private - - def set_module - @course_module = CourseModule.find_by!(id: params[:id]) - @course = @course_module.course - end -end diff --git a/app/controllers/course_second_categories_controller.rb b/app/controllers/course_second_categories_controller.rb deleted file mode 100644 index b295c0f9f..000000000 --- a/app/controllers/course_second_categories_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -class CourseSecondCategoriesController < ApplicationController - before_action :require_login, :check_auth - before_action :set_category - before_action :teacher_allowed - - # 目录重命名 - def rename_category - tip_exception("毕设子目录不能重命名") if @category.category_type == "graduation" - tip_exception("名称不能为空") if params[:name].blank? - tip_exception("已存在同名子目录") if @course_module.course_second_categories.exists?(name: params[:name].strip) - @category.update_attributes!(name: params[:name].strip) - normal_status(0, "更新成功") - end - - # 子目录的拖动 - def move_category - tip_exception("移动失败") if params[:position].blank? - unless params[:position].to_i == @category.position - if params[:position].to_i < @category.position - @course_module.course_second_categories.where("position < #{@category.position} and position >= ?", params[:position]).update_all("position = position + 1") - else - @course_module.course_second_categories.where("position > #{@category.position} and position <= ?", params[:position]).update_all("position = position - 1") - end - @category.update!(position: params[:position]) - normal_status(0, "移动成功") - else - normal_status(-1, "位置没有变化") - end - end - - def destroy - tip_exception("毕设子目录不能删除") if @category.category_type == "graduation" - ActiveRecord::Base.transaction do - begin - @course_module.course_second_categories.where("position > #{@category.position}").update_all("position = position - 1") - # 更新相应对象的子目录id - if @course_module.module_type == "shixun_homework" - @category.homework_commons.update_all(course_second_category_id: 0) - @right_url = "/courses/#{@course.id}/shixun_homeworks/#{@course_module.id}" - elsif @course_module.module_type == "attachment" - Attachment.where(course_second_category_id: @category.id).update_all(course_second_category_id: 0) - @right_url = "/courses/#{@course.id}/files/#{@course_module.id}" - end - - @category.destroy - rescue Exception => e - uid_logger_error(e.message) - tip_exception("删除子目录失败") - end - end - end - - private - - def set_category - @category = CourseSecondCategory.find_by!(id: params[:id]) - @course_module = @category.course_module - @course = @course_module.try(:course) - end -end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb deleted file mode 100644 index 75cb22b6c..000000000 --- a/app/controllers/courses_controller.rb +++ /dev/null @@ -1,1674 +0,0 @@ -class CoursesController < ApplicationController - include MessagesHelper - include CustomSortable - - # model validation error - rescue_from ActiveRecord::RecordInvalid do |ex| - render_error(ex.record.errors.full_messages.join(',')) - end - # form validation error - rescue_from ActiveModel::ValidationError do |ex| - render_error(ex.model.errors.full_messages.join(',')) - end - - before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, - :left_banner, :top_banner, :informs, :online_learning, :course_groups, :search_slim] - before_action :check_account, only: [:new, :create, :apply_to_join_course, :join_excellent_course] - before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, - :left_banner, :top_banner, :apply_to_join_course, :exit_course, :course_groups] - before_action :set_course, 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, :inform_up, :inform_down, - :graduation_group_list, :create_graduation_group, :join_graduation_group, - :course_group_list, :set_course_group, :change_course_admin, :change_course_teacher, - :delete_course_teacher, :teacher_application_review, :students, :all_course_groups, - :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, - :base_info, :get_historical_courses, :create_group_by_importing_file, :course_videos, - :attahcment_category_list,:export_member_scores_excel, :duplicate_course, :delete_course_video, - :switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course, - :informs, :update_informs, :online_learning, :update_task_position, :tasks_list, - :join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs, - :delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics, - :work_score, :act_score, :calculate_all_shixun_scores] - before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course, - :search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list] - before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, - :transfer_to_course_group, :delete_from_course, :export_member_scores_excel, - :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, - :add_teacher, :export_couser_info, :export_member_act_score, - :update_informs, :new_informs, :delete_informs, :switch_to_student] - before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, - :set_course_group, :create_group_by_importing_file, - :update_task_position, :tasks_list] - before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, - :change_course_teacher, :course_group_list, :change_member_role,:inform_up, :inform_down, - :teacher_application_review, :apply_teachers, :delete_course_teacher] - before_action :validate_course_name, only: [:create, :update] - before_action :find_board, only: :board_list - before_action :validate_page_size, only: :mine - before_action :course_tasks, only: [:tasks_list, :update_task_position] - before_action :validate_inform_params, only: [:update_informs, :new_informs] - before_action :course_member_allowed, only: [:statistics, :work_score, :act_score, :calculate_all_shixun_scores] - - if RUBY_PLATFORM =~ /linux/ - require 'simple_xlsx_reader' - require 'roo-xls' - end - - # GET /courses - # GET /courses.json - def index - @user = current_user - # 根据分类查询课堂(全部,我的,最新,最热) - @order = params[:order].present? ? params[:order] : "all" - @courses = current_laboratory.all_courses.not_deleted - if @order == "visits" - order_str = "courses.id = 1309 DESC, courses.visits DESC" - @courses = @courses.where(is_hidden: 0) - else - order_str = "courses.id = 1309 DESC, courses.homepage_show DESC, courses.created_at desc" - @courses = @courses.where(is_hidden: 0, is_end: 0) - end - - # 金课未开课的不显示在首页 - @courses = @courses.where("start_date is null or start_date <= '#{Date.today}'") - - # 根据搜索关键字进一步筛选 - if params[:search].present? - # REDO:Extension - #user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id) - #course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3) - # and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%") - # .pluck(:course_id) - #@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) - # 6:21 daiao - sql = %Q{ - (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword - or schools.name like :keyword - } - @courses = @courses.joins(:school, course_members: :user) - .where("#{sql}", keyword: "%#{params[:search]}%").distinct - end - @courses_count = @courses.count("courses.id") - @courses = @courses.order(order_str) - - # 分页 - page = params[:page] || 1 - limit = params[:limit] || 16 - - @courses = @courses.page(page).per(limit) - @courses = @courses.preload(:school, :none_hidden_course_modules, teacher: :user_extension) - end - - def course_videos - logger.info("########[#{@course}") - videos = @course.videos - videos = custom_sort(videos, params[:sort_by], params[:sort_direction]) - @count = videos.count - @videos = paginate videos - end - - def delete_course_video - video = Video.find_by(id: params[:video_id]) - tip_exception(404, "找不到资源") if video.blank? - tip_exception(403, "...") unless (video.user_id == current_user.id || current_user.admin_or_business?) - video.destroy! - AliyunVod::Service.delete_video([video.uuid]) rescue nil - render_ok - end - - def visits_plus_one - new_visits = @course.visits + 1 - @course.update_visits(new_visits) - normal_status("成功") - end - - # GET /courses/1 - # GET /courses/1.json - def show - # render :json => {first_category_url: module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).first, course)} - end - - # GET /courses/new - def new - @course = Course.new - unless params[:subject_id].blank? - subject = Subject.find_by(id: params[:subject_id], excellent: 1) - render :json => {status: 0, course_name: "#{subject&.name}第#{subject&.courses&.count.to_i + 1}期"} - else - normal_status("成功") - end - end - - # Get /courses/:id/settings - # Edit Page - def settings - @course_modules = @course.course_modules.where.not(module_type: 'activity') - end - - # POST /courses - # POST /courses.json - def create - begin - ActiveRecord::Base.transaction do - @course = Course.new(name: params[:name], class_period: params[:class_period], credit: params[:credit], - end_date: params[:end_date], is_public: params[:is_public], school_id: @school.id, - authentication: params[:authentication], professional_certification: params[:professional_certification]) - @course.tea_id = current_user.id - - if params[:subject_id].blank? - @course_list_name = params[:course_list_name].strip - @course_list = CourseList.find_by(name: @course_list_name) - if @course_list - @course.course_list_id = @course_list.id - else - new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0) - @course.course_list_id = new_course_list.id - end - else - subject = Subject.find_by!(id: params[:subject_id]) - @course.start_date = params[:start_date] - @course.subject_id = subject.id - @course.excellent = true - course_list = CourseList.find_by(name: subject.name) || CourseList.create!(name: subject.name, user_id: current_user.id, is_admin: 0) - @course.course_list_id = course_list.id - end - - @course.is_end = @course.end_date.present? && @course.end_date < Date.today - - if @course.save! - @course.generate_invite_code - CourseInfo.create!(user_id: current_user.id, course_id: @course.id) - CourseMember.create!(course_id: @course.id, user_id: current_user.id, role: 1) - - # 将实践课程的教学团队成员以教师身份加入课堂 - if @course.subject - @course.subject.subject_members.where.not(user_id: current_user.id).each do |s_member| - CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2) - end - - Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知") - - @course.create_stages @course.subject - end - - course_module_types = params[:course_module_types] - @course.create_course_modules(course_module_types) - end - end - CreateSubjectCourseStudentJob.perform_later(@course.id) if @course.subject && @course.subject.subject_appointments.count > 0 - rescue => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - # PATCH/PUT /courses/1 - # PATCH/PUT /courses/1.json - def update - ActiveRecord::Base.transaction do - begin - extra_params = Hash.new - extra_params[:school_id] = @school.id - - if @course.is_end && (course_params[:end_date].blank? || course_params[:end_date].to_date >= Date.today) - extra_params[:is_end] = 0 - elsif !@course.is_end && !course_params[:end_date].blank? && course_params[:end_date].to_date < Date.today - extra_params[:is_end] = 1 - end - - extra_params[:authentication] = params[:authentication] - extra_params[:professional_certification] = params[:professional_certification] - - if @course.subject - @course.start_date = params[:start_date] - else - extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0 - @course_list_name = params[:course_list_name].strip - @course_list = CourseList.find_by(name: @course_list_name) - if @course_list - extra_params[:course_list_id] = @course_list.id - else - new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0) - extra_params[:course_list_id] = new_course_list.id - end - end - - @course.update_attributes!(course_params.merge(extra_params)) - @course.update_course_modules(params[:course_module_types]) - Rails.logger.info("###############course_update_end") - normal_status(0, "成功") - rescue => e - uid_logger_error(e.message) - tip_exception("课堂更新失败,原因: #{e.message}") - raise ActiveRecord::Rollback - end - end - end - - def statistics - max_exp = User.where(id: @course.students.pluck(:user_id)).pluck(:experience).max - limit = params[:limit] || 5 - @top_scores = course_statistics(@course, max_exp, limit) - end - - def work_score - sort = params[:sort] || "desc" - group_ids = params[:group_ids].is_a?(Array) ? params[:group_ids] : params[:group_ids].split(",") if params[:group_ids] - @course_members = course_work_scores @course, sort, group_ids - if @user_course_identity == Course::STUDENT - user_ids = @course_members.map(&:user_id) - @rank = user_ids.index(current_user.id).to_i + 1 - @course_members = @course_members.select{|member| member.user_id == current_user.id} - else - @all_count = @course_members.size - @course_members = paginate @course_members - end - end - - def act_score - group_ids = params[:group_ids].is_a?(Array) ? params[:group_ids] : params[:group_ids].split(",") if params[:group_ids] - all_members = course_act_scores @course, group_ids - @course_members = all_members[0 .. 9] - # if @user_course_identity == Course::STUDENT - # user_ids = all_members.map(&:user_id) - # rank = user_ids.index(current_user.id).to_i + 1 - # if rank > 10 - # current_member = all_members.select{|member| member.user_id == current_user.id}.first - # @course_members << current_member if current_member.present? - # end - # end - end - - def join_excellent_course - tip_exception("您已是课堂成员") if current_user.member_of_course?(@course) - tip_exception("请通过邀请码加入课堂") unless @course.excellent - tip_exception("该课堂已结束") if @course.is_end - begin - new_student = CourseMember.new(user_id: current_user.id, course_id: @course.id, role: 4) - new_student.save! - - CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id]) - StudentJoinCourseNotifyJob.perform_later(current_user.id, @course.id) - normal_status(0, "加入成功") - rescue => e - uid_logger_error(e.message) - tip_exception(e.message) - end - end - - def informs - @informs = @course.informs.order("position desc") - end - - def inform_up - inform = @course.informs.find_by(id: params[:inform_id]) - next_inform = inform.next_inform - ActiveRecord::Base.transaction do - if next_inform.blank? - render_error('已经到达最顶部') - else - inform.update!(position: (inform.position + 1)) - next_inform.update!(position: inform.position - 1) - render_ok - end - end - end - - def inform_down - inform = @course.informs.find_by(id: params[:inform_id]) - last_inform = inform.last_inform - ActiveRecord::Base.transaction do - if last_inform.blank? - render_error('已经到达最底部') - else - inform.update!(position: (inform.position - 1)) - last_inform.update!(position: inform.position + 1) - render_ok - end - end - - end - - def new_informs - inform = Inform.new(container: @course) - inform.name = params[:name] - inform.description = params[:description] - inform.position = @course.informs.maximum(:position).to_i + 1 - inform.save! - normal_status("创建成功") - end - - def update_informs - inform = @course.informs.find_by(id: params[:inform_id]) - inform.update_attributes!(name: params[:name], description: params[:description]) - normal_status("更新成功") - end - - def delete_informs - inform = @course.informs.find_by(id: params[:inform_id]) - @course.informs.where("position > ?", inform.position).update_all("position = position - 1") - inform.destroy! - normal_status("删除成功") - end - - def online_learning - @subject = @course.subject - @stages = @course.course_stages.includes(:shixuns) - @user = current_user - @myshixuns = @user.myshixuns.where(shixun_id: @course.course_stage_shixuns.pluck(:shixun_id)) - @start_learning = @user_course_identity == Course::STUDENT && @myshixuns.present? - end - - def search_course_list - search = params[:search] ? "%#{params[:search].strip}%" : "%%" - @course_lists = CourseList.where("name like ?", "#{search}") - @search_count = @course_lists.size - end - - # 邀请码停用/启用 - def set_invite_code_halt - begin - @course.update!(invite_code_halt: @course.invite_code_halt == 0 ? 1 : 0) - normal_status(0, "成功") - rescue => e - uid_logger_error(e.message) - tip_exception("停用/启用课堂失败") - end - end - - # 设置课堂私有/公有 - def set_public_or_private - begin - @course.update!(is_public: @course.is_public == 1 ? 0 : 1) - normal_status(0, "成功") - rescue => e - uid_logger_error(e.message) - tip_exception("设置课堂公有/私有失败") - end - end - - # DELETE /courses/1 - # DELETE /courses/1.json - def destroy - if @course.is_delete == 0 - @course.delete! - Tiding.where(belong_container: @course).update_all(is_delete: 1) - Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id, - container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name) - normal_status(0, "成功") - else - normal_status(-1, "课堂已删除,无需重复操作") - end - end - - # 课堂的基本信息 - def base_info - - end - - # --- 教师列表相关API --- START - - # 教师列表以及教师搜索 - def teachers - tip_exception(403, "无权限访问") if @course.excellent && @user_course_identity > Course::ASSISTANT_PROFESSOR - @search_str = params[:search].present? ? params[:search].strip : "" - - if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582 - @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3) - and LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_str}%") - else - @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} - and course_members.role = 2)) and LOWER(concat(users.lastname, users.firstname)) - LIKE ?", "%#{@search_str}%") - end - - @teacher_list_size = @teacher_list.size - - @has_graduation_design = @course.course_modules.graduation_module_not_hidden.any? - - sort = params[:sort] || "asc" - @order = params[:order] ? params[:order].to_i : 1 - if @order.present? - case @order - when 1 - @teacher_list = @teacher_list.order("role #{sort}") - when 2 - @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci #{sort}") - when 3 - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name #{sort}") - else - @teacher_list = @teacher_list.order("role #{sort}") - end - else - @teacher_list = @teacher_list.order("role #{sort}") - end - - @is_admin = @user_course_identity < Course::PROFESSOR - - @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size - - page = params[:page] || 1 - limit = params[:limit] || 20 - @teacher_list = @teacher_list.page(page).per(limit) - @teacher_list = @teacher_list.preload(:graduation_group, :user, :teacher_course_groups) - end - - def apply_teachers - search_str = params[:search].present? ? params[:search].strip : "" - @applications = CourseMessage.unhandled_join_course_requests_by_course(@course). - joins("join users on course_messages.course_message_id=users.id"). - where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") - if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582 - teacher_list = @course.course_members.where("course_members.role in (1, 2, 3)") - else - teacher_list = @course.course_members.where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} - and course_members.role = 2))") - end - @teacher_list_size = teacher_list.size - @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size - @is_admin = @user_course_identity < Course::PROFESSOR - end - - # 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有) - def add_teacher_popup - @graduation_groups = @course.graduation_groups - @course_groups = @course.course_groups - @school_name = School.find(current_user.school_id).try(:name) - end - - # 添加教师或助教弹窗中的搜索接口 - def search_teacher_candidate - name = params[:name] - school_name = params[:school_name] - - # user_ids_of_course_members = @course.course_members.where(role: [1,2,3]).pluck(:user_id) - # @users = User.where.not(id: user_ids_of_course_members) - - @users = User.where(status: User::STATUS_ACTIVE) - @users = @users.where(laboratory_id: current_laboratory.id) unless current_laboratory.main_site? - @users = @users.where("concat(users.lastname, users.firstname) like '%#{name}%'") if name.present? - # REDO:Extension - @users = @users.joins(user_extension: :school).where("schools.name like '%#{school_name}%'") if school_name.present? - - @users_size = @users.size - - page = params[:page] || 1 - limit = params[:limit] || 10 - @users = @users.page(page).per(limit) - end - - # 添加教师或者助教 - def add_teacher - ActiveRecord::Base.transaction do - begin - @user_list = params[:user_list].present? ? params[:user_list] : [] - return tip_exception("请先选择成员") if @user_list.blank? - - @graduation_group_id = params[:graduation_group_id].present? ? GraduationGroup.find(params[:graduation_group_id]).id : 0 - - @course_group_id = params[:course_group_id].present? ? CourseGroup.find(params[:course_group_id]).id : 0 - - role = params[:role].to_i - - teacher_ids = [] - @user_list.each do |user| - active_student_exist = CourseMember.where(user_id: user[:user_id], role: 4, course_id: @course.id, is_active: 1).any? - is_active = active_student_exist ? 0 : 1 - user_id = User.find(user[:user_id]).id - existing_teacher = CourseMember.find_by(course_id: @course.id, user_id: user_id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) - if existing_teacher.blank? - teacher_ids << user_id - member = CourseMember.create(course_id: @course.id, graduation_group_id: @graduation_group_id, user_id: user_id, role: role, is_active: is_active) - - member.teacher_course_groups << TeacherCourseGroup.new(course_group_id: @course_group_id, user_id: user_id, course_id: @course.id) if @course_group_id != 0 - end - end - TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, role, teacher_ids) if teacher_ids.present? - normal_status(0, "添加成功") - rescue => e - uid_logger_error(e.message) - tip_exception(-1, "添加失败") - raise ActiveRecord::Rollback - end - end - end - - # 获取当前课堂的所有答辩组 - def graduation_group_list - @graduation_group_list = @course.graduation_groups - end - - # 给当前课堂增加答辩组 - def create_graduation_group - begin - if params[:name].present? - identical_exist = GraduationGroup.where(course_id: @course.id, name: params[:name]).any? - if identical_exist - normal_status(-1, "已存在同名答辩组") - else - GraduationGroup.create(course_id: @course.id, user_id: current_user.id, name: params[:name]) - normal_status(0, "成功") - end - else - tip_exception(-1, "答辩组名称不能为空") - end - rescue => e - uid_logger_error(e.message) - tip_exception(-1, "添加失败") - raise ActiveRecord::Rollback - end - end - - # 将教师加入答辩组 - def join_graduation_group - ActiveRecord::Base.transaction do - begin - @course_member_list = params[:course_member_list].present? ? params[:course_member_list] : [] - - graduation_group_id = GraduationGroup.find(params[:graduation_group_id].to_i).id - @course_member_list.each do |course_member| - course_member = CourseMember.find(course_member[:course_member_id].to_i) - course_member.update!(graduation_group_id: graduation_group_id) - end - normal_status(0, "成功") - rescue => e - uid_logger_error(e.message) - tip_exception(-1, "加入失败") - raise ActiveRecord::Rollback - end - end - end - - # 获取当前课堂的所有分班, 以及当前教师是否对分班具有管理权限的状态 - def course_group_list - course_member_id = params[:course_member_id] - user_id = params[:user_id] - - @existed_course_group_ids = TeacherCourseGroup.where(course_id: @course.id, course_member_id: course_member_id, user_id: user_id) - .pluck(:course_group_id) - @all_course_groups = CourseGroup.where(course_id: @course.id) - end - - # 设置教师的管理权限(即设置该教师所能管理的分班) - def set_course_group - ActiveRecord::Base.transaction do - begin - course_group_ids = params[:course_group_ids] - user_id = User.find(params[:user_id].to_i).id - course_member_id = CourseMember.find(params[:course_member_id]).id - - teacher_course_groups = TeacherCourseGroup.where(course_id: @course.id, user_id: user_id, course_member_id: course_member_id) - teacher_course_groups.destroy_all - - course_group_ids.each do |course_group_id| - course_group_id = CourseGroup.where(id: course_group_id.to_i, course_id: @course.id).first.id - TeacherCourseGroup.create(course_id: @course.id, user_id: user_id, course_member_id: course_member_id, course_group_id: course_group_id) - end - normal_status(0, "成功") - rescue => e - uid_logger_error(e.message) - tip_exception( "分配管理权限失败") - raise ActiveRecord::Rollback - end - end - end - - # 变更管理员 - def change_course_admin - ActiveRecord::Base.transaction do - begin - new_admin_user = User.find(params[:user_id].to_i) - new_admin = CourseMember.find_by!(id: params[:course_member_id].to_i, course_id: @course.id, user_id: new_admin_user.id) - current_admin = CourseMember.find_by!(course_id: @course.id, role: 1) - - new_admin.CREATOR! - current_admin.PROFESSOR! - - @course.update_attributes!(tea_id: new_admin_user.id) - normal_status(0, "变更管理员成功") - rescue => e - uid_logger_error(e.message) - tip_exception( "变更管理员失败") - raise ActiveRecord::Rollback - end - end - end - - # 修改角色 - def change_member_role - tip_exception("请至少选择一个角色") if params[:roles].blank? - tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") - tip_exception("管理员不能切换为助教或老师") if params[:user_id].to_i == @course.tea_id && - (params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR")) - - course_members = @course.course_members.where(user_id: params[:user_id]) - tip_exception("非课堂成员不能修改角色") if course_members.blank? - - ActiveRecord::Base.transaction do - # 第一次修改为教师或助教身份时直接创建数据 - if params[:roles].include?("CREATOR") - teacher_member = course_members.where(role: %i[CREATOR]).take - elsif (params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR")) && !course_members.exists?(role: %i[PROFESSOR ASSISTANT_PROFESSOR]) - teacher_member = CourseMember.create!(course_id: @course.id, user_id: params[:user_id], role: params[:roles].include?("PROFESSOR") ? 2 : 3) - # 如果有未审批的申请教师/助教的记录,则修改状态为已审批 - apply_teacher = CourseMessage.where(course_id: @course.id, course_message_id: params[:user_id], status: 0).last - apply_teacher.update!(status: 1, apply_user_id: current_user.id) if apply_teacher.present? - elsif course_members.exists?(role: %i[PROFESSOR ASSISTANT_PROFESSOR]) - teacher_member = course_members.where(role: %i[PROFESSOR ASSISTANT_PROFESSOR]).take - if params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR") - # 如果之前有老师身份且老师身份要调整时,只需要修改role字段 - if !params[:roles].include?(teacher_member.role) && params[:roles].include?("PROFESSOR") - teacher_member.PROFESSOR! - elsif !params[:roles].include?(teacher_member.role) && params[:roles].include?("ASSISTANT_PROFESSOR") - teacher_member.ASSISTANT_PROFESSOR! - end - teacher_member.save! - else - # 不含教师的参数时删除记录 - teacher_member.destroy! - # CourseDeleteStudentNotifyJob.perform_later(@course.id, [teacher_member.user_id], current_user.id) - end - end - - # 学生身份的处理 - student_member = course_members.where(role: %i[STUDENT]).take - - # 不存在则创建学生身份 - if params[:roles].include?("STUDENT") && student_member.blank? - correspond_teacher_exist = CourseMember.exists?(user_id: params[:user_id], is_active: 1, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) - new_student = CourseMember.new(user_id: params[:user_id], course_id: @course.id, role: 4) - new_student.is_active = 0 if correspond_teacher_exist - new_student.save! - - CourseAddStudentCreateWorksJob.perform_later(@course.id, [params[:user_id]]) - # StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) - elsif !params[:roles].include?("STUDENT") && student_member.present? - # 删除学生身份时激活老师身份 - teacher_member.update_attributes!(is_active: 1) if student_member.is_active && teacher_member.present? - student_member.destroy! - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [params[:user_id]]) - # CourseDeleteStudentNotifyJob.perform_later(@course.id, [params[:user_id]], current_user.id) - elsif params[:roles].include?("STUDENT") && student_member.present? && !params[:roles].include?("PROFESSOR") && !params[:roles].include?("ASSISTANT_PROFESSOR") - # 学生身份存在且学生没有教师身份时更新is_active - student_member.update_attributes!(is_active: 1) - end - - normal_status(0, "修改成功") - end - end - - # 教师和助教角色转换的接口 - def change_course_teacher - begin - course_member = CourseMember.find_by!(id: params[:course_member_id].to_i, course_id: @course.id) - if course_member.PROFESSOR? - course_member.ASSISTANT_PROFESSOR! - elsif course_member.ASSISTANT_PROFESSOR? - course_member.PROFESSOR! - else - tip_exception( "变更教师/助教失败") - end - course_member.save! - normal_status(0, "变更教师/助教成功") - rescue => e - uid_logger_error(e.message) - tip_exception( "变更教师/助教失败") - end - end - - # 删除教师或助教 - def delete_course_teacher - begin - course_member = CourseMember.find_by!(id: params[:course_member_id].to_i, course_id: @course.id) - tip_exception("删除失败") if course_member.CREATOR? or course_member.STUDENT? - - course_student = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[STUDENT]) - # Tiding.create!(user_id: course_member.user_id, trigger_user_id: current_user.id, container_id: @course.id, - # container_type: 'DeleteCourseMember', tiding_type: 'System', belong_container: @course, extra: @course.name) - CourseDeleteStudentNotifyJob.perform_later(@course.id, [course_member.user_id], current_user.id) - - course_member.destroy! - course_student.update!(is_active: 1) if course_student.present? && !course_student.is_active - normal_status(0, "删除成功") - rescue => e - uid_logger_error(e.message) - tip_exception("删除失败") - end - end - - # 切换为教师 - def switch_to_teacher - begin - course_student = @course.students.find_by!(user_id: current_user.id, is_active: 1) - tip_exception("切换失败") unless course_student.present? - - course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[CREATOR PROFESSOR], course_id: @course.id) - ActiveRecord::Base.transaction do - course_student.destroy! - course_teacher.update!(is_active: 1) - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) - end - normal_status(0, "切换成功") - rescue => e - uid_logger_error(e.message) - tip_exception("切换失败") - end - end - - # 切换为助教 - def switch_to_assistant - begin - course_student = @course.course_members.find_by!(user_id: current_user.id, is_active: 1) - tip_exception("切换失败") unless course_student.present? - - course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[ASSISTANT_PROFESSOR], course_id: @course.id) - ActiveRecord::Base.transaction do - course_student.destroy! - course_teacher.update!(is_active: 1) - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) - end - normal_status(0, "切换成功") - rescue => e - uid_logger_error(e.message) - tip_exception("切换失败") - end - end - - # 切换为学生 - def switch_to_student - ActiveRecord::Base.transaction do - begin - course_member = @course.course_members.find_by!(user_id: current_user.id, is_active: 1) - tip_exception("切换失败") if course_member.STUDENT? - - course_student = CourseMember.find_by(user_id: current_user.id, role: %i[STUDENT], course_id: @course.id) - course_member.update_attributes!(is_active: 0) - if course_student - course_student.update_attributes!(is_active: 1) - else - # 学生身份不存在则创建 - CourseMember.create!(user_id: current_user.id, role: 4, course_id: @course.id) - CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id]) - end - normal_status(0, "切换成功") - rescue => e - uid_logger_error("switch_to_student error: #{e.message}") - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def exit_course - course_student = CourseMember.find_by!(user_id: current_user.id, role: %i[STUDENT], course_id: @course.id) - tip_exception("非课堂学生无法退出课堂") unless course_student.STUDENT? - # 课堂如果还有其他身份的用户则更新is_active - course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id) - course_student.destroy! - course_teacher.update!(is_active: 1) if course_teacher.present? && !course_teacher.is_active - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) - normal_status(0, "退出成功") - end - - # 教师申请加入课堂的审批 - def teacher_application_review - ActiveRecord::Base.transaction do - begin - course_message = CourseMessage.find_by!(id: params[:application_id].to_i, course_id: @course.id) - course_message.apply_user_id = current_user.id - applier_user = User.find_by!(id: params[:user_id].to_i) - - approval = params[:approval].to_i - if approval == 1 - course_message.pass! - - content = course_message.content.to_i - role = (content == 3 || content == 7) ? 3 : ((content == 2 || content == 9) ? 2 : nil) - if role - tip_exception("已存在教师/助教身份") if CourseMember.where(course_id: @course.id, user_id: applier_user.id, role: [1, 2 ,3]).any? - else - tip_exception("申请角色错误") - end - - new_teacher = CourseMember.new(course_id: @course.id, user_id: applier_user.id, role: role) - new_teacher.save! - - # 课堂管理员才有分配权限,且课堂分班数大于0 - if @user_course_identity < Course::PROFESSOR && @course.course_groups_count > 0 && params[:group_id] && params[:group_id].size > 0 - # 分班全选则是不限,不需要做处理 - unless @course.course_groups.where(id: params[:group_id]).size == @course.course_groups_count - @course.course_groups.where(id: params[:group_id]).each do |group| - unless TeacherCourseGroup.where(course_id: @course.id, user_id: applier_user.id, course_group_id: group.id, course_member_id: new_teacher.id).exists? - TeacherCourseGroup.create(course_id: @course.id, user_id: applier_user.id, course_member_id: new_teacher.id, course_group_id: group.id) - end - end - end - end - elsif approval == 2 - course_message.reject! - else - tip_exception("参数错误") - end - course_message.save! - normal_status(0, "操作成功") - rescue => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - # 已通过职业认证的教师复制课堂 - def duplicate_course - return tip_exception("没有复制权限") unless current_user.admin_or_business? || current_user.is_teacher? || current_user.teacher_of_course?(@course) - return tip_exception("教师职业认证未通过") unless current_user.pro_certification? - - new_course = @course.self_duplicate - render json: {new_course_id: new_course.id} - end - # --- 教师列表相关API --- END - - # --- 学生列表相关API --- START - - # 学生列表(包括各个子分班的学生列表)及搜索 - def students - tip_exception(403, "无权限访问") if @course.excellent && @user_course_identity > Course::ASSISTANT_PROFESSOR - - search = params[:search].present? ? params[:search].strip : nil - order = params[:order].present? ? params[:order].to_i : 1 - sort = params[:sort].present? ? params[:sort] : "asc" - course_group_id = params[:course_group_id].present? ? params[:course_group_id].to_i : nil - - @students = CourseMember.students(@course) - if search.present? - # REDO:Extension - @students = @students.joins(user: :user_extension).where("LOWER(CONCAT(users.lastname, users.firstname)) like ? or - user_extensions.student_id like ?", "%#{search}%", "%#{search}%") - end - - if order == 1 - # REDO:Extension - @students = @students.includes(user: :user_extension).order("user_extensions.student_id #{sort}, users.login #{sort}") - elsif order == 2 - @students = @students.includes(:course_group).order("course_groups.position #{sort}, users.login #{sort}") - else - # REDO:Extension - @students = @students.includes(user: :user_extension).order("user_extensions.student_id #{sort}, users.login #{sort}") - end - - if course_group_id.present? - @students = @students.where(course_group_id: course_group_id) - @course_group = CourseGroup.find(course_group_id) if course_group_id != 0 - end - - @students_count = @students.size - - page = params[:page] || 1 - limit = params[:limit] || 20 - @students= @students.page(page).per(limit) - @students = @students.includes(:course_group, user: :user_extension) - end - - # 获取当前课程所有分班 - def all_course_groups - if params[:all] # 返回所有分班 - @course_groups_array = @course.course_groups.to_a - else # 返回权限下的分班 - charge_group_ids = @course.charge_group_ids(current_user) - @course_groups_array = @course.course_groups.where(id: charge_group_ids).to_a - end - - current_course_group_id = params[:course_group_id] - - if current_course_group_id.present? - current_course_group = CourseGroup.find(current_course_group_id) - @course_groups_array.delete(current_course_group) - end - end - - # 分班列表 - def course_groups - @course_groups = @course.course_groups - @course_groups = @course_groups.where("name like ?", "%#{params[:search]}%") unless params[:search].blank? - @all_group_count = @course_groups.size - @teachers = @course.teachers.includes(:user, :teacher_course_groups) if @user_course_identity < Course::NORMAL - @current_group_id = @course.students.where(user_id: current_user.id).take&.course_group_id if @user_course_identity == Course::STUDENT - end - - # 学生自动加入分班 - def join_course_group - tip_exception("学生才能加入分班") if @user_course_identity != Course::STUDENT - course_group = CourseGroup.find_by!(id: params[:course_group_id], course_id: @course.id) - member = CourseMember.find_by!(user_id: current_user.id, course_id: @course.id, role: 4) - if course_group && member - member.update_attributes!(course_group_id: course_group.id) - normal_status(0, "加入成功") - end - end - - # 将学生批量移动到某个分班 - def transfer_to_course_group - ActiveRecord::Base.transaction do - begin - course_group_id = params[:course_group_id].to_i - - # course_group_id为0意味着移动学生到未分班 - if course_group_id != 0 - course_group = CourseGroup.find_by!(id: course_group_id, course_id: @course.id) - course_group_id = course_group.id - end - - @course.students.where(id: params[:students].pluck(:course_member_id)).each do |student| - student.update_attributes!(course_group_id: course_group_id) - end - normal_status(0, "操作成功") - rescue => e - uid_logger(e.message) - tip_exception("操作失败") - raise ActiveRecord::Rollback - end - end - end - - # 从当前课堂删除学生 - def delete_from_course - ActiveRecord::Base.transaction do - begin - students = params[:students] - student_ids = [] - - students.each do |student| - course_member = CourseMember.find_by(id: student[:course_member_id].to_i, course_id: @course.id) - if course_member.present? - member_teacher = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) - student_ids << course_member.user_id - course_member.destroy! - member_teacher.update!(is_active: 1) if member_teacher.present? - end - end - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present? - CourseDeleteStudentNotifyJob.perform_later(@course.id, student_ids, current_user.id) if student_ids.present? - normal_status(0, "操作成功") - rescue => e - uid_logger(e.message) - tip_exception("操作失败") - raise ActiveRecord::Rollback - end - end - end - - # 搜索添加学生 - def add_students_by_search - student_ids = [] - ActiveRecord::Base.transaction do - user_ids = params[:user_ids] - course_group_id = params[:course_group_id].to_i - if course_group_id != 0 - course_group = CourseGroup.find(course_group_id) - course_group_id = course_group.id - end - - user_ids.each do |user_id| - existing_course_member = @course.course_members.find_by(user_id: user_id.to_i) - new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4) - - if existing_course_member.present? - if existing_course_member.STUDENT? - existing_course_member.update!(course_group_id: course_group_id) - else - new_student.is_active = 0 if existing_course_member.is_active - new_student.save! - student_ids << user_id - end - else - new_student.save! - student_ids << user_id - end - end - end - - CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present? - TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present? - normal_status(0, "添加成功") - end - - # 获取历史课堂,即用户管理的所有课堂以及课堂下的分班(去除当前课堂) - def get_historical_courses - @courses = Course.where.not(id: @course.id).joins(:course_members). - where(is_delete: 0, course_members: {user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]}).includes(:course_groups) - # @courses = Course.includes(:course_groups).where(id: current_user.course_members, is_delete: 0) - end - - # 根据历史课堂的课堂id和分班id获取所有学生 - def get_historical_course_students - course_id = params[:course_id] - course_group_id = params[:course_group_id] - - @students = CourseMember.where(course_id: course_id, role: %i[STUDENT]) - if course_group_id.present? - @students = @students.where(course_group_id: course_group_id) - end - - @students = @students.includes(user: [user_extension: :school]) - @students_count = @students.size - end - - # 导入创建分班 - def create_group_by_importing_file - attachment_ids = [] - - params[:attachment_ids].each do |id| - attachment = Attachment.find(id.to_i) - attachment_ids << attachment.id - end - associate_result = Attachment.associate_container(attachment_ids, @course.id, @course.class) - return normal_status("参数错误") unless associate_result - - attachment_ids.each do |attachment_id| - attachment = Attachment.find attachment_id - - path = attachment.disk_directory - name = attachment.disk_filename - if name.split(".").last == "xls" - begin - attachment_folder = edu_setting('attachment_folder') - full_path = "#{attachment_folder}/#{path}/#{name}" - xls = Roo::Spreadsheet.open(full_path, extension: :xls) - worksheet = xls.sheet(0) - rows = worksheet.last_row.to_i #最后一行数 - if rows < 2 - return normal_status(-1, "请按照模板格式导入") - else - group_count = 0 - (2..rows).each do |row| - name = worksheet.cell(row, 1).to_s - - if @course.course_groups.where(:name => name).blank? - @course.course_groups << CourseGroup.new(:name => name, :position => @course.course_groups_count + 1) - group_count += 1 - end - end - return normal_status("已导入#{group_count}个分班") - end - rescue => e - uid_logger_error(e.message) - normal_status(-1, "无法完成导入,原因:文件内容无法读取") - end - else - normal_status(-1, "只支持xls文件的导入") - end - end - end - - # --- 学生列表相关API --- END - - # 根据姓名和单位搜索用户 - def search_users - name = params[:name] - school_name = params[:school_name] - - # REDO:Extension - @users = User.where(status: User::STATUS_ACTIVE) - @users = @users.where(laboratory_id: current_laboratory.id) unless current_laboratory.main_site? - @users = @users.where("concat(users.lastname, users.firstname) like '%#{name}%'") if name.present? - # REDO:Extension - @users = @users.joins(user_extension: :school).where("schools.name like '%#{school_name}%'") if school_name.present? - - @users_count = @users.size - - limit = params[:limit] || 20 - page = params[:page] || 1 - @users = @users.includes(user_extension: :school).page(page).per(limit) - end - - # 申请加入课堂 - def apply_to_join_course - ActiveRecord::Base.transaction do - begin - - # 邀请码验证 - return normal_status(-1, "邀请码不能为空") if params[:invite_code].blank? - invite_code = params[:invite_code] - course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0, laboratory_id: current_laboratory.id) - course_group = CourseGroup.find_by(invite_code: invite_code, invite_code_halt: 0) - if course.blank? - return normal_status(-1, "邀请码无效") if course_group.blank? - - course = Course.find_by(id: course_group.course_id, is_delete: 0, laboratory_id: current_laboratory.id) - return normal_status(-1, "邀请码无效") if course.blank? - end - - return normal_status(-1, "课堂已结束,无法加入") if course.is_end - - # 实名认证和职业认证的身份判断 - return normal_status(-2, "该课堂要求成员完成实名和职业认证") if course.authentication && - course.professional_certification && (!current_user.authentication && !current_user.professional_certification) - return normal_status(-2, "该课堂要求成员完成实名认证") if course.authentication && !current_user.authentication - return normal_status(-2, "该课堂要求成员完成职业认证") if course.professional_certification && !current_user.professional_certification - - # 身份验证 - if params[:professor].blank? && params[:assistant_professor].blank? && params[:student].blank? - return normal_status(-1, "请先选择身份") - end - if params[:professor].present? && params[:assistant_professor].present? - return normal_status(-1, "同一课堂不允许申请多个教师身份") - end - - # 验证是否存在同学号的学生 - # u_extension = current_user.user_extension - # if params[:student].present? && u_extension.student? - # same_student_id_users = UserExtension.where.not(user_id: current_user.id).where(student_id: u_extension.student_id, identity: %i[student], school_id: u_extension.school_id).pluck(:user_id) - # tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.exists?(user_id: same_student_id_users) - # end - - # 创建学生身份 - 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? - # 如果在该课堂已经存在学生身份,且邀请码为分班邀请码,则将其直接加入分班 - existing_student.update!(course_group_id: course_group.id) if course_group.present? - message = "您已是课堂成员" - else - correspond_teacher_exist = current_user.none_admin_teacher_of_course? course - new_student = CourseMember.new(user_id: current_user.id, course_id: course.id, role: 4) - new_student.is_active = 0 if correspond_teacher_exist - - new_student.course_group_id = course_group.id if course_group.present? - new_student.save! - - CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) - StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) - student_role = 1 - end - end - - # 创建教师身份 - 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, - course_message_type: "JoinCourseRequest", status: 0) - if existing_course_message.blank? - 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) - if params[:professor].present? && params[:professor].to_i == 1 - course_message.content = 2 - role = 9 - message = "教师申请已提交,请等待审核" - else - course_message.content = 3 - role = 7 - message = "助教申请已提交,请等待审核" - end - - course_message.save! - - # role = course_message.content == 2 ? '9' : '7' # 7:助教 9:教师 - ApplyTeacherRoleJoinCourseNotifyJob.perform_later(current_user.id, course.id, role) - # message = "#{course_message.content == 2 ? '教师' : '助教'}申请已提交,请等待审核" - else - message = "#{existing_course_message.content == '2' ? '教师' : '助教'}申请已提交,请等待审核" - end - else - message = "您已是课堂成员" - end - teacher_role = 1 - end - - if (teacher_role && student_role) || message.to_s == "您已是课堂成员" - render json: { status: 0, message: message, course_id: course.id} - elsif student_role.to_i == 1 - render json: { status: 0, message: "加入成功", course_id: course.id} - else - normal_status(message) - end - rescue => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def top_banner - @user = current_user - @switch_student = Course::BUSINESS < @user_course_identity && @user_course_identity < Course::STUDENT - @is_student = @user_course_identity == Course::STUDENT - @course.increment!(:visits) - end - - def left_banner - @user = current_user - @is_teacher = @user_course_identity < Course::ASSISTANT_PROFESSOR - @course_modules = @course.course_modules.where(hidden: 0) - @hidden_modules = @course.course_modules.where(hidden: 1) - @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] - end - - def board_list - begin - @course = @board.course - @current_user = current_user - return normal_status(403, "你没有权限操作") if !@current_user.teacher_of_course?(@course) && !@current_user.course_identity(@current_user) == 4 - @boards = @course.boards - rescue Exception => e - uid_logger(e.message) - tip_exception("获取数据失败") - raise ActiveRecord::Rollback - end - end - - def attahcment_category_list - @has_course_groups = @course.course_groups.exists? - @course_modules = @course.attachment_course_modules - end - - def mine - @page = params[:page] || 1 - @page_size = params[:page_size] || 15 - - @courses = Course.by_user(current_user).hidden(false).processing.not_deleted.by_keywords(params[:search]).distinct - - # @total_count = @courses.count - # offset = 0 - # while offset < @total_count - # - # offset = offset + @page_size.to_i + 1 - # @courses = @courses.offset(offset) - # end - - @courses= @courses.page(@page).per(@page_size) - end - - # 导出课堂信息 - def export_couser_info - if params[:export].present? && params[:export] - normal_status(0,"正在下载中") - else - set_export_cookies - course_info_to_xlsx @course - filename_ = "#{current_user.real_name}_#{@course.name}_课堂信息_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_course_info.xlsx.axlsx", - locals: {course_info: @course_info} - end - end - - # 导出活跃度 - def export_member_act_score - search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索 - group_id = params[:group_id] #分班的班级id - @all_members = @course.students - @all_members = @all_members.where(course_group_id: group_id) unless group_id.blank? - unless search.blank? - @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{search}%","%#{search}%") - end - - if @all_members.size == 0 - normal_status(-1,"暂无学生数据") - elsif params[:export].present? && params[:export] - normal_status(0,"正在下载中") - else - set_export_cookies - @all_members = student_act_score group_id, search - act_score_to_xlsx(@all_members) - filename_ = "#{current_user.real_name}_#{@course.name}_活跃度_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_member_act_score.xlsx.axlsx", - locals: {activity_level:@user_activity_level} - end - end - - # 导出学生成绩 - def export_member_scores_excel - ActiveRecord::Base.transaction do - begin - @all_members = @course.students - search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索 - if params[:group_id].present? - group_ids = params[:group_id].is_a?(String) ? [params[:group_id].to_i] : params[:group_id].map(&:to_i) - @all_members = @all_members.where(course_group_id: group_ids) - end - unless search.blank? - @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{search}%","%#{search}%") - end - - if @all_members.length == 0 - normal_status(-1,"暂无学生数据") - elsif params[:export].present? && params[:export] - normal_status(0,"正在下载中") - else - @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") - @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") - # @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") - @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") - - set_export_cookies - member_to_xlsx(@course, @all_members.includes(user: :user_extension), @c_homeworks, @c_exercises, @c_tasks) - filename_ = "#{current_user.real_name}_#{@course.name}_总成绩_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_member_scores_excel.xlsx.axlsx", - locals: {course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, - common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, - exercise_works:@exercise_work_arrays} - end - - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - # 计算课堂所有已发布的实训作业成绩 - def calculate_all_shixun_scores - tip_exception(-1, "课堂已结束") if @course.is_end - shixun_homeworks = @course.homework_commons.homework_published.where(homework_type: 4) - shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework| - homework.update_homework_work_score - end - normal_status(0, "更新成功") - end - - def search_slim - courses = current_user.manage_courses.not_deleted.processing - courses = courses.where(id: current_laboratory.all_courses) - - keyword = params[:keyword].to_s.strip - if keyword.present? - courses = courses.where('name LIKE ?', "%#{keyword}%") - end - - count = courses.count - courses = paginate(courses) - - render_ok(count: count, courses: courses.select(:id, :name).as_json) - end - - def tasks_list - case params[:container_type] - when 'shixun_homework' - @tasks = @course.practice_homeworks - when 'common_homework' - @tasks = @course.normal_homeworks - when 'group_homework' - @tasks = @course.group_homeworks - when 'exercise' - @tasks = @course.exercises - when 'poll' - @tasks = @course.polls - when 'graduation_topic' - @tasks = @course.graduation_topics - when 'graduation_task' - @tasks = @course.graduation_tasks - when 'attachment' - @tasks = @course.attachments - else - tip_exception("请指定任务类型") - end - end - - def update_task_position - Rails.logger.info("#######task_ids_length#{params[:task_ids].uniq.length}#########task_count:#{@tasks.count}") - tip_exception("task_ids参数有误") if params[:task_ids].blank? || params[:task_ids].uniq.length != @tasks.count - ActiveRecord::Base.transaction do - begin - @tasks.each do |task| - position = params[:task_ids].reverse.index(task.id).to_i + 1 - task.update_attributes!(position: position) - end - normal_status(0, "移动成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - private - - # Use callbacks to share common setup or constraints between actions. - def set_course - @course = Course.find_by!(id: params[:id]) - tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin_or_business? - end - - # Never trust parameters from the scary internet, only allow the white list through. - def course_params - params.require(:course).permit(:name, :class_period, :credit, :end_date, :is_public, :authentication, :professional_certification) - end - - def validate_course_name - tip_exception("课堂名称不能为空!") if params[:course][:name].blank? - if params[:subject_id].blank? && @course.blank? || (@course && @course.subject.blank?) - tip_exception("课程名称不能为空!") if params[:course_list_name].blank? - tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) && - params[:course][:name].index(params[:course_list_name]) == 0 - else - @subject = @course.present? ? @course.subject : Subject.find_by!(id: params[:subject_id]) - tip_exception("开始时间不能为空") if params[:start_date].blank? - tip_exception("结束时间不能为空") if params[:end_date].blank? - tip_exception("结束时间必须晚于开始时间") if strf_date(params[:end_date]) <= strf_date(params[:start_date]) - tip_exception("开始时间和结束时间不能早于往期开课时间") if @course.nil? && @subject.max_course_end_date && strf_date(params[:start_date]) <= strf_date(@subject.max_course_end_date) - validate_start_end_date if @course.present? - tip_exception("开放课堂必须包含公告栏和在线学习模块") unless params[:course_module_types].include?("announcement") && params[:course_module_types].include?("online_learning") - end - tip_exception("课堂所属单位不能为空!") if params[:school].blank? - tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank? - @school = School.find_by(name: params[:school].strip) - tip_exception("所属单位不存在") unless @school.present? - end - - def validate_start_end_date - prev_course = @subject.courses.where("id < #{@course.id}").last - next_course = @subject.courses.where("id > #{@course.id}").first - tip_exception("开始时间不能与往期开课时间重叠") if prev_course && strf_date(params[:start_date]) <= strf_date(prev_course.end_date) - tip_exception("结束时间不能与后期开课时间重叠") if next_course && strf_date(params[:end_date]) >= strf_date(next_course.start_date) - end - - # 超级管理员和课堂管理员的权限判断 - def admin_allowed - unless @user_course_identity < Course::PROFESSOR - tip_exception(403, "..") - end - end - - # 课堂教师的权限判断 - def teacher_allowed - unless @user_course_identity < Course::STUDENT - tip_exception(403, "..") - end - end - - # 课堂教师,课堂管理员以及超级管理员的权限判断 - def teacher_or_admin_allowed - unless @user_course_identity < Course::ASSISTANT_PROFESSOR - tip_exception(403, "..") - end - end - - def course_member_allowed - tip_exception(403, "..") if @user_course_identity > Course::STUDENT - end - - def course_tasks - case params[:container_type] - when 'shixun_homework' - @tasks = @course.practice_homeworks - when 'common_homework' - @tasks = @course.normal_homeworks - when 'group_homework' - @tasks = @course.group_homeworks - when 'exercise' - @tasks = @course.exercises - when 'poll' - @tasks = @course.polls - when 'graduation_topic' - @tasks = @course.graduation_topics - when 'graduation_task' - @tasks = @course.graduation_tasks - when 'attachment' - @tasks = @course.attachments - else - tip_exception("请指定任务类型") - end - end - - def validate_inform_params - tip_exception("公告标题不能为空") if params[:name].blank? - tip_exception("公告内容不能为空") if params[:description].blank? - end - - # def find_container - # case params[:container_type] - # when 'shixun_homework', 'common_homework', 'group_homework' - # @task = HomeworkCommon.find_by(id: params[:container_id]) - # when 'exercise' - # @task = Exercise.find_by(id: params[:container_id]) - # when 'poll' - # @task = Poll.find_by(id: params[:container_id]) - # when 'graduation_topic' - # @task = GraduationTopic.find_by(id: params[:container_id]) - # when 'graduation_task' - # @task = GraduationTask.find_by(id: params[:container_id]) - # when 'attachment' - # @task = Attachment.find_by(id: params[:container_id]) - # else - # tip_exception("container_type参数有误") - # end - # end - - def student_act_score group_id, search - sql_select = %Q{SELECT cm.*, - (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} - AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} - AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, - (SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course" - AND attachments.author_id = cm.user_id) AS resource_num, - (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND - jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num, - (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND - gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, - (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, - (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} - AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, - (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} - AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num - FROM course_members cm} - if search.present? && group_id.present? - sql_select += %Q{ join users on cm.user_id = users.id - join user_extensions ue on ue.user_id = users.id - WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} and - (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%')} - - elsif search.present? - sql_select += %Q{ join users on cm.user_id = users.id - join user_extensions ue on ue.user_id = users.id - WHERE cm.role = 4 and - (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%')} - elsif group_id.present? - group_id = group_id.is_a?(Array) ? group_id.map(&:to_i) : [group_id.to_i] - sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id in (#{group_id.join(",")})} - else - sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id}} - end - act_scores = CourseMember.find_by_sql(sql_select) - act_scores - end - - def course_statistics course, max_exp, limit - max_rate = max_exp.nil? || max_exp <= 0 ? 0 : 20.0 / max_exp - - sql_select = %Q{ SELECT a.*, (message_num*0.2 + message_reply_num*0.1 + resource_num*0.5 + homework_journal_num*0.1 + graduation_num + - homework_num + exercise_num + poll_num*0.7 + exercise_score * 0.7 + graduation_score * 0.7 + homework_score * 0.7 + exp*#{max_rate}) - AS score from - (select cm.*, users.experience as exp, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} - AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} - AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, - (SELECT count(attachments.id) FROM attachments WHERE container_id = #{course.id} and container_type = "Course" - AND attachments.author_id = cm.user_id) AS resource_num, - (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND - jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{course.id}) AS homework_journal_num, - (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND - gt.course_id = #{course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, - (SELECT IFNULL(sum(gw.work_score),0) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND - gt.course_id = #{course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_score, - (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, - (SELECT IFNULL(sum(ss.work_score),0) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_score, - (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} - AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, - (SELECT IFNULL(sum(eu.score),0) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} - AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_score, - (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{course.id} - AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num - FROM course_members cm join users on cm.user_id = users.id - WHERE cm.role = 4 and cm.course_id = #{course.id}) a ORDER BY score desc limit #{limit}; - } - CourseMember.find_by_sql(sql_select) - end - - def course_work_scores course, sort, group_ids - sql_select = %Q{ SELECT a.*, - (exercise_score + graduation_score + common_score + practice_score + group_score) AS score from - (select cm.*, - (SELECT IFNULL(sum(gw.work_score),0) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND - gt.course_id = #{course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_score, - (SELECT IFNULL(sum(ss.work_score),0) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id and hc.homework_type=1) AS common_score, - (SELECT IFNULL(sum(ss.work_score),0) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id and hc.homework_type=3) AS group_score, - (SELECT IFNULL(sum(ss.work_score),0) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id and hc.homework_type=4) AS practice_score, - (SELECT IFNULL(sum(eu.score),0) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} - AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_score - FROM course_members cm join users on cm.user_id = users.id - WHERE cm.role = 4 and cm.course_id = #{course.id} - } - - sql_select += %Q{ and cm.course_group_id in (#{group_ids.join(",")}) } if group_ids.present? - sql_select += %Q{ ) a ORDER BY score #{sort}; } - course_members = CourseMember.find_by_sql(sql_select) - course_members - end - - def course_act_scores course, group_ids - sql_select = %Q{ SELECT a.*, - (message_num*2 + message_reply_num + resource_num*5 + homework_journal_num + graduation_num*10 + homework_num*10 + exercise_num*10 + poll_num*7) AS score from - (select cm.*, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} - AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} - AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, - (SELECT count(attachments.id) FROM attachments WHERE container_id = #{course.id} and container_type = "Course" - AND attachments.author_id = cm.user_id) AS resource_num, - (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND - jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{course.id}) AS homework_journal_num, - (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND - gt.course_id = #{course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, - (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND - hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, - (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} - AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, - (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{course.id} - AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num - FROM course_members cm join users on cm.user_id = users.id - join user_extensions ue on ue.user_id = users.id - WHERE cm.role = 4 and cm.course_id = #{course.id} - } - - sql_select += %Q{ and cm.course_group_id in (#{group_ids.join(",")}) } if group_ids.present? - sql_select += %Q{ ) a ORDER BY score desc; } - course_members = CourseMember.find_by_sql(sql_select) - course_members - end -end diff --git a/app/controllers/departments_controller.rb b/app/controllers/departments_controller.rb deleted file mode 100644 index 73cb19156..000000000 --- a/app/controllers/departments_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -class DepartmentsController < ApplicationController - skip_before_action :check_sign - - def for_option - render_ok(departments: current_school.departments.without_deleted.select(:id, :name).as_json) - end - - private - - def current_school - @_current_school ||= School.find(params[:id]) - end -end \ No newline at end of file diff --git a/app/controllers/disciplines_controller.rb b/app/controllers/disciplines_controller.rb deleted file mode 100644 index 09d6f49a0..000000000 --- a/app/controllers/disciplines_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class DisciplinesController < ApplicationController - - def index - - end -end \ No newline at end of file diff --git a/app/controllers/edu_datas_controller.rb b/app/controllers/edu_datas_controller.rb deleted file mode 100644 index 02c1b285d..000000000 --- a/app/controllers/edu_datas_controller.rb +++ /dev/null @@ -1,29 +0,0 @@ -class EduDatasController < ApplicationController - before_action :find_game - skip_before_action :user_setup - # skip_before_action :setup_laboratory - # layout :false - include GitHelper - - # params[:game_id] - def game - @shixun = @challenge.shixun - @shixun_env = @shixun.mirror_name - @shixun_tags = @challenge.challenge_tags.map(&:name) - end - - def code_lines - path = @challenge.path - myshixun = @game.myshixun - # content = git_fle_content(myshixun.repo_path, path) || "" - @content = {"content":"#coding=utf-8\n\n#请在此处添加代码完成输出“Hello Python”,注意要区分大小写!\n###### Begin ######\n\n\n\n###### End ######\n\n"} - @content[:content].include?("Begin") - end - - private - def find_game - game_id = params[:game_id] - @game = Game.find(game_id) - @challenge = @game.challenge - end -end diff --git a/app/controllers/examination_banks_controller.rb b/app/controllers/examination_banks_controller.rb deleted file mode 100644 index bf3bb7a3a..000000000 --- a/app/controllers/examination_banks_controller.rb +++ /dev/null @@ -1,92 +0,0 @@ -class ExaminationBanksController < ApplicationController - include PaginateHelper - before_action :require_login - before_action :certi_identity_auth, only: [:create, :edit, :update, :destroy, :set_public, :revoke_item] - before_action :find_exam, except: [:index, :create] - before_action :edit_auth, only: [:update, :destroy, :set_public, :revoke_item] - before_action :identity_auth, only: [:index] - - def index - exams = ExaminationBankQuery.call(params) - @exams_count = exams.size - @exams = paginate exams.includes(:user, :examination_items) - end - - def show - @items = @exam.examination_items - @single_questions = @items.where(item_type: "SINGLE") - @multiple_questions = @items.where(item_type: "MULTIPLE") - @judgement_questions = @items.where(item_type: "JUDGMENT") - @program_questions = @items.where(item_type: "PROGRAM") - end - - def create - ActiveRecord::Base.transaction do - exam = ExaminationBank.new(user: current_user) - # 保存试卷基础信息 - exam = ExaminationBanks::SaveExaminationBankService.call(exam, form_params) - - # 将试题篮中的试题发送到试卷,试卷的题目与试题独立 - current_user.item_baskets.includes(:item_bank).each do |basket| - item = basket.item_bank - if item.present? - new_item = ExaminationItem.new - new_item.new_item(item, exam, basket.score, basket.position) - end - end - - current_user.item_baskets.destroy_all - end - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def edit; end - - def update - ExaminationBanks::SaveExaminationBankService.call(@exam, form_params) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def destroy - ActiveRecord::Base.transaction do - ApplyAction.where(container_type: "ExaminationBank", container_id: @exam.id).destroy_all - @exam.destroy! - render_ok - end - end - - def set_public - tip_exception(-1, "该试卷已公开") if @exam.public? - tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @exam.id, container_type: "ExaminationBank", status: 0).exists? - ApplyAction.create!(container_id: @exam.id, container_type: "ExaminationBank", user_id: current_user.id) - # @exam.update_attributes!(public: 1) - render_ok - end - - def revoke_item - item = @exam.examination_items.find_by!(item_bank_id: params[:item_id]) - ActiveRecord::Base.transaction do - @exam.examination_items.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1") - item.destroy! - end - render_ok - end - - private - - def form_params - params.permit(:discipline_id, :sub_discipline_id, :difficulty, :name, :duration, tag_discipline_id: []) - end - - def find_exam - @exam = ExaminationBank.find_by!(id: params[:id]) - end - - def edit_auth - current_user.admin_or_business? || @exam.user == current_user - end -end \ No newline at end of file diff --git a/app/controllers/examination_intelligent_settings_controller.rb b/app/controllers/examination_intelligent_settings_controller.rb deleted file mode 100644 index e9456b3dc..000000000 --- a/app/controllers/examination_intelligent_settings_controller.rb +++ /dev/null @@ -1,108 +0,0 @@ -class ExaminationIntelligentSettingsController < ApplicationController - before_action :require_login - before_action :certi_identity_auth, only: [:create, :optinal_items, :save_exam, :exchange_one_item, :exchange_items] - before_action :find_exam, only: [:exchange_one_item, :exchange_items, :save_exam] - - def optinal_items - sub_discipline_id = params[:sub_discipline_id] - tag_discipline_id = params[:tag_discipline_id] - difficulty = params[:difficulty] - source = params[:source] - - items = OptionalItemQuery.call(sub_discipline_id, tag_discipline_id, difficulty, source) - @single_question_count = items.select{ |item| item.item_type == "SINGLE" }.size - @multiple_question_count = items.select{ |item| item.item_type == "MULTIPLE" }.size - @judgement_question_count = items.select{ |item| item.item_type == "JUDGMENT" }.size - @program_question_count = items.select{ |item| item.item_type == "PROGRAM" }.size - end - - def create - ActiveRecord::Base.transaction do - exam = ExaminationIntelligentSetting.new(user: current_user) - # 保存试卷基础信息 - exam = ExaminationIntelligentSettings::SaveSettingService.call(exam, form_params) - render_ok({exam_setting_id: exam.id}) - end - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def save_exam - new_exam = ExaminationBank.new(user: current_user) - # 保存试卷基础信息 - ExaminationIntelligentSettings::SaveExaminationService.call(new_exam, save_params, @exam) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def exchange_one_item - item = @exam.item_baskets.find_by!(item_bank_id: params[:item_id]) - exam_type_setting = @exam.examination_type_settings.find_by!(item_type: item.item_type) - - # 获取可选的题 - items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public) - - # 可选题中去掉已组卷的试题 - type_items = items.select{ |t_item| t_item.item_type == item.item_type } - optional_item_ids = (type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id)).uniq - - # 如果可选的题数等于0则提示无可换的题 - tip_exception("无可换的题") if optional_item_ids.size == 0 - - new_item = ItemBank.find optional_item_ids.sample(1).first - ActiveRecord::Base.transaction do - @exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: item.position, score: item.score, item_type: new_item.item_type) - item.destroy! - end - render_ok - end - - def exchange_items - exam_type_setting = @exam.examination_type_settings.find_by!(item_type: params[:item_type]) - choosed_items = @exam.item_baskets.where(item_type: params[:item_type]) - - # 获取可选的题 - items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public) - type_items = items.select{ |t_item| t_item.item_type == params[:item_type] } - - # 可选题中去掉已组卷的试题 - choosed_item_ids = choosed_items.pluck(:item_bank_id) - optional_item_ids = (type_items.pluck(:id) - choosed_item_ids).uniq - - # 如果可选的题数等于0则提示无可换的题 - tip_exception("无可换的题") if optional_item_ids.size == 0 - - # 如果可选题数小于设置的题数(n),则在原来的选题中随机选n个,确保换题时能选到新的题 - if optional_item_ids.size < exam_type_setting.count - absence_count = exam_type_setting.count - optional_item_ids.size - optional_item_ids = optional_item_ids + choosed_item_ids.sample(absence_count) - end - - ActiveRecord::Base.transaction do - # 取试题分数 - score = choosed_items.first&.score || (params[:item_type] == "PROGRAM" ? 10 : 5) - choosed_items.destroy_all - optional_item_ids.sample(exam_type_setting.count).each_with_index do |item_id, index| - new_item = ItemBank.find item_id - @exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: index+1, score: score, item_type: new_item.item_type) - end - end - render_ok - end - - private - - def find_exam - @exam = ExaminationIntelligentSetting.find_by!(id: params[:id]) - tip_exception(403,"无权限编辑") unless current_user.admin_or_business? || @exam.user_id == current_user.id - end - - def form_params - params.permit(:discipline_id, :sub_discipline_id, :difficulty, :source, tag_discipline_id: [], question_settings: %i[item_type count]) - end - - def save_params - params.permit(:name, :duration) - end -end \ No newline at end of file diff --git a/app/controllers/examination_items_controller.rb b/app/controllers/examination_items_controller.rb deleted file mode 100644 index 97aac3bc6..000000000 --- a/app/controllers/examination_items_controller.rb +++ /dev/null @@ -1,85 +0,0 @@ -class ExaminationItemsController < ApplicationController - before_action :require_login - before_action :certi_identity_auth, only: [:create, :destroy, :delete_item_type, :set_score, :batch_set_score, :adjust_position] - before_action :validate_score, only: [:set_score, :batch_set_score] - before_action :find_exam, only: [:create, :batch_set_score, :delete_item_type] - before_action :find_item, except: [:create, :batch_set_score, :delete_item_type] - before_action :edit_auth - - def create - ExaminationItems::SaveItemService.call(current_user, create_params, @exam) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def destroy - ActiveRecord::Base.transaction do - @exam.examination_items.where(item_type: @item.item_type).where("position > #{@item.position}").update_all("position = position -1") - @item.destroy! - end - render_ok - end - - def delete_item_type - items = @exam.examination_items.where(item_type: params[:item_type]) - items.destroy_all - render_ok - end - - def set_score - @item.update_attributes!(score: params[:score]) - @questions_score = @exam.examination_items.where(item_type: @item.item_type).pluck(:score).sum - @all_score = @exam.examination_items.pluck(:score).sum - render_ok({questions_score: @questions_score, all_score: @all_score}) - end - - def batch_set_score - @exam.examination_items.where(item_type: params[:item_type]).update_all(score: params[:score]) - @questions_score = @exam.examination_items.where(item_type: params[:item_type]).pluck(:score).sum - @all_score = @exam.examination_items.pluck(:score).sum - render_ok({questions_score: @questions_score, all_score: @all_score}) - end - - def adjust_position - same_items = @exam.examination_items.where(item_type: @item.item_type) - max_position = same_items.size - tip_exception("position超出范围") unless params[:position].present? && params[:position].to_i <= max_position && params[:position].to_i >= 1 - ActiveRecord::Base.transaction do - if params[:position].to_i > @item.position - same_items.where("position > #{@item.position} and position <= #{params[:position].to_i}").update_all("position=position-1") - @item.update_attributes!(position: params[:position]) - elsif params[:position].to_i < @item.position - same_items.where("position < #{@item.position} and position >= #{params[:position].to_i}").update_all("position=position+1") - @item.update_attributes!(position: params[:position]) - else - return normal_status(-1, "排序无变化") - end - end - render_ok - end - - private - - def find_exam - @exam = ExaminationBank.find_by!(id: params[:exam_id]) - end - - def create_params - params.permit(item_ids: []) - end - - def find_item - @item = ExaminationItem.find_by!(id: params[:id]) - @exam = @item.examination_bank - end - - def validate_score - tip_exception("分值不能为空") unless params[:score].present? - tip_exception("分值需大于0") unless params[:score].to_f > 0 - end - - def edit_auth - current_user.admin_or_business? || @exam.user == current_user - end -end \ No newline at end of file diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb deleted file mode 100644 index 25e0de44a..000000000 --- a/app/controllers/files_controller.rb +++ /dev/null @@ -1,400 +0,0 @@ -class FilesController < ApplicationController - include MessagesHelper - - before_action :require_login, :check_auth, except: %i[index] - before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] - before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] - before_action :file_validate_sort_type, only: :index - before_action :validate_send_message_to_course_params, only: :bulk_send - before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] - before_action :validate_upload_params, only: %i[upload import] - before_action :find_file, only: %i[show setting update] - before_action :publish_params, only: %i[upload import update] - - SORT_TYPE = %w[created_on downloads quotes] - - def index - sort = params[:sort] || 0 # 0: 降序;1: 升序 - sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 - @course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - @user = current_user - @attachments = @course_second_category_id.to_i == 0 ? @course.attachments.includes(:course_second_category) : @course.attachments.by_course_second_category_id(@course_second_category_id) - @attachments = @attachments.includes(author: [:user_extension, :course_members]) - .ordered(sort: sort.to_i, sort_type: sort_type.strip) - - get_category(@course, @course_second_category_id) - @total_count = @attachments.size - - if @user.course_identity(@course) == 5 - member = @course.course_members.find_by(user_id: current_user.id, is_active: 1) - if member.try(:course_group_id).to_i == 0 - @attachments = @attachments.published.unified_setting - else - not_atta_ids = @course.attachment_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:attachment_id) - - @attachments = @attachments.where.not(id: not_atta_ids).published - end - elsif @user.course_identity(@course) > 5 - @attachments = @attachments.publiced.published - end - - @publish_count = @attachments.published.size - @unpublish_count = @total_count - @publish_count - @attachments = @attachments.by_keywords(params[:search]) - - @attachments = @attachments.page(@page).per(@page_size) - end - - def bulk_publish - return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5 - # tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0 - - attachments = @course.attachments.by_ids(@attachment_ids) - - ActiveRecord::Base.transaction do - # 有分班设置时 - # if @course.course_group_module? && @course.course_groups_count != 0 && params[:group_ids] - # group_ids = params[:group_ids]&.reject(&:blank?) - # charge_group_ids = @course.charge_group_ids(current_user) - # publish_groups = charge_group_ids & group_ids if group_ids - # - # attachments.each do |atta| - # if atta.published? && !atta.unified_setting || !atta.published? - # create_atta_group_settings atta - # atta.update_attributes!(unified_setting: 0) if atta.unified_setting - # none_publish_settings = atta.attachment_group_settings.where(course_group_id: publish_groups).none_published - # none_publish_settings.update_all(publish_time: Time.now) - # end - # end - # end - - # 未发布的资源更新状态 - attachments.where(is_publish: 0).update_all(is_publish: 1, publish_time: Time.now) - end - render_ok - end - - def bulk_delete - ActiveRecord::Base.transaction do - begin - @course.attachments.by_ids(@attachment_ids).destroy_all - rescue Exception => e - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def bulk_send - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@course) - course_ids = params[:to_course_ids] - - begin - @attachment_ids.each do |id| - @attachment = @course.attachments.find_by_id id - course_ids.each do |course_id| - course = Course.find_by_id course_id - unless @attachment.nil? || course.nil? - course.attachments << course.attachments.build(@attachment.attributes.except("id").merge( - quotes: 0, - downloads: 0, - author_id: current_user.id, - created_on: Time.now, - course_second_category_id: 0 # TODO 暂时只支持发送到其他课堂的主目录 - )) - end - end - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def bulk_move - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@course) - - to_category_id = params[:to_category_id] || 0 # 默认移动到主目录 - unless to_category_id == 0 - course_second_category = @course.course_second_categories.find_by_id to_category_id - return normal_status(2, "参数to_category_id有误,该目录不存在") if course_second_category.nil? - end - - begin - @course.attachments.by_ids(@attachment_ids).update_all(course_second_category_id: to_category_id) - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def bulk_public - @user = current_user - return normal_status(403, "您没有权限进行该操作") unless @user.teacher_of_course?(@course) - - @course.attachments.by_ids(@attachment_ids).update_all(is_public: 1) - end - - def public_with_course_and_project - @attachments = Attachment.publiced.simple_columns - .contains_course_and_project - .includes(:container, author: :user_extension) - .by_filename_or_user_name(params[:search]) - .ordered(sort: 0, sort_type: 'created_on') - - - @total_count = @attachments.size - @attachments = @attachments.page(@page).per(@page_size) - end - - def mine_with_course_and_project - @current_user = current_user - @attachments = Attachment.mine(current_user) - .simple_columns - .contains_course_and_project - .by_keywords(params[:search]) - .ordered(sort: 0, sort_type: 'created_on') - - @total_count = @attachments.size - @attachments = @attachments.page(@page).per(@page_size) - end - - # 上传资源 - def upload - attachment_ids = params[:attachment_ids] - course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - # is_unified_setting = params.has_key?(:is_unified_setting) ? params[:is_unified_setting] : true - # publish_time = params[:publish_time] - # course_group_publish_times = params[:course_group_publish_times] || [] - - begin - attachment_ids.each do |attchment_id| - attachment = Attachment.find_by_id attchment_id - unless attachment.nil? - attachment.container = @course - attachment.course_second_category_id = course_second_category_id - attachment.description = params[:description] - attachment.is_public = params[:is_public] && @course.is_public == 1 ? 1 : 0 - attachment.is_publish = @atta_is_publish - attachment.delay_publish = @atta_delay_publish - attachment.publish_time = @atta_publish_time - attachment.unified_setting = @unified_setting - if @unified_setting == 0 - attachment_group_setting attachment, params[:group_settings] - end - # attachment.set_publish_time(publish_time) if is_unified_setting - # attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank? - attachment.save! - end - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - # 选用资源 & 导入资源 - def import - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@course) || current_user.student_of_course?(@course) - - attachment_ids = params[:attachment_ids] - course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - - begin - attachment_ids.each do |attachment_id| - ori = Attachment.find_by_id(attachment_id) - # 同一个资源可以多次发送到课堂 - # @course.attachments.each do |att| - # @exist = false - # if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - # att.created_on = Time.now - # att.save - # @exist = true - # break - # end - # end - # - # next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.container = @course - attach_copied_obj.created_on = Time.now - attach_copied_obj.author = current_user - attach_copied_obj.is_public = 0 - attach_copied_obj.is_publish = @atta_is_publish - attach_copied_obj.delay_publish = @atta_delay_publish - attach_copied_obj.publish_time = @atta_publish_time - attach_copied_obj.unified_setting = @unified_setting - if @unified_setting == 0 - attachment_group_setting attach_copied_obj, params[:group_settings] - end - attach_copied_obj.course_second_category_id = course_second_category_id - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 4 - end - attach_copied_obj.save - ori.update_columns(quotes: ori.quotes.to_i + 1) - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - # 资源设置 - def update - return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@course) >= 5 && @file.author != current_user - - is_public = params[:is_public] - - @old_attachment = @file - @new_attachment = Attachment.find_by_id params[:new_attachment_id] - - begin - unless @new_attachment.nil? - @new_attachment_history = @old_attachment.become_history - @new_attachment_history.save! - - old_course_second_category_id = @old_attachment.course_second_category_id - @old_attachment.copy_attributes_from_new_attachment(@new_attachment) - @old_attachment.course_second_category_id = old_course_second_category_id - @old_attachment.save! - @new_attachment.delete - end - @old_attachment.is_public = is_public == true && @course.is_public == 1 ? 1 : 0 - @old_attachment.is_publish = @atta_is_publish - @old_attachment.delay_publish = @atta_delay_publish - @old_attachment.publish_time = @atta_publish_time - @old_attachment.unified_setting = @unified_setting - if @unified_setting == 0 - attachment_group_setting @old_attachment, params[:group_settings] - else - @old_attachment.attachment_group_settings.destroy_all - end - - if params[:description] && !params[:description].strip.blank? && params[:description] != @old_attachment.description - @old_attachment.description = params[:description] - end - - # @old_attachment.set_public(is_public) - - # if is_unified_setting - # @old_attachment.set_publish_time(publish_time) - # @old_attachment.attachment_group_settings.destroy_all - # end - - # if publish_time.blank? && @course.course_groups.size > 0 && !is_unified_setting - # @old_attachment.set_course_group_publish_time(@course, course_group_publish_times) - # end - - @old_attachment.save! - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def show - return normal_status(403, "您没有权限进行该操作") if !current_user.teacher_of_course?(@course) && current_user != @file.author - @attachment_histories = @file.attachment_histories - end - - def histories - @user = current_user - @file = @course.attachments.find_by_id params[:id] - - return normal_status(-2, "该课程下没有id为 #{params[:id]}的资源") if @file.nil? - return normal_status(403, "您没有权限进行该操作") if @user != @file.author && !@user.teacher_of_course?(@course) && !@file.public? - - @attachment_histories = @file.attachment_histories - end - - def get_category(course, category_id) - if category_id == 0 - category = course.attachment_course_modules.first - @category_id = category.try(:id) - @category_name = category.try(:module_name) - else - category = CourseSecondCategory.find category_id - @category_id = category.try(:id) - @category_name = category.try(:name) - end - end - - private - def find_file - @file = Attachment.find params[:id] - end - - def find_attachment_ids(attachment_ids = params[:attachment_ids]) - return normal_status(-2, "参数attachment_ids不能为空!") if attachment_ids.blank? - return normal_status(-2, "参数attachment_ids格式错误!") if !attachment_ids.is_a? Array - end - - def find_course_second_category_id - course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - if course_second_category_id != 0 - course_second_category = CourseSecondCategory.find_by(id: course_second_category_id, category_type: "attachment") - return normal_status(-2, "未来找到course_second_category为 #{course_second_category_id} 的目录") if course_second_category.nil? - end - end - - def find_ids - @attachment_ids = params[:ids] || [] - find_attachment_ids(@attachment_ids) - end - - def file_validate_sort_type - normal_status(-2, "参数sort_type暂时只支持 'created_on', 'quotes', 'downloads'") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) - end - - def validate_upload_params - find_attachment_ids - find_course_second_category_id - end - - def publish_params - tip_exception("缺少发布参数") if params[:delay_publish].blank? - @unified_setting = 1 - # if params[:delay_publish].to_i == 1 && @course.course_group_module? && @course.course_groups_count != 0 - # tip_exception("分班发布设置不能为空") if params[:group_settings].blank? - # min_publish_time = params[:group_settings].pluck(:publish_time).reject(&:blank?).min - # max_publish_time = params[:group_settings].pluck(:publish_time).reject(&:blank?).max - # tip_exception("分班发布设置不能为空") if min_publish_time.blank? - # - # # 分班设置中的时间一样且包含所有分班 则按统一设置处理,否则是非统一设置 - # @unified_setting = 0 unless min_publish_time == max_publish_time && params[:group_settings].pluck(:group_id).flatten.sort == @course.course_groups.pluck(:id).sort - # els - if params[:delay_publish].to_i == 1 - tip_exception("缺少延期发布的时间参数") if params[:publish_time].blank? - min_publish_time = params[:publish_time] - end - @atta_is_publish = params[:delay_publish].to_i == 1 && min_publish_time.to_time > Time.now ? 0 : 1 - @atta_delay_publish = params[:delay_publish].to_i - @atta_publish_time = params[:delay_publish].to_i == 1 ? min_publish_time : Time.now - end - - def create_atta_group_settings atta - if atta.attachment_group_settings.size != @course.course_groups.size - @course.course_groups.where.not(id: atta.attachment_group_settings.pluck(:course_group_id)).each do |group| - atta.attachment_group_settings << AttachmentGroupSetting.new(course_group_id: group.id, course_id: @course.id, - publish_time: atta.publish_time) - end - end - end - - def attachment_group_setting attachment, group_setting - create_atta_group_settings attachment - group_setting.each do |setting| - tip_exception("分班id不能为空") if setting[:group_id].length == 0 - tip_exception("发布时间不能为空") if setting[:publish_time].blank? - AttachmentGroupSetting.where(attachment_id: attachment.id, course_group_id: setting[:group_id]). - update_all(publish_time: setting[:publish_time]) - end - end -end diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb deleted file mode 100644 index 0767eab02..000000000 --- a/app/controllers/gits_controller.rb +++ /dev/null @@ -1,84 +0,0 @@ -class GitsController < ApplicationController - skip_before_action :check_sign - # 说明: - # 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器 - # 思路: - # 1、用户通过Git客户端推送代码的时候,这个时候Git客户端肯定会强制用户输入邮箱的 - # 2、通过web端版本库界面更新代码(如果用户邮箱不存在,则用系统备用邮箱) - # 供 git-workhorse反向调用认证 - def auth - # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" - decodes = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) - rand_code = decodes.sample(10).join - logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") - logger.info("1111111 git auth start: code is #{rand_code}, time is #{Time.now}") - - # logger.info("#########-----request_env: #{request.env}") - # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", - # "url"=>"forge01/cermyt39.git/info/refs"} - # - gituser = edu_setting('git_username') - gitpassword = edu_setting('git_password') - - result = false - if request.env["HTTP_AUTHORIZATION"] && request.env["HTTP_AUTHORIZATION"].split(" ").length == 2 - username_password = Base64.decode64(request.env["HTTP_AUTHORIZATION"].split(" ")[1]) - - if username_password.split(":")[0].nil? || username_password.split(":")[1].nil? - result = false - else - input_username = username_password.split(":")[0].strip() - input_password = username_password.split(":")[1].strip() - uid_logger("git start auth: input_username is #{input_username}") - - - # Git 超级权限用户 - if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip - result = true - else - # 用户是否对对象拥有权限 - system_user = User.find_by_login(input_username) || User.find_by_mail(input_username) || User.find_by_phone(input_username) - # 如果用户名密码错误 - if system_user.blank? || system_user && !system_user.check_password?(input_password) - uid_logger_error("git start: password is wrong") - result = false - else - git_url = params["url"] - username = git_url.split("/")[0] - shixunname = git_url.split("/")[1].split(".")[0] - repo_name = username + "/" + shixunname - uid_logger("git start: repo_name is #{repo_name}") - shixun = Shixun.select([:id, :user_id, :repo_name, :identifier]).where(repo_name: repo_name).first - if shixun.blank? - shixun_id = ShixunSecretRepository.where(repo_name: repo_name).pluck(:shixun_id).first - logger.info("####repo_name:#{repo_name}") - logger.info("####shixun_id:#{shixun_id}") - shixun = Shixun.select([:id, :user_id, :repo_name, :identifier]).find_by(id: shixun_id) - end - uid_logger("git start auth: shixun identifier is #{shixun.try(:identifier)}") - uid_logger("git start auth: systemuser is #{system_user.try(:login)}") - - if shixun.present? - logger.info("#######{system_user.manager_of_shixun?(shixun)}") - if system_user.present? && system_user.manager_of_shixun?(shixun) - result = true - else - uid_logger_error("gituser is not shixun manager") - result = false - end - else - uid_logger_error("shixun is not exist") - # result = false - result = true # 为了测试跳出 - end - end - end - end - end - - authenticate_or_request_with_http_basic do |username, password| - result - end - end - -end \ No newline at end of file diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb deleted file mode 100644 index c041750cb..000000000 --- a/app/controllers/graduation_works_controller.rb +++ /dev/null @@ -1,568 +0,0 @@ -class GraduationWorksController < ApplicationController - before_action :require_login, :check_auth - before_action :find_task, only: [:new, :create, :search_member_list, :check_project, :relate_project, - :cancel_relate_project, :delete_work] - before_action :find_work, only: [:show, :edit, :update, :revise_attachment, :supply_attachments, :comment_list, - :add_score, :delete_score, :adjust_score, :assign_teacher] - before_action :user_course_identity - before_action :task_public - before_action :teacher_allowed, only: [:add_score, :adjust_score, :assign_teacher] - before_action :course_student, only: [:new, :create, :edit, :update, :search_member_list, :relate_project, - :cancel_relate_project, :delete_work] - before_action :my_work, only: [:edit, :update, :revise_attachment] - before_action :published_task, only: [:new, :create, :edit, :update, :search_member_list, :relate_project, - :cancel_relate_project, :revise_attachment] - before_action :edit_duration, only: [:edit, :update, :delete_work] - before_action :open_work, only: [:show, :supply_attachments, :comment_list] - - def new - if @task.task_type == 2 && @task.base_on_project - work = @task.graduation_works.where(user_id: current_user.id).first - if work.present? && (work.work_status != 0 || work.project_id == 0) - normal_status(403, "") - end - end - @user = current_user - end - - # 搜索课堂学生 - def search_member_list - unless params[:search].blank? - # 有搜索条件时搜索课堂所有学生包括已提交的 - users = User.joins(:graduation_works).where("concat(users.lastname, users.firstname) like ? and - graduation_task_id = #{@task.id}", "%#{params[:search]}%") - user_ids = users.pluck(:id) - [current_user.id] - @members = @course.students.where(user_id: user_ids) - else - - # 没有搜索条件时搜索课堂所有未提交的学生 - user_ids = @task.graduation_works.where("work_status = 0").pluck(:user_id) - [current_user.id] - @members = @course.students.where(user_id: user_ids) - end - - page = params[:page] ? params[:page].to_i : 1 - limit = params[:limit] ? params[:limit].to_i : 10 - - # todo user_extension - @members = @members.page(page).per(limit).includes(:course_group, user: :user_extension) - end - - def delete_work - ActiveRecord::Base.transaction do - begin - work = @task.graduation_works.find_by!(user_id: params[:user_id]) - tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id - work.update!(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil, - update_time: nil, group_id: 0, commit_user_id: nil, final_score: nil, work_score: nil, - teacher_score: nil, teaching_asistant_score: nil, update_user_id: nil) - work.attachments.destroy_all - work.tidings.destroy_all - normal_status("删除成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - end - end - end - - # 判断项目是否已有其他作品关联上了 - def check_project - tip_exception("项目id不能为空") if params[:project_id].blank? - work = @task.graduation_works.where(project_id: params[:project_id]).first - @is_relate = work.present? - @relate_user = work.present? ? work.user.real_name : "" - end - - def relate_project - tip_exception("项目id不能为空") if params[:project_id].blank? - - ActiveRecord::Base.transaction do - begin - # 判断项目是否存在且当前用户是项目管理员 - project = Project.where(id: params[:project_id]).first - member = Member.where(project_id: project.try(:id), user_id: current_user.id).first - - if project.present? && member.present? && member.member_roles.first.try(:role_id) == 3 - - - work = @task.graduation_works.where("user_id = #{current_user.id}").first || - GraduationWork.create(user_id: current_user.id, graduation_task_id: @task.id, course_id: @task.course_id) - - if work.work_status == 0 && work.project_id == 0 - work.update!(project_id: project.id, update_time: Time.now) - - # 将老师加入项目 - project_member = project.members.where(user_id: @task.user_id).first - if project_member.present? - project_member.member_roles.first.update!(role_id: 3) if project_member.member_roles.first.present? - else - member = Member.create(user_id: @task.user_id, project_id: project.id) - member.member_roles << MemberRole.new(role_id: 3) - Tiding.create(user_id: @task.user_id, trigger_user_id: current_user.id, container_id: project.id, - container_type: 'ManagerJoinProject', belong_container_id: project.id, - belong_container_type: "Project", tiding_type: "System", extra: 3) - end - normal_status("关联成功") - else - tip_exception("不能重复关联项目") - end - else - tip_exception("该项目不存在") - end - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def cancel_relate_project - work = @task.graduation_works.where(user_id: current_user.id, work_status: 0).first - if work.present? && work.project.present? - ActiveRecord::Base.transaction do - begin - member = work.project.members.where(user_id: @task.user_id).first - member.destroy if member.present? - Tiding.where(user_id: @task.user_id, trigger_user_id: current_user.id, container_id: work.project.id, - container_type: 'ManagerJoinProject').destroy_all - - work.update!(project_id: 0) - normal_status("取消关联成功") - - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - else - tip_exception("无法取消关联") - end - end - - def create - graduation_work = @task.graduation_works.where(user_id: current_user.id).first || - GraduationWork.create(user_id: current_user.id, graduation_task_id: @task.id, course_id: @task.course_id) - - update_check graduation_work - - tip_exception("作业不可重复提交") if graduation_work.work_status != 0 - tip_exception("已过了提交时间") if @course.is_end || (@task.end_time < Time.now && (!@task.allow_late || - (@task.late_time.present? && @task.late_time < Time.now))) - - student_ids = [current_user.id] - ActiveRecord::Base.transaction do - begin - # work.update_attributes(graduation_work_params) - - graduation_work.description = params[:description] - graduation_work.commit_time = Time.now - graduation_work.update_time = Time.now - graduation_work.commit_user_id = current_user.id - graduation_work.update_user_id = current_user.id - graduation_work.course_id = @course.id - graduation_work.group_id = @task.task_type == 2 ? @task.graduation_works.where("work_status != 0").map(&:group_id).max.to_i + 1 : 0 - - #提交作品时,计算是否迟交 - graduation_work.late_penalty = @task.end_time < Time.now.to_s ? @task.late_penalty : 0 - graduation_work.work_status = @task.end_time < Time.now.to_s ? 2 : 1 - - if graduation_work.save! - Attachment.associate_container(params[:attachment_ids], graduation_work.id, graduation_work.class) - - if @task.task_type == 2 - members = (params[:user_ids] || []).collect(&:to_i) - [current_user.id] - members = @course.students.pluck(:user_id) & members - student_ids += members - for i in 0 .. members.count-1 - stu_work = @task.graduation_works.where(user_id: members[i].to_i).first || GraduationWork.new - stu_work.update!(user_id: members[i].to_i, description: graduation_work.description, - graduation_task_id: @task.id, project_id: graduation_work.project_id, - late_penalty: graduation_work.late_penalty, work_status: graduation_work.work_status, - commit_time: Time.now, update_time: Time.now, group_id: graduation_work.group_id, - commit_user_id: current_user.id, update_user_id: current_user.id) - stu_work.save! - graduation_work.attachments.each do |attachment| - att = attachment.copy - att.author_id = attachment.author_id - stu_work.attachments << att - end - end - end - @task.update_column(:updated_at, Time.now) - # todo 更新对应的毕设任务课堂动态 - # update_course_activity(@taskhomework.class,@task.id) - @work_id = graduation_work.id - end - - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - - SubmitGraduationWorkNotifyJob.perform_later(@task.id, student_ids) - end - end - - def edit - @task_user = current_user - if @task.task_type == 2 - @commit_user_id = @work.commit_user_id - @work_members = @course.students.where(user_id: @task.graduation_works.where(group_id: @work.group_id).pluck(:user_id)). - order("course_members.id=#{@work.commit_user_id} desc").includes(:course_group, user: :user_extension) - end - end - - def update - update_check @work - - student_ids = [] - ActiveRecord::Base.transaction do - begin - @work.description = params[:description] - @work.update_time = Time.now - @work.update_user_id = current_user.id - # @work.commit_user_id = current_user.id - if @work.save! - Attachment.associate_container(params[:attachment_ids], @work.id, @work.class) - - #如果学生作品被打分后修改,应该给老师提示 - student_ids << @work.user_id if @work.scored? - if @task.task_type == 2 - graduation_works = @task.graduation_works.where("group_id = #{@work.group_id} and user_id != #{@work.user_id}") - work_user_ids = graduation_works.pluck(:user_id) - params_user_ids = (params[:user_ids] || []).collect(&:to_i) - [@work.user_id] - params_user_ids = @course.students.pluck(:user_id) & params_user_ids - - # 原成员更新描述、更新时间以及附件 - @task.graduation_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work| - work.update!(update_time: Time.now, description: @work.description, update_user_id: current_user.id) - work.attachments.destroy_all - @work.attachments.each do |attachment| - att = attachment.copy - att.author_id = attachment.author_id - work.attachments << att - end - student_ids << work.user_id if work.scored? - end - - # 删除的成员 - delete_user_ids = work_user_ids - params_user_ids - @task.graduation_works.where(group_id: @work.group_id, user_id: delete_user_ids).each do |work| - work.attachments.destroy_all - # work.student_works_scores.destroy_all - work.tidings.destroy_all - end - @task.graduation_works.where(group_id: @work.group_id, user_id: delete_user_ids). - update_all(work_status: 0, description: nil, late_penalty: 0, commit_time: nil, update_time: nil, - final_score: nil, teacher_score: nil, work_score: nil, project_id: 0, group_id: 0, - commit_user_id: nil, update_user_id: nil) - - # 新增加的成员 - (params_user_ids - work_user_ids).each do |user_id| - stu_work = @task.graduation_works.where(user_id: user_id).empty? ? GraduationWork.new : - @task.graduation_works.where(user_id: user_id).first - stu_work.update!(user_id: user_id, description: @work.description, graduation_task_id: @task.id, - project_id: @work.project_id, late_penalty: @work.late_penalty, - work_status: @work.work_status, commit_time: Time.now, update_time: Time.now, - group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id) - @work.attachments.each do |attachment| - att = attachment.copy - att.author_id = attachment.author_id - stu_work.attachments << att - end - - student_ids << user_id - end - end - - normal_status("更新成功") - end - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - - SubmitGraduationWorkNotifyJob.perform_later(@task.id, student_ids) if student_ids.present? - end - end - - def show - @current_user = current_user - @is_author = @work.user_id == current_user.id - @work_members = @task.task_type == 1 ? [] : @task.graduation_works.where.not(user_id: @work.user_id). - where(group_id: @work.group_id).includes(:user) - @attachments = @work.attachments.where("attachtype != 7 or attachtype is null") - end - - def comment_list - @current_user = current_user - @last_comment = @work.graduation_work_scores.where(user_id: @current_user.id).last - @comment_scores = @work.graduation_work_scores.reorder("created_at desc").includes(:user) - end - - # 给作品评分 - def add_score - tip_exception("该学生的分数已经过调整,不能再评阅") if @work.ultimate_score - tip_exception("分数和评语不能都为空") if params[:score].blank? && params[:comment].blank? - tip_exception("分数不能超过0-100") if params[:score] && (params[:score].to_f < 0 || params[:score].to_f > 100) - - ActiveRecord::Base.transaction do - begin - # 没传score则取上次评分成绩 - score = GraduationWorkScore.where(user_id: current_user.id, graduation_work_id: @work.id).last - new_score = GraduationWorkScore.new - new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f - new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != "" - new_score.user_id = current_user.id - new_score.graduation_work_id = @work.id - new_score.graduation_task_id = @task.id - - # 如果作品是未提交的状态则更新为已提交 - if !new_score.score.nil? && @work.work_status == 0 - @work.update!(work_status: 1, commit_time: Time.now) - if @task.task_type == 2 - @work.update!(group_id: @task.graduation_works.where("work_status != 0").select("distinct group_id").count + 1) - end - end - - if @task.cross_comment && @work.graduation_work_comment_assignations.where(user_id: current_user.id).count > 0 - new_score.reviewer_role = 2 - else - new_score.reviewer_role = 1 - end - - if new_score.save! - Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class) - - # 该用户的历史评阅无效 - score.update_column('is_invalid', true) if score.present? && score.score.present? - - Tiding.create(user_id: @work.user_id, trigger_user_id: User.current.id, container_id: new_score.id, - container_type: "GraduationWorkScore", parent_container_id: @work.id, - parent_container_type: "GraduationWork", belong_container_id: @task.course_id, - belong_container_type: "Course", viewed: 0, tiding_type: "GraduationTask", extra: new_score.reviewer_role) - - case new_score.reviewer_role - when 1 #教师评分取平均分 - ts_score = GraduationWorkScore.find_by_sql("SELECT AVG(score) AS score FROM graduation_work_scores WHERE - graduation_work_id = #{@work.id} AND reviewer_role = 1 AND score IS NOT NULL AND is_invalid = 0") - - @work.teacher_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f - - # 分组作业整组同评 - if @task.task_type == 2 && params[:same_score] - add_graduation_score_to_member @work, @task, new_score - end - - when 2 #交叉评分显示平均分 - ts_score = GraduationWorkScore.find_by_sql("SELECT AVG(score) AS score FROM graduation_work_scores WHERE - graduation_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL AND is_invalid = 0") - @work.cross_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f - end - - @task.update_column('updated_at', Time.now) - # update_course_activity(@task.class, @task.id) - @work.save! - - normal_status("提交成功") - end - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def adjust_score - tip_exception("成绩不能为空") if params[:score].blank? - tip_exception("成绩不能小于零") if params[:score].to_f < 0 - tip_exception("成绩不能大于100") if params[:score].to_f.round(1) > 100 - tip_exception("调分原因不能超过100个字符") if params[:comment].present? && params[:comment].length > 100 - ActiveRecord::Base.transaction do - begin - # 分数不为空的历史评阅都置为失效 - @work.graduation_work_scores.where.not(score: nil).update_all(is_invalid: 1) - - new_score = GraduationWorkScore.new(graduation_work_id: @work.id, score: params[:score].to_f, - graduation_task_id: @task.id, comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}", - user_id: User.current.id, reviewer_role: 1, is_ultimate: 1) - new_score.save! - @work.update!(ultimate_score: 1, work_score: params[:score].to_f) - - Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id, - container_type: "AdjustScore", parent_container_id: @task.id, - parent_container_type: "GraduationTask", belong_container_id: @course.id, - belong_container_type: 'Course', tiding_type: "GraduationTask") - - normal_status("调分成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - # 删除教师/教辅的评分记录 - def delete_score - score = @work.graduation_work_scores.where(id: params[:comment_id]).first - if score.present? && (score.is_invalid || score.score.nil?) && (score.user == current_user || current_user.admin_or_business?) - begin - score.destroy - normal_status("删除成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - else - tip_exception("无法删除") - end - end - - def supply_attachments - @revise_attachments = @work.attachments.where(attachtype: 7) - @last_atta = @revise_attachments.last - end - - def revise_attachment - tip_exception("不在补交阶段内") if @course.is_end || @task.end_time > Time.now || !@task.allow_late || - (@task.late_time && @task.late_time < Time.now) - tip_exception("附件参数有误") if params[:attachment_ids].blank? || !params[:attachment_ids].is_a?(Array) - tip_exception("补交附件原因不能为空") if params[:description].blank? - - ActiveRecord::Base.transaction do - begin - revise_attachment = @work.attachments.where(attachtype: 7).reorder("created_on desc").last - if revise_attachment.present? && @work.graduation_work_scores.where("created_at > '#{revise_attachment.created_on}' - and score is not null").count == 0 - revise_attachment.destroy - end - Attachment.associate_container(params[:attachment_ids], @work.id, @work.class, 7) - revise_attachment = Attachment.where(attachtype: 7, container_id: @work.id, container_type: "GraduationWork").last - revise_attachment.update!(description: params[:description]) if revise_attachment.present? - - @work.update!(update_time: Time.now) - - normal_status("提交成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - # 交叉评阅分配老师 - def assign_teacher - tip_exception(-1, "user_id不能为空") if params[:user_id].nil? - @work_assign_teacher = @work.graduation_work_comment_assignations.find_by(user_id: params[:user_id]) - - if @work_assign_teacher.present? - # graduation_group_id: 已经是答辩组的需要 将答辩组清空 - @work_assign_teacher.update!(graduation_group_id: 0) - else - @work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id, - user_id: params[:user_id], - graduation_group_id: 0) - end - normal_status("分配成功") - end - - private - def find_task - begin - @task = GraduationTask.find(params[:graduation_task_id]) - @course = @task.course - rescue Exception => e - uid_logger(e.message) - tip_exception("id不存在") - end - end - - def find_work - begin - @work = GraduationWork.find(params[:id]) - @task = @work.graduation_task - @course = @task.course - rescue Exception => e - uid_logger(e.message) - tip_exception("id不存在") - end - end - - def task_public - tip_exception(403,"没有操作权限") if @user_course_identity > Course::STUDENT && (@course.is_public == 0 || - (@course.is_public == 1 && !@task.is_public)) - end - - def course_student - tip_exception(403,"没有操作权限") if @user_course_identity != Course::STUDENT - end - - def my_work - tip_exception(403,"没有操作权限") if @work.user_id != current_user.id || @work.work_status == 0 - end - - def published_task - tip_exception("不能在非提交时间内操作") if @task.status == 0 || (!@task.allow_late && @task.status > 1) || - (@task.allow_late && @task.late_time && @task.late_time < Time.now) - end - - def edit_duration - tip_exception("已过了修改时间") if @task.end_time && @task.end_time < Time.now - end - - # 作品是否公开 - def open_work - tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @task.open_work) - end - - def update_check work - tip_exception("作品描述不能为空") if params[:description].blank? - if @task.task_type == 2 - tip_exception("小组成员不能为空") if params[:user_ids].blank? - tip_exception("小组成员人数不合要求") if params[:user_ids].length > @task.max_num || params[:user_ids].length < @task.min_num - tip_exception("请先关联项目") if @task.base_on_project && work.project_id == 0 - end - end - - def graduation_work_params - params.require(:graduation_work).permit(:description) - end - - def add_graduation_score_to_member work, task, new_score - graduation_works = task.graduation_works.where("group_id = #{work.group_id} and id != #{work.id} and ultimate_score = 0") - graduation_works.each do |st_work| - st_score = GraduationWorkScore.new(user_id: new_score.user_id, score: new_score.score, - reviewer_role: new_score.reviewer_role, comment: new_score.comment) - st_work.graduation_work_scores << st_score - - score = GraduationWorkScore.where(user_id: new_score.user_id, graduation_work_id: st_work.id).last - # 该用户的历史评阅无效 - score.update_column('is_invalid', true) if score.present? && score.score.present? - - teacher_score = GraduationWorkScore.find_by_sql("SELECT AVG(score) AS score FROM graduation_work_scores WHERE - graduation_work_id = #{work.id} AND reviewer_role = 1 AND score IS NOT NULL AND is_invalid = 0") - - st_work.teacher_score = teacher_score.first.score.nil? ? nil : teacher_score.first.score.try(:round, 2).to_f - st_work.save! - - Tiding.create(user_id: st_work.user_id, trigger_user_id: User.current.id, container_id: st_score.id, - container_type: "GraduationWorkScore", parent_container_id: st_work.id, - parent_container_type: "GraduationWork", belong_container_id: task.course_id, - belong_container_type: "Course", viewed: 0, tiding_type: "GraduationTask", extra: st_score.reviewer_role) - # 评阅附件的复制 - new_score.attachments.each do |attachment| - att = attachment.copy - att.author_id = st_score.user_id - st_score.attachments << att - end - end - end -end diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb deleted file mode 100644 index 504868a6e..000000000 --- a/app/controllers/gtopic_banks_controller.rb +++ /dev/null @@ -1,38 +0,0 @@ -class GtopicBanksController < ApplicationController - before_action :require_login - before_action :find_bank, :bank_visit_auth - before_action :bank_admin, only: [:edit, :update] - - def show - @bank_attachments = @bank.attachments - end - - def edit - @attachments = @bank.attachments - end - - def update - ActiveRecord::Base.transaction do - @bank.update_attributes(gtopic_bank_params) - Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] - normal_status(0, "更新成功") - end - end - - private - - def find_bank - @bank = GtopicBank.find_by!(id: params[:id]) - end - - def bank_admin - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? - end - - def gtopic_bank_params - tip_exception("name参数不能为空") if params[:gtopic_bank][:name].blank? - tip_exception("description参数不能为空") if params[:gtopic_bank][:description].blank? - params.require(:gtopic_bank).permit(:name, :topic_type, :topic_source, :topic_property_first, :description, - :topic_property_second, :source_unit, :topic_repeat, :province, :city) - end -end diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb deleted file mode 100644 index 353833ee2..000000000 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ /dev/null @@ -1,220 +0,0 @@ -class HackUserLastestCodesController < ApplicationController - before_action :require_login, except: [:listen_result] - before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, :add_notes, - :listen_result, :result, :submit_records, :restore_initial_code] - before_action :update_user_hack_status, only: [:code_debug, :code_submit] - before_action :require_auth_identity, only: [:add_notes] - before_action :require_manager_identity, only: [:show, :update_code, :restore_initial_code, :sync_code] - skip_before_action :check_sign, only: [:listen_result] - - def show - @my_hack.update_attribute(:submit_status, 0) if @my_hack.submit_status == 1 - @modify = @my_hack.modify_time.to_i < @hack.hack_codes.first.modify_time.to_i - end - - def update_code - @my_hack.update_attribute(:code, params[:code]) - render_ok - end - - # 恢复初始代码 - def restore_initial_code - @my_hack.update_attribute(:code, @hack.code) - end - - # 同步代码 - def sync_code - @my_hack.update_attributes(code: @hack.code, modify_time: Time.now) - end - - # 调试代码 - def code_debug - exec_mode = "debug" - error_status = 501 - error_msg = "debug_error" - oj_evaluate exec_mode, error_status, error_msg - render_ok - end - - # 提交 - def code_submit - exec_mode = "submit" - error_status = 502 - error_msg = "submit_error" - oj_evaluate exec_mode, error_status, error_msg - render_ok - end - - # 提交结果显示 - def result - if @my_hack.submit_status == 1 - render json: {status: 1, message: "正在评测中"} - else - @mode = params[:mode] - @result = - if @mode == "submit" - @my_hack.hack_user_codes.last - elsif @mode == "debug" - @my_hack.hack_user_debug - end - end - end - - # 提交记录 - def submit_records - records = @my_hack.hack_user_codes - @records_count = records.count - @records = paginate records.created_order - - end - - # 提交记录详情 - def record_detail - @hack_user = HackUserCode.find params[:id] - set = HackSet.find_by(id: @hack_user.error_test_set_id) - @pass_set_count = set ? set.position - 1 : 0 - @set_count = @hack_user.hack.hack_sets.count - @my_hack = @hack_user.hack_user_lastest_code - end - - # 接收中间件返回结果接口 - # 调试模式: status: 0 表示评测无错误,其他 表示错误(如编译出错,执行出错,超时等) - def listen_result - logger.info("###########listen_result:#{params}") - begin - ojEvaResult = JSON.parse(params[:ojEvaResult]) - testCase = ojEvaResult['testCase'] - # 只有编译出错时,才正则匹配错误行数 - error_line= - if ojEvaResult['status'] == "4" || ojEvaResult['status'] == "5" - regular_match_error_line ojEvaResult['outPut'], @my_hack.hack.language - end - # debug 与submit 公用的参数 - - ds_params = {input: testCase['input'], output: testCase['output'], hack_id: @hack.id, - code: ojEvaResult['codeFileContent'], user_id: @my_hack.user_id, error_line: error_line, - status: ojEvaResult['status'], error_msg: ojEvaResult['outPut'], - execute_time: ojEvaResult['executeTime'], execute_memory: ojEvaResult['executeMem']} - ActiveRecord::Base.transaction do - # debug模式与submit模式 - if ojEvaResult['execMode'] == "debug" - save_debug_data ds_params - elsif ojEvaResult['execMode'] == "submit" - save_submit_data ds_params.merge(expected_output: testCase['expectedOutput'], - error_test_set_id: ojEvaResult['failCaseNum']) - end - # 评测完成后,还原评测中的状态 - @my_hack.update_attribute(:submit_status, 0) - end - render_ok - rescue Exception => e - logger.error("#########listen_result: #{e.message}") - end - - end - - def add_notes - @my_hack.update_attribute(:notes, params[:notes]) - render_ok - end - - private - def find_my_hack - @my_hack = HackUserLastestCode.find_by(identifier: params[:identifier]) - @hack = @my_hack.hack - end - - def oj_evaluate exec_mode, error_status, error_msg - request_url = "#{edu_setting('cloud_bridge')}/bridge/ojs/evaluate" - test_sets = - if exec_mode == "submit" - @hack.hack_sets.map{|set| {input: set.input, output: set.output, caseId: set.id}} - else - [{input: params[:input]}] - end - testCases = Base64.encode64(test_sets.to_json) - #codeFileContent = Base64.urlsafe_encode64(@my_hack.code) - debug_params = {execMode: exec_mode, - tpiID: @my_hack.identifier, - testCases: testCases, - platform: @my_hack.language, - codeFileContent: @my_hack.code, - timeLimit: @hack.time_limit, - sec_key: Time.now.to_i} - interface_json_post request_url, debug_params, error_status, error_msg - # 每次评测提交数增加 - @hack.increment!(:submit_num) - end - - # 正则错误行数 - def regular_match_error_line content, language - content = Base64.decode64(content).force_encoding("utf-8") - logger.info("######content: #{content}") - case language - when 'Java' - content.scan(/.java.\d+/).map{|s| s.match(/\d+/)[0].to_i}.min - when 'C', 'C++' - content.scan(/\d:\d+:/).map{|s| s.match(/\d+/)[0].to_i}.min - when 'Python' - content.scan(/line \d+/).map{|s| s.match(/\d+/)[0].to_i}.min - end - end - - # 存储debug数据 - def save_debug_data debug_params - if @my_hack.hack_user_debug.present? - @my_hack.hack_user_debug.update_attributes!(debug_params) - else - debug = HackUserDebug.new(debug_params) - debug.hack_user_lastest_code_id = @my_hack.id - debug.save! - end - end - - # 存储submit数据 - def save_submit_data submit_params - # 通关 - if submit_params[:status] == "0" - # 编程题已经发布,且之前未通关奖励积分 - @hack.increment!(:pass_num) - if @hack.status == 1 && !@my_hack.passed? - reward_attrs = { container_id: @hack.id, container_type: 'Hack', score: @hack.score } - RewardGradeService.call(@my_hack.user, reward_attrs) - RewardExperienceService.call(@my_hack.user, reward_attrs) - # 评测完成更新通过数 - @my_hack.update_attributes(passed: true, passed_time: Time.now) - end - end - # 创建用户评测记录 - logger.info("###########submit_params:#{submit_params}") - query_index = @my_hack.hack_user_codes.count +1 - @my_hack.hack_user_codes.create!(submit_params.merge(query_index: query_index)) - end - - # 调试或提交改变状态 - def update_user_hack_status - @my_hack.update_attribute(:submit_status, 1) - end - - # 只有自己才能改动代码 - def require_identity - if @my_hack.user_id != current_user.id - tip_exception(403, "..") - end - end - - # 老师、自己、管理可以查看他人的编程题 - def require_manager_identity - unless current_user.certification_teacher? || admin_or_business? || @my_hack.user_id == current_user.id - tip_exception(403, "..") - end - end - - # 只有自己才能评测 - def require_auth_identity - unless @my_hack.user_id == current_user.id - tip_exception(403, "..") - end - end - -end diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb deleted file mode 100644 index 6eb454feb..000000000 --- a/app/controllers/hacks_controller.rb +++ /dev/null @@ -1,282 +0,0 @@ -class HacksController < ApplicationController - before_action :require_login, except: [:index] - before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set, :destroy, :cancel_publish] - before_action :require_teacher_identity, only: [:create] - before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set, :destroy, :cancel_publish] - - - # 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可 - def start - # 未发布的编程题,只能作者、或管理员访问 - start_hack_auth - user_hack = @hack.hack_user_lastest_codes.where(user_id: current_user.id).first - logger.info("#user_hack: #{user_hack}") - identifier = - if user_hack.present? - logger.info("#####user_hack_id:#{user_hack.id}") - user_hack.identifier - else - user_identifier = generate_identifier HackUserLastestCode, 12 - user_code = {user_id: current_user.id, code: @hack.code, modify_time: Time.now, - identifier: user_identifier, language: @hack.language} - @hack.hack_user_lastest_codes.create!(user_code) - user_identifier - end - render_ok(identifier: identifier) - end - - # 首页 - def index - # 筛选过滤与排序 - params_filter_or_order - # 我解决的编程题数 - user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed - @simple_count = user_codes.where(hacks: {difficult: 1}).count - @medium_count = user_codes.where(hacks: {difficult: 2}).count - @diff_count = user_codes.where(hacks: {difficult: 3}).count - @pass_count = @simple_count + @medium_count + @diff_count - - @hacks_count = @hacks.count("hacks.id") - @hacks = paginate @hacks - end - - def create - begin - logger.info("##########{hack_params}") - tip_exception("一次只能增加50个测试集") if hack_sets_params.size > 50 - tip_exception("一次只能增加50个知识点") if params[:tags].size > 50 - hack = Hack.new(hack_params) - hack.user_id = current_user.id - hack.identifier = generate_identifier Hack, 8 - tag_params = params[:tags].map{|tag| {tag_discipline_id: tag}} - ActiveRecord::Base.transaction do - hack.save! - # 创建测试集与代码 - hack.hack_sets.create!(hack_sets_params) - # 新建知识点 - hack.tag_discipline_containers.create!(tag_params) if tag_params.present? - hack_codes = hack.hack_codes.new(hack_code_params) - hack_codes.modify_time = Time.now - hack_codes.save! - new_item_params = item_params.merge(container: hack, item_type: 'PROGRAM', difficulty: params[:hack][:difficult], user_id: current_user.id) - ItemBank.create!(new_item_params) - end - render_ok({identifier: hack.identifier}) - rescue => e - logger.error("########create_hack_error: #{e.message}") - render_error("创建失败: #{e.message}") - end - end - - def update - begin - # 知识点 - tag_discipline_ids = @hack.tag_discipline_containers.pluck(:tag_discipline_id) - new_tag_ids = params[:tags].to_a - tag_discipline_ids - tag_params = new_tag_ids.map{|tag| {tag_discipline_id: tag}} - ActiveRecord::Base.transaction do - @hack.update_attributes!(hack_params) - set_ids = @hack.hack_sets.pluck(:id) - # 更新 - param_update_sets params[:update_hack_sets], set_ids - # 新建 - @hack.hack_sets.create!(hack_sets_params) - # 更新代码 - code_params = params[:hack_codes][:code] != @hack.code ? hack_code_params.merge(modify_time: Time.now) : hack_code_params - @hack.hack_codes.first.update_attributes!(code_params) - @hack.tag_discipline_containers.create!(tag_params) if tag_params - @hack.tag_discipline_containers.where.not(tag_discipline_id: params[:tags]).destroy_all - - # 更新题库相关记录 - if @hack.item_bank.present? - update_item_params = item_params.merge({difficulty: params[:hack][:difficult]}) - @hack.item_bank.update!(update_item_params) - end - end - render_ok - rescue Exception => e - logger.error("####update_hack_error: #{e.message}") - render_error("更新失败: #{e.message}") - end - end - - # 更新测试集接口 - def update_set - set = @hack.hack_sets.find_by(id: params[:id]) - set.update_attributes!(hack_set_params) - render_ok - end - - # 单独删除测试集 - def delete_set - set = @hack.hack_sets.find_by(id: params[:id]) - set.destroy! - render_ok - end - - # 发布功能 - def publish - @hack.update_attribute(:status, 1) - base_attrs = { - trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id, - parent_container_type: "HackPublish", extra: @hack.identifier - } - @hack.tidings.create!(base_attrs) - render_ok - end - - # 取消发布 - def cancel_publish - @hack.update_attribute(:status, 0) - base_attrs = { - trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id, - parent_container_type: "HackUnPublish", extra: @hack.identifier - } - @hack.tidings.create!(base_attrs) - render_ok - end - - # 发布列表 - def unpulished_list - limit = params[:limit] || 16 - page = params[:page] || 1 - hacks = Hack.where(user_id: current_user.id, status: 0) - @hacks_count = hacks.count - @hacks = hacks.includes(:hack_sets).page(page).per(limit) - end - - def edit; - end - - def new; - end - - def destroy - begin - base_attrs = { - user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, - parent_container_type: "HackDelete", extra: "#{@hack.name}" - } - @hack.tidings.create!(base_attrs) - @hack.destroy - render_ok - rescue => e - logger.error("####hack_delete_error: #{e.message}") - render_error("删除失败") - end - - end - - private - - # 实名认证老师,管理员与运营人员权限 - def require_teacher_identity - unless current_user.certification_teacher? || admin_or_business? - tip_exception(403, "..") - end - end - - # 只有自己,或者管理员才能更新 - def require_auth_identity - unless @hack.user_id == current_user.id || admin_or_business? - tip_exception(403, "..") - end - end - - def find_hack - @hack = Hack.find_by_identifier(params[:identifier]) - end - - def hack_params - params.require(:hack).permit(:name, :description, :difficult, :open_or_not, :time_limit, :score, :sub_discipline_id) - end - - def item_params - params.require(:hack).permit(:name, :sub_discipline_id) - end - - def hack_sets_params - params.permit(hack_sets: [:input, :output, :position])[:hack_sets] - end - - def hack_set_params - params.require(:hack_set).permit(:id, :input, :output, :position) - end - - def hack_code_params - params.require(:hack_codes).permit(:code, :language) - end - - def publish_params - params.require(:hack).permit(:difficult, :category, :open_or_not, :time_limit, :score) - end - - def param_update_sets sets, all_sets_id - delete_set_ids = all_sets_id - sets.map {|set| set[:id]} - @hack.hack_sets.where(id: delete_set_ids).destroy_all - logger.info("#######sets:#{sets}") - sets.each do |set| - logger.info("###set[:id]: #{set[:id]}") - logger.info("###all_sets: #{all_sets_id.include?(set[:id])}") - if all_sets_id.include?(set[:id]) - update_attrs = {input: set[:input], output: set[:output], position: set[:position]} - @hack.hack_sets.find_by!(id: set[:id]).update_attributes!(update_attrs) - end - end - end - - def params_filter_or_order - # 如果有来源,就不管发布公开私有 - select_sql = "hacks.*, if(hacks.hack_user_lastest_codes_count=0, 0, hacks.pass_num/hacks.hack_user_lastest_codes_count) passed_rate" - if params[:come_from] - hacks = Hack.select(select_sql).mine(current_user.id) - else - # 全部包括已经发布的,和我的未发布的 - if current_user.admin_or_business? - hacks = Hack.select(select_sql) - else - hacks = Hack.select(select_sql).published.opening.or(Hack.select(select_sql).unpublish.mine(current_user.id)) - end - end - # 搜索 - if params[:search] - hacks = hacks.where("name like ?", "%#{params[:search]}%") - end - # 难度 - if params[:difficult] - hacks = hacks.where(difficult: params[:difficult]) - end - # 状态 - if params[:status] - user_hacks = HackUserLastestCode.where(user_id: current_user.id) - if params[:status].to_i == -1 - if user_hacks.present? - hacks = hacks.where.not(id: user_hacks.pluck(:hack_id)) - end - else - hacks = hacks.joins(:hack_user_lastest_codes).where(hack_user_lastest_codes: {status: params[:status]}) - end - end - # 分类 - if params[:category] - hacks = hacks.where(category: params[:category]) - end - - # 语言 - if params[:language] - hacks = hacks.joins(:hack_codes).where(hack_codes: {language: params[:language]}) - end - - # 排序 - sort_by = params[:sort_by] || "hack_user_lastest_codes_count" - sort_direction = params[:sort_direction] || "desc" - @hacks = hacks.order("#{sort_by} #{sort_direction}") - end - - def start_hack_auth - return true if @hack.status == 1 - require_auth_identity - end - - -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb deleted file mode 100644 index d0b8d67d9..000000000 --- a/app/controllers/home_controller.rb +++ /dev/null @@ -1,44 +0,0 @@ -class HomeController < ApplicationController - - def index - # banner图 - images = current_laboratory.portal_images.only_online.order(position: :asc) - images = default_laboratory.portal_images.only_online.order(position: :asc) if images.blank? # 未设置时使用EduCoder的轮播图 - - @images_url = [] - images.each do |image| - @images_url << {path: image.link, image_url: Util::FileManage.source_disk_file_url(image)} - end - - # 目录分级 - @rep_list = current_laboratory.shixun_repertoires - - shixuns = current_laboratory.shixuns - subjects = current_laboratory.subjects - - if current_laboratory.main_site? - shixuns = shixuns.where(homepage_show: true) - subjects = subjects.where(homepage_show: true) - else - shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { homepage: true, laboratory_id: current_laboratory.id}) - subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { homepage: true, laboratory_id: current_laboratory.id}) - end - - @shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8) - @subjects = subjects.includes(:repertoire, :shixuns).limit(8) - - @main_shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(8) - @main_subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(8) - - # if current_laboratory.main_site? - # @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") - # @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") - # end - end - - def search - @fuzzy_searchs = params[:keyword].split(" ").join("%") - @shixuns = Shixun.where("name like ?", "%#{@fuzzy_searchs}%") - @total_count = @shixuns.count - end -end diff --git a/app/controllers/hot_keywords_controller.rb b/app/controllers/hot_keywords_controller.rb deleted file mode 100644 index e0c536e42..000000000 --- a/app/controllers/hot_keywords_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class HotKeywordsController < ApplicationController - def index - keywords = [] - keywords = HotSearchKeyword.hot(8) if HotSearchKeyword.available? - render_ok(keywords: keywords) - end -end \ No newline at end of file diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb deleted file mode 100644 index ea10e865b..000000000 --- a/app/controllers/item_banks_controller.rb +++ /dev/null @@ -1,77 +0,0 @@ -class ItemBanksController < ApplicationController - include PaginateHelper - before_action :require_login - before_action :certi_identity_auth, only: [:create, :edit, :update, :destroy, :set_public] - before_action :find_item, except: [:index, :create] - before_action :edit_auth, only: [:update, :destroy, :set_public] - before_action :identity_auth, only: [:index] - - def index - items = ItemBankQuery.call(params) - @items_count = items.size - @items = paginate items.includes(:item_analysis, :user, :container) - exam = ExaminationBank.find_by(id: params[:exam_id]) if params[:exam_id].present? - exam_setting = ExaminationIntelligentSetting.find_by(id: params[:exam_setting_id]) if params[:exam_setting_id].present? - @item_basket_ids = if exam - exam.examination_items.pluck(:item_bank_id) - elsif exam_setting - exam_setting.item_baskets.pluck(:item_bank_id) - else - current_user.item_baskets.pluck(:item_bank_id) - end - end - - def create - item = ItemBank.new(user: current_user) - ItemBanks::SaveItemService.call(item, form_params) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def edit - - end - - def update - ItemBanks::SaveItemService.call(@item, form_params) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def destroy - ActiveRecord::Base.transaction do - ApplyAction.where(container_type: "ItemBank", container_id: @item.id).destroy_all - if @item.item_type == "PROGRAM" - @item.container&.destroy! - else - @item.destroy! - end - render_ok - end - end - - def set_public - tip_exception(-1, "该试题已公开") if @item.public? - tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @item.id, container_type: 'ItemBank', status: 0).exists? - ApplyAction.create!(container_id: @item.id, container_type: 'ItemBank', user_id: current_user.id) - # @item.update_attributes!(public: 1) - render_ok - end - - private - - def find_item - @item = ItemBank.find_by!(id: params[:id]) - end - - def edit_auth - current_user.admin_or_business? || @item.user == current_user - end - - def form_params - params.permit(:discipline_id, :sub_discipline_id, :item_type, :difficulty, :name, :analysis, tag_discipline_id: [], choices: %i[choice_text is_answer]) - end - -end \ No newline at end of file diff --git a/app/controllers/item_baskets_controller.rb b/app/controllers/item_baskets_controller.rb deleted file mode 100644 index b047e3d78..000000000 --- a/app/controllers/item_baskets_controller.rb +++ /dev/null @@ -1,96 +0,0 @@ -class ItemBasketsController < ApplicationController - before_action :require_login - before_action :certi_identity_auth, only: [:create, :delete_item_type, :destroy, :set_score, :batch_set_score, :adjust_position] - before_action :validate_score, only: [:set_score, :batch_set_score] - helper_method :current_basket - - def index - @item_baskets = basket_items - @single_questions = @item_baskets.where(item_type: "SINGLE") - @multiple_questions = @item_baskets.where(item_type: "MULTIPLE") - @judgement_questions = @item_baskets.where(item_type: "JUDGMENT") - @program_questions = @item_baskets.where(item_type: "PROGRAM") - end - - def basket_list - @basket_count = current_user.item_baskets.group(:item_type).count - end - - def create - ItemBaskets::SaveItemBasketService.call(current_user, create_params, exam_setting) - render_ok - rescue ApplicationService::Error => ex - render_error(ex.message) - end - - def destroy - item = basket_items.find_by!(item_bank_id: params[:id]) - ActiveRecord::Base.transaction do - basket_items.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1") - item.destroy! - end - render_ok - end - - def delete_item_type - baskets = basket_items.where(item_type: params[:item_type]) - baskets.destroy_all - render_ok - end - - def set_score - current_basket.update_attributes!(score: params[:score]) - @questions_score = basket_items.where(item_type: current_basket.item_type).pluck(:score).sum - @all_score = basket_items.pluck(:score).sum - end - - def batch_set_score - basket_items.where(item_type: params[:item_type]).update_all(score: params[:score]) - @questions_score = basket_items.where(item_type: params[:item_type]).pluck(:score).sum - @all_score = basket_items.pluck(:score).sum - end - - def adjust_position - same_items = basket_items.where(item_type: current_basket.item_type) - max_position = same_items.size - tip_exception("position超出范围") unless params[:position].present? && params[:position].to_i <= max_position && params[:position].to_i >= 1 - ActiveRecord::Base.transaction do - if params[:position].to_i > current_basket.position - same_items.where("position > #{current_basket.position} and position <= #{params[:position].to_i}").update_all("position=position-1") - current_basket.update_attributes!(position: params[:position]) - elsif params[:position].to_i < current_basket.position - same_items.where("position < #{current_basket.position} and position >= #{params[:position].to_i}").update_all("position=position+1") - current_basket.update_attributes!(position: params[:position]) - else - return normal_status(-1, "排序无变化") - end - end - render_ok - end - - private - - def create_params - params.permit(item_ids: []) - end - - def exam_setting - @_exam_setting = ExaminationIntelligentSetting.find_by(id: params[:exam_setting_id]) - end - - def basket_items - @_items = params[:exam_setting_id] ? exam_setting.item_baskets : current_user.item_baskets - end - - def current_basket - @_current_basket = ItemBasket.find_by!(id: params[:id]) - tip_exception(403, "无权限编辑") unless current_user.admin_or_business? || @_current_basket.user_id.to_i == current_user.id || - @_current_basket.examination_intelligent_setting&.user_id.to_i == current_user.id - @_current_basket - end - - def validate_score - tip_exception("分值不能为空") unless params[:score].present? - tip_exception("分值需大于0") unless params[:score].to_f > 0 - end -end \ No newline at end of file diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb deleted file mode 100644 index c0ea8d601..000000000 --- a/app/controllers/memos_controller.rb +++ /dev/null @@ -1,199 +0,0 @@ -class MemosController < ApplicationController - before_action :require_login, except: [:show, :index] - before_action :check_account, only: [:new, :create, :reply] - before_action :set_memo, only: [:show, :edit, :update, :destroy, :sticky_or_cancel, :hidden, :more_reply] - before_action :validate_memo_params, only: [:create, :update] - before_action :owner_or_admin, only: [:edit, :update, :destroy] - before_action :require_business, only: [:sticky_or_cancel, :hidden] - - include ApplicationHelper - # GET /memos - # GET /memos.json - def index - @user = current_user - @memos = Memo.all - s_order = (params[:order] == "replies_count" ? "all_replies_count" : params[:order]) || "updated_at" - # @tidding_count = unviewed_tiddings(current_user) if current_user.present? - page = params[:page] || 1 - limit = params[:limit] || 15 - search = params[:search] - forum_id = params[:forum] - tag_repertoire_id = params[:tag_repertoire_id] - - sql = - if forum_id - !search.blank? ? "forum_id = #{forum_id} and root_id is null and subject like '%#{search}%'" : - "forum_id = #{forum_id} and root_id is null" - elsif !search.blank? - "forum_id in(3, 5, 16) and root_id is null and subject like '%#{search}%'" - else - "forum_id in(3, 5, 16) and root_id is null" - end - - if tag_repertoire_id - memo_ids = MemoTagRepertoire.where(tag_repertoire_id: tag_repertoire_id).pluck(:memo_id) - memo_ids = memo_ids ? memo_ids.join(",") : -1 - sql += " and #{Memo.table_name}.id in(#{memo_ids})" - end - - if params[:order] == "updated_at" - sql += " and all_replies_count != 0" - end - - memos = Memo.field_for_list.where("#{sql}") - @memos_count = memos.length - @memos = memos.order("sticky = 1 desc, #{Memo.table_name}.#{s_order} desc").page(page).per(limit) - @memos = @memos.includes(:praise_treads, :tag_repertoires, author: :user_extension) - # @my_memos_count = Memo.user_posts(current_user.try(:id)).count - @tags_info = MemoTagRepertoire.find_by_sql("SELECT tag_repertoire_id, tr.name, count(*) cnt - FROM memo_tag_repertoires mtr join tag_repertoires tr on - tr.id = mtr.tag_repertoire_id group by tag_repertoire_id order by cnt desc, - tag_repertoire_id desc limit 9") - @hot_memos = Memo.field_for_recommend.posts.hot.includes(:tag_repertoires).limit(4) - @recommend_shixuns = DiscussesService.new.recommends - end - - # GET /memos/1.json - def show - # tidding_count = unviewed_tiddings(current_user) if current_user - @user = current_user - @memo.update_column(:viewed_count, @memo.viewed_count+1) - @memos = @memo.reply_for_memo.includes(:praise_treads, author: :user_extension).order("created_at desc").limit(10) - @attachments = @memo.attachments - @recommend_shixuns = DiscussesService.new.recommends - end - - # GET /memos/new - def new - @tag_list = TagRepertoire.field_for_list.order("name asc") - end - - # GET /memos/1/edit - def edit - @tag_list = TagRepertoire.field_for_list.order("name asc") - @memo_tags = @memo.tag_repertoires.field_for_list - @attachments = @memo.attachments - end - - # POST /memos.json - def create - ActiveRecord::Base.transaction do - begin - @memo = Memo.new(memo_params) - @memo.author = current_user - @memo.save! - Attachment.associate_container(params[:attachment_ids], @memo.id, @memo.class.name) - params[:tags].each do |tag| - MemoTagRepertoire.create!(memo_id: @memo.id, tag_repertoire_id: tag) - end - render :json => {memo_id: @memo.id, status: 0, message: "帖子创建成功"} - rescue Exception => e - tip_exception("帖子创建失败,原因:#{e}") - raise ActiveRecord::Rollback - end - end - end - - # PATCH/PUT /memos/1.json - def update - ActiveRecord::Base.transaction do - begin - @memo.update_attributes!(memo_params) - Attachment.associate_container(params[:attachment_ids], @memo.id, @memo.class.name) - @memo.memo_tag_repertoires.destroy_all - params[:tags].each do |tag| - MemoTagRepertoire.create!(memo_id: @memo.id, tag_repertoire_id: tag) - end - normal_status("帖子更新成功") - rescue Exception => e - tip_exception("帖子更新失败,原因:#{e}") - raise ActiveRecord::Rollback - end - end - end - - # DELETE /memos/1 - # DELETE /memos/1.json - def destroy - @memo.destroy - normal_status("删除成功") - end - - def sticky_or_cancel - tip_exception("只能对主贴进行置顶操作") unless @memo.parent_id.nil? - begin - @memo.update_attributes!(sticky: !@memo.sticky) - normal_status("更新成功") - rescue Exception => e - tip_exception("更新失败,原因:#{e}") - raise ActiveRecord::Rollback - end - end - - def hidden - tip_exception("不能对主贴进行隐藏操作") if @memo.parent_id.nil? - begin - @memo.update_attributes!(hidden: @memo.hidden == 0 ? 1 : 0) - normal_status("更新成功") - rescue Exception => e - tip_exception("更新失败,原因:#{e}") - raise ActiveRecord::Rollback - end - end - - def reply - tip_exception("parent_id不能为空") if params[:parent_id].blank? - tip_exception("content不能为空") if params[:content].blank? - tip_exception("内容不能超过2000字符") if params[:content].length > 2000 - - ActiveRecord::Base.transaction do - begin - memo = Memo.find_by!(id: params[:parent_id]) - @reply = Memo.new - @reply.content = params[:content] - @reply.author = current_user - @reply.forum_id = memo.forum_id - @reply.subject = memo.subject - @reply.root_id = memo.root_id || memo.id - memo.children << @reply - m = Memo.find_by!(id: @reply.root_id) - m.update_attributes!(all_replies_count: m.all_replies_count + 1) - rescue Exception => e - tip_exception("回复失败,原因:#{e}") - raise ActiveRecord::Rollback - end - end - end - - def more_reply - @user = current_user - page = params[:page] || 2 - limit = params[:limit] || 10 - offset = (page.to_i - 1) * limit - @memos_count = Memo.where(parent_id: @memo.id).count - @memos = Memo.limit(limit).where(parent_id: @memo.id).includes(:author, :praise_treads).order("created_at desc").offset(offset) - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_memo - @memo = Memo.find(params[:id]) - end - - def owner_or_admin - tip_exception(403, "无权限操作") unless @memo.author == current_user || current_user.admin? || current_user.business? - end - - # Never trust parameters from the scary internet, only allow the white list through. - def memo_params - params.require(:memo).permit(:subject, :content, :forum_id) - end - - def validate_memo_params - tip_exception("话题名称不能为空") if params[:subject].blank? - tip_exception("话题内容不能为空") if params[:content].blank? - tip_exception("话题类型不能为空") if params[:forum_id].blank? - tip_exception("技术标签不能为空") if params[:forum_id].to_i == 5 && params[:tags].blank? - end - -end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb deleted file mode 100644 index 0e28ccb4f..000000000 --- a/app/controllers/messages_controller.rb +++ /dev/null @@ -1,225 +0,0 @@ -class MessagesController < ApplicationController - include MessagesHelper - - SORT_TYPE = %w[time hot] - - before_action :require_login, :check_auth, only: %i[create update sticky_top bulk_delete create destroy bulk_send bulk_move bulk_public] - before_action :find_board, only: [:create, :index, :bulk_delete, :bulk_move, :bulk_send, :bulk_public] - before_action :find_message, only: [:update, :destroy, :sticky_top, :reply_list, :destroy, :reply] - before_action :validate_delete_params, only: %i[bulk_delete bulk_public] - before_action :message_validate_create_params, only: :create - before_action :validate_update_params, only: :update - before_action :validate_sort_type, only: :index - before_action :validate_send_message_to_course_params, only: :bulk_send - before_action :validate_move_params, only: :bulk_move - - def index - @page = params[:page] || 1 - @page_size = params[:page_size] || 15 - - sort = params[:sort].to_i == 1 ? 'asc' : 'desc' - sort_type = params[:sort_type] || 'time' - - if @board.parent_id == 0 - messages = Message.where(board_id: @board.course.boards.pluck(:id)) - else - messages = @board.messages - end - messages = messages.root_nodes.by_keywords(params[:search]) - - messages = messages.reorder('(sticky = 1) DESC') # 置顶 - - messages = - case sort_type - when 'time' then messages.order("created_on #{sort}") - when 'hot' then messages.order("descendants_count #{sort}") - else messages.order("created_on #{sort}") - end - - messages = messages.includes(:author, :board) - @messages = Kaminari.paginate_array(messages).page(@page).per(@page_size) - - ids = @messages.map(&:id) - @praises_count_map = Message.where(root_id: ids).group(:root_id).sum(:praises_count) - end - - def reply_list - @page = params[:page] || 1 - @page_size = params[:page_size] || 10 - @current_user = current_user || nil - - @messages = @message.children.preload_messages.includes(:message_detail, :praise_treads) - # @messages = @messages.ordered(sort: 1) unless @message.parent_id.nil? - - @user_course_identity = current_user.course_identity(@message.board.course) - case @user_course_identity - when 5, 6, 7 - @messages = @messages.visible - end - - @messages = @messages.reorder("messages.created_on desc") - @messages = @messages.page(@page).per(@page_size) - end - - def reply - return normal_status(-1, "回复内容不能为空") if params[:content].blank? - return normal_status(-1, "回复内容不能超过2000字符") if params[:content].length > 2000 - @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id, - author: current_user, parent: @message, - message_detail_attributes: { - content: params[:content] - }) - end - - def sticky_top - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@message.board.course) - - @message.update_attributes(:sticky => @message.sticky == 1 ? 0 : 1) - end - - def bulk_delete - ActiveRecord::Base.transaction do - begin - @messages = @board.messages.by_ids(params[:ids]) - @messages.destroy_all - rescue Exception => e - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - end - - def new - @message = Message.new - end - - def show - @message = Message.includes(:attachments, :message_detail, - :children, :author => :user_extension, - :board => [{course: :board_course_modules}]) - .find_by_id params[:id] - return normal_status(-2, "ID为#{params[:id]}的帖子不存在") if @message.nil? - - @attachment_size = @message.attachments.size - @message.update_visits - @current_user = current_user - end - - def update - return normal_status(403, "您没有权限进行该操作") if current_user != @message.author && !current_user.teacher_of_course?(@message.board.course) - - begin - board = @message.board&.course&.boards.find_by!(id: params[:select_board_id]) - - email_notify = @message.email_notify ? 1 : @message.board&.course.email_notify && params[:email_notify] - send_email = !@message.email_notify && email_notify - h = {is_md: true, email_notify: email_notify, board_id: board&.id} - m_params = message_params.merge(h) - @message.update_attributes(m_params) - Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) - @message.update_content(params[:content]) - notify_course_students(@message, @message.board&.course) if send_email - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def create - return normal_status(403, "您没有权限进行该操作") unless current_user.admin_or_business? || current_user.member_of_course?(@board.course) - - begin - @message = Message.new(message_params) - @message.author = current_user - @message.board_id = params[:select_board_id] - @message.message_detail_attributes = {content: params[:content]} - @message.email_notify = @board.course.email_notify && params[:email_notify] ? 1 : 0 - @message.save! - Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) - if @board.course.email_notify && params[:email_notify] - notify_course_students @message, @board.course - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def destroy - begin - return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@message.board.course) >= 5 || @message.author != current_user - @message.destroy! - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def bulk_send - return normal_status(403) unless current_user.teacher_or_admin?(@board.course) - ids = params[:ids] - course_ids = params[:to_course_ids] - - begin - ids.each do |id| - @message = Message.find_by_id id - if @message.try(:parent_id).nil? # TODO 暂时只支持目录下的跟节点发送 - course_ids.each do |course_id| - course = Course.find course_id - new_message = Message.create!(board: course.course_board, - subject: @message.subject, - author: current_user, - message_detail_attributes: { - content: @message.try(:message_detail).try(:content) - } - ) - @message.copy_attachments_to_new_message(new_message, current_user) - end - end - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - def bulk_move - # 课堂的目录之间移动,有子栏目的才显示此项 - return normal_status(403) unless current_user.teacher_of_course?(@board.course) - - Message.bulk_move_to_other_board(params[:ids], params[:to_board_id]) - end - - def bulk_public - @messages = @board.messages.root_nodes.by_ids Array(params[:ids]) - @messages.update_all(is_public: true) - end - - private - def validate_sort_type - normal_status(2, "参数sort_type暂时只支持 'time', 'hot'两种") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) - end - - def find_message - begin - @message = Message.find params[:id] - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - end - end - - def message_params - params.require(:message).permit(:subject, :sticky) - end - - def notify_course_students message, course - course.students.includes(:user).each do |student| - UserMailer.course_message_email(student&.user&.mail, message.id).deliver_later if student&.user&.mail - end - end -end diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb deleted file mode 100644 index dfa1b2017..000000000 --- a/app/controllers/partners_controller.rb +++ /dev/null @@ -1,138 +0,0 @@ -class PartnersController < ApplicationController - skip_before_action :check_sign - include Base::PaginateHelper - include Admins::RenderHelper - - layout 'college' - - before_action :require_login, :check_partner_present!, :check_permission! - before_action :check_admin_manager_group_permission!, except: [:customers] - - helper_method :current_partner, :manager_permission? - - def customers - customers = CustomerQuery.call(current_partner, current_user, params) - @customers = paginate(customers.includes(:school)) - - load_customer_extra_statistic_data - end - - def partner_manager_groups - @manager_groups = current_partner.partner_manager_groups.includes(users: :user_extension).to_a - end - - def manager_group - name = params[:manager_group_name].to_s.strip - - if params[:manager_group_id].present? - # 重命名 - @manager_group = current_partner.partner_manager_groups.find(params[:manager_group_id]) - return render_error('不能修改管理者权限组名称') if @manager_group.admin? - @manager_group.update!(name: name) - else - # 新建 - @manager_group = current_partner.partner_manager_groups.create!(name: name) - end - end - - def remove_manager_group - manager_group = current_partner.partner_manager_groups.find(params[:manager_group_id]) - return render_error('不能删除管理者权限组') if manager_group.admin? - manager_group.destroy! - - render_delete_success - end - - def partner_managers - user_ids = Array.wrap(params[:user_ids]) - @manager_group = current_partner.partner_manager_groups.find(params[:manager_group_id]) - - ActiveRecord::Base.transaction do - User.where(id: user_ids).pluck(:id).each do |user_id| - next if current_partner.partner_managers.exists?(partner_manager_group: @manager_group, user_id: user_id) - - current_partner.partner_managers.create!(partner_manager_group: @manager_group, user_id: user_id) - end - end - - @manager_group.reload - end - - def remove_partner_manager - partner_manager = current_partner.partner_managers.find(params[:manager_id]) - return render_error('不能删除自己') if partner_manager.user_id == current_user.id && partner_manager.partner_manager_group.admin? - - partner_manager.destroy! - - render_delete_success - end - - def customer_manager_group - customer = current_partner.customers.find(params[:customer_id]) - - if params[:manager_group_id].present? - manager_group = current_partner.partner_manager_groups.find(params[:manager_group_id]) - customer.update!(partner_manager_group: manager_group) - else - customer.update!(partner_manager_group_id: nil) - end - - render_ok - end - - private - - def current_partner - @_current_partner ||= Partner.find(params[:id].presence || params[:partner_id]) - end - - def check_partner_present! - return if current_partner.present? - - redirect_to '/404' - end - - def manager_permission? - admin_or_business? || current_user.partner_managers.exists?(partner_id: current_partner.id) - end - - def check_permission! - return if manager_permission? - - redirect_to '/403' - end - - def check_admin_manager_group_permission! - return if admin_or_business? - return if current_partner.admin_partner_manager_group.partner_managers.exists?(user: current_user) - - render_forbidden - end - - def load_customer_extra_statistic_data - school_ids = @customers.map(&:school_id) - - teacher_map = UserExtension.where(school_id: school_ids, identity: 0).group(:school_id).count - student_map = UserExtension.where(school_id: school_ids, identity: 1).group(:school_id).count - course_map = Course.where(school_id: school_ids, is_delete: 0).where.not(id: 1309).group(:school_id).count - shixun_map = Shixun.visible.joins('left join user_extensions on user_extensions.user_id = shixuns.user_id') - .where(user_extensions: { school_id: school_ids }).group('user_extensions.school_id').count - shixun_report_map = StudentWork.where(work_status: [1, 2]).where('myshixun_id != 0') - .joins('left join user_extensions on user_extensions.user_id = student_works.user_id') - .where(user_extensions: { school_id: school_ids }) - .group('user_extensions.school_id').count - course_time_map = Course.where(school_id: school_ids, is_delete: 0) - .where.not(id: 1309).group(:school_id).maximum(:updated_at) - - @customers.each do |customer| - customer._extra_data = { - teacher_count: teacher_map[customer.school_id], - student_count: student_map[customer.school_id], - course_count: course_map[customer.school_id], - shixun_count: shixun_map[customer.school_id], - shixun_report_count: shixun_report_map[customer.school_id], - course_time: course_time_map[customer.school_id] - } - end - end -end \ No newline at end of file diff --git a/app/controllers/repertoires_controller.rb b/app/controllers/repertoires_controller.rb deleted file mode 100644 index b62c94403..000000000 --- a/app/controllers/repertoires_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RepertoiresController < ApplicationController - def index - render_ok(repertoires: Repertoire.select(:id, :name).order(:created_at).as_json) - end -end \ No newline at end of file diff --git a/app/controllers/sync_forge_controller.rb b/app/controllers/sync_forge_controller.rb deleted file mode 100644 index ea4132947..000000000 --- a/app/controllers/sync_forge_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SyncForgeController < ApplicationController - skip_before_action :user_setup - skip_before_action :check_sign - - def create - SyncForgeJob.perform_later(params[:sync_params]) - end - -end \ No newline at end of file diff --git a/app/controllers/tag_disciplines_controller.rb b/app/controllers/tag_disciplines_controller.rb deleted file mode 100644 index c80071824..000000000 --- a/app/controllers/tag_disciplines_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -class TagDisciplinesController < ApplicationController - before_action :require_login - - def create - sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id]) - tip_exception("重复的知识点") if sub_discipline.tag_disciplines.exists?(name: params[:name].to_s.strip) - tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id, - position: sub_discipline.tag_disciplines.pluck(:position).max + 1) - render_ok({tag_discipline_id: tag_discipline.id}) - end -end \ No newline at end of file diff --git a/app/controllers/tem_tests_controller.rb b/app/controllers/tem_tests_controller.rb deleted file mode 100644 index a3336f3b2..000000000 --- a/app/controllers/tem_tests_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class TemTestsController < ApplicationController - before_action :set_tem_test, only: [:show, :edit, :update, :destroy] - - # GET /tem_tests - # GET /tem_tests.json - def index - @tem_tests = TemTest.all - end - - # GET /tem_tests/1 - # GET /tem_tests/1.json - def show - end - - # GET /tem_tests/new - def new - @tem_test = TemTest.new - end - - # GET /tem_tests/1/edit - def edit - end - - # POST /tem_tests - # POST /tem_tests.json - def create - @tem_test = TemTest.new(tem_test_params) - - respond_to do |format| - if @tem_test.save - format.html { redirect_to @tem_test, notice: 'Tem test was successfully created.' } - format.json { render :show, status: :created, location: @tem_test } - else - format.html { render :new } - format.json { render json: @tem_test.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /tem_tests/1 - # PATCH/PUT /tem_tests/1.json - def update - respond_to do |format| - if @tem_test.update(tem_test_params) - format.html { redirect_to @tem_test, notice: 'Tem test was successfully updated.' } - format.json { render :show, status: :ok, location: @tem_test } - else - format.html { render :edit } - format.json { render json: @tem_test.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /tem_tests/1 - # DELETE /tem_tests/1.json - def destroy - @tem_test.destroy - respond_to do |format| - format.html { redirect_to tem_tests_url, notice: 'Tem test was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_tem_test - @tem_test = TemTest.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def tem_test_params - params.require(:tem_test).permit(:name, :email) - end -end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb deleted file mode 100644 index efb114bdc..000000000 --- a/app/controllers/templates_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class TemplatesController < ApplicationController - def show - @template = EcTemplate.find_by_name!(params[:name]) - end -end \ No newline at end of file diff --git a/app/controllers/tidings_controller.rb b/app/controllers/tidings_controller.rb deleted file mode 100644 index 0a0b78cc8..000000000 --- a/app/controllers/tidings_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -class TidingsController < ApplicationController - include PaginateHelper - - before_action :require_login - after_action :update_onclick_time!, only: [:index] - - def index - tidings = current_user.tidings.visible - @onclick_time = current_user.click_time - - tiding_types = - case params[:type] - when 'notice' then 'System' - when 'apply' then 'Apply' - when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic) - when 'project' then 'Project' - when 'interaction' then %w(Comment Mentioned Praise Fan) - when 'project_package' then %w(Created Destroyed Bidding BiddingEnd BiddingWon BiddingLost) - end - tidings = tidings.where(tiding_type: tiding_types) if tiding_types.present? - - tidings = tidings.where(container_type: 'JoinCourse', status: 0) if params[:type] == 'course_apply' - # @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count - @course_apply_count = tidings.where(container_type: 'JoinCourse', status: 0).count - - tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package' - - @count = tidings.count - @tidings = paginate(tidings.order(created_at: :desc), per_page: 10) - end - - private - - def update_onclick_time! - current_user.onclick_time.touch(:onclick_time) - end -end diff --git a/app/controllers/trial_applies_controller.rb b/app/controllers/trial_applies_controller.rb deleted file mode 100644 index acfde75da..000000000 --- a/app/controllers/trial_applies_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -class TrialAppliesController < ApplicationController - before_action :require_user_login - - def create - Users::ApplyTrailService.call(current_user, create_params) - render_ok - rescue Users::ApplyTrailService::Error => ex - render_error(ex.message) - end - - private - - def create_params - params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip) - end - - def require_user_login - return if User.current.logged? - - render_unauthorized - end -end diff --git a/app/controllers/trustie_hacks_controller.rb b/app/controllers/trustie_hacks_controller.rb deleted file mode 100644 index 462a5a057..000000000 --- a/app/controllers/trustie_hacks_controller.rb +++ /dev/null @@ -1,72 +0,0 @@ -class TrustieHacksController < ApplicationController - before_action :require_admin, :except => [:index, :entry] - before_action :require_login, :except => [:index] - before_action :find_hackathon - before_action :find_hack, :except => [:create, :index, :edit_hackathon, :update_hackathon] - - def index - ## 分页参数 - page = params[:page] || 1 - limit = params[:limit] || 16 - search = params[:search] - hacks = @hackathon.trustie_hacks - - if search - hacks = hacks.where("name like ?", "%#{search}%") - end - - @hackathon_users_count = hacks.blank? ? 0 : hacks.sum(:hack_users_count) - @hacks_count = hacks.count - - @hacks = hacks.page(page).per(limit) - - end - - def edit;end - - def create - @hackathon.trustie_hacks.create!(name: params[:name], description: params[:description]) - render_ok - end - - def update - @hack.update_attributes(name: params[:name], description: params[:description]) - render_ok - end - - def destroy - @hack.destroy - render_ok - end - - def edit_hackathon - end - - def update_hackathon - @hackathon.update_attributes(name: params[:name], description: params[:description]) - render_ok - end - - # 报名入口 - def entry - if @hack.hack_users.exists?(user_id: current_user.id) - render_error('已经报名,请勿重复操作') - else - @hack.hack_users.create(user_id: current_user.id) - render_ok - end - end - - - private - - def find_hackathon - @hackathon = TrustieHackathon.first || - TrustieHackathon.create!(name: params[:name], description: params[:description]) - end - - def find_hack - @hack = TrustieHack.find params[:id] - end - -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9d63a712c..e722d681d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController - before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd] + before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects] before_action :check_user_exist, only: [:show, :homepage_info] before_action :require_login, only: %i[me list projects] skip_before_action :check_sign, only: [:attachment_show] @@ -113,7 +113,7 @@ class UsersController < ApplicationController end def projects - scope = Projects::ListMyQuery.call(params.merge(category: params[:category],is_public: params[:status]), current_user) + scope = Projects::ListMyQuery.call(params.merge(category: params[:category],is_public: params[:status]), @user) @total_count = scope.size @projects = paginate(scope) end diff --git a/app/controllers/users_for_partners_controller.rb b/app/controllers/users_for_partners_controller.rb deleted file mode 100644 index 409dacc3f..000000000 --- a/app/controllers/users_for_partners_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -class UsersForPartnersController < ApplicationController - include Base::PaginateHelper - - before_action :check_partner_manager_permission! - - def index - params[:sort_by] = params[:sort_by].presence || 'created_on' - params[:sort_direction] = params[:sort_direction].presence || 'desc' - - users = Admins::UserQuery.call(search_params) - @users = paginate users.includes(user_extension: :school) - end - - private - - def search_params - params.permit(:name, :sort_by, :sort_direction) - end - - def check_partner_manager_permission! - partner = Partner.find(params[:partner_id]) - return if admin_or_business? - return if partner.admin_partner_manager_group.partner_managers.exists?(user: current_user) - - render_forbidden - end -end \ No newline at end of file diff --git a/app/controllers/wechats/js_sdk_signatures_controller.rb b/app/controllers/wechats/js_sdk_signatures_controller.rb deleted file mode 100644 index 4ed1680b0..000000000 --- a/app/controllers/wechats/js_sdk_signatures_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Wechats::JsSdkSignaturesController < ApplicationController - def create - timestamp = Time.now.to_i - noncestr = ('A'..'z').to_a.sample(8).join - signature = Wechat::OfficialAccount.js_sdk_signature(params[:url], noncestr, timestamp) - - render_ok(appid: Wechat::OfficialAccount.appid, timestamp: timestamp, noncestr: noncestr, signature: signature) - rescue Wechat::Error => ex - render_error(ex.message) - end -end \ No newline at end of file diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb deleted file mode 100644 index 3deeaa97e..000000000 --- a/app/models/apply_add_department.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ApplyAddDepartment < ApplicationRecord - belongs_to :user - belongs_to :school - belongs_to :department - - has_many :applied_messages, as: :applied - has_many :tidings, as: :container, dependent: :destroy - - after_create :send_notify - - private - def send_notify - tidings.create!(user_id: 1, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply', status: 0) - end -end \ No newline at end of file diff --git a/app/models/apply_add_school.rb b/app/models/apply_add_school.rb deleted file mode 100644 index ac7c880cd..000000000 --- a/app/models/apply_add_school.rb +++ /dev/null @@ -1,22 +0,0 @@ -class ApplyAddSchool < ApplicationRecord - belongs_to :school - belongs_to :user - - has_many :applied_messages, as: :applied - has_many :tidings, as: :container, dependent: :destroy - - after_create :send_notify - # after_destroy :after_delete_apply - - private - - def send_notify - Tiding.create!(user_id: 1, status: 0, container_id: id, container_type: 'ApplyAddSchools', - trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply') - end - - # def after_delete_apply - # - # end - -end \ No newline at end of file diff --git a/app/models/attachment_group_setting.rb b/app/models/attachment_group_setting.rb index 3fefe5ceb..b7eb707f4 100644 --- a/app/models/attachment_group_setting.rb +++ b/app/models/attachment_group_setting.rb @@ -1,7 +1,7 @@ class AttachmentGroupSetting < ActiveRecord::Base belongs_to :attachment - belongs_to :course_group - belongs_to :course + # belongs_to :course_group + # belongs_to :course scope :none_published, -> {where("attachment_group_settings.publish_time IS NULL OR attachment_group_settings.publish_time > ?", Time.now)} diff --git a/app/models/attendance.rb b/app/models/attendance.rb deleted file mode 100644 index ffe3f63a1..000000000 --- a/app/models/attendance.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Attendance < ApplicationRecord - belongs_to :user - - default_scope { order(created_at: :desc) } - - def next_gold - # 超过1天即没有连续的签到则又从10个金币开始累加 - return 50 if Util.days_between(Time.zone.now, created_at) > 1 - - [[score.to_i, 50].max + 10, 100].min - end - - def today? - Util.days_between(Time.current, created_at).zero? - end -end diff --git a/app/models/career.rb b/app/models/career.rb deleted file mode 100644 index b7b6f11a1..000000000 --- a/app/models/career.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Career < ApplicationRecord -end diff --git a/app/models/challenge.rb b/app/models/challenge.rb deleted file mode 100644 index 70fac990b..000000000 --- a/app/models/challenge.rb +++ /dev/null @@ -1,150 +0,0 @@ -class Challenge < ApplicationRecord - # difficulty: 关卡难度: 1.简单 2.中等 3.困难 - # show_type: 效果展示:-1.无效果 1.图片 2.apk/exe 3.txt 4.html 5.mp3 6.mp4 - - belongs_to :shixun, :touch => true, counter_cache: true - belongs_to :user - has_many :challenge_samples, :dependent => :destroy - has_many :test_sets, :dependent => :destroy - has_many :challenge_tags, :dependent => :destroy - has_many :games, :dependent => :destroy - has_many :challenge_chooses, :dependent => :destroy - has_many :homework_challenge_settings, :dependent => :destroy - has_many :praise_treads, as: :praise_tread_object, dependent: :destroy - has_one :praise_tread_cache, as: :object, dependent: :destroy - has_many :tidings - # 参考答案 - has_many :challenge_answers, :dependent => :destroy - has_many :exercise_bank_shixun_challenges, :dependent => :destroy - # 回复 - has_many :discusses, :dependent => :destroy - - # acts_as_attachable - - scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer, :exec_time, :praises_count]) } - scope :choose_type, -> { where(st: 1) } - scope :practice_type, -> { where(st: 0) } - - scope :fields_for_list, -> { select([:id, :subject, :st, :score, :position, :shixun_id]) } - - validates :task_pass, length: { maximum: 35000, too_long: "不能超过35000个字符" } - - - after_commit :create_diff_record - - def next_challenge - position = self.position + 1 - Challenge.where(:position => position, :shixun_id => self.shixun).first - end - - # 用户关卡是否通关 - def has_passed?(user_id) - self.games.present? && self.games.select{|game| game.user_id == user_id && game.status == 2}.length > 0 - end - - ## 选择题总分 - def choose_score - self.score - #self.challenge_chooses.pluck(:score).sum - end - - def challenge_difficulty - case difficulty - when 1 then "简单" - when 2 then "中等" - when 3 then "困难" - else '' - end - end - - # 关卡总分 - def all_score - self.score - # if self.st == 1 - # self.choose_score - # else - # self.score - # end - end - - # 开启挑战 - def open_game user_id, shixun - game = self.games.where(user_id: user_id).first - if game.present? - shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" - else - "/api/shixuns/#{shixun.identifier}/shixun_exec" - end - end - - # # 开启挑战 - # def open_game(user_id, shixun) - # - # - # game = self.games.select([:status, :identifier]).where(user_id: user_id).first - # game = self.games.select{|game| game.user_id == user_id} - # if game.present? - # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" - # else - # "/api/shixuns/#{shixun.identifier}/shixun_exec" - # end - # end - - ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 - def user_tpi_status user_id - # todo: 以前没加索引导致相同关卡,同一用户有多个games - # 允许跳关则直接开启 - game = games.where(user_id: user_id).take - if game.blank? - position == 1 ? 1 : 0 - else - if game.status == 3 - shixun.task_pass ? 1 : 0 - elsif game.status == 2 - 2 - else - 1 - end - end - end - - def tags_show - if self.challenge_tags.nil? - "--" - else - self.try(:challenge_tags).map(&:name).join(";") - end - end - - ## 选择题答案 - def choose_answer - result = [] - self.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - end - - # 关卡用户通关数 - def user_passed_count - games.where(status: 2).count - end - - # 关卡用户正在挑战的人数 - def playing_count - games.where(status: [0, 1]).count - end - - def last_challenge - Challenge.find_by(position: position - 1, shixun_id: shixun_id) - end - - # 关卡评测文件 - - private - - def create_diff_record - return unless task_pass_previously_changed? - CreateDiffRecordJob.perform_later(User.current.id, id, 'Challenge', 'task_pass', task_pass_before_last_save, task_pass) - end -end diff --git a/app/models/challenge_answer.rb b/app/models/challenge_answer.rb deleted file mode 100644 index 8196a7b7e..000000000 --- a/app/models/challenge_answer.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ChallengeAnswer < ApplicationRecord - default_scope { order("challenge_answers.level asc") } - belongs_to :challenge - has_many :game_answers, :dependent => :destroy - - validates :contents, length: { maximum: 25000 , too_long: "不能超过25000个字符"} - - def view_answer_time(user_id) - game_answers.where(user_id: user_id).last&.view_time - end -end diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb deleted file mode 100644 index bedddea07..000000000 --- a/app/models/challenge_choose.rb +++ /dev/null @@ -1,9 +0,0 @@ -class ChallengeChoose < ApplicationRecord - default_scope {order("challenge_chooses.position asc")} - belongs_to :challenge, optional: true - has_many :challenge_tags, :dependent => :destroy - has_many :challenge_questions, dependent: :destroy - - validates :subject, length: { maximum: 25000, too_long: "不能超过25000个字符" } - -end diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb deleted file mode 100644 index d5c26d90e..000000000 --- a/app/models/challenge_question.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ChallengeQuestion < ApplicationRecord - belongs_to :challenge_choose - - validates :option_name, length: { maximum: 500, too_long: "不能超过500个字符" } - -end diff --git a/app/models/challenge_sample.rb b/app/models/challenge_sample.rb deleted file mode 100644 index e523a8087..000000000 --- a/app/models/challenge_sample.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ChallengeSample < ApplicationRecord - belongs_to :challenge -end - diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb deleted file mode 100644 index acea39770..000000000 --- a/app/models/challenge_tag.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ChallengeTag < ApplicationRecord - include Searchable::Dependents::ChallengeTag - - belongs_to :challenge, counter_cache: true - belongs_to :challenge_choose, optional: true -end diff --git a/app/models/challenge_work_score.rb b/app/models/challenge_work_score.rb deleted file mode 100644 index 8d27b8107..000000000 --- a/app/models/challenge_work_score.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ChallengeWorkScore < ApplicationRecord - belongs_to :user - belongs_to :student_work - belongs_to :challenge - has_many :tidings, as: :container, dependent: :destroy - - validates :comment, length: { maximum: 500, too_long: "不能超过500个字符" } - - def create_tiding trigger_user_id - tidings << Tiding.new(user_id: student_work.user_id, trigger_user_id: trigger_user_id, container_id: id, - container_type: "ChallengeWorkScore", parent_container_id: student_work_id, - parent_container_type: "StudentWork", belong_container_id: student_work&.homework_common&.course_id, - belong_container_type: "Course", viewed: 0, tiding_type: "HomeworkCommon") - end -end diff --git a/app/models/commit.rb b/app/models/commit.rb deleted file mode 100644 index d11672cd3..000000000 --- a/app/models/commit.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Commit < ApplicationRecord - belongs_to :project, foreign_key: :project_id - -end \ No newline at end of file diff --git a/app/models/commit_issue.rb b/app/models/commit_issue.rb deleted file mode 100644 index b7947f69c..000000000 --- a/app/models/commit_issue.rb +++ /dev/null @@ -1,4 +0,0 @@ -class CommitIssue < ApplicationRecord - belongs_to :issue, foreign_key: :issue_id - -end \ No newline at end of file diff --git a/app/models/compose.rb b/app/models/compose.rb deleted file mode 100644 index 0b3733943..000000000 --- a/app/models/compose.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Compose < ApplicationRecord - #组织 - belongs_to :user - has_many :compose_projects - has_many :compose_users - - validates :title, presence: {message: "组织名称不能为空"}, uniqueness: {message: "组织名称已存在"} - - scope :compose_includes, ->{includes(:compose_projects, :compose_users, :user)} - -end - diff --git a/app/models/compose_project.rb b/app/models/compose_project.rb deleted file mode 100644 index 3c2d099e1..000000000 --- a/app/models/compose_project.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ComposeProject < ApplicationRecord - #组织的项目记录表 - belongs_to :compose -end diff --git a/app/models/compose_user.rb b/app/models/compose_user.rb deleted file mode 100644 index e3b514b3e..000000000 --- a/app/models/compose_user.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ComposeUser < ApplicationRecord - belongs_to :compose - belongs_to :user -end diff --git a/app/models/cooperation.rb b/app/models/cooperation.rb deleted file mode 100644 index f0eb30cf6..000000000 --- a/app/models/cooperation.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Cooperation < ApplicationRecord - def user_type_text - case user_type.to_i - when 1 then '高校合作' - when 2 then '企业合作' - when 3 then '实训投稿' - end - end -end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb deleted file mode 100644 index 08e2e36f5..000000000 --- a/app/models/course.rb +++ /dev/null @@ -1,455 +0,0 @@ -class Course < ApplicationRecord - include Searchable::Course - - has_many :boards, dependent: :destroy - - belongs_to :teacher, class_name: 'User', foreign_key: :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 - belongs_to :school, class_name: 'School', foreign_key: :school_id #定义一个方法school,该方法通过school_id来调用School表 - belongs_to :course_list, optional: true - - belongs_to :laboratory, optional: true - - # 所属实践课程 - belongs_to :subject, optional: true - has_many :informs, as: :container, dependent: :destroy - - has_many :course_infos, dependent: :destroy - # 课堂左侧导航栏的模块 - has_many :course_modules, dependent: :destroy - has_many :none_hidden_course_modules, -> { not_hidden }, class_name: "CourseModule" - has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" - has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" - has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" - has_many :group_course_modules, -> { group_homework_module }, class_name: "CourseModule" - has_many :shixun_course_modules, -> { shixun_homework_module }, class_name: "CourseModule" - - # 课堂模块的二级目录 - has_many :course_second_categories, dependent: :destroy - # 课堂分班 - has_many :course_groups, dependent: :destroy - # 答辩组 - has_many :graduation_groups, dependent: :destroy - - has_many :course_members, dependent: :destroy - has_many :students, -> { course_students }, class_name: 'CourseMember' - has_many :teacher_course_members, -> { teachers_and_admin }, class_name: 'CourseMember' - has_many :teacher_users, through: :teacher_course_members, source: :user - has_many :course_messages, dependent: :destroy - - has_many :homework_commons, dependent: :destroy - has_many :normal_homeworks, -> { normals }, class_name: 'HomeworkCommon' - has_many :group_homeworks, -> { groups }, class_name: 'HomeworkCommon' - has_many :practice_homeworks, -> { practices }, class_name: 'HomeworkCommon' - - has_many :homework_group_settings - has_many :graduation_works, dependent: :destroy - - # 实训作业的二级目录(已弃用) - has_many :course_homework_categories, dependent: :destroy - has_many :exercises, dependent: :destroy - - #课堂的试卷 - has_many :exercise_group_settings, :dependent => :destroy - - # 课堂的问卷 - has_many :polls, dependent: :destroy - has_many :poll_group_settings, :dependent => :destroy - - # 毕业设计 - has_many :graduation_topics, dependent: :destroy - has_many :graduation_tasks, dependent: :destroy - has_many :student_graduation_topics, :dependent => :destroy - has_many :teacher_course_groups, :dependent => :destroy - - # 资源 - has_many :attachments, as: :container, dependent: :destroy - has_many :attachment_group_settings, :dependent => :destroy - - # 课堂学生,弃用 - has_many :student, :class_name => 'StudentsForCourse', :source => :user - - - # 课堂动态 - has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy - has_many :course_activities - - has_many :tidings, as: :container, dependent: :destroy - - # 开放课堂 - has_many :course_stages, -> { order("course_stages.position ASC") }, dependent: :destroy - has_many :course_stage_shixuns, dependent: :destroy - has_many :shixuns, through: :course_stage_shixuns - - # 老版的members弃用 现用course_members - has_many :members - - # 视频 - has_many :course_videos, dependent: :destroy - has_many :videos, through: :course_videos - - # 直播 - has_many :live_links, dependent: :destroy - - validate :validate_sensitive_string - - scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } - scope :ended, ->(is_end = true) { where(is_end: is_end) } - scope :processing, -> { where(is_end: false) } - scope :not_deleted, -> { where(is_delete: 0) } - scope :not_excellent, -> { where(excellent: 0) } - scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) } - scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) } - scope :by_keywords, lambda { |keywords| - where("name LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank? - } - scope :started, -> { where("start_date is null or start_date <= '#{Date.today}'") } - - # acts_as_taggable - - - # 课程权限判断 - ADMIN = 0 # 超级管理员 - BUSINESS = 1 # 运营人员 - CREATOR = 2 # 课程创建者 - PROFESSOR = 3 # 课程老师 - ASSISTANT_PROFESSOR = 4 # 课程助教 - STUDENT = 5 # 学生 - NORMAL = 6 # 普通用户 - Anonymous = 7 # 普未登录 - - validates :name, presence: true, length: { maximum: 60, too_long: "不能超过60个字符" } - - before_save :set_laboratory - after_create :create_board_sync, :act_as_course_activity, :send_tiding - - def course_member? user_id, role - course_members.where(user_id: user_id, role: role).exists? - end - - def course_group_module? - course_modules.exists?(module_type: "course_group", hidden: 0) - end - - # 作业对应的子目录/父目录名称 - def category_info type - course_module = course_modules.find_by(module_type: type) - { category_id: course_module&.id, category_name: course_module&.module_name } - end - - # 未分班的学生数 - def none_group_count - course_members.where(role: 4, course_group_id: 0).size - end - - def course_member(user_id) - course_members.find_by(user_id: user_id, is_active: 1) - end - - def course_student(user_id) - course_members.find_by(user_id: user_id, role: %i(STUDENT)) - end - - def user_group_name(user_id) - students.find_by(user_id: user_id)&.course_group_name - end - - - def teacher_group(user_id) - data = - if teacher_course_groups.exists?(user_id: user_id) - teacher_course_groups.joins(:course_group).where(user_id: user_id) - .pluck('course_groups.id', 'course_groups.name') - else - course_groups.pluck(:id, :name) - end - - data.map { |arr| { group_id: arr.first, group_name: arr.last } } - end - - #当前老师的班级id - def teacher_course_ids(user_id) - course_teacher_member = teacher_course_groups.get_user_groups(user_id).select(:course_group_id) #获取当前老师的分班 - if course_teacher_member.blank? - if none_group_count > 0 #有未分班的,则发布到未发布分班 - un_group_ids = [0] - else - un_group_ids = [] - end - course_groups.pluck(:id) + un_group_ids #所有分班和未分班 - else - course_teacher_member.pluck(:course_group_id).reject(&:blank?).uniq #当前用户所在的班级,老师可能有多个班级 - end - end - - # 查询老师分班的所有学生 - def teacher_group_user_ids user_id - teachers = teacher_course_groups.where(user_id: user_id) - if teachers.exists? - students.where(course_group_id: teachers.pluck(:course_group_id)).pluck(:user_id) - else - students.pluck(:user_id) - end - end - - # 创建课程模块 - def create_course_modules(course_module_types) - course_modules.destroy_all if course_modules.present? - - all_course_module_types.each do |type| - name = get_name_by_type(type) - position = get_position_by_type(type) - - hidden = course_module_types.include?(type) ? 0 : 1 - CourseModule.create(course_id: id, module_type: type, position: position, hidden: hidden, module_name: name) - end - end - - # 更新课程模块 - def update_course_modules(course_module_types) - all_course_module_types.each do |type| - hidden_value = course_module_types.include?(type) ? 0 : 1 - - course_module = course_modules.where(module_type: type).first - course_module.update_attribute(:hidden, hidden_value) if course_module.present? - end - end - - def all_course_module_types - %w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video] - end - - def get_course_module_by_type(type) - #CourseModule.where(course_id: course_id, module_type: type).first - self.course_modules.where(module_type: type).first - end - - # 创建课程讨论区 - def create_board_sync - boards.create(name: '讨论区', description: name, project_id: -1) - end - - def delete! - update_attribute(:is_delete, true) - end - - def attachment_count - Attachment.where(container: self).count - end - - # 课堂某角色的成员数量:[1, 2, 3] 是教师身份、4 学生身份 - def course_member_count(roles) - course_members.where(role: roles).size - end - - # 课堂老师 - def teachers - course_members.where(role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) - end - - def teachers_without_assistant_professor - course_members.where(role: %i[CREATOR PROFESSOR]) - end - - # 更新课程的访问人数 - def update_visits(new_visits) - update_attributes(visits: new_visits) - end - - # 老师负责的分班id - def charge_group_ids user - member = course_member(user.id) - group_ids = if member.present? - member.teacher_course_groups.size > 0 ? member.teacher_course_groups.pluck(:course_group_id) : course_groups.pluck(:id) - elsif user.admin_or_business? - course_groups.pluck(:id) - else - [] - 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 - return invite_code if invite_code.present? && invite_code.size >= 5 - - code = CODES.sample(5).join - while Course.exists?(invite_code: code) do - code = CODES.sample(5).join - end - update_attribute(:invite_code, code) - - code - end - - # 课堂主讨论区 - def course_board - board = boards.find_by(parent_id: 0) - return board if board.present? - - create_board_sync - Board.find_by(parent_id: 0, course_id: id) - end - - # 是否是课堂的成员(未实现,暂时返回true) - def member?(user) - true - end - - # 是否具有分班权限,返回分班的id - def group_course_power(user_id) - teacher_course_groups.where(user_id: user_id).pluck(:course_group_id) - end - - #课程动态公共表记录 - def act_as_course_activity - self.course_act << CourseActivity.new(user_id: tea_id, course_id: id) - end - - # 当前老师分班下的所有学生 - def user_group_students(user_id) - group_ids = teacher_course_groups.where(user_id: user_id).pluck(:course_group_id) - course_members.where(course_group_id: group_ids) - end - - def self_duplicate - DuplicateCourseService.call(self, User.current) - end - - def update_quotes attachment - if attachment.copy_from - attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}") - else - attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}") - end - attachment.quotes = get_qute_number attachment - attachment.save - attachments.each do |att| - att.quotes = attachment.quotes - att.save - end - end - - def get_qute_number attachment - if attachment.copy_from - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") - else - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") - end - if result.nil? || result.count <= 0 - 0 - else - result[0].number - end - end - - #获取试卷/问卷已发布的班级id,名称和人数。当为统一设置时,显示全部,否则只显示当前已发布的班级信息 - def get_ex_published_course(common_ids) - teacher_power_courses = [] - publish_groups = course_groups.where(id: common_ids) - if common_ids.include?(0) - teacher_power_courses << {course_name:"未分班", course_id: 0, student_count: none_group_count} - end - if publish_groups.present? - publish_groups.each do |group| - teacher_power_courses << {course_name: group&.name,course_id: group&.id, student_count: group&.course_members_count} - end - end - teacher_power_courses - end - - def create_stages subject - if subject - subject.stages.each do |stage| - new_stage = CourseStage.create!(course_id: id, name: stage.name, description: stage.description, position: stage.position) - stage.stage_shixuns.each do |stage_shixun| - CourseStageShixun.create!(course_id: id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position) - end - end - end - end - - def learning? user_id - Myshixun.where(user_id: user_id, shixun_id: shixuns).exists? - end - - def my_subject_progress myshixuns - my_challenge_count = Game.where(myshixun_id: myshixuns.pluck(:id), status: 2).pluck(:challenge_id).uniq.size - course_challeng_count = shixuns.pluck(:challenges_count).sum - count = course_challeng_count == 0 ? 0 : ((my_challenge_count.to_f / course_challeng_count).round(2) * 100).to_i - end - - # 课堂实训作业的评测次数 - def evaluate_count - course_user_ids = students.pluck(:user_id) - shixun_ids = homework_commons.joins(:homework_commons_shixun).where(homework_type: 4).pluck(:shixun_id) - return 0 if shixun_ids.blank? - Game.joins(:challenge).where(challenges: {shixun_id: shixun_ids}, games: {user_id: course_user_ids}).sum(:evaluate_count) - end - - def max_activity_time - course_acts.pluck(:updated_at).max - end - - # 课堂作业数 - def course_homework_count type - homework_commons.select{|homework| homework.homework_type == type}.size - end - - private - - #创建课程后,给该用户发送消息 - def send_tiding - self.tidings << Tiding.new(user_id: tea_id, trigger_user_id: 0, belong_container_id: id, - belong_container_type: 'Course', tiding_type: 'System') - end - - def get_name_by_type(type) - case type - when 'activity' then '动态' - when 'announcement' then '公告栏' - when 'online_learning' then '课程学习' - when 'shixun_homework' then '实训作业' - when 'common_homework' then '普通作业' - when 'group_homework' then '分组作业' - when 'graduation' then '毕业设计' - when 'exercise' then '试卷' - when 'poll' then '问卷' - when 'attachment' then '资源' - when 'video' then '视频直播' - when 'board' then '讨论' - when 'course_group' then '分班' - when 'statistics' then '统计' - else '' - end - end - - def get_position_by_type(type) - case type - when 'activity' then 1 - when 'announcement' then 2 - when 'online_learning' then 3 - when 'shixun_homework' then 4 - when 'common_homework' then 5 - when 'group_homework' then 6 - when 'graduation' then 7 - when 'exercise' then 8 - when 'poll' then 9 - when 'attachment' then 10 - when 'video' then 11 - when 'board' then 12 - when 'course_group' then 13 - when 'statistics' then 14 - else 100 - end - end - - def set_laboratory - return unless new_record? # 新记录才需要标记 - - self.laboratory = Laboratory.current if laboratory_id.blank? - end - - def validate_sensitive_string - raise("课堂名称包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(name) - end -end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb deleted file mode 100644 index d9930596c..000000000 --- a/app/models/course_activity.rb +++ /dev/null @@ -1,54 +0,0 @@ -class CourseActivity < ApplicationRecord - belongs_to :course_act, polymorphic: true - belongs_to :course - belongs_to :user - belongs_to :exercise - belongs_to :poll - belongs_to :course_message - belongs_to :homework_common - - # after_create :add_course_lead - - def container_name - case course_act_type - when "HomeworkCommon" - course_act&.name - when "Exercise" - course_act&.exercise_name - when "Poll" - course_act&.poll_name - when "Message" - course_act&.subject - else - "" - end - end - - # 发布新课导语 - # 导语要放置在课程创建信息之后 - def add_course_lead - # 避免空数据迁移报错问题 - if self.course_act_type == "Course" - sample = PlatformSample.where(:samples_type => "courseGuide").first - if sample.present? && sample.contents.present? - content = sample.contents - elsif Message.find(12440) - lead_message = Message.find(12440) - content = lead_message.content - end - if content - # message的status状态为0为正常,为1表示创建课程时发送的message - # author_id 默认为课程使者创建 - message = Message.create(subject: "新课导语", - board_id: course.course_board.try(:id), - author_id: 1, - sticky: true, - status: true, - message_detail_attributes: {content: content} - ) - # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一致 - message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first - end - end - end -end diff --git a/app/models/course_group.rb b/app/models/course_group.rb deleted file mode 100644 index 5bd27804f..000000000 --- a/app/models/course_group.rb +++ /dev/null @@ -1,34 +0,0 @@ -class CourseGroup < ApplicationRecord - default_scope { order("course_groups.position ASC") } - belongs_to :course, counter_cache: true - has_many :course_members - has_many :exercise_group_settings,:dependent => :destroy - has_many :attachment_group_settings, :dependent => :destroy - has_many :homework_group_reviews, :dependent => :destroy - has_many :teacher_course_groups, :dependent => :destroy - has_many :homework_group_settings, :dependent => :destroy - scope :by_group_ids, lambda { |ids| where(id: ids)} - - validates :name, length: { maximum: 60, too_long: "不能超过60个字符" } - validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班" - - after_create :generate_invite_code - - # 延迟生成邀请码 - def invite_code - return generate_invite_code - 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 = read_attribute(:invite_code) - if !code || code.size < 6 - code = CODES.sample(6).join - return generate_invite_code if CourseGroup.where(invite_code: code).present? - update_attribute(:invite_code, code) - end - code - end - -end diff --git a/app/models/course_homework_category.rb b/app/models/course_homework_category.rb deleted file mode 100644 index 79f105da8..000000000 --- a/app/models/course_homework_category.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CourseHomeworkCategory < ApplicationRecord - belongs_to :course -end diff --git a/app/models/course_info.rb b/app/models/course_info.rb deleted file mode 100644 index 1cd0a763c..000000000 --- a/app/models/course_info.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CourseInfo < ApplicationRecord - belongs_to :course -end diff --git a/app/models/course_list.rb b/app/models/course_list.rb deleted file mode 100644 index ab7404a9e..000000000 --- a/app/models/course_list.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CourseList < ApplicationRecord - has_many :courses - has_many :question_banks - has_many :homework_banks - has_many :exercise_banks - has_many :gtask_banks - has_many :gtopic_banks - belongs_to :user - - validate :validate_sensitive_string - - def validate_sensitive_string - raise("课程名称包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(name) - end -end diff --git a/app/models/course_member.rb b/app/models/course_member.rb deleted file mode 100644 index 65849e5de..000000000 --- a/app/models/course_member.rb +++ /dev/null @@ -1,159 +0,0 @@ -class CourseMember < ApplicationRecord - # role 1:创建者 2:老师 3:助教 4:学生 - enum role: { CREATOR: 1, PROFESSOR: 2, ASSISTANT_PROFESSOR: 3, STUDENT: 4 } - # is_active: true:当前活跃身份(多重身份的用户) - - belongs_to :course, counter_cache: true - belongs_to :user - belongs_to :course_group, counter_cache: true, optional: true - belongs_to :graduation_group, optional: true - has_many :teacher_course_groups, dependent: :destroy - - scope :teachers_and_admin, -> { where(role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) } - scope :students, ->(course) { where(course_id: course.id, role: %i[STUDENT])} - scope :course_find_by_ids, lambda { |k,ids| where("#{k}": ids)} - scope :course_students, -> {where(role: %i[STUDENT])} - - #用户的身份查询 - scope :course_user_role, lambda { |k| where(role: k)} - - # 未分班 - scope :ungroup_students, -> { where(course_group_id: 0, role: 4) } - - # after_destroy :delete_works - # after_create :work_operation - def delete_works - if self.role == "STUDENT" - course = self.course - student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id}) - student_works.update_all(is_delete: 1) - - exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id}) - exercise_users.update_all(is_delete: 1) - - poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id}) - poll_users.update_all(is_delete: 1) - - course.graduation_works.where(user_id: self.user_id).update_all(is_delete: 1) - end - end - - def work_operation - if self.role == "STUDENT" - recover_works - create_exercise_users - create_graduation_works - create_poll_users - create_student_works - end - end - - # 加入班级时还原作品(如果有已删除作品的话) - def recover_works - course = self.course - - student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id}) - student_works.update_all(is_delete: 0) - - exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id}) - exercise_users.update_all(is_delete: 0) - - poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id}) - poll_users.update_all(is_delete: 0) - - graduation_works = course.graduation_works.where(user_id: self.user_id) - graduation_works.update_all(is_delete: 0) - end - - # 加入班级时创建作业的作品(如果没有作品才创建) - def create_student_works - course = self.course - - homework_commons = course.homework_commons.where(homework_type: %i[normal group practice]) - str = "" - homework_commons.each do |homework| - next if homework.student_works.where(user_id: self.user_id).any? - str += "," if str != "" - str += "(#{homework.id}, #{user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into student_works (homework_common_id, user_id, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end - end - - # 加入班级时创建已发布试卷的作品(如果没有作品才创建) - def create_exercise_users - course = self.course - exercises = course.exercises - - str = "" - exercises.each do |exercise| - next if exercise.exercise_users.where(user_id: self.user_id).any? - str += "," if str != "" - str += "(#{user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end - end - - # 加入班级时创建已发布问卷的作品(如果没有作品才创建) - def create_poll_users - course = self.course - polls = course.polls - - str = "" - polls.each do |poll| - next if poll.poll_users.where(user_id: self.user_id).any? - str += "," if str != "" - str += "(#{user_id}, #{poll.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into poll_users (user_id, poll_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end - end - - # 创建毕设任务作品(如果没有作品才创建) - def create_graduation_works - course = self.course - tasks = course.graduation_tasks - - str = "" - tasks.each do |task| - next if task.graduation_works.where(user_id: self.user_id).any? - str += "," if str != "" - str += "(#{task.id}, #{user_id}, #{course_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into graduation_works (graduation_task_id, user_id, course_id, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end - end - - # 分班名称 - def course_group_name - self.course_group_id == 0 ? "未分班" : course_group.try(:name) - end - - # 学生的分班老师 - def member_teachers - teacher_groups = course.teacher_course_groups - if teacher_groups.count > 0 - member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - - none_group_teachers = teacher_groups.pluck(:course_member_id).compact.size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 - teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or - course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") - else - teachers = course.teachers - end - teachers - end -end diff --git a/app/models/course_module.rb b/app/models/course_module.rb deleted file mode 100644 index 32a6a7794..000000000 --- a/app/models/course_module.rb +++ /dev/null @@ -1,28 +0,0 @@ -class CourseModule < ApplicationRecord - default_scope { order("course_modules.position ASC") } - belongs_to :course - - # 二级目录 - has_many :course_second_categories - - validates :module_name, length: { maximum: 20, too_long: "不能超过20个字符" } - - scope :not_hidden, -> { where(hidden: 0) } - scope :graduation_module, -> { where(module_type: "graduation") } - scope :graduation_module_not_hidden, -> { graduation_module.where(hidden: 0) } - scope :board_module, -> { where(module_type: 'board') } - scope :attachment_module, -> { includes(:course_second_categories).where(module_type: 'attachment') } - scope :common_homework_module, -> { where(module_type: 'common_homework') } - scope :group_homework_module, -> { where(module_type: 'group_homework') } - scope :shixun_homework_module, -> { where(module_type: 'shixun_homework') } - scope :search_by_module_type, -> (type) {where(module_type:type)} - - # 课堂模块的子目录 - def course_second_categories - if module_type == "graduation" && CourseSecondCategory.where(course_module_id: self.id).count == 0 - CourseSecondCategory.create!(course_module_id: self.id, course_id: self.course_id, name: "毕设选题", category_type: "graduation", position: 1) - CourseSecondCategory.create!(course_module_id: self.id, course_id: self.course_id, name: "毕设任务", category_type: "graduation", position: 2) - end - CourseSecondCategory.where(course_module_id: self.id) - end -end diff --git a/app/models/course_second_category.rb b/app/models/course_second_category.rb deleted file mode 100644 index 963367e0b..000000000 --- a/app/models/course_second_category.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CourseSecondCategory < ApplicationRecord - default_scope { order("course_second_categories.position ASC") } - - belongs_to :course - belongs_to :course_module - has_many :homework_commons - - validates :name, length: { maximum: 60, too_long: "不能超过60个字符" } - - def category_type_str - category_type == "graduation" && name == "毕设选题" ? "graduation_topics" : ( - category_type == "graduation" && name == "毕设任务" ? "graduation_tasks" : category_type - ) - end -end diff --git a/app/models/course_stage.rb b/app/models/course_stage.rb deleted file mode 100644 index 0fecfb434..000000000 --- a/app/models/course_stage.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CourseStage < ApplicationRecord - belongs_to :course - - has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy - has_many :shixuns, :through => :course_stage_shixuns - - validates :name, length: { maximum: 60 , too_long: "不能超过60个字符"} - validates :description, length: { maximum: 1000, too_long: "不能超过1000个字符" } -end diff --git a/app/models/course_stage_shixun.rb b/app/models/course_stage_shixun.rb deleted file mode 100644 index 6ab2707a4..000000000 --- a/app/models/course_stage_shixun.rb +++ /dev/null @@ -1,5 +0,0 @@ -class CourseStageShixun < ApplicationRecord - belongs_to :course - belongs_to :course_stage, counter_cache: :shixuns_count - belongs_to :shixun -end diff --git a/app/models/course_video.rb b/app/models/course_video.rb deleted file mode 100644 index e61a439dc..000000000 --- a/app/models/course_video.rb +++ /dev/null @@ -1,4 +0,0 @@ -class CourseVideo < ApplicationRecord - belongs_to :course - belongs_to :video -end diff --git a/app/models/customer.rb b/app/models/customer.rb deleted file mode 100644 index b0dfcee88..000000000 --- a/app/models/customer.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Customer < ApplicationRecord - default_scope { order(created_at: :desc) } - - belongs_to :school - belongs_to :partner_manager_group, optional: true - - has_many :partner_customers, dependent: :destroy - has_many :partners, through: :partner_customers - - has_many :users -end \ No newline at end of file diff --git a/app/models/department.rb b/app/models/department.rb deleted file mode 100644 index 2c537fd91..000000000 --- a/app/models/department.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Department < ApplicationRecord - belongs_to :school - - has_many :department_members, dependent: :destroy - has_many :member_users, through: :department_members, source: :user - - has_many :user_extensions, dependent: :nullify - has_many :apply_add_departments, dependent: :destroy - - scope :without_deleted, -> { where(is_delete: false) } - - def member?(user) - department_members.exists?(user_id: user.id) - end - - def soft_delete! - update!(is_delete: true) - end -end diff --git a/app/models/department_member.rb b/app/models/department_member.rb deleted file mode 100644 index f1f3859ec..000000000 --- a/app/models/department_member.rb +++ /dev/null @@ -1,4 +0,0 @@ -class DepartmentMember < ApplicationRecord - belongs_to :user - belongs_to :department -end diff --git a/app/models/discipline.rb b/app/models/discipline.rb deleted file mode 100644 index 06ecf825f..000000000 --- a/app/models/discipline.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Discipline < ApplicationRecord - default_scope { order(position: :asc) } - - has_many :sub_disciplines, -> { order("sub_disciplines.position ASC") }, dependent: :destroy - - has_many :shixun_sub_disciplines, -> { where("shixun = 1") }, class_name: "SubDiscipline" - has_many :subject_sub_disciplines, -> { where("subject = 1") }, class_name: "SubDiscipline" - has_many :question_sub_disciplines, -> { where("question = 1") }, class_name: "SubDiscipline" - - validates_presence_of :name - -end diff --git a/app/models/experience.rb b/app/models/experience.rb deleted file mode 100644 index a5d828da3..000000000 --- a/app/models/experience.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Experience < ApplicationRecord - belongs_to :user -end diff --git a/app/models/forum.rb b/app/models/forum.rb deleted file mode 100644 index cd9b76a96..000000000 --- a/app/models/forum.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Forum < ApplicationRecord - has_many :memos, dependent: :destroy -end diff --git a/app/models/issue.rb b/app/models/issue.rb index 2cdb66b04..3d222a31d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -11,7 +11,7 @@ class Issue < ApplicationRecord belongs_to :issue_status, foreign_key: :status_id,optional: true has_many :commit_issues has_many :attachments, as: :container, dependent: :destroy - has_many :memos + # has_many :memos has_many :journals, :as => :journalized, :dependent => :destroy has_many :journal_details, through: :journals has_many :issue_tags_relates, dependent: :destroy diff --git a/app/models/item_analysis.rb b/app/models/item_analysis.rb deleted file mode 100644 index e7177c2f8..000000000 --- a/app/models/item_analysis.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ItemAnalysis < ApplicationRecord - belongs_to :item_bank, touch: true - validates :analysis, length: { maximum: 5000, too_long: "不能超过5000个字符" } -end diff --git a/app/models/item_bank.rb b/app/models/item_bank.rb deleted file mode 100644 index 71cfd07a4..000000000 --- a/app/models/item_bank.rb +++ /dev/null @@ -1,45 +0,0 @@ -class ItemBank < ApplicationRecord - # difficulty: 1 简单 2 适中 3 困难 - enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 } - # item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程 - - belongs_to :user - belongs_to :sub_discipline, optional: true - - has_one :item_analysis, dependent: :destroy - has_many :item_choices, dependent: :destroy - has_many :item_baskets, dependent: :destroy - has_many :tag_discipline_containers, as: :container, dependent: :destroy - has_many :tag_disciplines, through: :tag_discipline_containers - - belongs_to :container, polymorphic: true, optional: true - validates :name, presence: true, length: { maximum: 1000, too_long: "不能超过1000个字符" } - - def analysis - item_analysis&.analysis - end - - def apply? - !public && ApplyAction.exists?(container_type: "ItemBank", container_id: id, status: 0) - end - - def type_string - case item_type - when "SINGLE" then "单选题" - when "MULTIPLE" then "多选题" - when "JUDGMENT" then "判断题" - when "COMPLETION" then "填空题" - when "SUBJECTIVE" then "简答题" - when "PRACTICAL" then "实训题" - when "PROGRAM" then "编程题" - end - end - - def difficulty_string - case difficulty - when 1 then "简单" - when 2 then "适中" - when 3 then "困难" - end - end -end diff --git a/app/models/item_basket.rb b/app/models/item_basket.rb deleted file mode 100644 index eb849d403..000000000 --- a/app/models/item_basket.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ItemBasket < ApplicationRecord - enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 } - - belongs_to :item_bank - belongs_to :user, optional: true - belongs_to :examination_intelligent_setting, optional: true -end diff --git a/app/models/item_choice.rb b/app/models/item_choice.rb deleted file mode 100644 index adee69f66..000000000 --- a/app/models/item_choice.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ItemChoice < ApplicationRecord - belongs_to :item_bank, touch: true - validates :choice_text, presence: true, length: { maximum: 500, too_long: "不能超过500个字符" } - -end diff --git a/app/models/live_link.rb b/app/models/live_link.rb index 9b59eb8c1..9c6531f87 100644 --- a/app/models/live_link.rb +++ b/app/models/live_link.rb @@ -1,5 +1,5 @@ class LiveLink < ApplicationRecord - belongs_to :course + # belongs_to :course belongs_to :user has_many :tidings, as: :container, dependent: :destroy diff --git a/app/models/member.rb b/app/models/member.rb index 132b96692..054a072b6 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,6 +1,6 @@ class Member < ApplicationRecord belongs_to :user - belongs_to :course, optional: true + # belongs_to :course, optional: true belongs_to :project, optional: true has_many :member_roles, dependent: :destroy diff --git a/app/models/memo.rb b/app/models/memo.rb deleted file mode 100644 index 7be2cf080..000000000 --- a/app/models/memo.rb +++ /dev/null @@ -1,72 +0,0 @@ -class Memo < ApplicationRecord - include Searchable::Memo - - belongs_to :forum, touch: true - - has_many :memo_tag_repertoires, dependent: :destroy - has_many :tag_repertoires, :through => :memo_tag_repertoires - - has_many :praise_treads, as: :praise_tread_object, dependent: :destroy - has_one :praise_tread_cache, as: :object, dependent: :destroy - - belongs_to :author, class_name: 'User', foreign_key: 'author_id' - belongs_to :parent, class_name: 'Memo', foreign_key: 'parent_id' - - has_many :descendants, foreign_key: :root_id, class_name: 'Memo' - has_many :children, foreign_key: :parent_id, class_name: 'Memo' - has_many :attachments, as: :container, dependent: :destroy - has_many :tidings, as: :container, dependent: :destroy - validate :validate_sensitive_string - - scope :field_for_list, lambda{ - select([:id, :subject, :author_id, :sticky, :updated_at, :language, :reward, :all_replies_count, :viewed_count, :forum_id]) - } - scope :user_posts, -> (user_id){ where(root_id: nil, author_id: user_id, forum_id: [3, 5]) } - scope :field_for_recommend, -> { select([:id, :subject, :language, :forum_id, :all_replies_count]) } - scope :memo_replies, -> (id) { where(root_id: id) } - scope :hot, -> { order("all_replies_count desc, updated_at desc") } - scope :posts, -> { where(root_id: nil, forum_id: [3, 5]) } - - validates :content, length: { maximum: 10000, too_long: "不能超过10000个字符" } - - after_create :send_tiding - - # 帖子的回复 - def reply_for_memo - Memo.where(parent_id: id) - end - - # 子回复 - def children_of_reply - Memo.where(parent_id: id).includes(:author).reorder("created_at asc") - end - - # 主贴的名称 - def main_subject - memo = Memo.find_by(root_id: id) - Rails.logger.info("###############memo: #{memo&.subject}") - memo ? memo.subject : subject - end - - private - - def send_tiding - tiding_attr = { - trigger_user_id: author_id, viewed: 0, tiding_type: 'Comment', - parent_container_type: 'Memo', belong_container_id: forum_id, belong_container_type: 'Forum' - } - if parent_id.present? - tiding_attr.merge!(user_id: parent.author_id, parent_container_id: root_id) - else - # 新帖子给超级管理员发消息 - tiding_attr.merge!(user_id: 1, parent_container_id: id) - end - - self.tidings << Tiding.new(tiding_attr) - end - - def validate_sensitive_string - raise("标题包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(subject) - raise("内容包含敏感词汇,请重新输入") unless HarmoniousDictionary.clean?(content) - end -end diff --git a/app/models/memo_tag_repertoire.rb b/app/models/memo_tag_repertoire.rb deleted file mode 100644 index 99bb04f78..000000000 --- a/app/models/memo_tag_repertoire.rb +++ /dev/null @@ -1,4 +0,0 @@ -class MemoTagRepertoire < ApplicationRecord - belongs_to :memo - belongs_to :tag_repertoire -end diff --git a/app/models/message_detail.rb b/app/models/message_detail.rb index d589ada3e..51f4b17a9 100644 --- a/app/models/message_detail.rb +++ b/app/models/message_detail.rb @@ -1,5 +1,5 @@ class MessageDetail < ApplicationRecord - belongs_to :message, :touch => true + # belongs_to :message, :touch => true validates :content, length: { maximum: 10000, too_long: "内容不能超过10000个字符" } end diff --git a/app/models/mirror_operation_record.rb b/app/models/mirror_operation_record.rb deleted file mode 100644 index 39e352a0f..000000000 --- a/app/models/mirror_operation_record.rb +++ /dev/null @@ -1,7 +0,0 @@ -# status: 0 创建镜像; 1 修改镜像ID; 2 修改镜像name 3 删除镜像 4.从主节点同步镜像到子节点(子节点发生异常), 5. 修改镜像别名, 6. 修改镜像的状态 -# user_id: -1时,证明是非人为因素造成,中间层异常导致 -class MirrorOperationRecord < ActiveRecord::Base - default_scope { order(created_at: :desc) } - - belongs_to :mirror_repository -end diff --git a/app/models/mirror_repository.rb b/app/models/mirror_repository.rb deleted file mode 100644 index 315813e51..000000000 --- a/app/models/mirror_repository.rb +++ /dev/null @@ -1,16 +0,0 @@ -class MirrorRepository < ApplicationRecord - has_many :shixun_mirror_repositories, :dependent => :destroy - has_many :shixun, :through => :shixun_mirror_repositories - has_many :mirror_scripts, :dependent => :destroy - - - - scope :published_mirror, -> { where(status: [1,2,3,5]) } - scope :published_main_mirror, -> { published_mirror.where(main_type: 1) } - scope :published_small_mirror, -> { published_mirror.where(main_type: 0) } - scope :small_mirror, -> { where(main_type: 0) } - - def deletable? - status != 1 && !shixun_mirror_repositories.exists? - end -end diff --git a/app/models/mirror_script.rb b/app/models/mirror_script.rb deleted file mode 100644 index f4cb60867..000000000 --- a/app/models/mirror_script.rb +++ /dev/null @@ -1,4 +0,0 @@ -class MirrorScript < ApplicationRecord - belongs_to :mirror_repository - -end diff --git a/app/models/module_setting.rb b/app/models/module_setting.rb deleted file mode 100644 index 36fc45e6f..000000000 --- a/app/models/module_setting.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ModuleSetting < ApplicationRecord -end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb deleted file mode 100644 index 8d2012381..000000000 --- a/app/models/myshixun.rb +++ /dev/null @@ -1,118 +0,0 @@ -class Myshixun < ApplicationRecord - include ApplicationHelper - has_many :games, :dependent => :destroy - has_many :student_works - has_one :shixun_modify, :dependent => :destroy - - belongs_to :user - belongs_to :user_extension, foreign_key: :user_id - belongs_to :shixun, counter_cache: true - - has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game' - has_one :last_task, -> { all }, class_name: 'Game' - - validates_uniqueness_of :shixun_id, :scope => :user_id, :message => "shixun_id and user_id unique error" - scope :finished, lambda { where(status: 1) } - scope :search_myshixun_user, ->(user_id){where(user_id:user_id)} - - - def owner - self.user - rescue ActiveRecord::RecordNotFound - end - - def output_times - games.map(&:evaluate_count).sum.to_i - end - - def repo_path - "#{self.repo_name}.git" - end - - - def repo_save_path - self.repo_name.split('/').last - end - - def is_complete? - self.status == 1 - end - - # 判断TPM的代码是否被修改了 - # 判断依据是看tpm的最新提交记录和tpi数据库中存储的commit_id是否一致 - def repository_is_modified shixun_repo_path - myshixun_commit_id = self.commit_id - if myshixun_commit_id.blank? - myshixun_commit_id = GitService.commits(repo_path: self.repo_path).last["id"] - self.update_column(:commit_id, myshixun_commit_id) - end - shixun_commit_id = GitService.commits(repo_path: shixun_repo_path).first["id"] - Rails.logger.warn("###############shixun_commit_id is #{shixun_commit_id}") - Rails.logger.warn("###############myshixun_commit_id is #{self.commit_id}") - result = myshixun_commit_id != shixun_commit_id ? true :false - return result - end - - def mirror_name - self.shixun.mirror_repositories.map(&:type_name).blank? ? "" : self.shixun.mirror_repositories.map(&:type_name) - end - - def main_mirror - self.shixun.mirror_repositories.published_main_mirror.try(:first) - end - - # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) - # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 - # 如果都完成,则当前任务为最后一个任务 - def current_task games - current_game = games.select{|game| game.status == 1 || game.status == 0}.last - if current_game.blank? - current_game = games.last - end - current_game - end - - - # 挑战至第几关(已完成关卡数+1) - def exec_count - gcount = self.games.select{|game| game.status == 2}.size - gcount = gcount < self.games.size ? (gcount + 1) : gcount - end - - # 个人实训得分 - def total_score - self.games.select{|game| game.status == 2 && game.final_score > 0}.pluck(:final_score).sum.to_i - end - - # 个人通关数 - def passed_count - self.games.select{|game| game.status == 2}.size - end - - # 指定时间前完成的关卡数 - def time_passed_count time - time.present? ? self.games.select{|game| game.status == 2 && game.end_time < time}.size : 0 - end - - # 查看答案的关卡数,只统计通关前看的关卡 - def view_answer_count - answer_ids = user.grades.joins("join games on grades.container_id = games.id").where("container_type = 'Answer' and games.status=2 and games.end_time > grades.created_at").pluck(:container_id) - self.games.select{|game| game.status == 2 && game.answer_open != 0 && answer_ids.include?(game.id)}.size - end - - # 通关时间 - def passed_time - self.status == 1 ? self.games.select{|game| game.status == 2}.map(&:end_time).max : "--" - end - - # 耗时 - def total_spend_time - game_spend_time total_cost_time - end - - # 通关总耗时 - def total_cost_time - self.games.select{|game| game.status == 2}.map(&:cost_time).sum.to_i - end - -end diff --git a/app/models/old_message_detail.rb b/app/models/old_message_detail.rb deleted file mode 100644 index 5c1b94f51..000000000 --- a/app/models/old_message_detail.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OldMessageDetail < ApplicationRecord -end diff --git a/app/models/output.rb b/app/models/output.rb deleted file mode 100644 index 7a4a22e7e..000000000 --- a/app/models/output.rb +++ /dev/null @@ -1,15 +0,0 @@ -# 字段说明: -# code:-1表示评测未通过,0表示评测成功,实质是status的值 -# mes: -# out_put: -# test_set_position: 测试集序号(排序) -# actual_output: -# result: -# is_public:测试集是否是公开 -# query_index:评测次数 -# compile_success: -# text_scor: -# sec_key:每次评测的唯一标识 -class Output < ApplicationRecord - belongs_to :game -end diff --git a/app/models/program_bank.rb b/app/models/program_bank.rb deleted file mode 100644 index c9be9af9f..000000000 --- a/app/models/program_bank.rb +++ /dev/null @@ -1,34 +0,0 @@ -class ProgramBank < ApplicationRecord - - def oj_language - result = case language - when '1' - then 'C' - when '2' - then 'C++' - when '3' - then 'Python' - when '4' - then 'Java' - end - result - end - - def strip_description - strip_html description - end - - def oj_sub_discipline_id - result = case language - when '1' - then 3 - when '2' - then 4 - when '3' - then 5 - when '4' - then 2 - end - result - end -end diff --git a/app/models/program_bank_test.rb b/app/models/program_bank_test.rb deleted file mode 100644 index ea336ae91..000000000 --- a/app/models/program_bank_test.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ProgramBankTest < ApplicationRecord -end diff --git a/app/models/relationship.rb b/app/models/relationship.rb deleted file mode 100644 index d71987867..000000000 --- a/app/models/relationship.rb +++ /dev/null @@ -1,8 +0,0 @@ -# TODO: 已废弃 -class Relationship < ApplicationRecord - belongs_to :follower, class_name: "User" - belongs_to :followed, class_name: "User" - - validates :follower_id, presence: true - validates :followed_id, presence: true -end diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb deleted file mode 100644 index 72e1ebfff..000000000 --- a/app/models/repertoire.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Repertoire < ApplicationRecord - has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy - - has_many :tag_repertoires, through: :sub_repertoires - has_many :user_interests, dependent: :delete_all -end diff --git a/app/models/run_code_message.rb b/app/models/run_code_message.rb deleted file mode 100644 index 1fcac1cf7..000000000 --- a/app/models/run_code_message.rb +++ /dev/null @@ -1,3 +0,0 @@ -class RunCodeMessage < ApplicationRecord - belongs_to :game -end diff --git a/app/models/school.rb b/app/models/school.rb index 9c6eb10b5..f3b7ac0ab 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -1,44 +1,44 @@ class School < ApplicationRecord has_many :departments, dependent: :destroy - has_many :shixun_schools, :dependent => :destroy - has_many :shixuns, :through => :shixun_schools - - has_many :ec_school_users, :dependent => :destroy - has_many :users, :through => :ec_school_users - - has_many :ec_major_schools, :dependent => :destroy - has_many :ec_majors, :through => :ec_major_schools - - has_many :school_daily_reports, dependent: :destroy - has_many :courses + # has_many :shixun_schools, :dependent => :destroy + # has_many :shixuns, :through => :shixun_schools + # + # has_many :ec_school_users, :dependent => :destroy + # has_many :users, :through => :ec_school_users + # + # has_many :ec_major_schools, :dependent => :destroy + # has_many :ec_majors, :through => :ec_major_schools + # + # has_many :school_daily_reports, dependent: :destroy + # has_many :courses has_many :customers, dependent: :destroy - has_one :partner, dependent: :destroy - - has_many :apply_add_departments, dependent: :destroy + # has_one :partner, dependent: :destroy + # + # has_many :apply_add_departments, dependent: :destroy has_many :user_extensions, dependent: :nullify after_create do SyncTrustieJob.perform_later("school", 1) if allow_sync_to_trustie? #同步到trustie end - # 学校管理员 - def manager?(user) - ec_school_users.exists?(user_id: user.id) - end - - # 专业管理员 - def major_manager?(user) - relations = ec_major_schools.not_template.joins(:ec_major_school_users) - relations.exists?(ec_major_school_users: { user_id: user.id }) - end - - # 课程管理员 - def course_manager?(user) - relations = ec_major_schools.not_template.joins(ec_years: :ec_course_users) - relations.exists?(ec_course_users: { user_id: user.id }) - end + # # 学校管理员 + # def manager?(user) + # ec_school_users.exists?(user_id: user.id) + # end + # + # # 专业管理员 + # def major_manager?(user) + # relations = ec_major_schools.not_template.joins(:ec_major_school_users) + # relations.exists?(ec_major_school_users: { user_id: user.id }) + # end + # + # # 课程管理员 + # def course_manager?(user) + # relations = ec_major_schools.not_template.joins(ec_years: :ec_course_users) + # relations.exists?(ec_course_users: { user_id: user.id }) + # end def manage_permission?(user) manager?(user) || major_manager?(user) || course_manager?(user) diff --git a/app/models/tag_discipline.rb b/app/models/tag_discipline.rb deleted file mode 100644 index cc4f656fb..000000000 --- a/app/models/tag_discipline.rb +++ /dev/null @@ -1,12 +0,0 @@ -class TagDiscipline < ApplicationRecord - belongs_to :sub_discipline - belongs_to :user, optional: true - has_many :tag_discipline_containers, dependent: :destroy - - validates_presence_of :name - validates :name, length: { maximum: 15, too_long: "不能超过15个字符" } - - def discipline - sub_discipline&.discipline - end -end diff --git a/app/models/tag_discipline_container.rb b/app/models/tag_discipline_container.rb deleted file mode 100644 index 44b28af1a..000000000 --- a/app/models/tag_discipline_container.rb +++ /dev/null @@ -1,5 +0,0 @@ -class TagDisciplineContainer < ApplicationRecord - belongs_to :tag_discipline - - belongs_to :container, polymorphic: true, optional: true, touch: true -end diff --git a/app/models/tag_repertoire.rb b/app/models/tag_repertoire.rb deleted file mode 100644 index fe7054e23..000000000 --- a/app/models/tag_repertoire.rb +++ /dev/null @@ -1,13 +0,0 @@ -class TagRepertoire < ApplicationRecord - belongs_to :sub_repertoire - - has_many :shixun_tag_repertoires, dependent: :destroy - has_many :shixuns, through: :shixun_tag_repertoires - - has_many :memo_tag_repertoires, :dependent => :destroy - has_many :memos, :through => :memo_tag_repertoires - - - scope :field_for_list, lambda{select([:id, :name])} - -end diff --git a/app/models/teacher_course_group.rb b/app/models/teacher_course_group.rb deleted file mode 100644 index 769026366..000000000 --- a/app/models/teacher_course_group.rb +++ /dev/null @@ -1,17 +0,0 @@ -class TeacherCourseGroup < ApplicationRecord - belongs_to :course_group - belongs_to :course, optional: true - belongs_to :user - - belongs_to :course_member, optional: true - - scope :find_teacher_group_ids, lambda { |ids| where(course_group_id: ids) unless ids.blank?} - scope :get_user_groups,lambda {|ids| where(user_id:ids)} - - validates_uniqueness_of :course_group_id, scope: :course_member_id - - def course_members - self.course_group.course_members - end - -end diff --git a/app/models/team_member.rb b/app/models/team_member.rb deleted file mode 100644 index cf131f762..000000000 --- a/app/models/team_member.rb +++ /dev/null @@ -1,18 +0,0 @@ -class TeamMember < ApplicationRecord - belongs_to :user - - scope :only_teachers, -> { where(is_teacher: true) } - scope :without_teachers, -> { where(is_teacher: false) } - - def creator? - role == 1 - end - - def en_role - is_teacher? ? 'teacher' : 'member' - end - - def user_name - user&.real_name - end -end diff --git a/app/models/trustie_hack.rb b/app/models/trustie_hack.rb deleted file mode 100644 index 87d9d31d8..000000000 --- a/app/models/trustie_hack.rb +++ /dev/null @@ -1,10 +0,0 @@ -class TrustieHack < ApplicationRecord - validates_length_of :description, maximum: 500, message: "不能超过500个字符" - has_many :hack_users, :dependent => :destroy - belongs_to :trustie_hackathon, counter_cache: true - - - def entry_info(user_id) - hack_users.exists?(user_id: user_id) - end -end diff --git a/app/models/trustie_hackathon.rb b/app/models/trustie_hackathon.rb deleted file mode 100644 index 3a45687ce..000000000 --- a/app/models/trustie_hackathon.rb +++ /dev/null @@ -1,5 +0,0 @@ -class TrustieHackathon < ApplicationRecord - #validates_length_of :description, maximum: 10000 - has_many :trustie_hacks, :dependent => :destroy - -end diff --git a/app/models/user.rb b/app/models/user.rb index 56e0baa1c..f26fcb094 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -85,7 +85,7 @@ class User < ApplicationRecord has_many :repositories, dependent: :destroy # 教学案例 - has_many :libraries, dependent: :destroy + # has_many :libraries, dependent: :destroy has_many :project_trends, dependent: :destroy # Groups and active users diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb index 538369f1a..ebe7ed03c 100644 --- a/app/models/user_agent.rb +++ b/app/models/user_agent.rb @@ -1,5 +1,5 @@ class UserAgent < ApplicationRecord - has_many :user_actionss, :foreign_key => "ip", :primary_key => "ip" + has_many :user_actions, :foreign_key => "ip", :primary_key => "ip" USER_AD = 1 # 广告宣传的引流 USER_REGISTER = 2 # 引流注册 USER_COMPETITION = 3 # 引流参加竞赛 diff --git a/app/models/user_interest.rb b/app/models/user_interest.rb index bdb6e77d4..1c2d8bc84 100644 --- a/app/models/user_interest.rb +++ b/app/models/user_interest.rb @@ -1,4 +1,4 @@ class UserInterest < ApplicationRecord belongs_to :user - belongs_to :repertoire + # belongs_to :repertoire end \ No newline at end of file diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 652761f24..d2677d93c 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -1,21 +1,21 @@ class Projects::ListMyQuery < ApplicationQuery - attr_reader :params, :current_user + attr_reader :params, :user # sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc - def initialize(params,current_user) + def initialize(params,user) @params = params - @current_user = current_user + @user = user end def call if params[:category].blank? - projects = Project.joins(:members).where(members: { user_id: current_user.id }) + projects = Project.joins(:members).where(members: { user_id: user.id }) elsif params[:category].to_s == "manage" - projects = Project.where(user_id: current_user.id) + projects = Project.where(user_id: user.id) else - projects = Project.where.not(user_id: current_user.id).joins(:members).where(members: { user_id: current_user.id }) + projects = Project.where.not(user_id: user.id).joins(:members).where(members: { user_id: user.id }) end unless params[:is_public].blank? projects = projects.where(is_public: (params[:is_public].to_s == "publicly")) diff --git a/app/views/challenges/_challenge.json.jbuilder b/app/views/challenges/_challenge.json.jbuilder deleted file mode 100644 index ea105ad2c..000000000 --- a/app/views/challenges/_challenge.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.name challenge.subject -json.position challenge.position -json.tag_count challenge.challenge_tags_count diff --git a/app/views/challenges/_top_common_data.jbuilder b/app/views/challenges/_top_common_data.jbuilder deleted file mode 100644 index b3715b656..000000000 --- a/app/views/challenges/_top_common_data.jbuilder +++ /dev/null @@ -1,19 +0,0 @@ -# 新建关卡 -json.choice_url new_shixun_challenge_path(shixun_identifier, st: 1) if @power == 0 -json.practice_url new_shixun_challenge_path(shixun_identifier, st: 0) if @power == 0 -json.go_back_url shixun_challenges_path -if @prev_challenge - json.prev_challenge do - json.id @prev_challenge.id - json.st @prev_challenge.st - end -end -if @next_challenge - json.next_challenge do - json.id @next_challenge.id - json.st @next_challenge.st - end -end -json.position @position -json.name @challenge.try(:subject) - diff --git a/app/views/challenges/answer.json.jbuilder b/app/views/challenges/answer.json.jbuilder deleted file mode 100644 index 0a3c01ccf..000000000 --- a/app/views/challenges/answer.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.array! @answers do |answer| - json.(answer, :id, :name, :contents, :level, :score) -end \ No newline at end of file diff --git a/app/views/challenges/create.json.jbuilder b/app/views/challenges/create.json.jbuilder deleted file mode 100644 index 534873669..000000000 --- a/app/views/challenges/create.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.status 1 -json.messages "新建成功" -json.challenge_id @challenge.id \ No newline at end of file diff --git a/app/views/challenges/create_choose_question.json.jbuilder b/app/views/challenges/create_choose_question.json.jbuilder deleted file mode 100644 index a6a512e19..000000000 --- a/app/views/challenges/create_choose_question.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.challenge_choose_id @challenge_choose.id \ No newline at end of file diff --git a/app/views/challenges/crud_answer.json.jbuilder b/app/views/challenges/crud_answer.json.jbuilder deleted file mode 100644 index e16f09423..000000000 --- a/app/views/challenges/crud_answer.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status 1 -json.message "操作成功" \ No newline at end of file diff --git a/app/views/challenges/destroy.json.jbuilder b/app/views/challenges/destroy.json.jbuilder deleted file mode 100644 index edd1290f0..000000000 --- a/app/views/challenges/destroy.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status 1 -json.message "删除成功!" \ No newline at end of file diff --git a/app/views/challenges/destroy_challenge_choose.json.jbuilder b/app/views/challenges/destroy_challenge_choose.json.jbuilder deleted file mode 100644 index d5dc043ea..000000000 --- a/app/views/challenges/destroy_challenge_choose.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status @status -json.challenge_id @challenge.id \ No newline at end of file diff --git a/app/views/challenges/edit.json.jbuilder b/app/views/challenges/edit.json.jbuilder deleted file mode 100644 index 9a135ff56..000000000 --- a/app/views/challenges/edit.json.jbuilder +++ /dev/null @@ -1,26 +0,0 @@ -json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier -json.chooses do - json.array! @chooses do |choose| - json.choose_id choose.id - json.type choose.category - end -end -json.st @challenge.st - -if @tab == 0 - # 本关任务tab的编辑模式 - json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time, :st) - json.tags @challenge.challenge_tags.map(&:name) -elsif @tab == 1 - # 评测设置的编辑模式 - json.(@challenge, :id, :path, :exec_path, :show_type, :original_picture_path, :expect_picture_path, :picture_path, - :web_route, :test_set_score, :test_set_average, :exec_time) - json.has_web_route @shixun.has_web_route? - json.test_sets @challenge.test_sets do |set| - json.hidden (set.is_public ? 0 : 1) - json.(set, :input, :output, :score, :match_rule) - end -elsif @tab == 2 - # 参考答案 - json.(@challenge, :answer) -end \ No newline at end of file diff --git a/app/views/challenges/edit_choose_question.json.jbuilder b/app/views/challenges/edit_choose_question.json.jbuilder deleted file mode 100644 index 0405c0598..000000000 --- a/app/views/challenges/edit_choose_question.json.jbuilder +++ /dev/null @@ -1,11 +0,0 @@ -json.(@challenge_choose, :challenge_id, :subject, :answer, - :standard_answer, :score, :difficult, - :position, :category) -json.st @challenge.st -# 选项的参数 -json.choose_contents @challenge_choose.challenge_questions do |question| - json.(question, :option_name, :position, :right_key) -end - -json.tags @challenge_choose.challenge_tags.map(&:name) - diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder deleted file mode 100644 index c53ab9c58..000000000 --- a/app/views/challenges/index.json.jbuilder +++ /dev/null @@ -1,32 +0,0 @@ -# 公共接口,新建关卡任务 -# json.partial! 'challenges/new_link', shixun_identifier: @shixun.identifier -json.description @shixun.description -json.power @editable -json.shixun_identifier @shixun.identifier -json.shixun_status @shixun.status -json.is_jupyter @shixun.is_jupyter? -json.allow_skip @shixun.task_pass - - -# 列表 -if @challenges.present? - json.challenge_list @challenges do |challenge| - json.challenge_id challenge.id - json.position challenge.position - json.st challenge.st - json.name challenge.subject - json.score challenge.score - json.passed_count challenge.user_passed_count - json.playing_count challenge.playing_count - json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - #json.open_game challenge.open_game(@user.id, @shixun) - if @editable - json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.up_url index_up_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) unless challenge.position < 2 - json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position - end - #json.passed challenge.has_passed?(@user.id) - json.status challenge.user_tpi_status @user.id - end -end diff --git a/app/views/challenges/index_down.json.jbuilder b/app/views/challenges/index_down.json.jbuilder deleted file mode 100644 index d0530a9be..000000000 --- a/app/views/challenges/index_down.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status 1 -json.message "下移成功" \ No newline at end of file diff --git a/app/views/challenges/index_up.json.jbuilder b/app/views/challenges/index_up.json.jbuilder deleted file mode 100644 index b91f30a75..000000000 --- a/app/views/challenges/index_up.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status 1 -json.message "上移成功" \ No newline at end of file diff --git a/app/views/challenges/new.json.jbuilder b/app/views/challenges/new.json.jbuilder deleted file mode 100644 index b2d079960..000000000 --- a/app/views/challenges/new.json.jbuilder +++ /dev/null @@ -1,13 +0,0 @@ -# 导航栏公共数据 -json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier - -# st: 0 实践任务, 1 选择题任务 -json.st @st - -# 过关任务的默认值 -json.task_pass_default @task_pass_default - -json.submit_url shixun_challenges_path(@shixun, :st => @st) - - - diff --git a/app/views/challenges/show.json.jbuilder b/app/views/challenges/show.json.jbuilder deleted file mode 100644 index fb86683b4..000000000 --- a/app/views/challenges/show.json.jbuilder +++ /dev/null @@ -1,10 +0,0 @@ -# 导航栏公共数据 -json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier -json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time, :st) -json.tags @challenge.challenge_tags.map(&:name) - - - - - - diff --git a/app/views/challenges/show_choose_question.json.jbuilder b/app/views/challenges/show_choose_question.json.jbuilder deleted file mode 100644 index 5513d8e1b..000000000 --- a/app/views/challenges/show_choose_question.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.(@challenge_choose, :challenge_id, :subject, :answer, - :standard_answer, :score, :difficult, - :position, :category) \ No newline at end of file diff --git a/app/views/challenges/update.json.jbuilder b/app/views/challenges/update.json.jbuilder deleted file mode 100644 index d927bd450..000000000 --- a/app/views/challenges/update.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.status 1 -json.messages "更新成功!" -json.challenge_id @challenge.id \ No newline at end of file diff --git a/app/views/challenges/update_choose_question.json.jbuilder b/app/views/challenges/update_choose_question.json.jbuilder deleted file mode 100644 index 3ee5d377c..000000000 --- a/app/views/challenges/update_choose_question.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.challenge_choose_id @challenge_choose.try(:id) \ No newline at end of file diff --git a/app/views/course_groups/_course_group.json.jbuilder b/app/views/course_groups/_course_group.json.jbuilder deleted file mode 100644 index 972891e96..000000000 --- a/app/views/course_groups/_course_group.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.course_group_id attachment_group_setting.course_group.id -json.course_group_name attachment_group_setting.course_group.name -json.course_group_publish_time attachment_group_setting.publish_time \ No newline at end of file diff --git a/app/views/course_groups/destroy.json.jbuilder b/app/views/course_groups/destroy.json.jbuilder deleted file mode 100644 index 0fbd93d7f..000000000 --- a/app/views/course_groups/destroy.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.status 0 -json.message "删除成功" -json.right_url "/courses/#{@course.id}/students" \ No newline at end of file diff --git a/app/views/course_second_categories/destroy.json.jbuilder b/app/views/course_second_categories/destroy.json.jbuilder deleted file mode 100644 index c1726ab8e..000000000 --- a/app/views/course_second_categories/destroy.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.status 0 -json.right_url @right_url \ No newline at end of file diff --git a/app/views/courses/_course.json.jbuilder b/app/views/courses/_course.json.jbuilder deleted file mode 100644 index 3c109f8b4..000000000 --- a/app/views/courses/_course.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.extract! course, :id, :created_at, :updated_at -json.url course_url(course, format: :json) diff --git a/app/views/courses/act_score.json.jbuilder b/app/views/courses/act_score.json.jbuilder deleted file mode 100644 index ed6929b13..000000000 --- a/app/views/courses/act_score.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.course_members @course_members.each do |member| - user = member.user - json.user_login user&.login - json.user_name user&.real_name - # json.course_group member.course_group_name - json.total_score member.score -end \ No newline at end of file diff --git a/app/views/courses/add_teacher_popup.json.jbuilder b/app/views/courses/add_teacher_popup.json.jbuilder deleted file mode 100644 index a77d05b47..000000000 --- a/app/views/courses/add_teacher_popup.json.jbuilder +++ /dev/null @@ -1,13 +0,0 @@ -json.school_name @school_name -json.graduation_groups do - json.array! @graduation_groups do |graduation_group| - json.id graduation_group.id - json.name graduation_group.name - end -end -json.course_groups do - json.array! @course_groups do |course_group| - json.id course_group.id - json.name course_group.name - end -end \ No newline at end of file diff --git a/app/views/courses/all_course_groups.json.jbuilder b/app/views/courses/all_course_groups.json.jbuilder deleted file mode 100644 index e64b9929a..000000000 --- a/app/views/courses/all_course_groups.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.course_groups do - json.array! @course_groups_array do |course_group| - json.id course_group.id - json.name course_group.name - end -end -json.course_groups_count @course_groups_array.size \ No newline at end of file diff --git a/app/views/courses/apply_teachers.json.jbuilder b/app/views/courses/apply_teachers.json.jbuilder deleted file mode 100644 index b81f5d77b..000000000 --- a/app/views/courses/apply_teachers.json.jbuilder +++ /dev/null @@ -1,15 +0,0 @@ -json.teacher_list_size @teacher_list_size -json.apply_size @applications_size -json.is_admin @is_admin -json.application_list do - json.array! @applications do |application| - json.application_id application.id - json.user_id application.course_message_id - json.name application.application_user.real_name - json.name_link user_path(application.application_user) - json.login application.application_user.login - json.image_url url_to_avatar(application.application_user) - json.school_name application.application_user.school_name - json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" - end -end \ No newline at end of file diff --git a/app/views/courses/attahcment_category_list.json.jbuilder b/app/views/courses/attahcment_category_list.json.jbuilder deleted file mode 100644 index 217b1092e..000000000 --- a/app/views/courses/attahcment_category_list.json.jbuilder +++ /dev/null @@ -1,10 +0,0 @@ -json.has_course_groups @has_course_groups -json.course_modules do - json.array! @course_modules do |course_module| - json.id course_module.id - json.module_name course_module.module_name - json.course_second_categories do - json.array! course_module.course_second_categories, :id, :name - end - end -end diff --git a/app/views/courses/base_info.json.jbuilder b/app/views/courses/base_info.json.jbuilder deleted file mode 100644 index c32617968..000000000 --- a/app/views/courses/base_info.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.course_id @course.id -json.course_name @course.name \ No newline at end of file diff --git a/app/views/courses/board_list.json.jbuilder b/app/views/courses/board_list.json.jbuilder deleted file mode 100644 index 2115f1752..000000000 --- a/app/views/courses/board_list.json.jbuilder +++ /dev/null @@ -1,10 +0,0 @@ -json.partial! 'commons/success' - -json.data do - json.course_id @course.id - json.user_course_identity @current_user.course_identity(@course) - json.boards do - json.array! @boards, :id, :name - end - json.email_notify @course.email_notify -end diff --git a/app/views/courses/course_group_list.json.jbuilder b/app/views/courses/course_group_list.json.jbuilder deleted file mode 100644 index 8c30a6b20..000000000 --- a/app/views/courses/course_group_list.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.course_groups do - json.array! @all_course_groups do |course_group| - json.id course_group.id - json.name course_group.name - json.checked @existed_course_group_ids.include? course_group.id - end -end \ No newline at end of file diff --git a/app/views/courses/course_groups.json.jbuilder b/app/views/courses/course_groups.json.jbuilder deleted file mode 100644 index 0057befb6..000000000 --- a/app/views/courses/course_groups.json.jbuilder +++ /dev/null @@ -1,12 +0,0 @@ -json.course_groups @course_groups.each do |group| - json.(group, :id, :course_members_count, :name, :invite_code_halt) - json.invite_code group.invite_code if @user_course_identity < Course::STUDENT - json.member_manager member_manager(group, @teachers) if @user_course_identity < Course::NORMAL - json.edit_auth edit_auth(group, @teachers) if @user_course_identity < Course::STUDENT -end - -if @user_course_identity == Course::STUDENT - json.current_group_id @current_group_id -end -json.none_group_member_count @course.none_group_count -json.group_count @all_group_count \ No newline at end of file diff --git a/app/views/courses/course_videos.json.jbuilder b/app/views/courses/course_videos.json.jbuilder deleted file mode 100644 index 807ff92bb..000000000 --- a/app/views/courses/course_videos.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.count @count -json.videos @videos, partial: 'users/videos/video', as: :video -json.course_id @course.id \ No newline at end of file diff --git a/app/views/courses/create.json.jbuilder b/app/views/courses/create.json.jbuilder deleted file mode 100644 index be20a994b..000000000 --- a/app/views/courses/create.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.course_id @course.id -json.first_category_url module_url(@course.none_hidden_course_modules.first, @course) \ No newline at end of file diff --git a/app/views/courses/export_course_info.xlsx.axlsx b/app/views/courses/export_course_info.xlsx.axlsx deleted file mode 100644 index 789f5c43b..000000000 --- a/app/views/courses/export_course_info.xlsx.axlsx +++ /dev/null @@ -1,29 +0,0 @@ -wb = xlsx_package.workbook -wb.use_shared_strings = true -wb.styles do |s| - no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } - sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} - - #课堂信息摘要 - wb.add_worksheet(name:course_info[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - course_main_info = course_info[1] - course_group_info = course_info[2] - group_info_d = course_group_info[0] - group_info_detail = course_group_info[1] - course_main_info.each do |c| - sheet.add_row c, :style => sz_all #用户id - end - sheet["A1:A7"].each { |c| c.style = row_cell } - sheet.add_row [],:style => sz_all - if group_info_detail.count > 0 - sheet.add_row group_info_d, :style => blue_cell - group_info_detail.each do |group| - sheet.add_row group, :style => sz_all #用户id - end - sheet.column_info.second.width = 40 - end - end #add_worksheet -end diff --git a/app/views/courses/export_member_act_score.xlsx.axlsx b/app/views/courses/export_member_act_score.xlsx.axlsx deleted file mode 100644 index 357b28a34..000000000 --- a/app/views/courses/export_member_act_score.xlsx.axlsx +++ /dev/null @@ -1,25 +0,0 @@ -wb = xlsx_package.workbook -wb.use_shared_strings = true -wb.styles do |s| - no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } - sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} - - #课堂活跃度统计 - wb.add_worksheet(name:activity_level[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - sheet_title = activity_level[1] - sheet_content = activity_level[2] - sheet.add_row sheet_title, :height => 25,:style => blue_cell - if sheet_content.count > 0 - sheet_content.each_with_index do |c,index| - c_1 = (index+1) - c_2 = [c_1] + c.values - sheet.add_row c_2, :height => 25, :style => sz_all #用户id - end - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 8 - end - end #add_worksheet -end diff --git a/app/views/courses/export_member_scores_excel.xlsx.axlsx b/app/views/courses/export_member_scores_excel.xlsx.axlsx deleted file mode 100644 index 20cd65b6f..000000000 --- a/app/views/courses/export_member_scores_excel.xlsx.axlsx +++ /dev/null @@ -1,145 +0,0 @@ -wb = xlsx_package.workbook -wb.use_shared_strings = true -wb.styles do |s| - no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } - sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} - - #学生总成绩 - wb.add_worksheet(name:course_scores[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - sheet_title = course_scores[1] #头部标题 - sheet_title_counts = course_scores[2] #总成绩的作业数(包含每一项的总得分)如实训作业的作业数+总成绩 - sheet_content = course_scores[3] - sheet_length = sheet_title.count - sheet.add_row [""]*sheet_length, :style => blue_cell - sheet.add_row [""]*sheet_length, :style => blue_cell - sheet.merge_cells("A1:A2") - sheet.merge_cells("B1:B2") - sheet.merge_cells("C1:C2") - sheet.merge_cells("D1:D2") - sheet.merge_cells("E1:E2") - sheet.merge_cells("F1:F2") - sheet.merge_cells("G1:G2") - sheet.merge_cells("H1:H2") - # sheet.merge_cells (Axlsx::cell_r(sheet_length-1,0) + ':' + Axlsx::cell_r(sheet_length-1,1)) #最后一行的合并 - sheet_first = sheet.rows.first #第一行 - sheet_second = sheet.rows.second #第二行 - work_head_title = %w(实训作业 普通作业 分组作业 毕设任务 试卷) - (0..(sheet_length-1)).each do |i| - if i <= 7 - sheet_first.cells[i].value = sheet_title[i] - else - sheet_second.cells[i].value = sheet_title[i] - end - end - st_col = 8 - sheet_title_counts.each_with_index do |c,index| - end_col = (st_col + c - 1) - sheet.merge_cells sheet_first.cells[(st_col..end_col)] - sheet_first.cells[st_col].value = work_head_title[index.to_i] - st_col = end_col + 1 - end - - if sheet_content.count > 0 - sheet_content.each_with_index do |c,index| - c_1 = (index+1) - c_2 = [c_1] + c - sheet.add_row c_2, :height => 25,:style => sz_all #用户id - end - end - sheet.column_widths *([15]*sheet.column_info.count) - sheet.column_info.first.width = 8 - sheet.rows[1].height = 40 - end #add_worksheet - - #实训作业 - if shixun_works.count > 0 - shixun_works.each do |shixun| - wb.add_worksheet(name:shixun[0]) do |sheet| - head_title = shixun[1] - content_shixun = shixun[2] - sheet.sheet_view.show_grid_lines = false - sheet.add_row head_title, :style => blue_cell - if content_shixun.count > 0 - content_shixun.each do |user| - sheet.add_row user, :height => 25,:style => sz_all - end #each_widh_index - end - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 12 - end #add_worksheet - end - end - - #普通作业 - if common_works.count > 0 - common_works.each do |work| - wb.add_worksheet(name:work[0]) do |sheet| - head_title = work[1] - content_ = work[2] - sheet.sheet_view.show_grid_lines = false - sheet.add_row head_title, :style => blue_cell - if content_.count > 0 - content_.each do |user| - sheet.add_row user, :height => 25,:style => no_wrap_sz - end #each_widh_index - end - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 12 - end #add_worksheet - end - end - - #分组作业 - if group_works.count > 0 - group_works.each do |work| - wb.add_worksheet(name:work[0]) do |sheet| - head_title = work[1] - content_ = work[2] - sheet.sheet_view.show_grid_lines = false - sheet.add_row head_title, :style => blue_cell - if content_.count > 0 - content_.each do |user| - sheet.add_row user, :height => 25,:style => sz_all - end #each_widh_index - end - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 12 - end #add_worksheet - end - end - - #毕设任务 - if task_works.count > 0 - task_works.each do |task| - wb.add_worksheet(name:task[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - content_ = task[2] - sheet.add_row task[1], :style => blue_cell - content_.each do |user| - sheet.add_row user, :height => 25,:style => sz_all - end #each_widh_index - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 12 - end #add_worksheet - end - end - - #试卷 - if exercise_works.count > 0 - exercise_works.each do |ex| - wb.add_worksheet(name: ex[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - content_ = ex[2] - sheet.add_row ex[1], :style => blue_cell - content_.each do |user| - sheet.add_row user, :height => 25,:style => sz_all #用户id - end #each_widh_index - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 12 - end #add_worksheet - end - end -end diff --git a/app/views/courses/get_historical_course_students.json.jbuilder b/app/views/courses/get_historical_course_students.json.jbuilder deleted file mode 100644 index be58ff06a..000000000 --- a/app/views/courses/get_historical_course_students.json.jbuilder +++ /dev/null @@ -1,9 +0,0 @@ -json.students do - json.array! @students do |student| - json.user_id student.user_id - json.name student.user.real_name - json.student_id student.user.student_id - json.school_name student.user.school_name - end -end -json.students_count @students_count \ No newline at end of file diff --git a/app/views/courses/get_historical_courses.json.jbuilder b/app/views/courses/get_historical_courses.json.jbuilder deleted file mode 100644 index 74b190d8e..000000000 --- a/app/views/courses/get_historical_courses.json.jbuilder +++ /dev/null @@ -1,14 +0,0 @@ -json.courses do - json.array! @courses do |course| - if course.course_groups.present? - course.course_groups.each do |course_group| - json.name course.name + "-" + course_group.name - json.course_id course.id - json.course_group_id course_group.id - end - else - json.name course.name - json.course_id course.id - end - end -end \ No newline at end of file diff --git a/app/views/courses/graduation_group_list.json.jbuilder b/app/views/courses/graduation_group_list.json.jbuilder deleted file mode 100644 index e9036bce2..000000000 --- a/app/views/courses/graduation_group_list.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.graduation_group_list do - json.array! @graduation_group_list do |graduation_group| - json.id graduation_group.id - json.name graduation_group.name - end -end -json.graduation_groups_count @graduation_group_list.size \ No newline at end of file diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder deleted file mode 100644 index 8a0d06475..000000000 --- a/app/views/courses/index.json.jbuilder +++ /dev/null @@ -1,17 +0,0 @@ -json.courses @courses do |course| - json.id course.id - json.name course.name - json.avatar_url url_to_avatar(course.teacher) - json.creator course.teacher.real_name - json.school course.school&.name - json.technical_title "" # course.teacher.identity - json.course_members_count course.course_members_count - json.tasks_count get_tasks_count course - json.visits course.visits - json.is_public course.is_public - json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL - json.is_end course.is_end - json.first_category_url module_url(course.none_hidden_course_modules.first, course) - json.excellent course.excellent -end -json.courses_count @courses_count diff --git a/app/views/courses/informs.json.jbuilder b/app/views/courses/informs.json.jbuilder deleted file mode 100644 index 7fc396184..000000000 --- a/app/views/courses/informs.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.informs @informs do |inform| - json.id inform.id - json.name inform.name - json.description inform.description -end \ No newline at end of file diff --git a/app/views/courses/left_banner.json.jbuilder b/app/views/courses/left_banner.json.jbuilder deleted file mode 100644 index f3b80b4f5..000000000 --- a/app/views/courses/left_banner.json.jbuilder +++ /dev/null @@ -1,45 +0,0 @@ -json.is_teacher @is_teacher -json.course_modules @course_modules.each do |mod| - json.id mod.id - json.name mod.module_name - json.type mod.module_type - json.position mod.position - json.task_count course_task_count(@course, mod.module_type) - json.main_id mod.module_type == "board" ? @course.course_board.try(:id) : @course.id - json.category_url module_url(mod, @course) - if @second_category_type.include?(mod.module_type) - case mod.module_type - when "course_group" - # json.none_group_count @course.none_group_count - # json.second_category left_group_info @course - when "board" - course_board = @course.course_board - if course_board.present? - json.second_category course_board.children.each do |board| - json.category_id board.id - json.category_name board.name - json.position board.position - json.category_count board.messages_count - json.category_type "messages" - json.second_category_url "/courses/#{@course.id}/boards/#{board.id}" - end - end - else - json.second_category mod.course_second_categories.each do |category| - json.category_id category.id - json.category_name category.name - json.position category.position - json.category_count category_task_count(@course, category, @user) - json.category_type category.category_type_str - json.second_category_url category_url(category, @course) - end - end - end -end - -json.hidden_modules @hidden_modules.each do |mod| - json.id mod.id - json.name mod.module_name - json.type mod.module_type - json.position mod.position -end \ No newline at end of file diff --git a/app/views/courses/mine.json.jbuilder b/app/views/courses/mine.json.jbuilder deleted file mode 100644 index fc6a5becc..000000000 --- a/app/views/courses/mine.json.jbuilder +++ /dev/null @@ -1,6 +0,0 @@ -json.partial! "commons/success" -json.data @courses do |course| - json.(course, :id, :name, :updated_at, :end_date) - json.created_at course.created_at.strftime("%Y-%m-%d") -end - diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder deleted file mode 100644 index d6b3db136..000000000 --- a/app/views/courses/online_learning.json.jbuilder +++ /dev/null @@ -1,12 +0,0 @@ -json.stages @stages do |stage| - json.partial! 'stages/stage', locals: {stage: stage, user: @user, subject: @subject, myshixuns: @myshixuns} -end - -# json.description @subject&.description - -json.start_learning @start_learning -json.subject_id @subject.id - -json.learned @start_learning ? @course.my_subject_progress(@myshixuns) : 0 - -json.last_shixun @start_learning ? last_subject_shixun(@course, @myshixuns) : "" \ No newline at end of file diff --git a/app/views/courses/search_course_list.json.jbuilder b/app/views/courses/search_course_list.json.jbuilder deleted file mode 100644 index be751e064..000000000 --- a/app/views/courses/search_course_list.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.course_lists @course_lists do |course_list| - json.id course_list.id - json.name course_list.name -end -json.search_count @search_count \ No newline at end of file diff --git a/app/views/courses/search_teacher_candidate.json.jbuilder b/app/views/courses/search_teacher_candidate.json.jbuilder deleted file mode 100644 index cfe781165..000000000 --- a/app/views/courses/search_teacher_candidate.json.jbuilder +++ /dev/null @@ -1,14 +0,0 @@ -json.candidates do - json.array! @users do |user| - json.id user.id - json.name user.real_name - json.nickname user.nickname - json.login user.login - json.school_name user.user_extension.school.try(:name) - json.school_id user.user_extension.school.try(:id) - json.added @course.course_member?(user.id, [1, 2, 3]) - json.image_url url_to_avatar(user) - json.phone user.hidden_phone - end -end -json.candidates_count @users_size \ No newline at end of file diff --git a/app/views/courses/search_users.json.jbuilder b/app/views/courses/search_users.json.jbuilder deleted file mode 100644 index 61362de66..000000000 --- a/app/views/courses/search_users.json.jbuilder +++ /dev/null @@ -1,11 +0,0 @@ -json.users do - json.array! @users do |user| - json.id user.id - json.login user.login - json.name user.real_name - json.student_id user&.student_id - json.school_name user&.school_name - json.added @course.course_member?(user.id, 4) - end -end -json.users_count @users_count \ No newline at end of file diff --git a/app/views/courses/settings.json.jbuilder b/app/views/courses/settings.json.jbuilder deleted file mode 100644 index 27dc9aac4..000000000 --- a/app/views/courses/settings.json.jbuilder +++ /dev/null @@ -1,20 +0,0 @@ -json.course_list_id @course.course_list&.id -json.course_list_name @course.course_list&.name -json.name @course.name -json.course_id @course.id -json.school @course.school&.name -json.class_period @course.class_period -json.credit @course.credit -json.start_date @course.start_date -json.end_date @course.end_date -json.is_public @course.is_public -json.course_module_types @course.course_modules.where(hidden: 0).pluck(:module_type) -json.course_modules @course_modules do |module_type| - json.module_type module_type.module_type - json.hidden module_type.hidden - json.module_name module_type.module_name -end -json.authentication @course.authentication -json.professional_certification @course.professional_certification -json.subject_id @course.subject_id -json.excellent @course.excellent \ No newline at end of file diff --git a/app/views/courses/show.json.jbuilder b/app/views/courses/show.json.jbuilder deleted file mode 100644 index 2ea056fa8..000000000 --- a/app/views/courses/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "courses/course", course: @course diff --git a/app/views/courses/statistics.json.jbuilder b/app/views/courses/statistics.json.jbuilder deleted file mode 100644 index c530171fc..000000000 --- a/app/views/courses/statistics.json.jbuilder +++ /dev/null @@ -1,6 +0,0 @@ -json.top_scores @top_scores.each do |cm_score| - user = cm_score.user - json.user_name user.real_name - json.user_login user.login - json.avatar_url url_to_avatar(user) -end \ No newline at end of file diff --git a/app/views/courses/students.json.jbuilder b/app/views/courses/students.json.jbuilder deleted file mode 100644 index 93d05b623..000000000 --- a/app/views/courses/students.json.jbuilder +++ /dev/null @@ -1,21 +0,0 @@ -json.students do - json.array! @students do |student| - json.user_id student.user_id - json.login student.user.try(:login) - json.name student.user.try(:real_name) - json.name_link user_path(student.user) - json.student_id student.user.try(:student_id) - json.course_group_name student.course_group_name - json.course_member_id student.id - if @user_course_identity < Course::ASSISTANT_PROFESSOR && !params[:course_group_id].present? - json.member_roles student.user.course_role(@course) - end - json.user_phone @course.excellent ? "" : student.user.hidden_phone - json.user_mail @course.excellent ? "" : student.user.hidden_mail - end -end -json.students_count @students_count -if @course_group.present? - json.course_group_name @course_group.name - json.invite_code @course_group.invite_code -end \ No newline at end of file diff --git a/app/views/courses/tasks_list.json.jbuilder b/app/views/courses/tasks_list.json.jbuilder deleted file mode 100644 index 29de925a6..000000000 --- a/app/views/courses/tasks_list.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.tasks @tasks.each do |task| - json.user_name task.user.real_name - json.task_id task.id - json.task_name task.name - json.category task.course_second_category&.name - json.position task.position -end \ No newline at end of file diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder deleted file mode 100644 index 19a92790d..000000000 --- a/app/views/courses/teachers.json.jbuilder +++ /dev/null @@ -1,26 +0,0 @@ -json.teacher_list do - json.array! @teacher_list do |teacher| - json.course_member_id teacher.id - json.name teacher.user.real_name - json.name_link user_path(teacher.user) - json.login teacher.user.login - json.user_id teacher.user.id - json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教" - json.course_groups do - if @course.course_groups_count > 0 - json.array! @course.course_groups.select{|group| teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id)} do |course_group| - json.name course_group.name - json.id course_group.id - end - end - end - json.graduation_group teacher.graduation_group.try(:name) - json.graduation_group_id teacher.graduation_group.try(:id) - if @user_course_identity < Course::ASSISTANT_PROFESSOR - json.member_roles teacher.user.course_role(@course) - end - end -end -json.teacher_list_size @teacher_list_size -json.apply_size @applications_size -json.is_admin @is_admin \ No newline at end of file diff --git a/app/views/courses/top_banner.json.jbuilder b/app/views/courses/top_banner.json.jbuilder deleted file mode 100644 index b5ed437e3..000000000 --- a/app/views/courses/top_banner.json.jbuilder +++ /dev/null @@ -1,28 +0,0 @@ -json.name @course.name -json.teacher_name @course.teacher.real_name -json.teacher_login @course.teacher.login -json.teacher_img url_to_avatar(@course.teacher) -json.teacher_school @course.school.try(:name) -json.teacher_count @course.course_member_count([1, 2, 3]) -json.student_count @course.course_member_count(4) -json.course_group_count @course.course_groups_count -json.credit @course.credit -json.course_end @course.is_end -json.deadline course_end_date @course.end_date -json.educoder_teacher @user.is_teacher? -#json.is_student @is_student -json.is_admin @user_course_identity < Course::PROFESSOR -json.is_public @course.is_public == 1 -json.code_halt @course.invite_code_halt == 1 -json.invite_code @course.invite_code_halt == 0 ? @course.generate_invite_code : "" -json.switch_to_student @switch_student -json.switch_to_teacher switch_teacher_role(@is_student, @course, @user) -json.switch_to_assistant switch_assistant_role(@is_student, @course, @user) -#json.join_course !@user.member_of_course?(@course) -#json.copy_course !@user.member_of_course?(@course) && @user.is_teacher? -json.course_identity @user_course_identity -json.excellent @course.excellent -if @course.is_end == 0 - json.days_remaining (@course.end_date.to_date - Time.now.to_date).to_i -end -json.teacher_applies_count CourseMessage.unhandled_join_course_requests_by_course(@course).size if @user_course_identity < Course::ASSISTANT_PROFESSOR \ No newline at end of file diff --git a/app/views/courses/work_score.json.jbuilder b/app/views/courses/work_score.json.jbuilder deleted file mode 100644 index 2d7e30bb3..000000000 --- a/app/views/courses/work_score.json.jbuilder +++ /dev/null @@ -1,14 +0,0 @@ -json.course_members @course_members.each do |member| - user = member.user - json.user_login user.login - json.user_name user.real_name - json.course_group member.course_group_name - json.common_score member.common_score - json.group_score member.group_score - json.practice_score member.practice_score - json.exercise_score member.exercise_score - json.graduation_score member.graduation_score - json.total_score member.score - json.rank @rank if @user_course_identity == Course::STUDENT -end -json.all_count @all_count \ No newline at end of file diff --git a/app/views/members/index.json.jbuilder b/app/views/members/index.json.jbuilder index dbffc6f38..4629d8ec4 100644 --- a/app/views/members/index.json.jbuilder +++ b/app/views/members/index.json.jbuilder @@ -1,6 +1,8 @@ json.total_count @total_count json.members @members do |member| - json.partial! 'member', user: member.user - json.is_owner @project.owner?(member.user) - json.role member.roles.last.name + if member.user.present? + json.partial! 'member', user: member.user + json.is_owner @project.owner?(member.user) + json.role member.roles.last.name + end end