Merge branch 'master' of git://github.com/diaspora/diaspora
This commit is contained in:
commit
dc8e9565e9
18 changed files with 135 additions and 107 deletions
|
|
@ -19,7 +19,7 @@ class AspectsController < ApplicationController
|
|||
@selected_contacts.uniq!
|
||||
|
||||
# redirect to signup
|
||||
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile?
|
||||
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile? && !request.format.js?
|
||||
redirect_to getting_started_path
|
||||
else
|
||||
if params[:sort_order].blank? and session[:sort_order].blank?
|
||||
|
|
|
|||
|
|
@ -8,29 +8,6 @@ class PostsController < ApplicationController
|
|||
skip_before_filter :which_action_and_user
|
||||
skip_before_filter :set_grammatical_gender
|
||||
|
||||
def index
|
||||
if current_user
|
||||
@posts = StatusMessage.joins(:aspects).where(:pending => false
|
||||
).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true))
|
||||
).select('DISTINCT `posts`.*')
|
||||
else
|
||||
@posts = StatusMessage.where(:public => true, :pending => false)
|
||||
end
|
||||
|
||||
params[:tag] ||= 'partytimeexcellent'
|
||||
|
||||
@posts = @posts.tagged_with(params[:tag])
|
||||
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
|
||||
|
||||
profiles = Profile.tagged_with(params[:tag]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
||||
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
|
||||
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
@commenting_disabled = true
|
||||
@pod_url = AppConfig[:pod_uri].host
|
||||
end
|
||||
|
||||
def show
|
||||
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first
|
||||
|
||||
|
|
|
|||
30
app/controllers/tags_controller.rb
Normal file
30
app/controllers/tags_controller.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class TagsController < ApplicationController
|
||||
skip_before_filter :count_requests
|
||||
skip_before_filter :set_invites
|
||||
skip_before_filter :which_action_and_user
|
||||
skip_before_filter :set_grammatical_gender
|
||||
|
||||
def show
|
||||
if current_user
|
||||
@posts = StatusMessage.joins(:aspects).where(:pending => false
|
||||
).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true))
|
||||
).select('DISTINCT `posts`.*')
|
||||
else
|
||||
@posts = StatusMessage.where(:public => true, :pending => false)
|
||||
end
|
||||
|
||||
@posts = @posts.tagged_with(params[:name])
|
||||
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
|
||||
|
||||
profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
||||
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
|
||||
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
@commenting_disabled = true
|
||||
end
|
||||
end
|
||||
|
|
@ -17,8 +17,12 @@ module Job
|
|||
def self.create_visibilities(post, recipient_user_ids)
|
||||
aspects = Aspect.where(:user_id => recipient_user_ids).joins(:contacts).where(:contacts => {:person_id => post.author_id}).select('aspects.id, aspects.user_id')
|
||||
aspects.each do |aspect|
|
||||
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
|
||||
post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user
|
||||
begin
|
||||
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
|
||||
rescue ActiveRecord::RecordNotUnique => e
|
||||
Rails.logger.info(:event => :unexpected_pv, :aspect_id => aspect.id, :post_id => post.id)
|
||||
#The post was already visible to that aspect
|
||||
end
|
||||
end
|
||||
end
|
||||
def self.socket_to_users(post, recipient_user_ids)
|
||||
|
|
|
|||
|
|
@ -33,12 +33,16 @@ class Photo < Post
|
|||
photo = super(params)
|
||||
image_file = params.delete(:user_file)
|
||||
photo.random_string = gen_random_string(10)
|
||||
|
||||
photo.processed = false
|
||||
photo.image.store! image_file
|
||||
photo.update_photo_remote_path
|
||||
photo
|
||||
end
|
||||
|
||||
def not_processed?
|
||||
!self.processed
|
||||
end
|
||||
|
||||
def update_photo_remote_path
|
||||
unless self.image.url.match(/^https?:\/\//)
|
||||
pod_url = AppConfig[:pod_url].dup
|
||||
|
|
@ -66,7 +70,9 @@ class Photo < Post
|
|||
end
|
||||
|
||||
def url(name = nil)
|
||||
if remote_photo_path
|
||||
if self.not_processed? || (!self.image.path.blank? && self.image.path.include?('.gif'))
|
||||
image.url
|
||||
elsif remote_photo_path
|
||||
name = name.to_s + '_' if name
|
||||
remote_photo_path + name.to_s + remote_photo_name
|
||||
else
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class ImageUploader < CarrierWave::Uploader::Base
|
|||
end
|
||||
|
||||
self.recreate_versions!
|
||||
self.model.processed = true
|
||||
self.model.update_photo_remote_path
|
||||
self.model.save
|
||||
else
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
|
||||
- content_for :page_title do
|
||||
- if params[:tag]
|
||||
= "##{params[:tag]}"
|
||||
- if params[:name]
|
||||
= "##{params[:name]}"
|
||||
|
||||
- else
|
||||
= t('.whatup', :pod => @pod_url)
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
.span-24.last
|
||||
%h1.tag
|
||||
= "##{params[:tag]}"
|
||||
= "##{params[:name]}"
|
||||
|
||||
.span-15
|
||||
#main_stream.stream
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
%a.paginate
|
||||
= t("more")
|
||||
- else
|
||||
= t('.nobody_talking', :tag => "##{params[:tag]}")
|
||||
= t('.nobody_talking', :tag => "##{params[:name]}")
|
||||
= will_paginate @posts
|
||||
|
||||
.prepend-2.span-7.last
|
||||
|
|
@ -405,8 +405,9 @@ en:
|
|||
|
||||
posts:
|
||||
doesnt_exist: "that post does not exist!"
|
||||
index:
|
||||
whatup: "What's happening on %{pod}"
|
||||
|
||||
tags:
|
||||
show:
|
||||
posts_tagged_with: "Posts tagged with #%{tag}"
|
||||
nobody_talking: "Nobody is talking about %{tag} yet."
|
||||
people_tagged_with: "People tagged with %{tag}"
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
Diaspora::Application.routes.draw do
|
||||
|
||||
|
||||
resources :status_messages, :only => [:new, :create, :destroy, :show]
|
||||
resources :comments, :only => [:create]
|
||||
resources :requests, :only => [:destroy, :create]
|
||||
|
||||
match 'tags/:name' => 'tags#show'
|
||||
resources :tags, :only => [:show]
|
||||
|
||||
resource :profile
|
||||
match 'services/inviter/:provider' => 'services#inviter', :as => 'service_inviter'
|
||||
match 'services/finder/:provider' => 'services#finder', :as => 'friend_finder'
|
||||
|
|
@ -19,7 +20,7 @@ Diaspora::Application.routes.draw do
|
|||
|
||||
match 'notifications/read_all' => 'notifications#read_all'
|
||||
resources :notifications, :only => [:index, :update]
|
||||
resources :posts, :only => [:show, :index], :path => '/p/'
|
||||
resources :posts, :only => [:show], :path => '/p/'
|
||||
|
||||
resources :contacts
|
||||
resources :aspect_memberships, :only => [:destroy, :create]
|
||||
|
|
|
|||
9
db/migrate/20110319005509_add_processed_to_post.rb
Normal file
9
db/migrate/20110319005509_add_processed_to_post.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class AddProcessedToPost < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column(:posts, :processed, :boolean, :default => true)
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column(:posts, :processed)
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110318012008) do
|
||||
ActiveRecord::Schema.define(:version => 20110319005509) do
|
||||
|
||||
create_table "aspect_memberships", :force => true do |t|
|
||||
t.integer "aspect_id", :null => false
|
||||
|
|
@ -210,6 +210,7 @@ ActiveRecord::Schema.define(:version => 20110318012008) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "mongo_id"
|
||||
t.boolean "processed", :default => true
|
||||
end
|
||||
|
||||
add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ module Diaspora
|
|||
return text if opts[:plain_text]
|
||||
regex = /(^|\s)#(\w+)/
|
||||
form_message = text.gsub(regex) do |matched_string|
|
||||
"#{$~[1]}<a href=\"/p?tag=#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
|
||||
"#{$~[1]}<a href=\"/tags/#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
|
||||
end
|
||||
form_message.html_safe
|
||||
end
|
||||
|
|
|
|||
|
|
@ -111,8 +111,25 @@ describe AspectsController do
|
|||
assigns(:posts).should == @posts.reverse
|
||||
end
|
||||
end
|
||||
context 'with getting_started = true' do
|
||||
before do
|
||||
@alice.getting_started = true
|
||||
@alice.save
|
||||
end
|
||||
it 'redirects to getting_started' do
|
||||
get :index
|
||||
response.should redirect_to getting_started_path
|
||||
end
|
||||
it 'does not redirect mobile users to getting_started' do
|
||||
get :index, :format => :mobile
|
||||
response.should_not be_redirect
|
||||
end
|
||||
it 'does not redirect ajax to getting_started' do
|
||||
get :index, :format => :js
|
||||
response.should_not be_redirect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'performance', :performance => true do
|
||||
before do
|
||||
require 'benchmark'
|
||||
|
|
|
|||
|
|
@ -10,70 +10,6 @@ describe PostsController do
|
|||
before do
|
||||
@user = alice
|
||||
end
|
||||
describe '#index' do
|
||||
context 'signed in' do
|
||||
before do
|
||||
sign_in :user, @user
|
||||
end
|
||||
it 'works' do
|
||||
get :index
|
||||
response.status.should == 200
|
||||
end
|
||||
it "shows the signed in user's posts" do
|
||||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
it "shows any posts that the user can see" do
|
||||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << bob.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
end
|
||||
it 'restricts the posts by tag' do
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||
end
|
||||
2.times do
|
||||
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
||||
end
|
||||
|
||||
get :index, :tag => 'what'
|
||||
assigns[:posts].should =~ posts
|
||||
|
||||
end
|
||||
it 'shows the most recent public posts' do
|
||||
pending
|
||||
posts = []
|
||||
3.times do
|
||||
posts << @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
it' shows only local posts' do
|
||||
pending
|
||||
3.times do
|
||||
@user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
@user.person.update_attributes(:owner_id => nil)
|
||||
get :index
|
||||
assigns[:posts].should == []
|
||||
end
|
||||
end
|
||||
describe '#show' do
|
||||
it 'shows a public post' do
|
||||
status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
|
|
|
|||
37
spec/controllers/tags_controller_spec.rb
Normal file
37
spec/controllers/tags_controller_spec.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
end
|
||||
describe '#show' do
|
||||
context 'signed in' do
|
||||
before do
|
||||
sign_in :user, @user
|
||||
end
|
||||
it 'works' do
|
||||
get :show, :name => 'testing'
|
||||
response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
it 'restricts the posts by tag' do
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||
end
|
||||
2.times do
|
||||
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
||||
end
|
||||
|
||||
get :show, :name => 'what'
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -25,9 +25,15 @@ describe Job::ReceiveLocalBatch do
|
|||
end
|
||||
describe '.create_visibilities' do
|
||||
it 'creates a visibility for each user' do
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_false
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first.id, :post_id => @post.id).should be_false
|
||||
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_true
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first.id, :post_id => @post.id).should be_true
|
||||
end
|
||||
it 'does not raise if a visibility already exists' do
|
||||
PostVisibility.create!(:aspect_id => bob.aspects.first.id, :post_id => @post.id)
|
||||
lambda {
|
||||
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
describe '.socket_to_users' do
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ describe Photo do
|
|||
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
|
||||
|
||||
@photo = @user.build_post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||
@photo.processed = true
|
||||
@photo2 = @user.build_post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||
@photo2.processed = true
|
||||
end
|
||||
|
||||
describe "protected attributes" do
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ describe Diaspora::Taggable do
|
|||
@object.save!
|
||||
end
|
||||
it 'links the tag to /p' do
|
||||
link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag')
|
||||
link = link_to('#what', '/tags/what', :class => 'tag')
|
||||
@object.format_tags(@str).should include(link)
|
||||
end
|
||||
it 'responds to plain_text' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue