[mb-commits] branch, mbs-5700, updated. MBS-5700: When an editor deletes their account, unsubscribe anyone subscribed...

MusicBrainz Git Server <[email protected]> Mon, 28 Jan 2013 11:48:53 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1TznCn-0001cJ-Px@wiley>
The branch, mbs-5700 has been updated
  discards  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=ca4f866eadd7abac6cadfc6e51004ed984e5b417 (commit)
       via  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=657f6ad83c2be9f8e8da94b4fc2aa84df732acb7 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (ca4f866eadd7abac6cadfc6e51004ed984e5b417)
            \
             N -- N -- N (657f6ad83c2be9f8e8da94b4fc2aa84df732acb7)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Summary of changes:

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 657f6ad83c2be9f8e8da94b4fc2aa84df732acb7
Author: Oliver Charles <[email protected]>
Date:   Fri Jan 25 11:29:19 2013 +0000

    MBS-5700: When an editor deletes their account, unsubscribe anyone subscribed to them

diff --git a/admin/sql/updates/20130125-unsubscribe-to-deleted-editors.sql b/admin/sql/updates/20130125-unsubscribe-to-deleted-editors.sql
new file mode 100644
index 0000000..55d4f40
--- /dev/null
+++ b/admin/sql/updates/20130125-unsubscribe-to-deleted-editors.sql
@@ -0,0 +1,8 @@
+BEGIN;
+
+DELETE FROM editor_subscribe_editor
+WHERE subscribed_editor IN (
+  SELECT id FROM editor WHERE name ~ E'^Deleted Editor #(\\d+)$'
+) order by name asc;
+
+COMMIT;
diff --git a/lib/MusicBrainz/Server/Data/Editor.pm b/lib/MusicBrainz/Server/Data/Editor.pm
index 5cf0f2f..989c688 100644
--- a/lib/MusicBrainz/Server/Data/Editor.pm
+++ b/lib/MusicBrainz/Server/Data/Editor.pm
@@ -478,6 +478,7 @@ sub delete {
     $self->c->model('EditorLanguage')->delete_editor($editor_id);
 
     $self->c->model('EditorSubscriptions')->delete_editor($editor_id);
+    $self->c->model('Editor')->unsubscribe_to($editor_id);
     $self->c->model('Collection')->delete_editor($editor_id);
     $self->c->model('WatchArtist')->delete_editor($editor_id);
 
@@ -553,6 +554,13 @@ sub last_24h_edit_count
     return $self->sql->select_single_value($query, $editor_id);
 }
 
+sub unsubscribe_to {
+    my ($self, $editor_id) = @_;
+    $self->sql->do(
+        'DELETE FROM editor_subscribe_editor WHERE subscribed_editor = ?',
+        $editor_id);
+}
+
 no Moose;
 __PACKAGE__->meta->make_immutable;
 1;
diff --git a/t/lib/t/MusicBrainz/Server/Data/Editor.pm b/t/lib/t/MusicBrainz/Server/Data/Editor.pm
index 066a72e..c9c4e35 100644
--- a/t/lib/t/MusicBrainz/Server/Data/Editor.pm
+++ b/t/lib/t/MusicBrainz/Server/Data/Editor.pm
@@ -241,6 +241,21 @@ test 'Deleting an editor cancels all open edits' => sub {
     is($c->model('Edit')->get_by_id($open_edit->id)->status, $STATUS_DELETED);
 };
 
+test 'Deleting an editor unsubscribes anyone who was subscribed to them' => sub {
+    my $test = shift;
+    my $c = $test->c;
+
+    $c->sql->do(<<'EOSQL');
+INSERT INTO editor (id, name, password)
+  VALUES (1, 'Subject', ''), (2, 'Subscriber', '');
+INSERT INTO editor_subscribe_editor (editor, subscribed_editor, last_edit_sent)
+  VALUES (2, 1, 1);
+EOSQL
+
+    $c->model('Editor')->delete(1);
+    is(scalar($c->model('Editor')->subscription->get_subscriptions(2)), 0);
+};
+
 test 'Open edit and last-24-hour counts' => sub {
     my $test = shift;
     my $c = $test->c;

-----------------------------------------------------------------------


hooks/post-receive
-- 
mb_server