diff plugins/redmine_bibliography/app/models/authorship.rb @ 1366:7e85f7988ab8 luisf

Fixes another possible cause for Bug #658 - was not saving publication when author was new...
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 19 Aug 2013 16:23:24 +0100
parents 4d5d25039a5f
children a2e51c0a7860
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/models/authorship.rb	Mon Aug 19 16:05:50 2013 +0100
+++ b/plugins/redmine_bibliography/app/models/authorship.rb	Mon Aug 19 16:23:24 2013 +0100
@@ -47,31 +47,37 @@
 
   protected
   def associate_author_user
+
+    logger.error { "search_author_class '#{self.search_author_class}'" }
+
     case self.search_author_class
-      when "User"
-        author = Author.new
-        author.save
-        self.author_id = author.id
+    when ""
+      logger.debug { "Unknown Author to be added..." }
+    when "User"
+      author = Author.new
+      author.save
+      self.author_id = author.id
+
+    when "Author"
+      selected = self.search_results
+      selected_classname = Kernel.const_get(self.search_author_class)
+      selected_id = self.search_author_id
+      object = selected_classname.find(selected_id)
+
+      if object.respond_to? :name_on_paper
+        # Authorship
+        self.author_id = object.author.id
       else
-        selected = self.search_results
-        selected_classname = Kernel.const_get(self.search_author_class)
-        selected_id = self.search_author_id
-        object = selected_classname.find(selected_id)
-
-        if object.respond_to? :name_on_paper
-          # Authorship
+        # User
+        unless object.author.nil?
           self.author_id = object.author.id
         else
-          # User
-          unless object.author.nil?
-            self.author_id = object.author.id
-          else
-            author = Author.new
-            object.author = author
-            object.save
-            self.author_id = object.author.id
-          end
+          author = Author.new
+          object.author = author
+          object.save
+          self.author_id = object.author.id
         end
+      end
     end
   end
 end