[Git][noosfero/noosfero][master] 3 commits: Adds hotspot to override sigin redirection url

Rodrigo Souto gitlab at mg.gitlab.com
Thu Mar 1 15:40:33 BRT 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
d3eec5b3 by Gabriel Silva at 2018-02-28T17:15:08Z
Adds hotspot to override sigin redirection url

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -
6f8bc1fc by Gabriel Silva at 2018-02-28T17:15:39Z
Removes option to change redirection url from control panel

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -
599c46ac by Rodrigo Souto at 2018-03-01T18:40:24Z
Merge branch 'signin-redirection' into 'master'

Adds hotspot to override sign in redirection from plugins

See merge request noosfero/noosfero!1407
- - - - -


6 changed files:

- app/controllers/public/account_controller.rb
- − app/views/profile_editor/_redirection_after_login.html.erb
- app/views/profile_editor/edit.html.erb
- lib/noosfero/plugin.rb
- test/functional/account_controller_test.rb
- test/functional/profile_editor_controller_test.rb


Changes:

=====================================
app/controllers/public/account_controller.rb
=====================================
--- a/app/controllers/public/account_controller.rb
+++ b/app/controllers/public/account_controller.rb
@@ -427,8 +427,14 @@ 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


=====================================
app/views/profile_editor/_redirection_after_login.html.erb deleted
=====================================
--- a/app/views/profile_editor/_redirection_after_login.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% content_for :head do %>
-  <%= javascript_include_tag 'redirection_after_login' %>
-<% end %>
-
-<h2><%= _('Page to redirect after login') %></h2>
-<%= f.select :redirection_after_login, Environment.login_redirection_options.map{ |key,value| [value,key] }, selected: @profile.preferred_login_redirection %>
-
-<%= f.text_field :custom_url_redirection %>
-


=====================================
app/views/profile_editor/edit.html.erb
=====================================
--- a/app/views/profile_editor/edit.html.erb
+++ b/app/views/profile_editor/edit.html.erb
@@ -49,10 +49,6 @@
   <%= content_tag( 'small', _('Who will be able to see your wall?')) %>
   <%= access_slider_field_tag('wall-access', 'profile_data[wall_access]', @profile, @profile.wall_access, @profile.wall_access_levels) %>
 
-  <% if environment.enabled?('allow_change_of_redirection_after_login') %>
-    <%= render 'redirection_after_login', f: f %>
-  <% end %>
-
   <h2><%= _('Translations') %></h2>
   <%= labelled_check_box(
     _('Automaticaly redirect the visitor to the article translated to his/her language'),


=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -747,6 +747,13 @@ 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
+  end
+
   def method_missing(method, *args, &block)
     # This is a generic hotspot for all controllers on Noosfero.
     # If any plugin wants to define filters to run on any controller, the name of


=====================================
test/functional/account_controller_test.rb
=====================================
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -1049,4 +1049,34 @@ 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
+
 end


=====================================
test/functional/profile_editor_controller_test.rb
=====================================
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -1114,24 +1114,6 @@ class ProfileEditorControllerTest < ActionController::TestCase
     assert_no_tag :tag => 'input', :attributes => {:name => 'profile_data[is_template]'}
   end
 
-  should 'display select to change redirection after login if enabled' do
-    e = Environment.default
-    e.enable('allow_change_of_redirection_after_login')
-    e.save
-
-    get :edit, :profile => profile.identifier
-    assert_tag :tag => 'select', :attributes => {:id => 'profile_data_redirection_after_login'}
-  end
-
-  should 'not display select to change redirection after login if not enabled' do
-    e = Environment.default
-    e.disable('allow_change_of_redirection_after_login')
-    e.save
-
-    get :edit, :profile => profile.identifier
-    assert_no_tag :tag => 'select', :attributes => {:id => 'profile_data_redirection_after_login'}
-  end
-
   should 'uncheck all field privacy fields' do
     person = profile
     assert_equal({}, person.fields_privacy)



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/323ed78a94fb4e10c4d35233fcf5f8e3640207fa...599c46accb92fa8edcea4b22b3f0a3baf19b348b

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/323ed78a94fb4e10c4d35233fcf5f8e3640207fa...599c46accb92fa8edcea4b22b3f0a3baf19b348b
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/20180301/198a24f0/attachment-0001.html>


More information about the Noosfero-dev mailing list