From 466c3b90966621ec20367efd882f0e5fab440000 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 9 Mar 2020 20:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=A4=96=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 52 +++++++++++++------ .../20200309123121_add_link_to_attachments.rb | 5 ++ 2 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20200309123121_add_link_to_attachments.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 25e0de44a..fbf798c64 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -7,7 +7,7 @@ class FilesController < ApplicationController before_action :file_validate_sort_type, only: :index before_action :validate_send_message_to_course_params, only: :bulk_send before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] - before_action :validate_upload_params, only: %i[upload import] + before_action :validate_upload_params, only: %i[import] before_action :find_file, only: %i[show setting update] before_action :publish_params, only: %i[upload import update] @@ -163,6 +163,7 @@ class FilesController < ApplicationController # 上传资源 def upload + find_course_second_category_id attachment_ids = params[:attachment_ids] course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id # is_unified_setting = params.has_key?(:is_unified_setting) ? params[:is_unified_setting] : true @@ -170,25 +171,42 @@ class FilesController < ApplicationController # course_group_publish_times = params[:course_group_publish_times] || [] begin - attachment_ids.each do |attchment_id| - attachment = Attachment.find_by_id attchment_id - unless attachment.nil? - attachment.container = @course - attachment.course_second_category_id = course_second_category_id - attachment.description = params[:description] - attachment.is_public = params[:is_public] && @course.is_public == 1 ? 1 : 0 - attachment.is_publish = @atta_is_publish - attachment.delay_publish = @atta_delay_publish - attachment.publish_time = @atta_publish_time - attachment.unified_setting = @unified_setting - if @unified_setting == 0 - attachment_group_setting attachment, params[:group_settings] + if attachment_ids.present? + attachment_ids.each do |attchment_id| + attachment = Attachment.find_by_id attchment_id + unless attachment.nil? + attachment.container = @course + attachment.course_second_category_id = course_second_category_id + attachment.description = params[:description] + attachment.is_public = params[:is_public] && @course.is_public == 1 ? 1 : 0 + attachment.is_publish = @atta_is_publish + attachment.delay_publish = @atta_delay_publish + attachment.publish_time = @atta_publish_time + attachment.unified_setting = @unified_setting + if @unified_setting == 0 + attachment_group_setting attachment, params[:group_settings] + end + # attachment.set_publish_time(publish_time) if is_unified_setting + # attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank? + attachment.save! end - # attachment.set_publish_time(publish_time) if is_unified_setting - # attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank? - attachment.save! end + else + attachment = Attachment.new + attachment.container = @course + attachment.course_second_category_id = course_second_category_id + attachment.description = params[:description] + attachment.is_public = params[:is_public] && @course.is_public == 1 ? 1 : 0 + attachment.is_publish = @atta_is_publish + attachment.delay_publish = @atta_delay_publish + attachment.publish_time = @atta_publish_time + attachment.unified_setting = @unified_setting + if @unified_setting == 0 + attachment_group_setting attachment, params[:group_settings] + end + attachment.save! end + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/db/migrate/20200309123121_add_link_to_attachments.rb b/db/migrate/20200309123121_add_link_to_attachments.rb new file mode 100644 index 000000000..23510be26 --- /dev/null +++ b/db/migrate/20200309123121_add_link_to_attachments.rb @@ -0,0 +1,5 @@ +class AddLinkToAttachments < ActiveRecord::Migration[5.2] + def change + add_column :attachments, :link, :string + end +end