From d167bfca64713d0b5e88d68ecbfe89ee5a559783 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 15 Nov 2019 20:19:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gits_controller.rb | 3 +-- app/services/subjects/copy_subject_service.rb | 7 ++++++- db/migrate/20191115121529_add_laborary_id_for_shixun.rb | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20191115121529_add_laborary_id_for_shixun.rb diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 0d949a1a2..973f1e9dc 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -49,8 +49,7 @@ class GitsController < ApplicationController shixunname = git_url.split("/")[1].split(".")[0] repo_name = username + "/" + shixunname uid_logger("git start: repo_name is #{repo_name}") - user_id = User.find_by_login(username) - shixun = Shixun.select([:id, :user_id, :repo_name, :identifier]).where(repo_name: repo_name, user_id: user_id).first + shixun = Shixun.select([:id, :user_id, :repo_name, :identifier]).where(repo_name: repo_name, laboratory_id: nil).first uid_logger("git start auth: shixun identifier is #{shixun.try(:identifier)}") uid_logger("git start auth: systemuser is #{system_user.try(:login)}") diff --git a/app/services/subjects/copy_subject_service.rb b/app/services/subjects/copy_subject_service.rb index 924eb10ef..7d32189a5 100644 --- a/app/services/subjects/copy_subject_service.rb +++ b/app/services/subjects/copy_subject_service.rb @@ -62,6 +62,9 @@ class Subjects::CopySubjectService < ApplicationService 'use_scope', 'averge_star', 'myshixuns_count') to_shixun.identifier = Util::UUID.generate_identifier(Shixun, 8) to_shixun.user_id = user_id + if laboratory + to_shixun.laboratory_id = laboratory.id + end to_shixun.save! copy_shixun_info_data!(shixun, to_shixun) @@ -72,7 +75,9 @@ class Subjects::CopySubjectService < ApplicationService copy_shixun_members_data!(to_shixun) # 云上实验室 - laboratory.laboratory_shixuns.create(shixun: to_shixun) if laboratory + if laboratory + laboratory.laboratory_shixuns.create(shixun: to_shixun) + end to_shixun end diff --git a/db/migrate/20191115121529_add_laborary_id_for_shixun.rb b/db/migrate/20191115121529_add_laborary_id_for_shixun.rb new file mode 100644 index 000000000..ea67d19d4 --- /dev/null +++ b/db/migrate/20191115121529_add_laborary_id_for_shixun.rb @@ -0,0 +1,5 @@ +class AddLaboraryIdForShixun < ActiveRecord::Migration[5.2] + def change + add_column :shixuns, :laboratory_id, :integer + end +end