Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_item_bank

dev_jupyter
杨树林 5 years ago
commit 5f410d5bb6

@ -1,7 +1,7 @@
class EduSettingsController < ApplicationController class EduSettingsController < ApplicationController
before_action :require_admin before_action :require_admin
before_action :set_edu_setting, only: [:show, :edit, :update, :destroy] before_action :set_edu_setting, only: [:show, :edit, :update, :destroy]
skip_before_action :check_sign
# GET /edu_settings # GET /edu_settings
# GET /edu_settings.json # GET /edu_settings.json
def index def index

@ -171,8 +171,8 @@ class GraduationTopicsController < ApplicationController
unless teacher_group.present? unless teacher_group.present?
member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first
tip_exception("分班名称不能为空") if params[:course_group_name].blank? tip_exception("分班名称不能为空") if params[:course_group_name].blank?
course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id) course_group = CourseGroup.find_or_create_by!(:name => params[:course_group_name], :course_id => @course.id)
teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id), teacher_group = TeacherCourseGroup.find_or_create_by!(:course_id => @course.id, :course_member_id => member.try(:id),
:user_id => @graduation_topic.tea_id, :user_id => @graduation_topic.tea_id,
:course_group_id => course_group.try(:id)) :course_group_id => course_group.try(:id))
end end

@ -892,7 +892,7 @@ class ShixunsController < ApplicationController
content = upload_file.tempfile.read content = upload_file.tempfile.read
author_name = current_user.real_name author_name = current_user.real_name
author_email = current_user.git_mail author_email = current_user.git_mail
update_file_content(content, @repo_path, author_email, author_name, "upload by browser") update_file_content(content, @repo_path, author_email, author_name, "upload file by browser")
render_ok render_ok
end end

@ -2,13 +2,15 @@ class CourseGroup < ApplicationRecord
default_scope { order("course_groups.position ASC") } default_scope { order("course_groups.position ASC") }
belongs_to :course, counter_cache: true belongs_to :course, counter_cache: true
has_many :course_members has_many :course_members
has_many :exercise_group_settings,:dependent => :destroy has_many :exercise_group_settings,:dependent => :destroy
has_many :attachment_group_settings, :dependent => :destroy has_many :attachment_group_settings, :dependent => :destroy
has_many :homework_group_reviews, :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)} scope :by_group_ids, lambda { |ids| where(id: ids)}
validates :name, length: { maximum: 60 } validates :name, length: { maximum: 60 }
validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班"
after_create :generate_invite_code after_create :generate_invite_code

@ -8,6 +8,8 @@ class TeacherCourseGroup < ApplicationRecord
scope :find_teacher_group_ids, lambda { |ids| where(course_group_id: ids) unless ids.blank?} 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)} scope :get_user_groups,lambda {|ids| where(user_id:ids)}
validates_uniqueness_of :course_group_id, scope: :course_member_id
def course_members def course_members
self.course_group.course_members self.course_group.course_members
end end

@ -0,0 +1,18 @@
class ModifyCourseGroupForCourses < ActiveRecord::Migration[5.2]
def change
groups = CourseGroup.where(course_id:3128).order("created_at desc").group(:name)
ActiveRecord::Base.transaction do
groups.each do |g|
CourseGroup.where(name: g.name).where.not(id: g.id).each do |cg|
cg.course_members.update_all(course_group_id: g.id)
cg.exercise_group_settings.update_all(course_group_id: g.id)
cg.attachment_group_settings.update_all(course_group_id: g.id)
cg.homework_group_reviews.update_all(course_group_id: g.id)
cg.homework_group_settings.update_all(course_group_id: g.id)
cg.teacher_course_groups.update_all(course_group_id: g.id)
cg.destroy!
end
end
end
end
end
Loading…
Cancel
Save