Remove diaspora_handle from shareables

We can determine diaspora_handle from a relation with people for the
shareables (posts, photos). So we don't need to store diaspora_handle in
the DB. Also remove tmp_old_id from photos which is not refenrenced anywhere.
This commit is contained in:
cmrd Senya 2016-03-07 18:47:21 +03:00
parent bc72851ef9
commit 2986aa8b24
6 changed files with 12 additions and 10 deletions

View file

@ -86,7 +86,6 @@ class Photo < ActiveRecord::Base
photo.author = params[:author] photo.author = params[:author]
photo.public = params[:public] if params[:public] photo.public = params[:public] if params[:public]
photo.pending = params[:pending] if params[:pending] photo.pending = params[:pending] if params[:pending]
photo.diaspora_handle = photo.author.diaspora_handle
photo.random_string = SecureRandom.hex(10) photo.random_string = SecureRandom.hex(10)

View file

@ -137,7 +137,6 @@ class Post < ActiveRecord::Base
new_post.author = params[:author] new_post.author = params[:author]
new_post.public = params[:public] if params[:public] new_post.public = params[:public] if params[:public]
new_post.pending = params[:pending] if params[:pending] new_post.pending = params[:pending] if params[:pending]
new_post.diaspora_handle = new_post.author.diaspora_handle
new_post new_post
end end

View file

@ -0,0 +1,7 @@
class CleanupHandles < ActiveRecord::Migration
def change
remove_column :photos, :tmp_old_id, :integer
remove_column :photos, :diaspora_handle, :string
remove_column :posts, :diaspora_handle, :string
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160302025129) do ActiveRecord::Schema.define(version: 20160307142216) do
create_table "account_deletions", force: :cascade do |t| create_table "account_deletions", force: :cascade do |t|
t.string "diaspora_handle", limit: 255 t.string "diaspora_handle", limit: 255
@ -341,10 +341,8 @@ ActiveRecord::Schema.define(version: 20160302025129) do
add_index "people", ["pod_id"], name: "people_pod_id_fk", using: :btree add_index "people", ["pod_id"], name: "people_pod_id_fk", using: :btree
create_table "photos", force: :cascade do |t| create_table "photos", force: :cascade do |t|
t.integer "tmp_old_id", limit: 4
t.integer "author_id", limit: 4, null: false t.integer "author_id", limit: 4, null: false
t.boolean "public", default: false, null: false t.boolean "public", default: false, null: false
t.string "diaspora_handle", limit: 255
t.string "guid", limit: 255, null: false t.string "guid", limit: 255, null: false
t.boolean "pending", default: false, null: false t.boolean "pending", default: false, null: false
t.text "text", limit: 65535 t.text "text", limit: 65535
@ -418,7 +416,6 @@ ActiveRecord::Schema.define(version: 20160302025129) do
create_table "posts", force: :cascade do |t| create_table "posts", force: :cascade do |t|
t.integer "author_id", limit: 4, null: false t.integer "author_id", limit: 4, null: false
t.boolean "public", default: false, null: false t.boolean "public", default: false, null: false
t.string "diaspora_handle", limit: 255
t.string "guid", limit: 255, null: false t.string "guid", limit: 255, 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

View file

@ -24,12 +24,11 @@ module Diaspora
module InstanceMethods module InstanceMethods
include Diaspora::Logging include Diaspora::Logging
def diaspora_handle def diaspora_handle
read_attribute(:diaspora_handle) || author.diaspora_handle author.diaspora_handle
end end
def diaspora_handle=(author_handle) def diaspora_handle=(author_handle)
self.author = Person.where(diaspora_handle: author_handle).first self.author = Person.where(diaspora_handle: author_handle).first
write_attribute(:diaspora_handle, author_handle)
end end
# @param [User] user The user that is receiving this shareable. # @param [User] user The user that is receiving this shareable.

View file

@ -39,7 +39,8 @@ describe "Receive federation messages feature" do
:reshare_entity, root_diaspora_id: alice.diaspora_handle, root_guid: post.guid, diaspora_id: sender_id) :reshare_entity, root_diaspora_id: alice.diaspora_handle, root_guid: post.guid, diaspora_id: sender_id)
post_message(generate_xml(reshare, sender)) post_message(generate_xml(reshare, sender))
expect(Reshare.exists?(root_guid: post.guid, diaspora_handle: sender_id)).to be_truthy expect(Reshare.exists?(root_guid: post.guid)).to be_truthy
expect(Reshare.where(root_guid: post.guid).last.diaspora_handle).to eq(sender_id)
end end
it "reshare of private post fails" do it "reshare of private post fails" do
@ -50,7 +51,7 @@ describe "Receive federation messages feature" do
post_message(generate_xml(reshare, sender)) post_message(generate_xml(reshare, sender))
}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Only posts which are public may be reshared." }.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Only posts which are public may be reshared."
expect(Reshare.exists?(root_guid: post.guid, diaspora_handle: sender_id)).to be_falsey expect(Reshare.exists?(root_guid: post.guid)).to be_falsey
end end
end end