Skip to content
Extraits de code Groupes Projets
Valider edc1a23f rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

Merge pull request #5478 from margori/Purge_orphan_conversation

Destroy conversation when all participants leave it
parents e25a48cc e6c605d9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -76,6 +76,7 @@ This is disabled by default since it requires the installation of additional pac
* Update rack-protection [#5403](https://github.com/diaspora/diaspora/pull/5403)
* Cleanup diaspora.yml [#5426](https://github.com/diaspora/diaspora/pull/5426)
* Replace `opengraph_parser` with `open_graph_reader` [#5462](https://github.com/diaspora/diaspora/pull/5462)
* Make sure conversations without any visibilities left are deleted [#5478](https://github.com/diaspora/diaspora/pull/5478)
## Bug fixes
* orca cannot see 'Add Contact' button [#5158](https://github.com/diaspora/diaspora/pull/5158)
......
......@@ -3,4 +3,14 @@ class ConversationVisibility < ActiveRecord::Base
belongs_to :conversation
belongs_to :person
after_destroy :check_orphan_conversation
private
def check_orphan_conversation
conversation = Conversation.find_by_id(self.conversation.id)
if conversation
conversation.destroy if conversation.participants.count == 0
end
end
end
class PurgeOrphanConversations < ActiveRecord::Migration
def up
Conversation.joins("LEFT JOIN conversation_visibilities ON conversation_visibilities.conversation_id = conversations.id").group('conversations.id').having("COUNT(conversation_visibilities.id) = 0").delete_all
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141209041241) do
ActiveRecord::Schema.define(version: 20141216213423) do
create_table "account_deletions", force: true do |t|
t.string "diaspora_handle"
......
# 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 ConversationVisibility, :type => :model do
before do
@user1 = alice
@participant_ids = [@user1.contacts.first.person.id, @user1.person.id]
@create_hash = {
:author => @user1.person,
:participant_ids => @participant_ids,
:subject => "cool stuff",
:messages_attributes => [ {:author => @user1.person, :text => 'hey'} ]
}
@conversation = Conversation.create(@create_hash)
end
it 'destroy conversation when no participant' do
@conversation.conversation_visibilities.each do |visibility|
visibility.destroy
end
expect(Conversation).not_to exist(@conversation.id)
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter