diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index abba8e8..6559906 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,7 +3,7 @@ def edit @languages = Language.order("name") - @identifier_schemes = IdentifierScheme.order(:name) + @identifier_schemes = IdentifierScheme.where(active: true).order(:name) end # GET /resource diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index e000aa3..9b65b77 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -2,7 +2,7 @@ ## # Dynamically build a handler for each omniauth provider # ------------------------------------------------------------- - IdentifierScheme.all.each do |scheme| + IdentifierScheme.where(active: true).each do |scheme| define_method(scheme.name.downcase) do handle_omniauth(scheme) end diff --git a/app/models/identifier_scheme.rb b/app/models/identifier_scheme.rb index e200ffd..45b8922 100644 --- a/app/models/identifier_scheme.rb +++ b/app/models/identifier_scheme.rb @@ -3,5 +3,4 @@ has_many :users, through: :user_identifiers validates :name, uniqueness: true, presence: true - validates :landing_page_uri, url: true, allow_nil: true end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 51e6ea0..c2986d0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,21 +1,12 @@ class User < ActiveRecord::Base include GlobalHelpers - # First check for existence of the IdentifierSchemes table. Rake will attempt to - # compile this code during the DB migrations because both Devise and ActiveAdmin - # need to initialize this object when Rails initializes its routes.rb - if ActiveRecord::Base.connection.table_exists?('identifier_schemes') - omniauth_schemes = IdentifierScheme.all.collect{ |scheme| scheme.name.downcase.to_sym } - else - omniauth_schemes = [] - end - # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, - :omniauthable, :omniauth_providers => omniauth_schemes + :omniauthable, omniauth_providers: [:orcid] #associations between tables belongs_to :user_type @@ -288,7 +279,7 @@ # Load the user based on the scheme and id provided by the Omniauth call # -------------------------------------------------------------- def self.from_omniauth(auth) - scheme = IdentifierScheme.find_by(name: auth.provider.upcase) + scheme = IdentifierScheme.find_by(name: auth.provider.downcase) if scheme.nil? throw Exception.new('Unknown OAuth provider: ' + auth.provider) diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb index b8f97fd..03c1588 100644 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -1,5 +1,3 @@ -<% api_key = scheme.api_key ||= '' %> -
); background-size: 16px 16px;"> @@ -12,7 +10,7 @@ title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> <% else %> - <% uri = "#{scheme.landing_page_uri.gsub(/\{id\}/, id.identifier)}" %> + <% 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") %> diff --git a/config/initializers/devise.rb.example b/config/initializers/devise.rb.example index 80bdc41..cce856a 100644 --- a/config/initializers/devise.rb.example +++ b/config/initializers/devise.rb.example @@ -248,18 +248,9 @@ # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' - # Dynamically register the Omniauth Providers - ActiveSupport.on_load(:active_record) do - if ActiveRecord::Base.connection.table_exists?('identifier_schemes') - IdentifierScheme.all.each do |scheme| - puts "Registering Omniauth Provider - #{scheme.name}" - config.omniauth scheme.name.downcase.to_sym, - scheme.api_key ||= '', - scheme.api_secret ||= '', - (scheme.params.empty? ? {} : JSON.parse(scheme.params)) - end - end - end + # Any entries here MUST match a corresponding entry in the identifier_schemes table as + # well as an identifier_schemes.schemes section in each locale file! + config.omniauth :orcid, 'client_id', 'client_secret', {'scope': '/authenticate'} # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/locales/de.yml b/config/locales/de.yml index 37c64fc..eb85724 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -693,8 +693,9 @@ new_login_failure: 'Wir waren nicht in der Lage, Ihr Konto zu überprüfen. Bitte benutzen Sie das folgende Formular ein neues Konto zu erstellen. Sie können danach Ihr neues Konto zu verknüpfen.' schemes: - ORCID: + orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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 a2553c4..dc1135f 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -748,8 +748,9 @@ new_login_failure: 'We were unable to verify your account. Please use the following form to create a new account. You will be able to link your new account afterward.' schemes: - ORCID: + orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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 1c1fd8d..221c51e 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -734,8 +734,9 @@ new_login_failure: 'We were unable to verify your account. Please use the following form to create a new account. You will be able to link your new account afterward.' schemes: - ORCID: + orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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 ac633e4..99d18ed 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -706,8 +706,9 @@ new_login_failure: "Nous avons été en mesure de vérifier votre compte. S'il vous plaît utiliser le formulaire ci-dessous pour créer un nouveau compte. Vous serez en mesure de lier votre nouveau compte par la suite." schemes: - ORCID: + orcid: logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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/config/routes.rb b/config/routes.rb index 0ed5f51..02f2e14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,18 +1,13 @@ Rails.application.routes.draw do - # Table check to prevent conflicts running 'rake db:migrate' which initializes - # the Rails app before the migrations have actually run which in turn causes - # an error to be thrown because the identifier_schemes table does not yet exist - if ActiveRecord::Base.connection.table_exists?('identifier_schemes') - devise_for :users, controllers: { - registrations: "registrations", - confirmations: 'confirmations', - passwords: 'passwords', - sessions: 'sessions', - omniauth_callbacks: 'users/omniauth_callbacks'} do - - get "/users/sign_out", :to => "devise/sessions#destroy" - end + devise_for :users, controllers: { + registrations: "registrations", + confirmations: 'confirmations', + passwords: 'passwords', + sessions: 'sessions', + omniauth_callbacks: 'users/omniauth_callbacks'} do + + get "/users/sign_out", :to => "devise/sessions#destroy" end # WAYFless access point - use query param idp diff --git a/db/migrate/20161024163546_create_user_identifier_scheme.rb b/db/migrate/20161024163546_create_user_identifier_scheme.rb index 311bc59..657d0e5 100644 --- a/db/migrate/20161024163546_create_user_identifier_scheme.rb +++ b/db/migrate/20161024163546_create_user_identifier_scheme.rb @@ -2,12 +2,8 @@ def change create_table :identifier_schemes do |t| t.string :name - t.string :logo - t.string :api_key - t.string :api_secret - t.string :landing_page_uri - t.string :params - + t.string :description + t.boolean :active t.timestamps end end diff --git a/db/migrate/20161104161345_remove_logo_from_identifier_schemes.rb b/db/migrate/20161104161345_remove_logo_from_identifier_schemes.rb deleted file mode 100644 index f7b27bf..0000000 --- a/db/migrate/20161104161345_remove_logo_from_identifier_schemes.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveLogoFromIdentifierSchemes < ActiveRecord::Migration - def change - remove_column :identifier_schemes, :logo - end -end diff --git a/db/migrate/20161108214240_add_domain_to_identifier_schemes.rb b/db/migrate/20161108214240_add_domain_to_identifier_schemes.rb deleted file mode 100644 index a9c022a..0000000 --- a/db/migrate/20161108214240_add_domain_to_identifier_schemes.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddDomainToIdentifierSchemes < ActiveRecord::Migration - def change - add_column :identifier_schemes, :domain, :string - end -end diff --git a/db/schema.rb b/db/schema.rb index f9d0e8a..671fdb9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161108214240) do +ActiveRecord::Schema.define(version: 20161102221313) do create_table "answers", force: :cascade do |t| t.text "text" @@ -124,13 +124,10 @@ create_table "identifier_schemes", force: :cascade do |t| t.string "name" - t.string "api_key" - t.string "api_secret" - t.string "landing_page_uri" - t.string "params" + t.string "description" + t.boolean "active" t.datetime "created_at" t.datetime "updated_at" - t.string "domain" end create_table "languages", force: :cascade do |t| @@ -185,6 +182,7 @@ t.boolean "is_other" t.string "sort_name" t.text "banner_text" + t.string "logo_file_name" t.integer "region_id" t.integer "language_id" t.string "logo_uid" @@ -374,6 +372,13 @@ t.integer "identifier_scheme_id" end + create_table "user_role_types", force: :cascade do |t| + t.string "name" + t.text "description" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "user_statuses", force: :cascade do |t| t.string "name" t.text "description" diff --git a/db/seeds.rb b/db/seeds.rb index 91f7e3f..e263b66 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -88,12 +88,9 @@ identifier_schemes = { 'orcid' => { - name: 'ORCID', - domain: 'orcid.org', - landing_page_uri: 'https://orcid.org/{id}', - api_key: 'ABCD1234', - api_secret: 'secret', - params: '{"scope": "/authenticate"}' + name: 'orcid', + description: 'ORCID provides a persistent digital identifier for researchers', + active: true } } diff --git a/test/fixtures/identifier_schemes.yml b/test/fixtures/identifier_schemes.yml index 1e35c75..c70bb17 100644 --- a/test/fixtures/identifier_schemes.yml +++ b/test/fixtures/identifier_schemes.yml @@ -2,9 +2,6 @@ <% I18n.t("identifier_schemes.schemes").each do |k,v| %> <%= k.downcase %>: name: <%= "#{k}" %> - domain: <%= "#{k.downcase}.org" %> - api_key: 'ABCDEFG' - api_secret: '123456' - landing_page_uri: <%= "http://#{k.downcase}.org/landing_page/{id}" %> - params: '{"scope":"/do_something"}' + description: <%= "#{k.downcase}.org - testing" %> + active: true <% end %> \ No newline at end of file diff --git a/test/unit/identifier_schemes_test.rb b/test/unit/identifier_schemes_test.rb index 2e70fe0..3422612 100644 --- a/test/unit/identifier_schemes_test.rb +++ b/test/unit/identifier_schemes_test.rb @@ -9,7 +9,7 @@ # --------------------------------------------------- test "required fields are required" do assert_not IdentifierScheme.new.valid? - assert_not IdentifierScheme.new(domain: 'example.org').valid? + assert_not IdentifierScheme.new(description: 'we are testing').valid? # Ensure that the bare minimum of fields is still valid assert IdentifierScheme.new(name: 'testing').valid? @@ -24,28 +24,14 @@ end # --------------------------------------------------- - test "landing_page_uri must be a valid url" do - assert_not IdentifierScheme.new(name: 'testing', landing_page_uri: 'example.org').valid? - assert_not IdentifierScheme.new(name: 'testing', landing_page_uri: 'ehgegg://wrgfre.example.org').valid? - assert_not IdentifierScheme.new(name: 'testing', landing_page_uri: 'http://example/dir/page').valid? - assert_not IdentifierScheme.new(name: 'testing', landing_page_uri: 'file://example.org/file/name.txt').valid? - - assert IdentifierScheme.new(name: 'testing', landing_page_uri: 'http://example.org').valid? - assert IdentifierScheme.new(name: 'testing', landing_page_uri: 'https://example.org').valid? - assert IdentifierScheme.new(name: 'testing', landing_page_uri: 'http://example.org/path/page').valid? - assert IdentifierScheme.new(name: 'testing', landing_page_uri: 'http://example.org/path/page?p=1&r=2').valid? - assert IdentifierScheme.new(name: 'testing', landing_page_uri: 'http://example.org/path/page?p=abc%2F').valid? - end - - # --------------------------------------------------- test "can CRUD" do is = IdentifierScheme.create(name: 'testing') assert_not is.id.nil?, "was expecting to be able to create a new IdentifierScheme: #{is.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - is.api_key = 'Testing It Out' + is.description = 'Testing It Out' is.save! is.reload - assert_equal 'Testing It Out', is.api_key, "Was expecting to be able to update the api_key of the IdentifierScheme!" + assert_equal 'Testing It Out', is.description, "Was expecting to be able to update the api_key of the IdentifierScheme!" assert is.destroy!, "Was unable to delete the IdentifierScheme!" end