From 8947d6e90be6804a2a7f7a0bb43a7b324b04a998 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 16 Jul 2021 00:29:58 -0400 Subject: [PATCH] Issue datacite#1260 - Fabrica is not showing assigned Roles to contacts when relationship are created with the API (role_name can be nil). --- app/controllers/contacts_controller.rb | 5 ++--- app/models/contact.rb | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 9234383fb..b8d9030d1 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -196,17 +196,16 @@ def set_provider_contacts # Make sure no other contact with this provider claims these roles. @contact.provider.contacts.each do | contact | if !@contact.is_me?(contact) - if contact.remove_roles!(@contact.role_name) + if contact.remove_roles!(Array.wrap(@contact.role_name)) contact.update_attribute("role_name", contact.role_name) end end end - end end def remove_provider_contacts - @contact.role_name.each do | role | + Array.wrap(@contact.role_name).each do | role | if @contact.has_provider_role?(role) @contact.set_provider_role(role, nil) end diff --git a/app/models/contact.rb b/app/models/contact.rb index 8521be1b6..2280e274b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -447,12 +447,12 @@ def self.roles end def has_role?(role = "") - role_name.include?(role) + Array.wrap(role_name).include?(role) end def remove_roles!(roles = []) roles.each do | role | - role_name.delete(role) + Array.wrap(role_name).delete(role) end self.changed? end