diff --git a/app/assets/images/remove.png b/app/assets/images/remove.png new file mode 100644 index 0000000..b2ef137 --- /dev/null +++ b/app/assets/images/remove.png Binary files differ diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 1ac40b3..8d49dc7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,21 +1,17 @@ class SessionsController < Devise::SessionsController + # POST /auth/:provider/callback + # --------------------------------------------------------------------- def oauth_create existing_user = User.find_by_email(params[:user][:email]) unless params[:omniauth].nil? - -puts "OMNIAUTH: #{params[:omniauth].inspect}" -puts "REQUEST: #{request.env['omniauth.auth'].inspect}" - existing_user = UserIdentifier.find_by(identifier: params[:omniauth][:auth]) - end - end # Capture the user's shibboleth id if they're coming in from an IDP - # ------------------------------------------------------------ + # --------------------------------------------------------------------- def create existing_user = User.find_by_email(params[:user][:email]) diff --git a/app/controllers/user_identifiers_controller.rb b/app/controllers/user_identifiers_controller.rb new file mode 100644 index 0000000..040a50b --- /dev/null +++ b/app/controllers/user_identifiers_controller.rb @@ -0,0 +1,25 @@ +class UserIdentifiersController < ApplicationController + + # DELETE /users/identifiers + # --------------------------------------------------------------------- + def destroy + if user_signed_in? then + user = User.find(current_user.id) + identifier = UserIdentifier.find(params[:id]) + + # If the requested identifier belongs to the current user remove it + if user.user_identifiers.include?(identifier) + identifier.destroy! + flash[:notice] = t('identifier_schemes.disconnect_success', + scheme: identifier.identifier_scheme.name) + + else + flash[:notice] = t('identifier_schemes.disconnect_failure', + scheme: identifier.identifier_scheme.name) + end + + redirect_to edit_user_registration_path + end + end + +end \ No newline at end of file diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 96dbd26..74a9b8c 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -40,50 +40,22 @@ else # If the user could not be found by that uid then attach it to their record if user.email.nil? || user.email.empty? - UserIdentifier.create!(identifier_scheme: scheme, - identifier: request.env["omniauth.auth"].uid, - user: current_user) + if UserIdentifier.create(identifier_scheme: scheme, + identifier: request.env["omniauth.auth"].uid, + user: current_user) + + flash[:notice] = t('identifier_schemes.connect_success', scheme: scheme.name) + else + flash[:notice] = t('identifier_schemes.connect_failure', scheme: scheme.name) + end end redirect_to edit_user_registration_path end end -=begin - # We could consider combining these callbacks into a shared generic version - # ------------------------------------------------------------- - def orcid - scheme = IdentifierScheme.find_by(name: request.env["omniauth.auth"].provider.upcase) - user = User.from_omniauth(request.env["omniauth.auth"]) - - # If the user isn't logged in - if current_user.nil? - session["devise.orcid_data"] = request.env["omniauth.auth"] - - # If the uid didn't have a match in the system send them to register - if user.email.nil? - redirect_to new_user_registration_url - - # Otherwise sign them in - else - sign_in_and_redirect @user, event: :authentication - set_flash_message(:notice, :success, kind: 'Orcid') if is_navigational_format? - end - - # The user is just registering the uid with us - else - # If the user could not be found by that uid then attach it to their record - if user.email.nil? || user.email.empty? - UserIdentifier.create!(identifier_scheme: scheme, - identifier: request.env["omniauth.auth"].uid, - user: current_user) - end - - redirect_to edit_user_registration_path - end - end -=end - + + # ------------------------------------------------------------- def shibboleth if user_signed_in? && current_user.shibboleth_id.present? && current_user.shibboleth_id.length > 0 then diff --git a/app/models/user.rb b/app/models/user.rb index ee78a1b..9a76d53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -80,10 +80,9 @@ # Returns the user's identifier for the specified scheme name # # @param the identifier scheme name (e.g. ORCID) - # @return [String] the user's identifier for that scheme + # @return [UserIdentifier] the user's identifier for that scheme def identifier_for(scheme) - user_identifier = user_identifiers.where(identifier_scheme: scheme).first - (user_identifier.nil? ? '' : user_identifier.identifier) + user_identifiers.where(identifier_scheme: scheme).first end ## diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb index 3faef43..38533d4 100644 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -1,9 +1,9 @@ <% api_key = scheme.api_key ||= '' %>
+ style="background-image: url(<%= t("identifier_schemes.#{scheme.name}.logo") %>); background-size: 16px 16px;"> - <% if id.nil? || id == '' %> + <% if id.nil? || id.identifier == '' %> <%= link_to "#{t("identifier_schemes.#{scheme.name}.connect")}", Rails.application.routes.url_helpers.send( @@ -12,8 +12,12 @@ title: t("identifier_schemes.#{scheme.name}.tooltip") %> <% else %> - <% uri = "#{scheme.landing_page_uri.gsub(/\{id\}/, id)}" %> + <% uri = "#{scheme.landing_page_uri.gsub(/\{id\}/, id.identifier)}" %> <%= link_to uri, uri, target: '_blank', title: t("identifier_schemes.#{scheme.name}.tooltip") %> + + <%= link_to '', destroy_user_identifier_path(id), method: :delete, + title: t("identifier_schemes.#{scheme.name}.disconnect"), + class: 'remove' %> <% end %>
diff --git a/config/locales/de.yml b/config/locales/de.yml index 10420f2..1a6e157 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -861,9 +861,15 @@ bad_resource: '{"Error":"You do not have authorisation to view this resource"}' identifier_schemes: + connect_success: 'Ihr Konto wurde mit %{scheme}' + connect_failure: 'Wir konnten nicht auf Ihr Konto %{scheme} verbinden' + disconnect_success: 'Ihr Konto wurde von %{scheme} getrennt' + disconnect_failure: 'Wir waren nicht in der Lage, Ihr Konto zu trennen von %{scheme}' ORCID: - connect: 'Schließen sie ihr konto ORCID' - tooltip: 'ORCID bietet eine persistente digitale Kennung, die Sie von anderen Forschern unterscheidet.' + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + connect: 'Erstellen oder Verbinden Sie Ihren ORCID ID' + disconnect: 'Trennen Sie Ihren ORCID ID' + tooltip: 'ORCID bietet eine persistente digitale Kennung, die Sie von anderen Forschern unterscheidet. Erfahren Sie mehr unter orcid.org' magic_strings: organisation_types: diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 0a7a42c..c04a9ec 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -957,9 +957,15 @@ bad_resource: '{"Error":"You do not have authorisation to view this resource"}' identifier_schemes: + connect_success: 'Your account has bee connected to %{scheme}' + connect_failure: 'We could not connect your account to %{scheme}' + disconnect_success: 'Your account has been disconnected from %{scheme}' + disconnect_failure: 'We were unable to disconnect your account from %{scheme}' ORCID: - connect: 'Connect your ORCID' - tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers.' + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + connect: 'Create or Connect your ORCID ID' + disconnect: 'Disconnect your ORCID ID' + tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' magic_strings: organisation_types: diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index f404a38..0b6cda4 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -947,9 +947,15 @@ bad_resource: '{"Error":"You do not have authorisation to view this resource"}' identifier_schemes: + connect_success: 'Your account has bee connected to %{scheme}' + connect_failure: 'We could not connect your account to %{scheme}' + disconnect_success: 'Your account has been disconnected from %{scheme}' + disconnect_failure: 'We were unable to disconnect your account from %{scheme}' ORCID: - connect: 'Connect your ORCID' - tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers.' + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + connect: 'Create or Connect your ORCID ID' + disconnect: 'Disconnect your ORCID ID' + tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' magic_strings: organisation_types: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 59d12ad..e9e108c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -845,9 +845,16 @@ bad_resource: '{"Error":"You do not have authorisation to view this resource"}' identifier_schemes: + connect_success: 'Votre compte a été connecté à %{scheme}' + connect_failure: 'Nous ne pouvions pas connecter votre compte %{scheme}' + disconnect_success: 'Votre compte a été déconnecté de %{scheme}' + disconnect_failure: 'Nous avons été incapables de déconnecter votre compte %{scheme}' ORCID: - connect: 'Connectez votre compte pour ORCID' - tooltip: 'ORCID fournit un identifiant numérique persistant qui vous distingue des autres chercheurs.' + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' + connect: 'Créer ou Connectez votre ID ORCID' + disconnect: 'Déconnectez votre ID ORCID' + tooltip: 'ORCID fournit un identifiant numérique persistant qui vous distingue des autres chercheurs. En savoir plus sur orcid.org' magic_strings: organisation_types: diff --git a/config/routes.rb b/config/routes.rb index 34b418f..6e63fd9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ passwords: 'passwords', sessions: 'sessions', omniauth_callbacks: 'users/omniauth_callbacks'} do + get "/users/sign_out", :to => "devise/sessions#destroy" end @@ -14,12 +15,14 @@ get 'auth/shibboleth/assoc' => 'users/omniauth_shibboleth_request#associate', :as => 'user_shibboleth_assoc' post '/auth/:provider/callback' => 'sessions#oauth_create' - + # fix for activeadmin signout bug devise_scope :user do get '/users/sign_out' => 'devise/sessions#destroy' end + delete '/users/identifiers/:id', to: 'user_identifiers#destroy', as: 'destroy_user_identifier' + ActiveAdmin.routes(self) #organisation admin area