Migration to turn ActivityStreams::Photo to StatusMessage
deletes ActivityStream model and all it's references update migration with the without_protection option to disable mass assignment protection
This commit is contained in:
parent
4710144b02
commit
f6fe74aeae
16 changed files with 29 additions and 209 deletions
|
|
@ -76,10 +76,6 @@ app.views.Reshare = app.views.Content.extend({
|
|||
templateName : "reshare"
|
||||
});
|
||||
|
||||
app.views.ActivityStreams__Photo = app.views.Content.extend({
|
||||
templateName : "activity-streams-photo"
|
||||
});
|
||||
|
||||
app.views.OEmbed = app.views.Base.extend({
|
||||
templateName : "oembed",
|
||||
events : {
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class ActivityStreams::Photo < Post
|
||||
|
||||
xml_name self.name.underscore.gsub!('/', '-')
|
||||
xml_attr :image_url
|
||||
xml_attr :image_height
|
||||
xml_attr :image_width
|
||||
xml_attr :object_url
|
||||
xml_attr :actor_url
|
||||
xml_attr :objectId
|
||||
|
||||
validates_presence_of :image_url,
|
||||
:object_url,
|
||||
:provider_display_name,
|
||||
:actor_url,
|
||||
:objectId
|
||||
|
||||
# This creates a new ActivityStreams::Photo from a json hash.
|
||||
# Right now, it is only used by Cubbi.es, but there will be objects for all the AS types.
|
||||
# @param [Hash] json An {http://www.activitystrea.ms ActivityStreams} compliant (we hope!) json hash.
|
||||
# @return [ActivityStreams::Photo]
|
||||
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"],
|
||||
:objectId => json["object"]["id"],
|
||||
|
||||
:provider_display_name => json["provider"]["displayName"],
|
||||
:actor_url => json["actor"]["url"]
|
||||
)
|
||||
end
|
||||
|
||||
# A hack used in the stream_element partial to display cubbi.es posts correctly.
|
||||
# A better solution is needed.
|
||||
# @return [Boolean] true
|
||||
def activity_streams?; true; end
|
||||
|
||||
def comment_email_subject
|
||||
I18n.t("photos.comment_email_subject", :name => author.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -40,10 +40,10 @@ RailsAdmin.config do |config|
|
|||
|
||||
# ==> Included models
|
||||
# Add all excluded models here:
|
||||
config.excluded_models = [ActivityStreams::Photo, AspectMembership, AspectVisibility, ShareVisibility, ConversationVisibility, NotificationActor, Notifications::AlsoCommented, Notifications::CommentOnPost, Notifications::Liked, Notifications::Mentioned, Notifications::PrivateMessage, Notifications::RequestAccepted, Notifications::Reshared, Notifications::StartedSharing, Reshare, Services::Facebook, Services::Tumblr, Services::Twitter, UserPreference]
|
||||
config.excluded_models = [AspectMembership, AspectVisibility, ShareVisibility, ConversationVisibility, NotificationActor, Notifications::AlsoCommented, Notifications::CommentOnPost, Notifications::Liked, Notifications::Mentioned, Notifications::PrivateMessage, Notifications::RequestAccepted, Notifications::Reshared, Notifications::StartedSharing, Reshare, Services::Facebook, Services::Tumblr, Services::Twitter, UserPreference]
|
||||
|
||||
# Add models here if you want to go 'whitelist mode':
|
||||
# config.included_models = [AccountDeletion, ActivityStreams::Photo, ActsAsTaggableOn::Tag, Aspect, AspectMembership, AspectVisibility, Block, Comment, Contact, Conversation, ConversationVisibility, Invitation, InvitationCode, Like, Mention, Message, Notification, NotificationActor, Notifications::AlsoCommented, Notifications::CommentOnPost, Notifications::Liked, Notifications::Mentioned, Notifications::PrivateMessage, Notifications::RequestAccepted, Notifications::Reshared, Notifications::StartedSharing, OEmbedCache, Participation, Person, Photo, Pod, Post, Profile, Reshare, Service, ServiceUser, Services::Facebook, Services::Tumblr, Services::Twitter, ShareVisibility, StatusMessage, TagFollowing, User, UserPreference]
|
||||
# config.included_models = [AccountDeletion, ActsAsTaggableOn::Tag, Aspect, AspectMembership, AspectVisibility, Block, Comment, Contact, Conversation, ConversationVisibility, Invitation, InvitationCode, Like, Mention, Message, Notification, NotificationActor, Notifications::AlsoCommented, Notifications::CommentOnPost, Notifications::Liked, Notifications::Mentioned, Notifications::PrivateMessage, Notifications::RequestAccepted, Notifications::Reshared, Notifications::StartedSharing, OEmbedCache, Participation, Person, Photo, Pod, Post, Profile, Reshare, Service, ServiceUser, Services::Facebook, Services::Tumblr, Services::Twitter, ShareVisibility, StatusMessage, TagFollowing, User, UserPreference]
|
||||
|
||||
# Application wide tried label methods for models' instances
|
||||
# config.label_methods << :description # Default is [:name, :title]
|
||||
|
|
@ -101,57 +101,7 @@ RailsAdmin.config do |config|
|
|||
# create do; end
|
||||
# update do; end
|
||||
# end
|
||||
# config.model ActivityStreams::Photo do
|
||||
# # Found associations:
|
||||
# configure :author, :belongs_to_association
|
||||
# configure :reshares, :has_many_association
|
||||
# configure :o_embed_cache, :belongs_to_association
|
||||
# configure :likes, :has_many_association
|
||||
# configure :dislikes, :has_many_association
|
||||
# configure :comments, :has_many_association
|
||||
# configure :aspect_visibilities, :has_many_association
|
||||
# configure :aspects, :has_many_association
|
||||
# configure :share_visibilities, :has_many_association
|
||||
# configure :contacts, :has_many_association
|
||||
# configure :participations, :has_many_association
|
||||
# configure :mentions, :has_many_association
|
||||
# configure :resharers, :has_many_association # # Found columns:
|
||||
# configure :id, :integer
|
||||
# configure :author_id, :integer # Hidden
|
||||
# configure :public, :boolean
|
||||
# configure :diaspora_handle, :string
|
||||
# configure :guid, :string
|
||||
# configure :pending, :boolean
|
||||
# configure :type, :string
|
||||
# configure :text, :text
|
||||
# configure :remote_photo_path, :text
|
||||
# configure :remote_photo_name, :string
|
||||
# configure :random_string, :string
|
||||
# configure :processed_image, :string
|
||||
# configure :created_at, :datetime
|
||||
# configure :updated_at, :datetime
|
||||
# configure :unprocessed_image, :string
|
||||
# configure :object_url, :string
|
||||
# configure :image_url, :string
|
||||
# configure :image_height, :integer
|
||||
# configure :image_width, :integer
|
||||
# configure :provider_display_name, :string
|
||||
# configure :actor_url, :string
|
||||
# configure :objectId, :string
|
||||
# configure :root_guid, :string # Hidden
|
||||
# configure :status_message_guid, :string
|
||||
# configure :likes_count, :integer
|
||||
# configure :comments_count, :integer
|
||||
# configure :o_embed_cache_id, :integer # Hidden
|
||||
# configure :reshares_count, :integer
|
||||
# configure :interacted_at, :datetime # # Sections:
|
||||
# list do; end
|
||||
# export do; end
|
||||
# show do; end
|
||||
# edit do; end
|
||||
# create do; end
|
||||
# update do; end
|
||||
# end
|
||||
|
||||
# config.model ActsAsTaggableOn::Tag do
|
||||
# # Found associations:
|
||||
# configure :taggings, :has_many_association # Hidden # # Found columns:
|
||||
|
|
@ -1109,4 +1059,4 @@ RailsAdmin.config do |config|
|
|||
# update do; end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -65,11 +65,6 @@ Diaspora::Application.routes.draw do
|
|||
put :make_profile_photo
|
||||
end
|
||||
|
||||
# ActivityStreams routes
|
||||
scope "/activity_streams", :module => "activity_streams", :as => "activity_streams" do
|
||||
resources :photos, :controller => "photos", :only => [:create]
|
||||
end
|
||||
|
||||
resources :conversations do
|
||||
resources :messages, :only => [:create, :show]
|
||||
delete 'visibility' => 'conversation_visibilities#destroy'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
class MigrateActivityStreamToStatusMessage < ActiveRecord::Migration
|
||||
def up
|
||||
posts_stream_photos = Post.where(:type => 'ActivityStreams::Photo')
|
||||
posts_stream_photos.each do |p|
|
||||
p.update_attributes(:text => "#{p.text} ", :type => "StatusMessage", without_protection: true)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Can't recover the deleted ActivityStreams::Photo"
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130613203350) do
|
||||
ActiveRecord::Schema.define(:version => 20130717104359) do
|
||||
|
||||
create_table "account_deletions", :force => true do |t|
|
||||
t.string "diaspora_handle"
|
||||
|
|
@ -213,7 +213,7 @@ ActiveRecord::Schema.define(:version => 20130613203350) do
|
|||
t.text "data", :null => false
|
||||
end
|
||||
|
||||
add_index "o_embed_caches", ["url"], :name => "index_o_embed_caches_on_url"
|
||||
add_index "o_embed_caches", ["url"], :name => "index_o_embed_caches_on_url", :length => {"url"=>767}
|
||||
|
||||
create_table "participations", :force => true do |t|
|
||||
t.string "guid"
|
||||
|
|
|
|||
|
|
@ -51,16 +51,13 @@ require Rails.root.join('spec', 'support', 'user_methods')
|
|||
|
||||
print "Seeding post data..."
|
||||
time_interval = 1000
|
||||
(1..25).each do |n|
|
||||
(1..23).each do |n|
|
||||
[alice, bob, eve].each do |u|
|
||||
print '.'
|
||||
if(n%3==1)
|
||||
if(n%2==0)
|
||||
post = u.post :status_message, :text => "#{u.username} - #{n} - #seeded", :to => u.aspects.first.id
|
||||
elsif(n%3==2)
|
||||
post = u.post(:reshare, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => 'all')
|
||||
else
|
||||
post = FactoryGirl.create(:activity_streams_photo, :public => true, :author => u.person)
|
||||
u.add_to_streams(post, u.aspects)
|
||||
post = u.post(:reshare, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => 'all')
|
||||
end
|
||||
|
||||
post.created_at = post.created_at - time_interval
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Stream::Base
|
||||
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
|
||||
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare']
|
||||
|
||||
attr_accessor :max_time, :order, :user, :publisher
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ class TemplatePicker
|
|||
TEMPLATES = %w{ status_with_photo_backdrop
|
||||
note
|
||||
photo_backdrop
|
||||
activity_streams_photo
|
||||
status
|
||||
}
|
||||
|
||||
|
|
@ -32,10 +31,6 @@ class TemplatePicker
|
|||
post.photos.size == 1
|
||||
end
|
||||
|
||||
def activity_streams_photo?
|
||||
post.type == "ActivityStreams::Photo"
|
||||
end
|
||||
|
||||
def status?
|
||||
post.text?
|
||||
end
|
||||
|
|
@ -47,4 +42,4 @@ class TemplatePicker
|
|||
def self.jsonify_name(name)
|
||||
name.gsub('_', '-')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,12 +50,6 @@ describe PostsController do
|
|||
}.to change(Notification.where(:unread => true), :count).by(-2)
|
||||
end
|
||||
|
||||
it 'succeeds with a AS/photo' do
|
||||
photo = FactoryGirl.create(:activity_streams_photo, :author => bob.person)
|
||||
get :show, :id => photo.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it '404 if the post is missing' do
|
||||
expect {
|
||||
get :show, :id => 1234567
|
||||
|
|
|
|||
|
|
@ -176,18 +176,6 @@ FactoryGirl.define do
|
|||
end
|
||||
end
|
||||
|
||||
factory(:activity_streams_photo, :class => ActivityStreams::Photo) do
|
||||
association(:author, :factory => :person)
|
||||
image_url "#{AppConfig.environments.url}/assets/asterisk.png"
|
||||
image_height 154
|
||||
image_width 154
|
||||
object_url "http://example.com/awesome_things.gif"
|
||||
objectId "http://example.com/awesome_things.gif"
|
||||
actor_url "http://notcubbes/cubber"
|
||||
provider_display_name "not cubbies"
|
||||
public true
|
||||
end
|
||||
|
||||
factory(:tag, :class => ActsAsTaggableOn::Tag) do
|
||||
name "partytimeexcellent"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ describe EvilQuery::Participation do
|
|||
before do
|
||||
@status_messageA = FactoryGirl.create(:status_message, :author => bob.person)
|
||||
@status_messageB = FactoryGirl.create(:status_message, :author => bob.person)
|
||||
@photoC = FactoryGirl.create(:activity_streams_photo, :author => bob.person)
|
||||
@status_messageD = FactoryGirl.create(:status_message, :author => bob.person)
|
||||
@status_messageE = FactoryGirl.create(:status_message, :author => bob.person)
|
||||
|
||||
|
|
@ -47,9 +46,6 @@ describe EvilQuery::Participation do
|
|||
alice.like!(@status_messageA)
|
||||
Timecop.travel time += 1.month
|
||||
|
||||
alice.comment!(@photoC, "party")
|
||||
Timecop.travel time += 1.month
|
||||
|
||||
alice.comment!(@status_messageE, "party")
|
||||
end
|
||||
|
||||
|
|
@ -60,11 +56,11 @@ describe EvilQuery::Participation do
|
|||
|
||||
it "doesn't include Posts that aren't acted on" do
|
||||
posts.map(&:id).should_not include(@status_messageD.id)
|
||||
posts.map(&:id).should =~ [@status_messageA.id, @status_messageB.id, @photoC.id, @status_messageE.id]
|
||||
posts.map(&:id).should =~ [@status_messageA.id, @status_messageB.id, @status_messageE.id]
|
||||
end
|
||||
|
||||
it "returns the posts that the user has commented on or liked with the most recently acted on ones first" do
|
||||
posts.map(&:id).should == [@status_messageE.id, @photoC.id, @status_messageA.id, @status_messageB.id]
|
||||
posts.map(&:id).should == [@status_messageE.id, @status_messageA.id, @status_messageB.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ describe Stream::Aspect do
|
|||
stream.posts
|
||||
end
|
||||
|
||||
it 'is called with 3 types' do
|
||||
it 'is called with 2 types' do
|
||||
stream = Stream::Aspect.new(@alice, [1,2], :order => 'created_at')
|
||||
@alice.should_receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'])).and_return(stub.as_null_object)
|
||||
@alice.should_receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare'])).and_return(stub.as_null_object)
|
||||
stream.posts
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -50,13 +50,6 @@ describe TemplatePicker do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#activity_stream_photo' do
|
||||
it 'is true if the post is of type activity_streams_photo' do
|
||||
photo = stub(:type => "ActivityStreams::Photo")
|
||||
TemplatePicker.new(photo).should be_activity_streams_photo
|
||||
end
|
||||
end
|
||||
|
||||
describe 'factories' do
|
||||
TemplatePicker::TEMPLATES.each do |template|
|
||||
describe "#{template} factory" do
|
||||
|
|
|
|||
|
|
@ -136,12 +136,6 @@ describe Notifier do
|
|||
like = reshare.likes.create!(:author => bob.person)
|
||||
mail = Notifier.liked(alice.id, like.author.id, like.id)
|
||||
end
|
||||
|
||||
it 'can handle a activity streams photo' do
|
||||
as_photo = FactoryGirl.create(:activity_streams_photo)
|
||||
like = as_photo.likes.create!(:author => bob.person)
|
||||
mail = Notifier.liked(alice.id, like.author.id, like.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".reshared" do
|
||||
|
|
@ -247,7 +241,7 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
[:reshare, :activity_streams_photo].each do |post_type|
|
||||
[:reshare].each do |post_type|
|
||||
context post_type.to_s do
|
||||
let(:commented_post) { FactoryGirl.create(post_type, :author => bob.person) }
|
||||
it 'succeeds' do
|
||||
|
|
@ -287,7 +281,7 @@ describe Notifier do
|
|||
comment_mail.body.encoded.should_not include(I18n.translate 'notifier.a_post_you_shared')
|
||||
end
|
||||
end
|
||||
[:reshare, :activity_streams_photo].each do |post_type|
|
||||
[:reshare].each do |post_type|
|
||||
context post_type.to_s do
|
||||
let(:commented_post) { FactoryGirl.create(post_type, :author => bob.person) }
|
||||
it 'succeeds' do
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
# Copyright (c) 2010-2011, 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","id":"http://cubbi.es/p/2","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.objectId.should == @json["object"]["id"]
|
||||
|
||||
photo.provider_display_name.should == @json["provider"]["displayName"]
|
||||
photo.actor_url.should == @json["actor"]["url"]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'serialization' do
|
||||
before do
|
||||
@photo = FactoryGirl.build(:activity_streams_photo)
|
||||
xml = @photo.to_diaspora_xml.to_s
|
||||
@marshalled = Diaspora::Parser.from_xml(xml)
|
||||
end
|
||||
it 'Diaspora::Parser should pick the right class' do
|
||||
@marshalled.class.should == ActivityStreams::Photo
|
||||
end
|
||||
it 'marshals the author' do
|
||||
@marshalled.author.should == @photo.author
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue