From 95a6f08bf2a846ef37ee0f56627e20ca954168d4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 11 Dec 2019 09:52:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f504554c3..4a0b56f17 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -374,10 +374,10 @@ class ShixunsController < ApplicationController def update # 镜像方面 - mirror_ids = MirrorRepository.where(id: params[:main_type]).or(id: params[:small_type]).pluck(:id) + mirror_ids = MirrorRepository.where(id: params[:main_type]).or( MirrorRepository.where(id: params[:small_type])).pluck(:id) old_mirror_ids = @shixun.shixun_mirror_repositories .where(mirror_repository_id: params[:main_type]) - .or(mirror_repository_id: params[:small_type]).pluck(:mirror_repository_id) + .or(@shixun.shixun_mirror_repositories.where(mirror_repository_id: params[:small_type])).pluck(:mirror_repository_id) new_mirror_id = (mirror_ids - old_mirror_ids).map{|id| {mirror_repository_id: id}} # 转换成数组hash方便操作 # 服务配置方面 service_params = service_config_params[:shixun_service_configs] @@ -393,6 +393,19 @@ class ShixunsController < ApplicationController # 镜像变动要更换服务配置 @shixun.shixun_service_configs.not(mirror_repository_id: old_mirror_ids).destroy_all @shixun.shixun_mirror_repositories.create!(service_params) + # 添加第二仓库(管理员权限) + if current_user.admin_or_business? + if params[:is_secret_repository] + add_secret_repository if @shixun.shixun_secret_repository.blank? + else + # 如果有仓库,就要删 + if @shixun.shixun_secret_repository&.repo_name + @shixun.shixun_secret_repository.lock! + GitService.delete_repository(repo_path: @shixun.shixun_secret_repository.repo_path) + @shixun.shixun_secret_repository.destroy + end + end + end end rescue => e uid_logger_error(e.message) @@ -423,19 +436,6 @@ class ShixunsController < ApplicationController begin ActiveRecord::Base.transaction do @shixun.update_attributes!(shixun_params) - # 添加第二仓库(管理员权限) - if current_user.admin_or_business? - if params[:is_secret_repository] - add_secret_repository if @shixun.shixun_secret_repository.blank? - else - # 如果有仓库,就要删 - if @shixun.shixun_secret_repository&.repo_name - @shixun.shixun_secret_repository.lock! - GitService.delete_repository(repo_path: @shixun.shixun_secret_repository.repo_path) - @shixun.shixun_secret_repository.destroy - end - end - end end rescue => e uid_logger_error("实训学习页面设置失败--------#{e.message}")