diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index 157957b03..870a1d90e 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -2,6 +2,8 @@ module LaboratoryHelper extend ActiveSupport::Concern included do + before_action :setup_laboratory + helper_method :current_laboratory helper_method :default_setting end @@ -17,4 +19,8 @@ module LaboratoryHelper def default_setting @_default_setting ||= LaboratorySetting.find_by(laboratory_id: 1) end + + def setup_laboratory + Laboratory.current = current_laboratory + end end \ No newline at end of file diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 05c3500ee..e2b78ee4b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -335,6 +335,9 @@ class ShixunsController < ApplicationController end end end + + # 将实训标志为该云上实验室建立 + Laboratory.current.laboratory_shixuns.create!(shixun: @shixun, ownership: true) rescue Exception => e uid_logger_error("copy shixun failed ##{e.message}") # 删除版本库 @@ -430,6 +433,9 @@ class ShixunsController < ApplicationController GitService.add_repository(repo_path: repo_path) # todo: 为什么保存的时候要去除后面的.git呢?? @shixun.update_column(:repo_name, repo_path.split(".")[0]) + + # 将实训标志为该云上实验室建立 + Laboratory.current.laboratory_shixuns.create!(shixun: @shixun, ownership: true) rescue Exception => e uid_logger_error(e.message) tip_exception("实训创建失败") diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index cbedf74b2..9c6980b69 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -117,6 +117,9 @@ class SubjectsController < ApplicationController @subject.user_id = current_user.id @subject.save! @subject.subject_members.create!(role: 1, user_id: current_user.id) + + # 将实践课程标记为该云上实验室建立 + Laboratory.current.laboratory_subjects.create!(subject: @subject, ownership: true) rescue Exception => e uid_logger_error(e.message) tip_exception("实训路径创建失败") diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 51f2f7867..ff8f89c5e 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -30,4 +30,12 @@ class Laboratory < ApplicationRecord find_by_identifier(subdomain) end + + def self.current=(laboratory) + Thread.current[:current_laboratory] = laboratory + end + + def self.current + Thread.current[:current_laboratory] ||= Laboratory.find(1) + end end \ No newline at end of file