From 840d5aa0e064a2438ec7b8106b8f6509ed79ca37 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Sun, 25 May 2014 21:33:43 -0300 Subject: [PATCH] Fix duplicate author folder creation and duplicate save of work assignments --- plugins/work_assignment/lib/ext/uploaded_file.rb | 4 +--- plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/work_assignment/lib/ext/uploaded_file.rb b/plugins/work_assignment/lib/ext/uploaded_file.rb index 1165c7d..f66b0d2 100644 --- a/plugins/work_assignment/lib/ext/uploaded_file.rb +++ b/plugins/work_assignment/lib/ext/uploaded_file.rb @@ -2,13 +2,11 @@ require_dependency 'article' require_dependency 'uploaded_file' class UploadedFile < Article - after_save do |uploaded_file| + before_validation do |uploaded_file| if uploaded_file.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment) author_folder = uploaded_file.parent.find_or_create_author_folder(uploaded_file.author) uploaded_file.name = WorkAssignmentPlugin::WorkAssignment.versioned_name(uploaded_file, author_folder) uploaded_file.parent = author_folder - logger.info("\n\n==> #{uploaded_file.name}\n\n") - uploaded_file.save! end end end diff --git a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb index b3485c2..ed88327 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb @@ -33,7 +33,7 @@ class WorkAssignmentPlugin::WorkAssignment < Folder end def find_or_create_author_folder(author) - children.find_by_slug(author.identifier.to_slug) || Folder.create!(:name => author.name, :slug => author.identifier.to_slug, :parent => self, :profile => profile) + children.find_by_slug(author.identifier) || Folder.create!(:name => author.name, :slug => author.identifier, :parent => self, :profile => profile) end def submissions -- libgit2 0.21.2