From f6fe74aeaed314382b256d5f4b355c99000de43c Mon Sep 17 00:00:00 2001 From: carolina Date: Wed, 17 Jul 2013 12:50:30 +0200 Subject: [PATCH] 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 --- .../javascripts/app/views/content_view.js | 4 -- app/models/activity_streams/photo.rb | 47 --------------- config/initializers/rails_admin.rb | 58 ++----------------- config/routes.rb | 5 -- ...grate_activity_stream_to_status_message.rb | 12 ++++ db/schema.rb | 4 +- db/seeds.rb | 9 +-- lib/stream/base.rb | 2 +- lib/template_picker.rb | 7 +-- spec/controllers/posts_controller_spec.rb | 6 -- spec/factories.rb | 12 ---- spec/lib/evil_query_spec.rb | 8 +-- spec/lib/stream/aspect_spec.rb | 4 +- spec/lib/template_picker_spec.rb | 7 --- spec/mailers/notifier_spec.rb | 10 +--- spec/models/activity_streams/photo_spec.rb | 43 -------------- 16 files changed, 29 insertions(+), 209 deletions(-) delete mode 100644 app/models/activity_streams/photo.rb create mode 100644 db/migrate/20130717104359_migrate_activity_stream_to_status_message.rb delete mode 100644 spec/models/activity_streams/photo_spec.rb diff --git a/app/assets/javascripts/app/views/content_view.js b/app/assets/javascripts/app/views/content_view.js index c869707b7..17762e057 100644 --- a/app/assets/javascripts/app/views/content_view.js +++ b/app/assets/javascripts/app/views/content_view.js @@ -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 : { diff --git a/app/models/activity_streams/photo.rb b/app/models/activity_streams/photo.rb deleted file mode 100644 index 626507a0c..000000000 --- a/app/models/activity_streams/photo.rb +++ /dev/null @@ -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 - diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index a666dcb54..becc7b84e 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -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 \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index 93ca0ae85..558fd070d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20130717104359_migrate_activity_stream_to_status_message.rb b/db/migrate/20130717104359_migrate_activity_stream_to_status_message.rb new file mode 100644 index 000000000..b993babd2 --- /dev/null +++ b/db/migrate/20130717104359_migrate_activity_stream_to_status_message.rb @@ -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} ![](#{p.image_url})", :type => "StatusMessage", without_protection: true) + end + end + + def down + raise ActiveRecord::IrreversibleMigration, "Can't recover the deleted ActivityStreams::Photo" + end +end diff --git a/db/schema.rb b/db/schema.rb index b6133442b..b92103eb5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/db/seeds.rb b/db/seeds.rb index 7cd2f1949..64616f5fb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/lib/stream/base.rb b/lib/stream/base.rb index 61eba6f93..9a00ee173 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -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 diff --git a/lib/template_picker.rb b/lib/template_picker.rb index 39fecc8bc..40b6f388e 100644 --- a/lib/template_picker.rb +++ b/lib/template_picker.rb @@ -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 \ No newline at end of file +end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 82efa7524..691d37c8d 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 55620acdd..fb86ad3b9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/lib/evil_query_spec.rb b/spec/lib/evil_query_spec.rb index 4b08377f4..f4fc94955 100644 --- a/spec/lib/evil_query_spec.rb +++ b/spec/lib/evil_query_spec.rb @@ -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 diff --git a/spec/lib/stream/aspect_spec.rb b/spec/lib/stream/aspect_spec.rb index 7072fb8fd..1fcbefd7c 100644 --- a/spec/lib/stream/aspect_spec.rb +++ b/spec/lib/stream/aspect_spec.rb @@ -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 diff --git a/spec/lib/template_picker_spec.rb b/spec/lib/template_picker_spec.rb index 119ce3ac7..32b47eb88 100644 --- a/spec/lib/template_picker_spec.rb +++ b/spec/lib/template_picker_spec.rb @@ -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 diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index ebb076962..187d865e2 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -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 diff --git a/spec/models/activity_streams/photo_spec.rb b/spec/models/activity_streams/photo_spec.rb deleted file mode 100644 index 9e05137a2..000000000 --- a/spec/models/activity_streams/photo_spec.rb +++ /dev/null @@ -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 <