[Git][noosfero/noosfero][master] 2 commits: Merge branch 'custom-redirect-hotspot' into 'master-1.x'
Rodrigo Souto
gitlab at mg.gitlab.com
Fri Jun 8 12:06:20 BRT 2018
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
c0c80cb1 by Gabriel Silva at 2018-05-10T19:56:36Z
Merge branch 'custom-redirect-hotspot' into 'master-1.x'
application-controller: hotspot for custom redirection
See merge request noosfero/noosfero!1470
(cherry picked from commit ce5ce294c41a281bc62ca76a072e0e93a4866010)
a592ef79 application-controller: hotspot for custom redirection
- - - - -
8ac59017 by Rodrigo Souto at 2018-06-08T15:06:00Z
Merge branch 'cherry-pick-ce5ce294'
- - - - -
5 changed files:
- app/controllers/application_controller.rb
- app/controllers/public/account_controller.rb
- lib/noosfero/plugin.rb
- test/functional/account_controller_test.rb
- test/functional/application_controller_test.rb
Changes:
=====================================
app/controllers/application_controller.rb
=====================================
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -211,4 +211,14 @@ class ApplicationController < ActionController::Base
end
end
end
+
+ def redirect_to_with_plugins(options = {}, response_status = {})
+ result = plugins.dispatch_first(:custom_redirect, user, params, options, response_status = {})
+ if result.present? && result[:options].present?
+ redirect_to_without_plugins(result[:options], result[:response_status])
+ else
+ redirect_to_without_plugins(options, response_status)
+ end
+ end
+ alias_method_chain :redirect_to, :plugins
end
=====================================
app/controllers/public/account_controller.rb
=====================================
--- a/app/controllers/public/account_controller.rb
+++ b/app/controllers/public/account_controller.rb
@@ -461,14 +461,8 @@ class AccountController < ApplicationController
end
def go_to_initial_page
- plugin_url = @plugins.dispatch_first(:custom_redirection_after_login,
- current_person)
-
if params[:return_to]
redirect_to url_for(params[:return_to])
- elsif plugin_url.present?
- plugin_url = plugin_url.is_a?(Hash) ? url_for(plugin_url) : plugin_url
- redirect_to plugin_url
elsif environment.enabled?('allow_change_of_redirection_after_login')
check_redirection_options(user, user.preferred_login_redirection, user.admin_url)
else
=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -761,11 +761,11 @@ class Noosfero::Plugin
nil
end
- # -> Redirects to a custom URL after login
- # (overrides any environment configuration)
- # returns = a location string or a options hash for an URL
- def custom_redirection_after_login(current_person)
- nil
+ # -> Overrides default redirection to a custom redirection
+ # returns = {options: options, response_status: response_status}
+ # Check #redirect_to method doc for further informations about the parameters
+ def custom_redirect(user, params, options, response_status)
+ {}
end
def method_missing(method, *args, &block)
=====================================
test/functional/account_controller_test.rb
=====================================
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -1094,36 +1094,6 @@ class AccountControllerTest < ActionController::TestCase
assert_response :redirect
end
- should 'override the redirection url with plugin returned hash' do
- url = { controller: 'profile', action: 'index', profile: 'ze' }
- Noosfero::Plugin::Manager.any_instance
- .expects(:dispatch_first)
- .with(:custom_redirection_after_login, anything)
- .returns(url)
- post :login, user: { login: 'johndoe', password: 'test' }
- assert_redirected_to url
- end
-
- should 'override the redirection url with plugin returned string' do
- url = { controller: 'profile', action: 'index', profile: 'ze' }
- Noosfero::Plugin::Manager.any_instance
- .expects(:dispatch_first)
- .with(:custom_redirection_after_login, anything)
- .returns('/profile/ze')
- post :login, user: { login: 'johndoe', password: 'test' }
- assert_redirected_to url
- end
-
- should 'not use plugin url when there is a return_to param' do
- url = { controller: 'home', action: 'index' }
- Noosfero::Plugin::Manager.any_instance
- .expects(:dispatch_first)
- .with(:custom_redirection_after_login, anything)
- .returns('/profile/ze')
- post :login, user: { login: 'johndoe', password: 'test' }, return_to: url
- assert_redirected_to url
- end
-
should 'generate new activation codes when requesting new codes' do
user = create_user_full
old_token = user.activation_code
=====================================
test/functional/application_controller_test.rb
=====================================
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -602,4 +602,18 @@ class ApplicationControllerTest < ActionController::TestCase
get :index, :theme => 'another_theme'
assert_nil @request.session[:theme]
end
+
+ should 'allow plugins to customize redirection' do
+ class Plugin1 < Noosfero::Plugin
+ def custom_redirect(user, params, options, response_status)
+ {options: '/plugin/custom_redirect', response_status: {}}
+ end
+ end
+ Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new])
+
+ @controller.stubs(:session).returns({})
+ @controller.stubs(:params).returns({})
+ @controller.expects(:redirect_to_without_plugins).with('/plugin/custom_redirect', {})
+ @controller.redirect_to
+ end
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/df623f7cb90ce333126a2f505bd306db6aa73ec6...8ac59017025386e5954559efa22e2fcd054caeb2
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/df623f7cb90ce333126a2f505bd306db6aa73ec6...8ac59017025386e5954559efa22e2fcd054caeb2
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180608/ac5c334d/attachment-0001.html>
More information about the Noosfero-dev
mailing list