Merge branch 'profiles' of github.com:diaspora/diaspora into profiles
This commit is contained in:
commit
dc0b5db0ac
25 changed files with 108 additions and 52 deletions
|
|
@ -5,7 +5,7 @@
|
|||
require File.join(Rails.root, "lib", 'stream', "person")
|
||||
|
||||
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]
|
||||
|
||||
respond_to :html, :except => [:tag_index]
|
||||
|
|
@ -108,6 +108,12 @@ class PeopleController < ApplicationController
|
|||
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
|
||||
if params[:diaspora_handle]
|
||||
Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true)
|
||||
|
|
|
|||
|
|
@ -35,12 +35,11 @@ module LayoutHelper
|
|||
end
|
||||
|
||||
def set_current_user_in_javascript
|
||||
return unless current_user
|
||||
current_user_presenter = UserPresenter.new(current_user)
|
||||
|
||||
return unless user_signed_in?
|
||||
user = UserPresenter.new(current_user).to_json
|
||||
content_tag(:script) do
|
||||
<<-JS.html_safe
|
||||
app.user(#{current_user_presenter.to_json});
|
||||
window.current_user_attributes = #{user}
|
||||
JS
|
||||
end
|
||||
end
|
||||
|
|
@ -92,4 +91,5 @@ module LayoutHelper
|
|||
end
|
||||
end.join(' ').html_safe
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,6 +76,13 @@ class Post < ActiveRecord::Base
|
|||
where("posts.created_at < ?", post.created_at).first
|
||||
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
|
||||
self.class.name
|
||||
end
|
||||
|
|
|
|||
|
|
@ -75,6 +75,13 @@ class PostPresenter
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def template_name
|
||||
@template_name ||= TemplatePicker.new(post).template_name
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def next_post
|
||||
post_base.next(post)
|
||||
end
|
||||
|
|
@ -83,12 +90,6 @@ class PostPresenter
|
|||
post_base.previous(post)
|
||||
end
|
||||
|
||||
def template_name
|
||||
@template_name ||= TemplatePicker.new(post).template_name
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def as_api(collection)
|
||||
collection.includes(:author => :profile).all.map do |element|
|
||||
element.as_api_response(:backbone)
|
||||
|
|
@ -96,11 +97,7 @@ class PostPresenter
|
|||
end
|
||||
|
||||
def post_base
|
||||
if current_user
|
||||
current_user.posts_from(self.post.author)
|
||||
else
|
||||
self.post.author.posts.all_public
|
||||
end
|
||||
Post.visible_from_author(self.post.author, current_user)
|
||||
end
|
||||
|
||||
def person
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
= render 'layouts/header'
|
||||
|
||||
.container
|
||||
- if @aspsect == :getting_started || @page == :logged_out
|
||||
- if @aspect == :getting_started || @page == :logged_out
|
||||
= yield
|
||||
- else
|
||||
.span-24.last
|
||||
|
|
|
|||
|
|
@ -30,12 +30,14 @@
|
|||
<![endif]-->
|
||||
|
||||
= jquery_include_tag
|
||||
|
||||
= set_current_user_in_javascript
|
||||
|
||||
- unless @landing_page
|
||||
= include_javascripts :main, :templates
|
||||
= load_javascript_locales
|
||||
|
||||
= set_asset_host
|
||||
= set_current_user_in_javascript
|
||||
= translation_missing_warnings
|
||||
= current_user_atom_tag
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
= person.name
|
||||
%span.diaspora_handle
|
||||
= person.diaspora_handle
|
||||
= link_to t('people.last_post'), last_post_person_path(person.to_param)
|
||||
|
||||
.description
|
||||
- if !person.profile.tag_string.blank? && user_signed_in?
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ module Diaspora
|
|||
|
||||
# Add additional load paths for your own custom dirs
|
||||
#config.autoload_paths += %W(#{config.root}/lib)
|
||||
config.autoload_paths += %W(#{config.root}/lib)
|
||||
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters)
|
||||
#OMG HAX PLZ FIX MAKE ALL LIB AUTOLOAD KTHNX
|
||||
config.autoload_paths += %W(#{config.root}/lib/*)
|
||||
config.autoload_paths += %W(#{config.root}/lib/*/*)
|
||||
config.autoload_paths += %W(#{config.root}/lib/*/*/*)
|
||||
|
|
|
|||
|
|
@ -575,6 +575,7 @@ en:
|
|||
add_contact_small:
|
||||
add_contact_from_tag: "add contact from tag"
|
||||
|
||||
last_post: "Last Post"
|
||||
photos:
|
||||
show:
|
||||
delete_photo: "Delete Photo"
|
||||
|
|
|
|||
|
|
@ -129,6 +129,11 @@ Diaspora::Application.routes.draw do
|
|||
resources :photos
|
||||
get :contacts
|
||||
get "aspect_membership_button" => :aspect_membership_dropdown, :as => "aspect_membership_button"
|
||||
|
||||
member do
|
||||
get :last_post
|
||||
end
|
||||
|
||||
collection do
|
||||
post 'by_handle' => :retrieve_remote, :as => 'person_by_handle'
|
||||
get :tag_index
|
||||
|
|
@ -136,6 +141,8 @@ Diaspora::Application.routes.draw do
|
|||
end
|
||||
get '/u/:username' => 'people#show', :as => 'user_profile'
|
||||
get '/u/:username/profile_photo' => 'users#user_photo'
|
||||
|
||||
|
||||
# Federation
|
||||
|
||||
controller :publics do
|
||||
|
|
|
|||
|
|
@ -6,12 +6,18 @@ Feature: Browsing Diaspora as a logged out user
|
|||
|
||||
Background:
|
||||
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
|
||||
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
|
||||
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() {
|
||||
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;
|
||||
$("header").prepend(app.header.el);
|
||||
app.header.render();
|
||||
}
|
||||
|
||||
|
||||
Backbone.history.start({pushState: true});
|
||||
|
||||
// there's probably a better way to do this...
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
app.models.User = Backbone.Model.extend({
|
||||
toggleNsfwState : function() {
|
||||
if(!app.currentUser.authenticated()){ return false }
|
||||
this.set({showNsfw : !this.get("showNsfw")});
|
||||
this.trigger("nsfwChanged");
|
||||
},
|
||||
|
||||
authenticated : function() {
|
||||
return !!this.id;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ app.pages.PostViewer = app.views.Base.extend({
|
|||
"#header-container" : "authorView"
|
||||
},
|
||||
|
||||
initialize : function() {
|
||||
this.initViews();
|
||||
initialize : function(options) {
|
||||
this.model = new app.models.Post({ id : options.id });
|
||||
this.model.fetch().success(_.bind(this.initViews, this));
|
||||
|
||||
this.prepIdleHooks();
|
||||
|
||||
$(document).bind("keypress", _.bind(this.commentAnywhere, this))
|
||||
|
|
@ -28,6 +30,8 @@ app.pages.PostViewer = app.views.Base.extend({
|
|||
templateName : "post-viewer/content/" + this.model.get("templateName"),
|
||||
attributes : {"data-template" : this.model.get("templateName")}
|
||||
});
|
||||
|
||||
this.render();
|
||||
},
|
||||
|
||||
prepIdleHooks : function () {
|
||||
|
|
|
|||
|
|
@ -39,14 +39,9 @@ app.Router = Backbone.Router.extend({
|
|||
},
|
||||
|
||||
singlePost : function(id) {
|
||||
new app.models.Post({id : id}).fetch({success : function(resp){
|
||||
|
||||
var page = new app.pages.PostViewer({
|
||||
model : new app.models.Post(resp)
|
||||
}).render();
|
||||
|
||||
var page = new app.pages.PostViewer({ id: id }).render();
|
||||
$("#container").html(page.el);
|
||||
}})
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ app.views.Base = Backbone.View.extend({
|
|||
|
||||
defaultPresenter : function(){
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -16,15 +16,14 @@ app.views.Comment = app.views.Content.extend({
|
|||
},
|
||||
|
||||
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() {
|
||||
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() {
|
||||
if(!app.user()){ return false }
|
||||
return this.ownComment() || this.postOwner()
|
||||
return app.currentUser.authenticated() && (this.ownComment() || this.postOwner())
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ app.views.Feedback = app.views.Base.extend({
|
|||
var rootExists = (isReshare ? this.model.get("root") : true)
|
||||
|
||||
var publicPost = this.model.get("public");
|
||||
var userIsNotAuthor = this.model.get("author").diaspora_id != app.user().get("diaspora_id");
|
||||
var userIsNotRootAuthor = rootExists && (isReshare ? this.model.get("root").author.diaspora_id != app.user().get("diaspora_id") : true)
|
||||
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.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() {
|
||||
this.initViews();
|
||||
|
||||
this.feedbackView.bind("invokePane", this.invokePane, this)
|
||||
this.feedbackView.bind("hidePane", this.hidePane, this)
|
||||
this.feedbackView && this.feedbackView.bind("invokePane", this.invokePane, this)
|
||||
this.feedbackView && this.feedbackView.bind("hidePane", this.hidePane, this)
|
||||
},
|
||||
|
||||
initViews : function() {
|
||||
this.reactionsView = new app.views.PostViewerReactions({ model : this.model })
|
||||
|
||||
/* subviews that require user */
|
||||
if(window.app.user()) {
|
||||
if(app.currentUser.authenticated()) {
|
||||
this.feedbackView = new app.views.PostViewerFeedback({ 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(){
|
||||
if(!window.app.user()) { return null }
|
||||
if(!app.currentUser.authenticated()) { return null }
|
||||
return new app.views.Feedback({model : this.model});
|
||||
},
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
},
|
||||
|
||||
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){
|
||||
|
|
@ -71,7 +71,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
|
||||
toggleNsfwState: function(evt){
|
||||
if(evt){ evt.preventDefault(); }
|
||||
app.user().toggleNsfwState();
|
||||
app.currentUser.toggleNsfwState();
|
||||
},
|
||||
|
||||
blockUser: function(evt){
|
||||
|
|
@ -118,7 +118,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
},
|
||||
|
||||
authorIsNotCurrentUser : function() {
|
||||
return this.model.get("author").id != (!!app.user() && app.user().id)
|
||||
return this.model.get("author").id != app.user().id
|
||||
},
|
||||
|
||||
isOnShowPage : function() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ describe("app", function() {
|
|||
it("sets the user if given one and returns the current user", function() {
|
||||
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"});
|
||||
|
||||
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(){
|
||||
beforeEach(function(){
|
||||
this.view = new app.views.CommentStream({model : factory.post()})
|
||||
loginAs({})
|
||||
})
|
||||
|
||||
describe("postRenderTemplate", function(){
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ describe("app.views.Feedback", function(){
|
|||
|
||||
context("when the current user owns the post", function(){
|
||||
beforeEach(function(){
|
||||
this.post.attributes.author = window.current_user;
|
||||
this.post.attributes.author = app.currentUser;
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ window.stubView = function stubView(text){
|
|||
}
|
||||
|
||||
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(){
|
||||
this.app._user = undefined
|
||||
return window.current_user = app.user()
|
||||
return app.currentUser = new app.models.User()
|
||||
}
|
||||
|
||||
spec.clearLiveEventBindings = function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue