MS DC show last post and show page works unauthenticated
phasing out app.user() for app.currentUser
This commit is contained in:
parent
5154500239
commit
b28508ecbc
22 changed files with 97 additions and 41 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
require File.join(Rails.root, "lib", 'stream', "person")
|
require File.join(Rails.root, "lib", 'stream', "person")
|
||||||
|
|
||||||
class PeopleController < ApplicationController
|
class PeopleController < ApplicationController
|
||||||
before_filter :authenticate_user!, :except => [:show]
|
before_filter :authenticate_user!, :except => [:show, :last_post]
|
||||||
before_filter :redirect_if_tag_search, :only => [:index]
|
before_filter :redirect_if_tag_search, :only => [:index]
|
||||||
|
|
||||||
respond_to :html, :except => [:tag_index]
|
respond_to :html, :except => [:tag_index]
|
||||||
|
|
@ -108,6 +108,12 @@ class PeopleController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_post
|
||||||
|
@person = Person.find_from_guid_or_username(params)
|
||||||
|
last_post = Post.visible_from_author(@person, current_user).last
|
||||||
|
redirect_to post_path(last_post)
|
||||||
|
end
|
||||||
|
|
||||||
def retrieve_remote
|
def retrieve_remote
|
||||||
if params[:diaspora_handle]
|
if params[:diaspora_handle]
|
||||||
Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true)
|
Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true)
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,11 @@ module LayoutHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_current_user_in_javascript
|
def set_current_user_in_javascript
|
||||||
return unless current_user
|
return unless user_signed_in?
|
||||||
current_user_presenter = UserPresenter.new(current_user)
|
user = UserPresenter.new(current_user).to_json
|
||||||
|
|
||||||
content_tag(:script) do
|
content_tag(:script) do
|
||||||
<<-JS.html_safe
|
<<-JS.html_safe
|
||||||
app.user(#{current_user_presenter.to_json});
|
window.current_user_attributes = #{user}
|
||||||
JS
|
JS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -92,4 +91,5 @@ module LayoutHelper
|
||||||
end
|
end
|
||||||
end.join(' ').html_safe
|
end.join(' ').html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,13 @@ class Post < ActiveRecord::Base
|
||||||
where("posts.created_at < ?", post.created_at).first
|
where("posts.created_at < ?", post.created_at).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.visible_from_author(author, current_user=nil)
|
||||||
|
if current_user.present?
|
||||||
|
current_user.posts_from(author)
|
||||||
|
else
|
||||||
|
author.posts.all_public
|
||||||
|
end
|
||||||
|
end
|
||||||
def post_type
|
def post_type
|
||||||
self.class.name
|
self.class.name
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,13 @@ class PostPresenter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def template_name
|
||||||
|
@template_name ||= TemplatePicker.new(post).template_name
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
def next_post
|
def next_post
|
||||||
post_base.next(post)
|
post_base.next(post)
|
||||||
end
|
end
|
||||||
|
|
@ -83,12 +90,6 @@ class PostPresenter
|
||||||
post_base.previous(post)
|
post_base.previous(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_name
|
|
||||||
@template_name ||= TemplatePicker.new(post).template_name
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def as_api(collection)
|
def as_api(collection)
|
||||||
collection.includes(:author => :profile).all.map do |element|
|
collection.includes(:author => :profile).all.map do |element|
|
||||||
element.as_api_response(:backbone)
|
element.as_api_response(:backbone)
|
||||||
|
|
@ -96,11 +97,7 @@ class PostPresenter
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_base
|
def post_base
|
||||||
if current_user
|
Post.visible_from_author(self.post.author, current_user)
|
||||||
current_user.posts_from(self.post.author)
|
|
||||||
else
|
|
||||||
self.post.author.posts.all_public
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def person
|
def person
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
= render 'layouts/header'
|
= render 'layouts/header'
|
||||||
|
|
||||||
.container
|
.container
|
||||||
- if @aspsect == :getting_started || @page == :logged_out
|
- if @aspect == :getting_started || @page == :logged_out
|
||||||
= yield
|
= yield
|
||||||
- else
|
- else
|
||||||
.span-24.last
|
.span-24.last
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,14 @@
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
= jquery_include_tag
|
= jquery_include_tag
|
||||||
|
|
||||||
|
= set_current_user_in_javascript
|
||||||
|
|
||||||
- unless @landing_page
|
- unless @landing_page
|
||||||
= include_javascripts :main, :templates
|
= include_javascripts :main, :templates
|
||||||
= 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
= person.name
|
= person.name
|
||||||
%span.diaspora_handle
|
%span.diaspora_handle
|
||||||
= person.diaspora_handle
|
= person.diaspora_handle
|
||||||
|
= link_to t('people.last_post'), last_post_person_path(person.to_param)
|
||||||
|
|
||||||
.description
|
.description
|
||||||
- if !person.profile.tag_string.blank? && user_signed_in?
|
- if !person.profile.tag_string.blank? && user_signed_in?
|
||||||
|
|
|
||||||
|
|
@ -575,6 +575,7 @@ en:
|
||||||
add_contact_small:
|
add_contact_small:
|
||||||
add_contact_from_tag: "add contact from tag"
|
add_contact_from_tag: "add contact from tag"
|
||||||
|
|
||||||
|
last_post: "Last Post"
|
||||||
photos:
|
photos:
|
||||||
show:
|
show:
|
||||||
delete_photo: "Delete Photo"
|
delete_photo: "Delete Photo"
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,11 @@ Diaspora::Application.routes.draw do
|
||||||
resources :photos
|
resources :photos
|
||||||
get :contacts
|
get :contacts
|
||||||
get "aspect_membership_button" => :aspect_membership_dropdown, :as => "aspect_membership_button"
|
get "aspect_membership_button" => :aspect_membership_dropdown, :as => "aspect_membership_button"
|
||||||
|
|
||||||
|
member do
|
||||||
|
get :last_post
|
||||||
|
end
|
||||||
|
|
||||||
collection do
|
collection do
|
||||||
post 'by_handle' => :retrieve_remote, :as => 'person_by_handle'
|
post 'by_handle' => :retrieve_remote, :as => 'person_by_handle'
|
||||||
get :tag_index
|
get :tag_index
|
||||||
|
|
@ -136,6 +141,8 @@ Diaspora::Application.routes.draw do
|
||||||
end
|
end
|
||||||
get '/u/:username' => 'people#show', :as => 'user_profile'
|
get '/u/:username' => 'people#show', :as => 'user_profile'
|
||||||
get '/u/:username/profile_photo' => 'users#user_photo'
|
get '/u/:username/profile_photo' => 'users#user_photo'
|
||||||
|
|
||||||
|
|
||||||
# Federation
|
# Federation
|
||||||
|
|
||||||
controller :publics do
|
controller :publics do
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,18 @@ Feature: Browsing Diaspora as a logged out user
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given a user named "Bob Jones" with email "bob@bob.bob"
|
Given a user named "Bob Jones" with email "bob@bob.bob"
|
||||||
Given "bob@bob.bob" has a public post with text "public stuff"
|
And "bob@bob.bob" has a public post with text "public stuff"
|
||||||
|
And I log out
|
||||||
|
|
||||||
Scenario: Visiting a profile page
|
Scenario: Visiting a profile page
|
||||||
When I am on "bob@bob.bob"'s page
|
When I am on "bob@bob.bob"'s page
|
||||||
Then I should see "public stuff"
|
Then I should see "public stuff" within "body"
|
||||||
|
|
||||||
|
Scenario: Clicking Last Post
|
||||||
|
When I am on "bob@bob.bob"'s page
|
||||||
|
And I follow "Last Post"
|
||||||
|
Then I should see "public stuff" within "body"
|
||||||
|
|
||||||
Scenario: Visiting a post show page
|
Scenario: Visiting a post show page
|
||||||
When I view "bob@bob.bob"'s first post
|
When I view "bob@bob.bob"'s first post
|
||||||
Then I should see "public stuff"
|
Then I should see "public stuff" within "body"
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,16 @@ var app = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
app.router = new app.Router();
|
app.router = new app.Router();
|
||||||
|
|
||||||
if(this._user){
|
app.currentUser = app.user(window.current_user_attributes) || new app.models.User()
|
||||||
|
|
||||||
|
|
||||||
|
if(app.currentUser.authenticated()){
|
||||||
app.header = new app.views.Header;
|
app.header = new app.views.Header;
|
||||||
$("header").prepend(app.header.el);
|
$("header").prepend(app.header.el);
|
||||||
app.header.render();
|
app.header.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Backbone.history.start({pushState: true});
|
Backbone.history.start({pushState: true});
|
||||||
|
|
||||||
// there's probably a better way to do this...
|
// there's probably a better way to do this...
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
app.models.User = Backbone.Model.extend({
|
app.models.User = Backbone.Model.extend({
|
||||||
toggleNsfwState : function() {
|
toggleNsfwState : function() {
|
||||||
|
if(!app.currentUser.authenticated()){ return false }
|
||||||
this.set({showNsfw : !this.get("showNsfw")});
|
this.set({showNsfw : !this.get("showNsfw")});
|
||||||
this.trigger("nsfwChanged");
|
this.trigger("nsfwChanged");
|
||||||
|
},
|
||||||
|
|
||||||
|
authenticated : function() {
|
||||||
|
return !!this.id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ app.views.Base = Backbone.View.extend({
|
||||||
|
|
||||||
defaultPresenter : function(){
|
defaultPresenter : function(){
|
||||||
var modelJson = this.model ? this.model.toJSON() : {}
|
var modelJson = this.model ? this.model.toJSON() : {}
|
||||||
return _.extend(modelJson, {current_user: app.user().attributes});
|
return _.extend(modelJson, {current_user: app.currentUser.attributes});
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function() {
|
render : function() {
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,14 @@ app.views.Comment = app.views.Content.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
ownComment : function() {
|
ownComment : function() {
|
||||||
return this.model.get("author").diaspora_id == app.user().get("diaspora_id")
|
return app.currentUser.authenticated() && this.model.get("author").diaspora_id == app.currentUser.get("diaspora_id")
|
||||||
},
|
},
|
||||||
|
|
||||||
postOwner : function() {
|
postOwner : function() {
|
||||||
return this.model.get("parent").author.diaspora_id == app.user().get("diaspora_id")
|
return app.currentUser.authenticated() && this.model.get("parent").author.diaspora_id == app.currentUser.get("diaspora_id")
|
||||||
},
|
},
|
||||||
|
|
||||||
canRemove : function() {
|
canRemove : function() {
|
||||||
if(!app.user()){ return false }
|
return app.currentUser.authenticated() && (this.ownComment() || this.postOwner())
|
||||||
return this.ownComment() || this.postOwner()
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,9 @@ app.views.Feedback = app.views.Base.extend({
|
||||||
var rootExists = (isReshare ? this.model.get("root") : true)
|
var rootExists = (isReshare ? this.model.get("root") : true)
|
||||||
|
|
||||||
var publicPost = this.model.get("public");
|
var publicPost = this.model.get("public");
|
||||||
var userIsNotAuthor = this.model.get("author").diaspora_id != app.user().get("diaspora_id");
|
var userIsNotAuthor = this.model.get("author").diaspora_id != app.currentUser.get("diaspora_id");
|
||||||
var userIsNotRootAuthor = rootExists && (isReshare ? this.model.get("root").author.diaspora_id != app.user().get("diaspora_id") : true)
|
var userIsNotRootAuthor = rootExists && (isReshare ? this.model.get("root").author.diaspora_id != app.currentUser.get("diaspora_id") : true)
|
||||||
|
|
||||||
return publicPost && userIsNotAuthor && userIsNotRootAuthor;
|
return publicPost && app.currentUser.authenticated() && userIsNotAuthor && userIsNotRootAuthor;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,15 @@ app.views.PostViewerInteractions = app.views.Base.extend({
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
this.initViews();
|
this.initViews();
|
||||||
|
|
||||||
this.feedbackView.bind("invokePane", this.invokePane, this)
|
this.feedbackView && this.feedbackView.bind("invokePane", this.invokePane, this)
|
||||||
this.feedbackView.bind("hidePane", this.hidePane, this)
|
this.feedbackView && this.feedbackView.bind("hidePane", this.hidePane, this)
|
||||||
},
|
},
|
||||||
|
|
||||||
initViews : function() {
|
initViews : function() {
|
||||||
this.reactionsView = new app.views.PostViewerReactions({ model : this.model })
|
this.reactionsView = new app.views.PostViewerReactions({ model : this.model })
|
||||||
|
|
||||||
/* subviews that require user */
|
/* subviews that require user */
|
||||||
if(window.app.user()) {
|
if(app.currentUser.authenticated()) {
|
||||||
this.feedbackView = new app.views.PostViewerFeedback({ model : this.model })
|
this.feedbackView = new app.views.PostViewerFeedback({ model : this.model })
|
||||||
this.newCommentView = new app.views.PostViewerNewComment({ model : this.model })
|
this.newCommentView = new app.views.PostViewerNewComment({ model : this.model })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
feedbackView : function(){
|
feedbackView : function(){
|
||||||
if(!window.app.user()) { return null }
|
if(!app.currentUser.authenticated()) { return null }
|
||||||
return new app.views.Feedback({model : this.model});
|
return new app.views.Feedback({model : this.model});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
showPost : function() {
|
showPost : function() {
|
||||||
return (app.user() && app.user().get("showNsfw")) || !this.model.get("nsfw")
|
return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw")
|
||||||
},
|
},
|
||||||
|
|
||||||
removeNsfwShield: function(evt){
|
removeNsfwShield: function(evt){
|
||||||
|
|
@ -71,7 +71,7 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
|
|
||||||
toggleNsfwState: function(evt){
|
toggleNsfwState: function(evt){
|
||||||
if(evt){ evt.preventDefault(); }
|
if(evt){ evt.preventDefault(); }
|
||||||
app.user().toggleNsfwState();
|
app.currentUser.toggleNsfwState();
|
||||||
},
|
},
|
||||||
|
|
||||||
blockUser: function(evt){
|
blockUser: function(evt){
|
||||||
|
|
@ -118,7 +118,7 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
authorIsNotCurrentUser : function() {
|
authorIsNotCurrentUser : function() {
|
||||||
return this.model.get("author").id != (!!app.user() && app.user().id)
|
return this.model.get("author").id != app.user().id
|
||||||
},
|
},
|
||||||
|
|
||||||
isOnShowPage : function() {
|
isOnShowPage : function() {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ describe("app", function() {
|
||||||
it("sets the user if given one and returns the current user", function() {
|
it("sets the user if given one and returns the current user", function() {
|
||||||
expect(app.user()).toBeFalsy()
|
expect(app.user()).toBeFalsy()
|
||||||
|
|
||||||
|
it("sets the user if given one and returns the current user", function() {
|
||||||
|
expect(app.user().authenticated()).toBeFalsy()
|
||||||
app.user({name: "alice"});
|
app.user({name: "alice"});
|
||||||
|
|
||||||
expect(app.user().get("name")).toEqual("alice");
|
expect(app.user().get("name")).toEqual("alice");
|
||||||
|
|
|
||||||
18
spec/javascripts/app/models/user_spec.js
Normal file
18
spec/javascripts/app/models/user_spec.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
describe("app.models.User", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.user = new app.models.User({})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("authenticated", function(){
|
||||||
|
it("should be true if ID is nil", function(){
|
||||||
|
expect(this.user.authenticated()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be true if ID is set', function(){
|
||||||
|
this.user.set({id : 1})
|
||||||
|
expect(this.user.authenticated()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
describe("app.views.CommentStream", function(){
|
describe("app.views.CommentStream", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
this.view = new app.views.CommentStream({model : factory.post()})
|
this.view = new app.views.CommentStream({model : factory.post()})
|
||||||
|
loginAs({})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("postRenderTemplate", function(){
|
describe("postRenderTemplate", function(){
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ describe("app.views.Feedback", function(){
|
||||||
|
|
||||||
context("when the current user owns the post", function(){
|
context("when the current user owns the post", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
this.post.attributes.author = window.current_user;
|
this.post.attributes.author = app.currentUser;
|
||||||
this.view.render();
|
this.view.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,12 @@ window.stubView = function stubView(text){
|
||||||
}
|
}
|
||||||
|
|
||||||
window.loginAs = function loginAs(attrs){
|
window.loginAs = function loginAs(attrs){
|
||||||
return window.current_user = app.user(factory.userAttrs(attrs))
|
return app.currentUser = app.user(factory.userAttrs(attrs))
|
||||||
}
|
}
|
||||||
|
|
||||||
window.logout = function logout(){
|
window.logout = function logout(){
|
||||||
this.app._user = undefined
|
this.app._user = undefined
|
||||||
return window.current_user = app.user()
|
return app.currentUser = new app.models.User()
|
||||||
}
|
}
|
||||||
|
|
||||||
spec.clearLiveEventBindings = function() {
|
spec.clearLiveEventBindings = function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue