diff --git a/app/controllers/redmine_oauth_controller.rb b/app/controllers/redmine_oauth_controller.rb index 68e33d3abb90265dcf0a65d01c11ca72c4dd8be5..4ac8bce51fec2ca814cb943a72797c82a286cf05 100644 --- a/app/controllers/redmine_oauth_controller.rb +++ b/app/controllers/redmine_oauth_controller.rb @@ -6,21 +6,21 @@ class RedmineOauthController < AccountController include Helpers::Checker def oauth_google if Setting.plugin_redmine_omniauth_google[:oauth_authentification] - redirect_to oauth_client.auth_code.authorize_url(redirect_uri: oauth_google_callback_url, scope: scopes) + redirect_to oauth_client.auth_code.authorize_url(:redirect_uri => oauth_google_callback_url, :scope => scopes) else password_authentication end end def oauth_google_callback - token = oauth_client.auth_code.get_token(params[:code], redirect_uri: oauth_google_callback_url) + token = oauth_client.auth_code.get_token(params[:code], :redirect_uri => oauth_google_callback_url) result = token.get('https://www.googleapis.com/oauth2/v1/userinfo') info = JSON.parse(result.body) if info && info["verified_email"] if allowed_domain_for?(info["email"]) try_to_login info else - flash[:error] = l(:notice_domain_not_allowed, domain: parse_email(info["email"])[:domain]) + flash[:error] = l(:notice_domain_not_allowed, :domain => parse_email(info["email"])[:domain]) redirect_to signin_path end else @@ -70,9 +70,9 @@ class RedmineOauthController < AccountController def oauth_client @client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret], - site: 'https://accounts.google.com', - authorize_url: '/o/oauth2/auth', - token_url: '/o/oauth2/token') + :site => 'https://accounts.google.com', + :authorize_url => '/o/oauth2/auth', + :token_url => '/o/oauth2/token') end def settings @@ -82,4 +82,4 @@ class RedmineOauthController < AccountController def scopes 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile' end -end \ No newline at end of file +end diff --git a/app/views/hooks/_view_account_login_bottom.html.erb b/app/views/hooks/_view_account_login_bottom.html.erb index 51a4061d896023997c4e0d5650b98506141b5328..3f35344172495d0189e491753c9fe0476562d77d 100644 --- a/app/views/hooks/_view_account_login_bottom.html.erb +++ b/app/views/hooks/_view_account_login_bottom.html.erb @@ -1,10 +1,10 @@ -<%= stylesheet_link_tag 'buttons', plugin: 'redmine_omniauth_google' %> +<%= stylesheet_link_tag 'buttons', :plugin => 'redmine_omniauth_google' %> <% if Setting.plugin_redmine_omniauth_google[:oauth_authentification] %> <%= link_to oauth_google_path do %> - <%= button_tag class: 'button-login' do %> - <%= image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.png', class: 'button-login-icon', alt: l(:login_via_google)) %> - <%= content_tag :div, l(:login_via_google), class: 'button-login-text' %> + <%= button_tag :class => 'button-login' do %> + <%= image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.png', :class => 'button-login-icon', :alt => l(:login_via_google)) %> + <%= content_tag :div, l(:login_via_google), :class => 'button-login-text' %> <% end %> <% end %> <% end %> diff --git a/app/views/settings/_google_settings.html.erb b/app/views/settings/_google_settings.html.erb index bd32d7723a787cb5f0e79b2878d7b1985be734e0..40e3a1d918a18b1ce9bda3b760e9d29f0136608e 100644 --- a/app/views/settings/_google_settings.html.erb +++ b/app/views/settings/_google_settings.html.erb @@ -8,9 +8,9 @@ </p> <p> <label>Available domains</label> - <%= text_area_tag "settings[allowed_domains]", @settings[:allowed_domains], rows: 5 %> + <%= text_area_tag "settings[allowed_domains]", @settings[:allowed_domains], :rows => 5 %> </p> <p> <label>Oauth authentification:</label> <%= check_box_tag "settings[oauth_authentification]", true, @settings[:oauth_authentification] %> -</p> \ No newline at end of file +</p> diff --git a/config/locales/en.yml b/config/locales/en.yml index ac32042448916fb056471aa7e89a92e2b19a8f19..82a366e6abfd51cd7e5297de792742f9ae126dc6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,4 @@ -# English strings go here for Rails i18n en: notice_unable_to_obtain_google_credentials: "Unable to obtain credentials from Google." notice_domain_not_allowed: "You can not login using %{domain} domain." - login_via_google: "Login via Google" \ No newline at end of file + login_via_google: "Login via Google" diff --git a/config/routes.rb b/config/routes.rb index c17eabadaad9712af5236ea2d3ef00a2108f22c3..a65030a8f5e5c3bb00e91274abb8920a5a211efe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,2 +1,2 @@ -get 'oauth_google', to: 'redmine_oauth#oauth_google' -get 'oauth2callback', to: 'redmine_oauth#oauth_google_callback', as: 'oauth_google_callback' +get 'oauth_google', :to => 'redmine_oauth#oauth_google' +get 'oauth2callback', :to => 'redmine_oauth#oauth_google_callback', :as => 'oauth_google_callback' diff --git a/init.rb b/init.rb index b4a10096b53a472126f1c3bd721a5454e8fd7b90..8f67cbce12cc157a8766e539ed707fa5f56305d2 100644 --- a/init.rb +++ b/init.rb @@ -9,10 +9,10 @@ Redmine::Plugin.register :redmine_omniauth_google do url 'https://github.com/twinslash/redmine_omniauth_google' author_url 'http://twinslash.com' - settings default: { - client_id: "", - client_secret: "", - oauth_autentification: false, - allowed_domains: "" - }, partial: 'settings/google_settings' + settings :default => { + :client_id => "", + :client_secret => "", + :oauth_autentification => false, + :allowed_domains => "" + }, :partial => 'settings/google_settings' end diff --git a/lib/helpers/mail_helper.rb b/lib/helpers/mail_helper.rb index 5515212f7b3a1e03e1886669051ea538e8054c95..eec5b41836846647a1090bf5ca3560249e187c00 100644 --- a/lib/helpers/mail_helper.rb +++ b/lib/helpers/mail_helper.rb @@ -2,7 +2,7 @@ module Helpers module MailHelper def parse_email email email_data = email && email.is_a?(String) ? email.match(/(.*?)@(.*)/) : nil - {login: email_data[1], domain: email_data[2]} if email_data + {:login => email_data[1], :domain => email_data[2]} if email_data end end -end \ No newline at end of file +end diff --git a/lib/hooks/view_account_login_bottom_hook.rb b/lib/hooks/view_account_login_bottom_hook.rb index 8cd147faaebe83eb4dcee9293d31769f5927ab7d..62df7df6dad7046867e950b81bcf5fd4e801e4ec 100644 --- a/lib/hooks/view_account_login_bottom_hook.rb +++ b/lib/hooks/view_account_login_bottom_hook.rb @@ -1,10 +1,9 @@ module Hooks class ViewAccountLoginBottomHook < Redmine::Hook::ViewListener - def view_account_login_bottom context = {} + def view_account_login_bottom(context = {}) context[:controller].send(:render_to_string, { - partial: "hooks/view_account_login_bottom", - locals: context - }) + :partial => "hooks/view_account_login_bottom", + :locals => context}) end end -end \ No newline at end of file +end diff --git a/test/functional/redmine_oauth_controller_test.rb b/test/functional/redmine_oauth_controller_test.rb index e584dd24134607732fbc632a690d68c7e8a82142..a1c28e92a41d9388faea4e73a048e593ec088baa 100644 --- a/test/functional/redmine_oauth_controller_test.rb +++ b/test/functional/redmine_oauth_controller_test.rb @@ -3,18 +3,18 @@ require File.expand_path('../../test_helper', __FILE__) class RedmineOauthControllerTest < ActionController::TestCase include Helpers::MailHelper def setup - @default_user_credentials = { firstname: 'Cool', - lastname: 'User', - mail: 'user@somedomain.com'} - @default_response_body = {verified_email: true, - name: 'Cool User', - given_name: 'Cool', - family_name: 'User', - email: 'user@somedomain.com'} + @default_user_credentials = { :firstname => 'Cool', + :lastname => 'User', + :mail => 'user@somedomain.com'} + @default_response_body = {:verified_email => true, + :name => 'Cool User', + :given_name => 'Cool', + :family_name => 'User', + :email => 'user@somedomain.com'} User.current = nil Setting.openid = '1' - OAuth2::AccessToken.any_instance.stubs(get: OAuth2::Response.new(nil)) - OAuth2::Client.any_instance.stubs(get_token: OAuth2::AccessToken.new('code', 'redirect_uri')) + OAuth2::AccessToken.any_instance.stubs(:get => OAuth2::Response.new(nil)) + OAuth2::Client.any_instance.stubs(:get_token => OAuth2::AccessToken.new('code', 'redirect_uri')) end #creates a new user with the credentials listed in the options and fills in the missing data by default data @@ -27,7 +27,7 @@ class RedmineOauthControllerTest < ActionController::TestCase #creates a new user with the credentials listed in the options and fills in the missing data by default data def set_response_body_stub options = {} - OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json) + OAuth2::Response.any_instance.stubs(:body => @default_response_body.merge(options).to_json) end def test_oauth_google_with_enabled_oauth_authentification @@ -38,7 +38,7 @@ class RedmineOauthControllerTest < ActionController::TestCase def test_oauth_google_callback_for_existing_non_active_user Setting.self_registration = '2' - user = new_user status: User::STATUS_REGISTERED + user = new_user :status => User::STATUS_REGISTERED assert user.save set_response_body_stub get :oauth_google_callback @@ -51,14 +51,14 @@ class RedmineOauthControllerTest < ActionController::TestCase assert user.save set_response_body_stub get :oauth_google_callback - assert_redirected_to controller: 'my', action: 'page' + assert_redirected_to :controller => 'my', :action => 'page' end def test_oauth_google_callback_for_new_user_with_valid_credentials_and_sefregistration_enabled Setting.self_registration = '3' set_response_body_stub get :oauth_google_callback - assert_redirected_to controller: 'my', action: 'account' + assert_redirected_to :controller => 'my', :action => 'account' user = User.find_by_mail(@default_response_body[:email]) assert_equal user.mail, @default_response_body[:email] assert_equal user.login, parse_email(@default_response_body[:email])[:login] @@ -73,7 +73,7 @@ class RedmineOauthControllerTest < ActionController::TestCase def test_oauth_google_callback_with_new_user_with_invalid_oauth_provider Setting.self_registration = '3' - set_response_body_stub verified_email: false + set_response_body_stub :verified_email => false get :oauth_google_callback assert_redirected_to signin_path end @@ -103,7 +103,7 @@ class RedmineOauthControllerTest < ActionController::TestCase Setting.plugin_redmine_omniauth_google[:allowed_domains] = "twinslash.com" set_response_body_stub get :oauth_google_callback - assert_redirected_to :signin + assert_redirected_to :signin end def test_oauth_google_callback_with_allowed_email_domain @@ -111,6 +111,6 @@ class RedmineOauthControllerTest < ActionController::TestCase Setting.plugin_redmine_omniauth_google[:allowed_domains] = parse_email(@default_response_body[:email])[:domain] set_response_body_stub get :oauth_google_callback - assert_redirected_to controller: 'my', action: 'account' + assert_redirected_to :controller => 'my', :action => 'account' end -end \ No newline at end of file +end