From fd2197a73de38db7bb3e7a5a1977e86de8345ee1 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 11:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=B5=84=E6=BA=90=E5=BA=93?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB=20?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0Version?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 ++ app/models/attachment.rb | 2 +- .../20160108021447_change_attachment_history.rb | 11 +++++++++++ db/schema.rb | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160108021447_change_attachment_history.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 105000495..f2b4f1138 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -268,6 +268,8 @@ class FilesController < ApplicationController else sort = "#{Attachment.table_name}.created_on desc" end + # @containers = [ Project.includes(:attachments).find(@project.id)] + # @containers += @project.versions.includes(:attachments).all @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c8fe0811e..d90b0368e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -618,7 +618,7 @@ class Attachment < ActiveRecord::Base end end def update_attachment_ealasticsearch_index - if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) || + if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) || ( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) || self.container_type == 'Principal') begin diff --git a/db/migrate/20160108021447_change_attachment_history.rb b/db/migrate/20160108021447_change_attachment_history.rb new file mode 100644 index 000000000..f217e595a --- /dev/null +++ b/db/migrate/20160108021447_change_attachment_history.rb @@ -0,0 +1,11 @@ +class ChangeAttachmentHistory < ActiveRecord::Migration + def up + attachments = Attachment.where("container_type =?", "Version") + attachments.each do |am| + am.update_attribute(:container_type, "Project") unless am.nil? + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index a3297de97..641f9c75c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160105073350) do +ActiveRecord::Schema.define(:version => 20160108021447) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false