diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 8f88c81..abba8e8 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -14,11 +14,11 @@ unless oauth.nil? # The OAuth provider could not be determined or there was no unique UID! if oauth.provider.nil? || oauth.uid.nil? - flash[:notice] = t('new_login_failure') + flash[:notice] = t('identifier_schemes.new_login_failure') else # Connect the new user with the identifier sent back by the OAuth provider - flash[:notice] = t('new_login_success') + flash[:notice] = t('identifier_schemes.new_login_success') UserIdentifier.create(identifier_scheme: oauth.provider.upcase, identifier: oauth.uid, user: @user) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 8d49dc7..3719d84 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,6 +2,7 @@ # POST /auth/:provider/callback # --------------------------------------------------------------------- +=begin def oauth_create existing_user = User.find_by_email(params[:user][:email]) @@ -9,7 +10,8 @@ existing_user = UserIdentifier.find_by(identifier: params[:omniauth][:auth]) end end - +=end + # Capture the user's shibboleth id if they're coming in from an IDP # --------------------------------------------------------------------- def create diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 03c5f13..383974f 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -20,25 +20,32 @@ # @scheme [IdentifierScheme] The IdentifierScheme for the provider # ------------------------------------------------------------- def handle_omniauth(scheme) + +puts "GOT IN" + user = User.from_omniauth(request.env["omniauth.auth"]) # If the user isn't logged in if current_user.nil? # If the uid didn't have a match in the system send them to register if user.nil? +puts "A" session["devise.#{scheme.name.downcase}_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url # Otherwise sign them in else +puts "B" sign_in_and_redirect @user, event: :authentication set_flash_message(:notice, :success, kind: scheme.name) if is_navigational_format? end # The user is already logged in and just registering the uid with us else +puts "C" # If the user could not be found by that uid then attach it to their record if user.nil? +puts "D" if UserIdentifier.create(identifier_scheme: scheme, identifier: request.env["omniauth.auth"].uid, user: current_user) @@ -55,7 +62,8 @@ end - + # TODO: We should consider rolling the below function up into the + # generic handler above # ------------------------------------------------------------- def shibboleth if user_signed_in? && current_user.shibboleth_id.present? && current_user.shibboleth_id.length > 0 then diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb index 199f4f8..b8f97fd 100644 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -1,24 +1,24 @@ <% api_key = scheme.api_key ||= '' %>
); background-size: 16px 16px;"> + style="background-image: url(<%= t("identifier_schemes.schemes.#{scheme.name}.logo") %>); background-size: 16px 16px;"> <% if id.nil? || id.identifier == '' %> - <%= link_to "#{t("identifier_schemes.#{scheme.name}.connect")}", + <%= link_to "#{t("identifier_schemes.schemes.#{scheme.name}.connect")}", Rails.application.routes.url_helpers.send( "user_#{scheme.name.downcase}_omniauth_authorize_path" ), - title: t("identifier_schemes.#{scheme.name}.connect_tooltip") %> + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> <% else %> <% uri = "#{scheme.landing_page_uri.gsub(/\{id\}/, id.identifier)}" %> <%= link_to uri, uri, target: '_blank', - title: t("identifier_schemes.#{scheme.name}.connect_tooltip") %> + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> <%= link_to image_tag('remove.png', height: '16px', width: '16px'), destroy_user_identifier_path(id), method: :delete, - title: t("identifier_schemes.#{scheme.name}.disconnect_tooltip"), - data: {confirm: t("identifier_schemes.#{scheme.name}.disconnect_confirmation")} %> + title: t("identifier_schemes.schemes.#{scheme.name}.disconnect_tooltip"), + data: {confirm: t("identifier_schemes.schemes.#{scheme.name}.disconnect_confirmation")} %> <% end %>
diff --git a/config/locales/de.yml b/config/locales/de.yml index 9d3f9fe..9c9d333 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -867,12 +867,14 @@ disconnect_failure: 'Wir waren nicht in der Lage, Ihr Konto zu trennen von %{scheme}' new_login_success: 'Sie haben nicht Setup ein Konto bei uns. Bitte füllen Sie das folgende Informationen, um Ihre Registrierung abzuschließen.' 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.' - ORCID: - logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - 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_tooltip: 'Trennen Sie Ihren ORCID ID' - disconnect_confirmation: 'Sind Sie sicher, dass Sie Ihre ORCID ID trennen möchten?' + + schemes: + ORCID: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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_tooltip: 'Trennen Sie Ihren ORCID ID' + disconnect_confirmation: 'Sind Sie sicher, dass Sie Ihre ORCID ID trennen möchten?' magic_strings: organisation_types: diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 08abb7d..d5824eb 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -963,12 +963,14 @@ disconnect_failure: 'We were unable to disconnect your account from %{scheme}' new_login_success: 'It does not look like you have setup an account with us yet. Please fill in the following information to complete your registration.' 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.' - ORCID: - logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - 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_tooltip: 'Disconnect your ORCID ID' - disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' + + schemes: + ORCID: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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_tooltip: 'Disconnect your ORCID ID' + disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' magic_strings: organisation_types: diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 5d3d8ea..4f45ca1 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -953,12 +953,14 @@ disconnect_failure: 'We were unable to disconnect your account from %{scheme}' new_login_success: 'It does not look like you have setup an account with us yet. Please fill in the following information to complete your registration.' 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.' - ORCID: - logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - 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_tooltip: 'Disconnect your ORCID ID' - disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' + + schemes: + ORCID: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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_tooltip: 'Disconnect your ORCID ID' + disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' magic_strings: organisation_types: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index aa04462..38c08d5 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -851,12 +851,14 @@ disconnect_failure: 'Nous avons été incapables de déconnecter votre compte %{scheme}' new_login_success: "Vous ne l'avez pas configurer un compte avec nous. S'il vous plaît remplir les informations ci-dessous pour terminer votre inscription." 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." - ORCID: - logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' - 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_tooltip: 'Déconnectez votre ID ORCID' - disconnect_confirmation: 'Etes-vous sûr que vous voulez déconnecter votre ID ORCID?' + + schemes: + ORCID: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + 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_tooltip: 'Déconnectez votre ID ORCID' + disconnect_confirmation: 'Etes-vous sûr que vous voulez déconnecter votre ID ORCID?' magic_strings: organisation_types: diff --git a/config/routes.rb b/config/routes.rb index 6e63fd9..7e696f2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ get 'auth/shibboleth' => 'users/omniauth_shibboleth_request#redirect', :as => 'user_omniauth_shibboleth' get 'auth/shibboleth/assoc' => 'users/omniauth_shibboleth_request#associate', :as => 'user_shibboleth_assoc' - post '/auth/:provider/callback' => 'sessions#oauth_create' + #post '/auth/:provider/callback' => 'sessions#oauth_create' # fix for activeadmin signout bug devise_scope :user do diff --git a/db/schema.rb b/db/schema.rb index d0c8124..9cd276f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,92 +14,92 @@ ActiveRecord::Schema.define(version: 20161104161345) do create_table "answers", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.integer "question_id", limit: 4 + t.text "text" + t.integer "plan_id" + t.integer "user_id" + t.integer "question_id" t.datetime "created_at" t.datetime "updated_at" end create_table "answers_options", id: false, force: :cascade do |t| - t.integer "answer_id", limit: 4, null: false - t.integer "option_id", limit: 4, null: false + t.integer "answer_id", null: false + t.integer "option_id", null: false end - add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id", using: :btree + add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id" create_table "comments", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "question_id", limit: 4 - t.text "text", limit: 65535 + t.integer "user_id" + t.integer "question_id" + t.text "text" t.datetime "created_at" t.datetime "updated_at" t.boolean "archived" - t.integer "plan_id", limit: 4 - t.integer "archived_by", limit: 4 + t.integer "plan_id" + t.integer "archived_by" end create_table "dmptemplates", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.boolean "published" - t.integer "user_id", limit: 4 - t.integer "organisation_id", limit: 4 + t.integer "user_id" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" - t.string "locale", limit: 255 + t.string "locale" t.boolean "is_default" end create_table "dmptemplates_guidance_groups", id: false, force: :cascade do |t| - t.integer "dmptemplate_id", limit: 4 - t.integer "guidance_group_id", limit: 4 + t.integer "dmptemplate_id" + t.integer "guidance_group_id" end create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.string "format", limit: 255 + t.integer "plan_id" + t.integer "user_id" + t.string "format" t.datetime "created_at" t.datetime "updated_at" end create_table "file_types", force: :cascade do |t| - t.string "name", limit: 255 - t.string "icon_name", limit: 255 - t.integer "icon_size", limit: 4 - t.string "icon_location", limit: 255 + t.string "name" + t.string "icon_name" + t.integer "icon_size" + t.string "icon_location" t.datetime "created_at" t.datetime "updated_at" end create_table "file_uploads", force: :cascade do |t| - t.string "name", limit: 255 - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "size", limit: 4 + t.string "name" + t.string "title" + t.text "description" + t.integer "size" t.boolean "published" - t.string "location", limit: 255 - t.integer "file_type_id", limit: 4 + t.string "location" + t.integer "file_type_id" t.datetime "created_at" t.datetime "updated_at" end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 191, null: false - t.integer "sluggable_id", limit: 4, null: false + t.string "slug", null: false + t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 40 t.datetime "created_at" end - add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true, using: :btree - add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree - add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree + add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true + add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" + add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" create_table "guidance_groups", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "organisation_id", limit: 4 + t.string "name" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "optional_subset" @@ -107,108 +107,108 @@ end create_table "guidance_in_group", id: false, force: :cascade do |t| - t.integer "guidance_id", limit: 4, null: false - t.integer "guidance_group_id", limit: 4, null: false + t.integer "guidance_id", null: false + t.integer "guidance_group_id", null: false end - add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id", using: :btree + add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id" create_table "guidances", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "guidance_group_id", limit: 4 + t.text "text" + t.integer "guidance_group_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "question_id", limit: 4 + t.integer "question_id" t.boolean "published" end create_table "identifier_schemes", force: :cascade do |t| - t.string "name", limit: 255 - t.string "api_key", limit: 255 - t.string "api_secret", limit: 255 - t.string "landing_page_uri", limit: 255 - t.string "params", limit: 255 + t.string "name" + t.string "api_key" + t.string "api_secret" + t.string "landing_page_uri" + t.string "params" t.datetime "created_at" t.datetime "updated_at" end create_table "languages", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation" + t.string "description" + t.string "name" t.boolean "default_language" end create_table "option_warnings", force: :cascade do |t| - t.integer "organisation_id", limit: 4 - t.integer "option_id", limit: 4 - t.text "text", limit: 65535 + t.integer "organisation_id" + t.integer "option_id" + t.text "text" t.datetime "created_at" t.datetime "updated_at" end create_table "options", force: :cascade do |t| - t.integer "question_id", limit: 4 - t.string "text", limit: 255 - t.integer "number", limit: 4 + t.integer "question_id" + t.string "text" + t.integer "number" t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end create_table "org_token_permissions", force: :cascade do |t| - t.integer "organisation_id", limit: 4 - t.integer "token_permission_type_id", limit: 4 + t.integer "organisation_id" + t.integer "token_permission_type_id" t.datetime "created_at" t.datetime "updated_at" end create_table "organisation_types", force: :cascade do |t| - t.string "name", limit: 255 - t.text "description", limit: 65535 + t.string "name" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "organisations", force: :cascade do |t| - t.string "name", limit: 255 - t.string "abbreviation", limit: 255 - t.string "target_url", limit: 255 - t.integer "organisation_type_id", limit: 4 - t.string "domain", limit: 255 - t.string "wayfless_entity", limit: 255 - t.integer "stylesheet_file_id", limit: 4 + t.string "name" + t.string "abbreviation" + t.string "target_url" + t.integer "organisation_type_id" + t.string "domain" + t.string "wayfless_entity" + t.integer "stylesheet_file_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "parent_id", limit: 4 + t.integer "parent_id" t.boolean "is_other" - t.string "sort_name", limit: 255 - t.text "banner_text", limit: 65535 - t.string "logo_file_name", limit: 255 - t.integer "region_id", limit: 4 - t.integer "language_id", limit: 4 - t.string "logo_uid", limit: 255 - t.string "logo_name", limit: 255 - t.string "contact_email", limit: 255 + 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" + t.string "logo_name" + t.string "contact_email" end create_table "phases", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 - t.integer "dmptemplate_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "dmptemplate_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 + t.string "slug" end - add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id", using: :btree - add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true, using: :btree + add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id" + add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true create_table "plan_sections", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "section_id", limit: 4 - t.integer "plan_id", limit: 4 + t.integer "user_id" + t.integer "section_id" + t.integer "plan_id" t.datetime "created_at" t.datetime "updated_at" t.datetime "release_time" @@ -216,8 +216,8 @@ create_table "plans", force: :cascade do |t| t.boolean "locked" - t.integer "project_id", limit: 4 - t.integer "version_id", limit: 4 + t.integer "project_id" + t.integer "version_id" t.datetime "created_at" t.datetime "updated_at" end @@ -225,239 +225,234 @@ create_table "project_groups", force: :cascade do |t| t.boolean "project_creator" t.boolean "project_editor" - t.integer "user_id", limit: 4 - t.integer "project_id", limit: 4 + t.integer "user_id" + t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "project_administrator" end create_table "project_guidance", id: false, force: :cascade do |t| - t.integer "project_id", limit: 4, null: false - t.integer "guidance_group_id", limit: 4, null: false + t.integer "project_id", null: false + t.integer "guidance_group_id", null: false end - add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id", using: :btree + add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id" create_table "projects", force: :cascade do |t| - t.string "title", limit: 255 - t.integer "dmptemplate_id", limit: 4 + t.string "title" + t.integer "dmptemplate_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 - t.integer "organisation_id", limit: 4 - t.string "grant_number", limit: 255 - t.string "identifier", limit: 255 - t.text "description", limit: 65535 - t.string "principal_investigator", limit: 255 - t.string "principal_investigator_identifier", limit: 255 - t.string "data_contact", limit: 255 - t.string "funder_name", limit: 255 + t.string "slug" + t.integer "organisation_id" + t.string "grant_number" + t.string "identifier" + t.text "description" + t.string "principal_investigator" + t.string "principal_investigator_identifier" + t.string "data_contact" + t.string "funder_name" end - add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree + add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true create_table "question_formats", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "questions", force: :cascade do |t| - t.text "text", limit: 65535 - t.text "default_value", limit: 65535 - t.text "guidance", limit: 65535 - t.integer "number", limit: 4 - t.integer "parent_id", limit: 4 - t.integer "dependency_id", limit: 4 - t.text "dependency_text", limit: 65535 - t.integer "section_id", limit: 4 + t.text "text" + t.text "default_value" + t.text "guidance" + t.integer "number" + t.integer "parent_id" + t.integer "dependency_id" + t.text "dependency_text" + t.integer "section_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id", limit: 4 - t.boolean "option_comment_display", default: true + t.integer "question_format_id" + t.boolean "option_comment_display", default: true end create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", limit: 4, null: false - t.integer "theme_id", limit: 4, null: false + t.integer "question_id", null: false + t.integer "theme_id", null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree + add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id" create_table "region_groups", force: :cascade do |t| - t.integer "super_region_id", limit: 4 - t.integer "region_id", limit: 4 + t.integer "super_region_id" + t.integer "region_id" end create_table "regions", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation" + t.string "description" + t.string "name" end create_table "roles", force: :cascade do |t| - t.string "name", limit: 191 + t.string "name" t.datetime "created_at" t.datetime "updated_at" t.boolean "role_in_plans" - t.integer "resource_id", limit: 4 - t.string "resource_type", limit: 255 + t.integer "resource_id" + t.string "resource_type" end - add_index "roles", ["name"], name: "index_roles_on_name", using: :btree - add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree + add_index "roles", ["name"], name: "index_roles_on_name" + add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" create_table "sections", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 - t.integer "version_id", limit: 4 - t.integer "organisation_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "version_id" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "published" end create_table "settings", force: :cascade do |t| - t.string "var", limit: 191, null: false - t.text "value", limit: 65535 - t.integer "target_id", limit: 4, null: false - t.string "target_type", limit: 191, null: false + t.string "var", null: false + t.text "value" + t.integer "target_id", null: false + t.string "target_type", null: false t.datetime "created_at" t.datetime "updated_at" end - add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true create_table "splash_logs", force: :cascade do |t| - t.string "destination", limit: 255 + t.string "destination" t.datetime "created_at" t.datetime "updated_at" end create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id", limit: 4 - t.integer "organisation_id", limit: 4 - t.text "text", limit: 65535 + t.integer "question_id" + t.integer "organisation_id" + t.text "text" t.datetime "created_at" t.datetime "updated_at" t.boolean "is_example" end create_table "themes", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.datetime "created_at" t.datetime "updated_at" - t.string "locale", limit: 255 + t.string "locale" end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id", limit: 4 - t.integer "guidance_id", limit: 4 + t.integer "theme_id" + t.integer "guidance_id" end create_table "token_permission_types", force: :cascade do |t| - t.string "token_type", limit: 255 - t.text "text_description", limit: 65535 + t.string "token_type" + t.text "text_description" t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier", limit: 255 + t.string "identifier" t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 - t.integer "identifier_scheme_id", limit: 4 + t.integer "user_id" + t.integer "identifier_scheme_id" end - add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0", using: :btree - add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb", using: :btree - create_table "user_role_types", force: :cascade do |t| - t.string "name", limit: 255 - t.text "description", limit: 65535 + 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", limit: 255 - t.text "description", limit: 65535 + t.string "name" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "user_types", force: :cascade do |t| - t.string "name", limit: 255 - t.text "description", limit: 65535 + t.string "name" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| - t.string "firstname", limit: 255 - t.string "surname", limit: 255 - t.string "email", limit: 191, default: "", null: false - t.string "orcid_id", limit: 255 - t.string "shibboleth_id", limit: 255 - t.integer "user_type_id", limit: 4 - t.integer "user_status_id", limit: 4 + t.string "firstname" + t.string "surname" + t.string "email", default: "", null: false + t.string "orcid_id" + t.string "shibboleth_id" + t.integer "user_type_id" + t.integer "user_status_id" t.datetime "created_at" t.datetime "updated_at" - t.string "encrypted_password", limit: 255, default: "" - t.string "reset_password_token", limit: 191 + t.string "encrypted_password", default: "" + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", limit: 4, default: 0 + t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.string "confirmation_token", limit: 191 + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token", limit: 191 + t.string "invitation_token" t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation", limit: 255 + t.string "other_organisation" t.boolean "dmponline3" t.boolean "accept_terms" - t.integer "organisation_id", limit: 4 - t.string "api_token", limit: 255 - t.integer "invited_by_id", limit: 4 - t.string "invited_by_type", limit: 255 - t.integer "language_id", limit: 4 + t.integer "organisation_id" + t.string "api_token" + t.integer "invited_by_id" + t.string "invited_by_type" + t.integer "language_id" end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + add_index "users", ["email"], name: "index_users_on_email", unique: true + add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true create_table "users_roles", id: false, force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "role_id", limit: 4 + t.integer "user_id" + t.integer "role_id" end - add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree + add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" create_table "versions", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.boolean "published" - t.integer "number", limit: 4 - t.integer "phase_id", limit: 4 + t.integer "number" + t.integer "phase_id" t.datetime "created_at" t.datetime "updated_at" end - add_index "versions", ["phase_id"], name: "index_versions_on_phase_id", using: :btree + add_index "versions", ["phase_id"], name: "index_versions_on_phase_id" - add_foreign_key "user_identifiers", "identifier_schemes" - add_foreign_key "user_identifiers", "users" end diff --git a/test/fixtures/identifier_schemes.yml b/test/fixtures/identifier_schemes.yml new file mode 100644 index 0000000..a6383be --- /dev/null +++ b/test/fixtures/identifier_schemes.yml @@ -0,0 +1,9 @@ +<% # Load the org types from thosedefined in the MagicStrings section of the locale %> +<% I18n.t("identifier_schemes.schemes").each do |k,v| %> +<%= k.downcase %>: + name: <%= "#{k}" %> + api_key: 'ABCDEFG' + api_secret: '123456' + landing_page_uri: 'http://example-site.edu' + params: '{"scope":"/do_something"}' +<% end %> \ No newline at end of file diff --git a/test/functional/users/omniauth_callbacks_controller_test.rb b/test/functional/users/omniauth_callbacks_controller_test.rb new file mode 100644 index 0000000..8bf6245 --- /dev/null +++ b/test/functional/users/omniauth_callbacks_controller_test.rb @@ -0,0 +1,53 @@ +class OmniauthCallbacksController < ActionDispatch::IntegrationTest + + setup do + + end + + ## + # Dynamically test the registered omniauth handlers + # ------------------------------------------------------------- + test "should redirect to registration page if user is not already logged in and the omniauth provider does not supply correct information" do + + IdentifierScheme.all.each do |scheme| + uri = Rails.application.routes.url_helpers.send( + "user_#{scheme.name.downcase}_omniauth_authorize_path") + + header = {"omniauth.auth": { + "provider": "#{scheme.name.downcase}", + "uid": "0000-0003-2012-0010", + "info": { + "name": "John Smith", + "email": nil + }, + "credentials": { + "token": "e82938fa-a287-42cf-a2ce-f48ef68c9a35", + "refresh_token": "f94c58dd-b452-44f4-8863-0bf8486a0071", + "expires_at": 1979903874, + "expires": true + }, + "extra": {} + }} + + # Not yet logged in, valid responses from provider + # -------------------------------------------------------------- +=begin + post "#{uri}/callback", headers: headers + + assert_equal I18n.t('identifier_schemes.new_login_success'), flash[:notice], "Expected a success message when simulating a valid callback from #{scheme.name}" + assert_redirected_to new_user_registration_url, "Expected a redirect to the registration page when the user is not logged in and we received a valid callback from #{scheme.name}" + + # Not yet logged in, invalid responses from provider + # -------------------------------------------------------------- + confirm_invalid_provider_response(scheme.name, uri, nil) + + confirm_invalid_provider_response(scheme.name, uri, {'omniauth.auth': {}}) + + confirm_invalid_provider_response(scheme.name, uri, {'omniauth.auth': {'provider': scheme.name.downcase}}) + + confirm_invalid_provider_response(scheme.name, uri, {'omniauth.auth': {'uid': '123456'}}) +=end + end + end + +end \ No newline at end of file diff --git a/test/routing_test.rb b/test/routing_test.rb index 8ac04af..c83d5a1 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -34,6 +34,24 @@ assert_routing "/#{I18n.locale}/terms", target end + # OAuth - Based on providers identified in the en-UK locale file + # ------------------------------------------------------------------- + test "GET /users/auth/[:provider] should resolve to OmniauthCallbackController#passthru" do + target = {controller: "users/omniauth_callbacks", action: "passthru"} + + IdentifierScheme.all.each do |scheme| + assert_routing "/users/auth/#{scheme.name.downcase}", target + end + end + + test "POST /auth/[:provider]/callback should resolve to OmniauthCallbackController#[:provider]" do + IdentifierScheme.all.each do |scheme| + target = {controller: "users/omniauth_callbacks", action: "#{scheme.name.downcase}"} + assert_routing "/users/auth/#{scheme.name.downcase}/callback", target + end + end + + # Routing for Users (Some resolve to UsersController and others to Devise's # RegistrationController) # -------------------------------------------------------------------