云上实验室fork版本库

dev_home
daiao 5 years ago
parent 2a2caf4375
commit 8ee4afda79

@ -10,7 +10,7 @@ class Admins::LaboratorySubjectsController < Admins::BaseController
def create
subject = Subject.find(params[:subject_id])
Subjects::CopySubjectService.call(subject, current_user.id, current_laboratory)
Subjects::CopySubjectService.call(subject, current_user, current_laboratory)
render_ok
end

@ -1,9 +1,9 @@
class Subjects::CopySubjectService < ApplicationService
attr_reader :subject, :to_subject, :user_id, :laboratory
attr_reader :subject, :to_subject, :user, :laboratory
def initialize(subject, user_id, laboratory=nil)
def initialize(subject, user, laboratory=nil)
@subject = subject
@user_id = user_id
@user = user
@laboratory = laboratory
subject_params = subject.attributes.dup.except('id', 'copy_subject_id', 'user_id', 'homepage_show')
@to_subject = Subject.new(subject_params)
@ -21,7 +21,7 @@ class Subjects::CopySubjectService < ApplicationService
# 复制实践课程表
def copy_subject!
to_subject.copy_subject_id = subject.id
to_subject.user_id = user_id
to_subject.user_id = user.id
to_subject.save!
copy_stages_data!(subject, to_subject)
@ -34,7 +34,7 @@ class Subjects::CopySubjectService < ApplicationService
subject.stages.each do |stage|
to_stage = to_subject.stages.new
to_stage.attributes = stage.attributes.dup.except('id', 'subject_id', 'user_id')
to_stage.user_id = user_id
to_stage.user_id = user.id
to_stage.save!
copy_stage_shixuns_data!(stage, to_stage)
@ -61,10 +61,15 @@ class Subjects::CopySubjectService < ApplicationService
to_shixun.attributes = shixun.attributes.dup.except('id', 'user_id', 'identifier', 'homepage_show',
'use_scope', 'averge_star', 'myshixuns_count')
to_shixun.identifier = Util::UUID.generate_identifier(Shixun, 8)
to_shixun.user_id = user_id
to_shixun.user_id = user.id
if laboratory
to_shixun.laboratory_id = laboratory.id
end
# 复制版本库
fork_repository_name = "#{user.login}/#{to_shixun.identifier}"
GitService.fork_repository(repo_path: "#{shixun.repo_name}.git",
fork_repository_path: (fork_repository_name + ".git"))
to_shixun.repo_name = fork_repository_name
to_shixun.save!
copy_shixun_info_data!(shixun, to_shixun)
@ -124,7 +129,7 @@ class Subjects::CopySubjectService < ApplicationService
shixun.challenges.each do |challenge|
to_challenge = to_shixun.challenges.new
to_challenge.attributes = challenge.attributes.dup.except('id', 'shixun_id', 'praises_count', 'user_id', 'visits')
to_challenge.user_id = user_id
to_challenge.user_id = user.id
to_challenge.shixun_id = to_shixun.id
to_challenge.save!
@ -201,12 +206,12 @@ class Subjects::CopySubjectService < ApplicationService
# 创建实训成员
def copy_shixun_members_data!(to_shixun)
to_shixun.shixun_members.create!(user_id: user_id, role: 1)
to_shixun.shixun_members.create!(user_id: user.id, role: 1)
end
# 创建课程成员
def copy_subject_members_data(to_subject)
to_subject.subject_members.create!(user_id: user_id, role: 1)
to_subject.subject_members.create!(user_id: user.id, role: 1)
end
end

Loading…
Cancel
Save