Commit a13915d99bc334a2e92c21d5913120d664741b14
Committed by
Rodrigo Souto
1 parent
b052d280
Exists in
master
and in
28 other branches
Creating hotspot to the user_data
Showing
4 changed files
with
29 additions
and
0 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -224,6 +224,8 @@ class AccountController < ApplicationController | @@ -224,6 +224,8 @@ class AccountController < ApplicationController | ||
224 | session[:notice] = nil # consume the notice | 224 | session[:notice] = nil # consume the notice |
225 | end | 225 | end |
226 | 226 | ||
227 | + @plugins.enabled_plugins.each { |plugin| user_data.merge!(plugin.user_data_extras) } | ||
228 | + | ||
227 | render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" | 229 | render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" |
228 | end | 230 | end |
229 | 231 |
lib/noosfero/plugin.rb
@@ -121,4 +121,10 @@ class Noosfero::Plugin | @@ -121,4 +121,10 @@ class Noosfero::Plugin | ||
121 | [] | 121 | [] |
122 | end | 122 | end |
123 | 123 | ||
124 | + # -> Adds stuff in user data hash | ||
125 | + # returns = { :some_data => some_value, :another_data => another_value } | ||
126 | + def user_data_extras | ||
127 | + {} | ||
128 | + end | ||
129 | + | ||
124 | end | 130 | end |
public/javascripts/application.js
@@ -475,6 +475,8 @@ jQuery(function($) { | @@ -475,6 +475,8 @@ jQuery(function($) { | ||
475 | if (data.notice) { | 475 | if (data.notice) { |
476 | display_notice(data.notice); | 476 | display_notice(data.notice); |
477 | } | 477 | } |
478 | + // Bind this event to do more actions with the user data (for example, inside plugins) | ||
479 | + $(window).trigger("userDataLoaded", data); | ||
478 | }); | 480 | }); |
479 | 481 | ||
480 | function loggedInDataCallBack(data) { | 482 | function loggedInDataCallBack(data) { |
test/functional/account_controller_test.rb
@@ -670,6 +670,25 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -670,6 +670,25 @@ class AccountControllerTest < Test::Unit::TestCase | ||
670 | assert_equal 'unavailable', assigns(:status_class) | 670 | assert_equal 'unavailable', assigns(:status_class) |
671 | end | 671 | end |
672 | 672 | ||
673 | + should 'merge user data with extra stuff from plugins' do | ||
674 | + plugin1 = mock() | ||
675 | + plugin1.stubs(:user_data_extras).returns({ :foo => 'bar' }) | ||
676 | + | ||
677 | + plugin2 = mock() | ||
678 | + plugin2.stubs(:user_data_extras).returns({ :test => 5 }) | ||
679 | + | ||
680 | + enabled_plugins = [plugin1, plugin2] | ||
681 | + | ||
682 | + plugins = mock() | ||
683 | + plugins.stubs(:enabled_plugins).returns(enabled_plugins) | ||
684 | + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | ||
685 | + | ||
686 | + login_as 'ze' | ||
687 | + | ||
688 | + xhr :get, :user_data | ||
689 | + assert_equal User.find_by_login('ze').data_hash.merge({ 'foo' => 'bar', 'test' => 5 }), ActiveSupport::JSON.decode(@response.body) | ||
690 | + end | ||
691 | + | ||
673 | protected | 692 | protected |
674 | def new_user(options = {}, extra_options ={}) | 693 | def new_user(options = {}, extra_options ={}) |
675 | data = {:profile_data => person_data} | 694 | data = {:profile_data => person_data} |