Merge pull request #6745 from cmrd-senya/remove_diaspora_handle_shareables

Remove diaspora_handle from shareables
This commit is contained in:
Dennis Schubert 2016-03-08 23:45:16 +01:00
commit 69ac153fe9
6 changed files with 12 additions and 10 deletions

View file

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

View file

@ -135,7 +135,6 @@ class Post < ActiveRecord::Base
def self.diaspora_initialize(params)
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_post|
new_post.author = params[:author]
new_post.diaspora_handle = new_post.author.diaspora_handle
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.
ActiveRecord::Schema.define(version: 20160302025129) do
ActiveRecord::Schema.define(version: 20160307142216) do
create_table "account_deletions", force: :cascade do |t|
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
create_table "photos", force: :cascade do |t|
t.integer "tmp_old_id", limit: 4
t.integer "author_id", limit: 4, null: false
t.boolean "public", default: false, null: false
t.string "diaspora_handle", limit: 255
t.string "guid", limit: 255, null: false
t.boolean "pending", default: false, null: false
t.text "text", limit: 65535
@ -418,7 +416,6 @@ ActiveRecord::Schema.define(version: 20160302025129) do
create_table "posts", force: :cascade do |t|
t.integer "author_id", limit: 4, null: false
t.boolean "public", default: false, null: false
t.string "diaspora_handle", limit: 255
t.string "guid", limit: 255, null: false
t.boolean "pending", default: false, null: false
t.string "type", limit: 40, null: false

View file

@ -24,12 +24,11 @@ module Diaspora
module InstanceMethods
include Diaspora::Logging
def diaspora_handle
read_attribute(:diaspora_handle) || author.diaspora_handle
author.diaspora_handle
end
def diaspora_handle=(author_handle)
self.author = Person.where(diaspora_handle: author_handle).first
write_attribute(:diaspora_handle, author_handle)
end
# @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)
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
it "reshare of private post fails" do
@ -50,7 +51,7 @@ describe "Receive federation messages feature" do
post_message(generate_xml(reshare, sender))
}.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