Put current user into gon
Fixed bug in app.js, removed unnecessray test
This commit is contained in:
parent
3da9b1bf7f
commit
fb9b3e35c3
5 changed files with 14 additions and 25 deletions
|
|
@ -34,7 +34,11 @@ var app = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
app.router = new app.Router();
|
app.router = new app.Router();
|
||||||
|
|
||||||
app.currentUser = app.user(window.current_user_attributes) || new app.models.User()
|
var currentUser = false;
|
||||||
|
if (window.preloads != undefined) {
|
||||||
|
currentUser = app.user(window.preloads.user)
|
||||||
|
}
|
||||||
|
app.currentUser = currentUser || new app.models.User();
|
||||||
|
|
||||||
if(app.currentUser.authenticated()){
|
if(app.currentUser.authenticated()){
|
||||||
app.header = new app.views.Header();
|
app.header = new app.views.Header();
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_filter :set_diaspora_header
|
before_filter :set_diaspora_header
|
||||||
before_filter :set_grammatical_gender
|
before_filter :set_grammatical_gender
|
||||||
before_filter :mobile_switch
|
before_filter :mobile_switch
|
||||||
|
before_filter :set_current_user_in_javascript
|
||||||
|
|
||||||
inflection_method :grammatical_gender => :gender
|
inflection_method :grammatical_gender => :gender
|
||||||
|
|
||||||
|
|
@ -136,4 +137,12 @@ class ApplicationController < ActionController::Base
|
||||||
def current_user_redirect_path
|
def current_user_redirect_path
|
||||||
current_user.getting_started? ? getting_started_path : stream_path
|
current_user.getting_started? ? getting_started_path : stream_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_current_user_in_javascript
|
||||||
|
return unless user_signed_in?
|
||||||
|
a_ids = session[:a_ids] || []
|
||||||
|
user = UserPresenter.new(current_user, a_ids)
|
||||||
|
gon.push({:user => user})
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,17 +37,6 @@ module LayoutHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_current_user_in_javascript
|
|
||||||
return unless user_signed_in?
|
|
||||||
a_ids = session[:a_ids] || []
|
|
||||||
user = UserPresenter.new(current_user, a_ids).to_json
|
|
||||||
content_tag(:script) do
|
|
||||||
<<-JS.html_safe
|
|
||||||
window.current_user_attributes = #{j user}
|
|
||||||
JS
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_user_atom_tag
|
def current_user_atom_tag
|
||||||
return #temp hax
|
return #temp hax
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
= load_javascript_locales
|
= load_javascript_locales
|
||||||
|
|
||||||
= set_asset_host
|
= set_asset_host
|
||||||
= set_current_user_in_javascript
|
|
||||||
= translation_missing_warnings
|
= translation_missing_warnings
|
||||||
= current_user_atom_tag
|
= current_user_atom_tag
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe LayoutHelper do
|
describe LayoutHelper do
|
||||||
describe "#set_current_user_in_javascript" do
|
|
||||||
it "doesn't allow xss" do
|
|
||||||
user = FactoryGirl.create :user
|
|
||||||
profile = user.profile
|
|
||||||
profile.update_attribute(:first_name, "</script><script>alert(0);</script>");
|
|
||||||
stub!(:user_signed_in?).and_return true
|
|
||||||
stub!(:current_user).and_return user
|
|
||||||
set_current_user_in_javascript.should_not be_empty
|
|
||||||
set_current_user_in_javascript.should_not include(profile.first_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#page_title" do
|
describe "#page_title" do
|
||||||
context "passed blank text" do
|
context "passed blank text" do
|
||||||
it "returns Diaspora*" do
|
it "returns Diaspora*" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue