# HG changeset patch # User luisf # Date 1312823610 -3600 # Node ID a76abc63257af93369514fa7d5a3dee063ad79fc # Parent 82a6e37563832756e9e596174abb868c044d461d working on the author<->user logic. diff -r 82a6e3756383 -r a76abc63257a vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Aug 05 17:44:17 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Aug 08 18:13:30 2011 +0100 @@ -11,11 +11,15 @@ def identify_author(author) if author.class == User + + Rails.logger.debug { "Identify Author: USER" } + author_info = { :name_on_paper => author.name, :email => author.mail, :user_id => author.id, - :institution => "" + :institution => "", + :is_user => "1" } unless author.ssamr_user_detail.nil? @@ -24,11 +28,14 @@ else if author.class == Author - author_info = { - :name_on_paper => author.name, - :user_id => author.user_id, - :id => author.id - } + Rails.logger.debug { "Identify Author: AUTHOR" } + + author_info = { + :name_on_paper => author.name, + :user_id => author.user_id, + :id => author.id, + :is_user => "0" + } end end diff -r 82a6e3756383 -r a76abc63257a vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Aug 05 17:44:17 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Aug 08 18:13:30 2011 +0100 @@ -7,28 +7,36 @@ accepts_nested_attributes_for :author accepts_nested_attributes_for :publication + attr_accessor :is_user, :author_user_id + before_save :associate_author_user - # setter and getter for virtual attribute :user_id - def user_id - end - - def user_id=(uid) - if uid.blank? - author = Author.new :name => self.name_on_paper - author.save! - self.author_id = author.id - else - user = User.find(uid) - - if user.author.nil? - # TODO: should reflect the name_on_paper parameter + protected + def associate_author_user + logger.error { "Before Save: associate_author_user" } + + case self.is_user + when "0" + author = Author.find(self.author_user_id) + self.author_id = author.id + when "1" + user = User.find(self.author_user_id) + + if user.author.nil? + author = Author.new :name => self.name_on_paper + author.save + self.author_id = author.id + user.author = author + user.save + else + author = user.author + self.author_id = author.id + end + else author = Author.new :name => self.name_on_paper - author.save! - user.author = author - user.save! - else - self.author_id = user.author.id + logger.error { "SAVED AUTHOR" } + author.save + self.author_id = author.id + end - end end end diff -r 82a6e3756383 -r a76abc63257a vendor/plugins/redmine_bibliography/app/models/publication.rb --- a/vendor/plugins/redmine_bibliography/app/models/publication.rb Fri Aug 05 17:44:17 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb Mon Aug 08 18:13:30 2011 +0100 @@ -26,7 +26,7 @@ authorships.each_with_index do |authorship, index| if authorship.auth_order.nil? authorship.auth_order = index - authorship.save! + authorship.update end end end diff -r 82a6e3756383 -r a76abc63257a vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Fri Aug 05 17:44:17 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Mon Aug 08 18:13:30 2011 +0100 @@ -20,7 +20,8 @@ <%= f.text_field :email, :size => 60 %>
<%= h l("text_author_email") %>
- <%= f.hidden_field :user_id %> + <%= f.hidden_field :is_user %> + <%= f.text_field :author_user_id %> <%= link_to_remove_fields l("remove_author"), f %> diff -r 82a6e3756383 -r a76abc63257a vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb --- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Fri Aug 05 17:44:17 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Mon Aug 08 18:13:30 2011 +0100 @@ -22,29 +22,29 @@ :name_on_paper => "", :email => "", :institution => "", - :user_id => self.id + :author_user_id => self.id, + :is_user => "1" } if self.author.nil? - logger.error { "NO AUTHOR HERE" } + logger.debug { "Bibliography: The current user has no author associated." } info[:name_on_paper] = self.name info[:email] = self.mail if not self.ssamr_user_detail.nil? info[:institution] = self.ssamr_user_detail.institution_name end else - logger.error { "-----> We've got an author associated with the user." } + logger.error { "Bibliography: We've got an author associated with the current user." } info[:name_on_paper] = self.author.name if self.author.authorships.length > 0 info[:email] = self.author.authorships.first.email info[:institution] = self.author.authorships.first.institution end - end - - return info - - end + end + return info + end + end #InstanceMethods end #UserPublicationsPatch