Merge branch 'cubbies-connection'
This commit is contained in:
commit
5fdc0fb8d8
15 changed files with 191 additions and 14 deletions
26
app/controllers/activity_streams/photos_controller.rb
Normal file
26
app/controllers/activity_streams/photos_controller.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
class ActivityStreams::PhotosController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
before_filter :redirect_unless_admin
|
||||||
|
skip_before_filter :verify_authenticity_token
|
||||||
|
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def create
|
||||||
|
@photo = ActivityStreams::Photo.from_activity(params[:activity])
|
||||||
|
@photo.author = current_user.person
|
||||||
|
@photo.public = true
|
||||||
|
|
||||||
|
if @photo.save
|
||||||
|
Rails.logger.info("event=create type=activitystreams_photo")
|
||||||
|
|
||||||
|
current_user.add_to_streams(@photo, current_user.aspects)
|
||||||
|
current_user.dispatch_post(@photo, :url => post_url(@photo))
|
||||||
|
|
||||||
|
render :nothing => true, :status => 201
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -31,7 +31,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
@aspect_ids = @aspects.map { |a| a.id }
|
@aspect_ids = @aspects.map { |a| a.id }
|
||||||
posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
||||||
:type => 'StatusMessage',
|
:type => ['StatusMessage','ActivityStreams::Photo'],
|
||||||
:order => session[:sort_order] + ' DESC',
|
:order => session[:sort_order] + ' DESC',
|
||||||
:max_time => params[:max_time].to_i
|
:max_time => params[:max_time].to_i
|
||||||
).includes(:comments, :mentions, :likes, :dislikes)
|
).includes(:comments, :mentions, :likes, :dislikes)
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,10 @@ class PeopleController < ApplicationController
|
||||||
else
|
else
|
||||||
@commenting_disabled = false
|
@commenting_disabled = false
|
||||||
end
|
end
|
||||||
@posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time))
|
@posts = current_user.posts_from(@person).where(:type => ["StatusMessage", "ActivityStreams::Photo"]).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time))
|
||||||
else
|
else
|
||||||
@commenting_disabled = true
|
@commenting_disabled = true
|
||||||
@posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC')
|
@posts = @person.posts.where(:type => ["StatusMessage", "ActivityStreams::Photo"], :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC')
|
||||||
end
|
end
|
||||||
|
|
||||||
@posts = PostsFake.new(@posts)
|
@posts = PostsFake.new(@posts)
|
||||||
|
|
|
||||||
|
|
@ -141,4 +141,14 @@ class UsersController < ApplicationController
|
||||||
tar_path = PhotoMover::move_photos(current_user)
|
tar_path = PhotoMover::move_photos(current_user)
|
||||||
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_filter :redirect_unless_admin, :only => :generate_new_token
|
||||||
|
def generate_new_token
|
||||||
|
if current_user.reset_authentication_token!
|
||||||
|
@token = current_user.authentication_token
|
||||||
|
else
|
||||||
|
@token = "No token created"
|
||||||
|
end
|
||||||
|
render :text => @token
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
38
app/models/activity_streams/photo.rb
Normal file
38
app/models/activity_streams/photo.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
class ActivityStreams::Photo < Post
|
||||||
|
include Diaspora::Socketable
|
||||||
|
|
||||||
|
validates_presence_of :image_url,
|
||||||
|
:object_url,
|
||||||
|
:provider_display_name,
|
||||||
|
:actor_url
|
||||||
|
|
||||||
|
def socket_to_user(user_or_id, opts={}) #adds aspect_ids to opts if they are not there
|
||||||
|
unless opts[:aspect_ids]
|
||||||
|
user_id = user_or_id.instance_of?(Fixnum) ? user_or_id : user_or_id.id
|
||||||
|
aspect_ids = AspectMembership.connection.execute(
|
||||||
|
AspectMembership.joins(:contact).where(:contacts => {:user_id => user_id, :person_id => self.author_id}).select('aspect_memberships.aspect_id').to_sql
|
||||||
|
).map{|r| r.first}
|
||||||
|
opts.merge!(:aspect_ids => aspect_ids)
|
||||||
|
end
|
||||||
|
super(user_or_id, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.from_activity(json)
|
||||||
|
self.new(
|
||||||
|
:image_url => json["object"]["image"]["url"],
|
||||||
|
:image_height => json["object"]["image"]["height"],
|
||||||
|
:image_width => json["object"]["image"]["width"],
|
||||||
|
:object_url => json["object"]["url"],
|
||||||
|
|
||||||
|
:provider_display_name => json["provider"]["displayName"],
|
||||||
|
:actor_url => json["actor"]["url"]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def activity_streams?; true; end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
devise :invitable, :database_authenticatable, :registerable,
|
devise :invitable, :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable,
|
:recoverable, :rememberable, :trackable, :validatable,
|
||||||
:timeoutable
|
:timeoutable, :token_authenticatable
|
||||||
|
|
||||||
before_validation :strip_and_downcase_username
|
before_validation :strip_and_downcase_username
|
||||||
before_validation :set_current_language, :on => :create
|
before_validation :set_current_language, :on => :create
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,11 @@
|
||||||
.from
|
.from
|
||||||
= person_link(post.author, :class => 'author')
|
= person_link(post.author, :class => 'author')
|
||||||
%time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i}
|
%time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i}
|
||||||
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
|
||||||
|
- if post.respond_to?(:activity_streams?)
|
||||||
|
= image_tag post.image_url
|
||||||
|
- else
|
||||||
|
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
||||||
|
|
||||||
.info
|
.info
|
||||||
- if post.public?
|
- if post.public?
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@
|
||||||
.from
|
.from
|
||||||
= person_link(post.author)
|
= person_link(post.author)
|
||||||
|
|
||||||
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
- if post.respond_to?(:activity_streams?)
|
||||||
|
= image_tag post.image_url
|
||||||
|
- else
|
||||||
|
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
||||||
|
|
||||||
.info
|
.info
|
||||||
%span.time{:integer => post.created_at.to_i}
|
%span.time{:integer => post.created_at.to_i}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ Devise.setup do |config|
|
||||||
|
|
||||||
# ==> Configuration for :token_authenticatable
|
# ==> Configuration for :token_authenticatable
|
||||||
# Defines name of the authentication token params key
|
# Defines name of the authentication token params key
|
||||||
# config.token_authentication_key = :auth_token
|
config.token_authentication_key = :auth_token
|
||||||
|
|
||||||
# ==> Scopes configuration
|
# ==> Scopes configuration
|
||||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,16 @@ Diaspora::Application.routes.draw do
|
||||||
:invitations => "invitations"} do
|
:invitations => "invitations"} do
|
||||||
get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend'
|
get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# generating a new user token (for devise)
|
||||||
|
match 'users/generate_new_token' => 'users#generate_new_token'
|
||||||
|
|
||||||
|
# ActivityStreams routes
|
||||||
|
scope "/activity_streams", :module => "activity_streams" do
|
||||||
|
resources :photos, :controller => "photos", :only => :create, :as => "as_photos"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
get 'login' => redirect('/users/sign_in')
|
get 'login' => redirect('/users/sign_in')
|
||||||
|
|
||||||
scope 'admins', :controller => :admins do
|
scope 'admins', :controller => :admins do
|
||||||
|
|
|
||||||
11
db/migrate/20110518184453_add_token_auth_to_user.rb
Normal file
11
db/migrate/20110518184453_add_token_auth_to_user.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class AddTokenAuthToUser < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column(:users, :authentication_token, :string, :limit => 30)
|
||||||
|
add_index(:users, :authentication_token, :unique => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_index(:users, :column => :authentication_token)
|
||||||
|
remove_column(:users, :authentication_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
class AddColumnForActivityStreamsPhoto < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column(:posts, :object_url, :string)
|
||||||
|
add_column(:posts, :image_url, :string)
|
||||||
|
add_column(:posts, :image_height, :integer)
|
||||||
|
add_column(:posts, :image_width, :integer)
|
||||||
|
|
||||||
|
add_column(:posts, :provider_display_name, :string)
|
||||||
|
add_column(:posts, :actor_url, :string)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column(:posts, :actor_url)
|
||||||
|
remove_column(:posts, :provider_display_name)
|
||||||
|
|
||||||
|
remove_column(:posts, :image_width)
|
||||||
|
remove_column(:posts, :image_height)
|
||||||
|
remove_column(:posts, :image_url)
|
||||||
|
remove_column(:posts, :object_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
20
db/schema.rb
20
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110518010050) do
|
ActiveRecord::Schema.define(:version => 20110518222303) do
|
||||||
|
|
||||||
create_table "aspect_memberships", :force => true do |t|
|
create_table "aspect_memberships", :force => true do |t|
|
||||||
t.integer "aspect_id", :null => false
|
t.integer "aspect_id", :null => false
|
||||||
|
|
@ -225,12 +225,12 @@ ActiveRecord::Schema.define(:version => 20110518010050) do
|
||||||
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
|
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
|
||||||
|
|
||||||
create_table "posts", :force => true do |t|
|
create_table "posts", :force => true do |t|
|
||||||
t.integer "author_id", :null => false
|
t.integer "author_id", :null => false
|
||||||
t.boolean "public", :default => false, :null => false
|
t.boolean "public", :default => false, :null => false
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
t.string "guid", :null => false
|
t.string "guid", :null => false
|
||||||
t.boolean "pending", :default => false, :null => false
|
t.boolean "pending", :default => false, :null => false
|
||||||
t.string "type", :limit => 40, :null => false
|
t.string "type", :limit => 40, :null => false
|
||||||
t.text "text"
|
t.text "text"
|
||||||
t.integer "status_message_id"
|
t.integer "status_message_id"
|
||||||
t.text "remote_photo_path"
|
t.text "remote_photo_path"
|
||||||
|
|
@ -242,6 +242,12 @@ ActiveRecord::Schema.define(:version => 20110518010050) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
t.string "mongo_id"
|
||||||
t.string "unprocessed_image"
|
t.string "unprocessed_image"
|
||||||
|
t.string "object_url"
|
||||||
|
t.string "image_url"
|
||||||
|
t.integer "image_height"
|
||||||
|
t.integer "image_width"
|
||||||
|
t.string "provider_display_name"
|
||||||
|
t.string "actor_url"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
|
add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
|
||||||
|
|
@ -361,8 +367,10 @@ ActiveRecord::Schema.define(:version => 20110518010050) do
|
||||||
t.integer "invitation_limit"
|
t.integer "invitation_limit"
|
||||||
t.integer "invited_by_id"
|
t.integer "invited_by_id"
|
||||||
t.string "invited_by_type"
|
t.string "invited_by_type"
|
||||||
|
t.string "authentication_token", :limit => 30
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
|
||||||
add_index "users", ["email"], :name => "index_users_on_email"
|
add_index "users", ["email"], :name => "index_users_on_email"
|
||||||
add_index "users", ["invitation_service", "invitation_identifier"], :name => "index_users_on_invitation_service_and_invitation_identifier", :unique => true
|
add_index "users", ["invitation_service", "invitation_identifier"], :name => "index_users_on_invitation_service_and_invitation_identifier", :unique => true
|
||||||
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
||||||
|
|
|
||||||
|
|
@ -138,4 +138,22 @@ describe UsersController do
|
||||||
assigns[:email_prefs]['mentioned'].should be_false
|
assigns[:email_prefs]['mentioned'].should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
describe '#generate_new_token' do
|
||||||
|
before do
|
||||||
|
AppConfig[:admins] = [@user.username]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'generates a new token for the current user' do
|
||||||
|
lambda {
|
||||||
|
get 'generate_new_token'
|
||||||
|
}.should change{ @user.reload.authentication_token }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays a token' do
|
||||||
|
get 'generate_new_token'
|
||||||
|
response.body.should include(@user.reload.authentication_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
||||||
28
spec/models/activity_streams/photo_spec.rb
Normal file
28
spec/models/activity_streams/photo_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# 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 ActivityStreams::Photo do
|
||||||
|
describe '.from_activity' do
|
||||||
|
before do
|
||||||
|
@json = JSON.parse <<JSON
|
||||||
|
{"activity":{"actor":{"url":"http://cubbi.es/daniel","displayName":"daniel","objectType":"person"},"published":"2011-05-19T18:12:23Z","verb":"save","object":{"objectType":"photo","url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","image":{"url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","width":637,"height":469}},"provider":{"url":"http://cubbi.es/","displayName":"Cubbi.es"}}}
|
||||||
|
JSON
|
||||||
|
@json = @json["activity"]
|
||||||
|
end
|
||||||
|
it 'marshals into an object' do
|
||||||
|
photo = ActivityStreams::Photo.from_activity(@json)
|
||||||
|
|
||||||
|
photo.image_url.should == @json["object"]["image"]["url"]
|
||||||
|
photo.image_height.should == @json["object"]["image"]["height"]
|
||||||
|
photo.image_width.should == @json["object"]["image"]["width"]
|
||||||
|
photo.object_url.should == @json["object"]["url"]
|
||||||
|
|
||||||
|
photo.provider_display_name.should == @json["provider"]["displayName"]
|
||||||
|
photo.actor_url.should == @json["actor"]["url"]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue