diff --git a/Gemfile b/Gemfile index e1c9c28..05ba158 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,7 @@ gem 'omniauth' gem 'omniauth-shibboleth' gem 'omniauth-orcid' + #rolify for roles gem 'rolify' # Gems for repository integration diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index fe5a071..1a05dca 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController - def index + def index if user_signed_in? name = current_user.name(false) if name.blank? diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb index 03c1588..bbc8d75 100644 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -10,10 +10,15 @@ title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> <% else %> - <% uri = t("identifier_schemes.schemes.#{scheme.name}.user_landing_page").gsub(/\{id\}/, id.identifier) %> - <%= link_to uri, uri, target: '_blank', - title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> - + <% if t("identifier_schemes.schemes.#{scheme.name}.user_landing_page").nil? %> + <%= t("identifier_schemes.schemes.connect_success").gsub(/%\{scheme\}/, scheme.name.capitalize) %> + + <% else %> + <% uri = t("identifier_schemes.schemes.#{scheme.name}.user_landing_page").gsub(/%\{id\}/, id.identifier) %> + <%= link_to uri, uri, target: '_blank', + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> + <% end %> + <%= link_to image_tag('remove.png', height: '16px', width: '16px'), destroy_user_identifier_path(id), method: :delete, title: t("identifier_schemes.schemes.#{scheme.name}.disconnect_tooltip"), diff --git a/config/application.rb b/config/application.rb index f13810f..f4e3351 100644 --- a/config/application.rb +++ b/config/application.rb @@ -98,6 +98,5 @@ # Load Branded terminology (e.g. organization name, application name, etc.) config.branding = config_for(:branding).deep_symbolize_keys - end end diff --git a/config/environment.rb b/config/environment.rb index c82b616..bd7d90e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,5 +5,38 @@ Rails.logger = Logger.new(STDOUT) # Initialize the Rails application. -#DMPonline4::Application.initialize! -Rails.application.initialize! \ No newline at end of file +Rails.application.initialize! + +# Devise configuration helper +# ---------------------------------------------------- +if !Devise.nil? + # Check to see what Omniauth providers were registered with Devise + # Compare them to the entries in the DB and adjust the DB records accordingly + defined = IdentifierScheme.where(active: true)#.collect{ |scheme| scheme.name } + registered = Devise.omniauth_providers + + # Deactivate any entries that are not defined in the config/initializers/devise.rb + defined.each do |scheme| + unless registered.include?(scheme.name.to_sym) + Rails.logger.info "Detected an unsupported identifier_scheme, #{scheme.name}, in the DB, deactivating the entry - if this is a mistake add it to your config/initializers/devise.rb" + scheme.update_attributes(active: false) + end + end + + # If an entry was defined in config/initializers/devise.rb but is not in the DB, add it + diff = registered.reject{ |i| defined.collect{ |d| d.name }.include?(i.to_s) } + diff.each do |scheme| + is = IdentifierScheme.find_by(name: scheme.to_s) + + if is.nil? + Rails.logger.info "Detected a new Omniauth provider in config/initializers/devise.rb that is not defined in the DB - adding #{scheme.to_s} to the identifier_schemes table. The new provider will only be available in the user's profile page. To enable it for login, please update the DB accordingly." + IdentifierScheme.create!({name: scheme.to_s, description: '', active: true, use_for_login: false}) + + else + Rails.logger.warn "Detected an Omniauth provider, #{scheme.to_s}, in config/initializers/devise.rb but it is inactive in the identifier_schemes table!" + end + end + +else + Rails.logger.error "Devise was not properly initialized! Please make sure you have defined the config/initializers/devise.rb initializer." +end diff --git a/config/locales/de.yml b/config/locales/de.yml index e492d21..4e15f8b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -696,7 +696,7 @@ schemes: orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - user_landing_page: 'https://orcid.org/{id}' + user_landing_page: 'https://orcid.org/%{id}' connect: 'Erstellen oder Verbinden Sie Ihren ORCID ID' connect_tooltip: 'ORCID bietet eine persistente digitale Kennung, die Sie von anderen Forschern unterscheidet. Erfahren Sie mehr unter orcid.org' disconnect_confirmation: 'Sind Sie sicher, dass Sie Ihre ORCID ID trennen möchten?' diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 174993b..1222de3 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -751,7 +751,7 @@ schemes: orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - user_landing_page: 'https://orcid.org/{id}' + user_landing_page: 'https://orcid.org/%{id}' connect: 'Create or Connect your ORCID ID' connect_tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 213c21e..f29896e 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -737,7 +737,7 @@ schemes: orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - user_landing_page: 'https://orcid.org/{id}' + user_landing_page: 'https://orcid.org/%{id}' connect: 'Create or Connect your ORCID ID' connect_tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index de740a2..56904e5 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -709,7 +709,7 @@ schemes: orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - user_landing_page: 'https://orcid.org/{id}' + user_landing_page: 'https://orcid.org/%{id}' connect: 'Créer ou Connectez votre ID ORCID' connect_tooltip: 'ORCID fournit un identifiant numérique persistant qui vous distingue des autres chercheurs. En savoir plus sur orcid.org' disconnect_confirmation: 'Êtes-vous certain que vous voulez déconnecter votre ID orcid?' diff --git a/lib/assets/images/remove.png b/lib/assets/images/remove.png new file mode 100644 index 0000000..b2ef137 --- /dev/null +++ b/lib/assets/images/remove.png Binary files differ