# HG changeset patch # User luisf # Date 1355251713 0 # Node ID ca871a83c0f425ba414a312ce3ec4b3d0588759a # Parent 70849df4eae160030c8be3d11cbfb2c59553507d creates the author in case it no suggestion was made by the user. diff -r 70849df4eae1 -r ca871a83c0f4 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Dec 11 16:49:41 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Dec 11 18:48:33 2012 +0000 @@ -96,7 +96,6 @@ def create_from_bibtex find_project_by_project_id - # todo: drop unknown parameters from params hash lf.07122012 @publication = Publication.new(:title => params[:pub][:title]) @publication.build_bibtex_entry(params[:pub][:bibtex_entry]) @publication.projects << @project unless @project.nil? @@ -106,8 +105,12 @@ authorship = Authorship.new :name_on_paper => auth[:name_on_paper] - unless auth[:parent].nil? - logger.error { "AUTH PRENT #{auth[:parent]}" } + # when there's no association at all + if auth[:parent].nil? + logger.error { "Creating new author (no assoc)" } + author = Author.new + else + logger.error { "AUTH PARENT #{auth[:parent]}" } parent_class, parent_id = auth[:parent].split "_" if parent_class == "user" @@ -116,13 +119,12 @@ else author = Author.find(parent_id) end - - authorship.author_id = author.id end - # todo: test success + authorship.author_id = author.id authorship.save! + @pubication.authors << author @publication.authorships << authorship end @@ -256,6 +258,7 @@ logger.error { "Suggest Authors: Found #{authorships.count} Authorships " } suggested_authors = [] + # todo. should be careful with nil author_ids suggested_authors = authorships.map { |a| a.author } unless authorships.empty? suggested_authors.uniq! unless suggested_authors.empty? diff -r 70849df4eae1 -r ca871a83c0f4 vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Tue Dec 11 16:49:41 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Tue Dec 11 18:48:33 2012 +0000 @@ -7,6 +7,7 @@
<%- suggestions[1][:authors].each do |auth| -%> + <%= create_author_suggestion_radio("pub[authorships][#{index}][parent]", auth) -%> <%- end -%>