Commit a13915d99bc334a2e92c21d5913120d664741b14
Committed by
Rodrigo Souto
1 parent
b052d280
Exists in
master
and in
22 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 | 224 | session[:notice] = nil # consume the notice |
| 225 | 225 | end |
| 226 | 226 | |
| 227 | + @plugins.enabled_plugins.each { |plugin| user_data.merge!(plugin.user_data_extras) } | |
| 228 | + | |
| 227 | 229 | render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" |
| 228 | 230 | end |
| 229 | 231 | ... | ... |
lib/noosfero/plugin.rb
public/javascripts/application.js
| ... | ... | @@ -475,6 +475,8 @@ jQuery(function($) { |
| 475 | 475 | if (data.notice) { |
| 476 | 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 | 482 | function loggedInDataCallBack(data) { | ... | ... |
test/functional/account_controller_test.rb
| ... | ... | @@ -670,6 +670,25 @@ class AccountControllerTest < Test::Unit::TestCase |
| 670 | 670 | assert_equal 'unavailable', assigns(:status_class) |
| 671 | 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 | 692 | protected |
| 674 | 693 | def new_user(options = {}, extra_options ={}) |
| 675 | 694 | data = {:profile_data => person_data} | ... | ... |