From d1a72ce0480b577c226ebcfdf2df60aa9283df3a Mon Sep 17 00:00:00 2001 From: "vit.jonas@gmail.com" Date: Tue, 24 May 2011 19:51:10 +0000 Subject: [PATCH] * finished Issue 30: File upload strange behavior for files with same filename git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@78 5e329b0b-a2ee-ea63-e329-299493fc886d --- app/controllers/dmsf_detail_controller.rb | 7 ++++--- app/models/dmsf_file.rb | 7 ++++--- app/views/dmsf_detail/file_detail.html.erb | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/dmsf_detail_controller.rb b/app/controllers/dmsf_detail_controller.rb index 39ace185..40b5d26c 100644 --- a/app/controllers/dmsf_detail_controller.rb +++ b/app/controllers/dmsf_detail_controller.rb @@ -126,13 +126,14 @@ class DmsfDetailController < ApplicationController end @revision.set_workflow(params[:workflow]) - if @revision.save + @file.name = @revision.name + @file.folder = @revision.folder + + if @revision.save && @file.valid? unless file_upload.nil? @revision.copy_file_content(file_upload) end - @file.name = @revision.name - @file.folder = @revision.folder if @file.locked? DmsfFileLock.file_lock_state(@file, false) flash[:notice] = l(:notice_file_unlocked) + ", " diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 7235590a..39dc566a 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -39,11 +39,12 @@ class DmsfFile < ActiveRecord::Base validates_format_of :name, :with => DmsfFolder.invalid_characters, :message => l(:error_contains_invalid_character) - validate_on_create :validates_name_uniqueness + validate :validates_name_uniqueness def validates_name_uniqueness - errors.add(:name, "has already been taken") if - !DmsfFile.find_file_by_name(self.project, self.folder, self.name).nil? + existing_file = DmsfFile.find_file_by_name(self.project, self.folder, self.name) + errors.add(:name, "has already been taken") unless + existing_file.nil? || existing_file.id == self.id end acts_as_event :title => Proc.new {|o| "#{o.name}"}, diff --git a/app/views/dmsf_detail/file_detail.html.erb b/app/views/dmsf_detail/file_detail.html.erb index 7ec9a1a0..7fb85708 100644 --- a/app/views/dmsf_detail/file_detail.html.erb +++ b/app/views/dmsf_detail/file_detail.html.erb @@ -47,6 +47,7 @@ <% end %> +<%= error_messages_for("file") %> <%= error_messages_for("revision") %> <% if User.current.allowed_to?(:file_manipulation, @file.project) %> @@ -155,7 +156,7 @@ }); }); - <% if @revision.valid? %> + <% if @revision.valid? && @file.valid? %>