[mb-commits] branch, data-nes, updated. Correctly 404 on unknown works

MusicBrainz Git Server <[email protected]> Fri, 18 Jan 2013 12:28:05 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1TwB3F-0001lZ-H2@wiley>
The branch, data-nes has been updated
       via  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=09ebef0867c96c787f10fce40f07dd2cdb4d09a3 (commit)
       via  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=dfc166add78ceae744371d17248c697b3e656f0b (commit)
      from  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=524f96b02aa7c60c87dbf4f7ec31d59474e51950 (commit)

Summary of changes:
 lib/MusicBrainz/Server/Data/EditNote.pm        |   72 ++++++++++++------------
 lib/MusicBrainz/Server/Data/NES/Work.pm        |    2 +
 lib/MusicBrainz/Server/NES/Controller/Utils.pm |   18 +++++-
 3 files changed, 53 insertions(+), 39 deletions(-)

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 09ebef0867c96c787f10fce40f07dd2cdb4d09a3
Author: Oliver Charles <[email protected]>
Date:   Fri Jan 18 12:27:48 2013 +0000

    Correctly 404 on unknown works

diff --git a/lib/MusicBrainz/Server/Data/NES/Work.pm b/lib/MusicBrainz/Server/Data/NES/Work.pm
index 14c2b86..4d3fc50 100644
--- a/lib/MusicBrainz/Server/Data/NES/Work.pm
+++ b/lib/MusicBrainz/Server/Data/NES/Work.pm
@@ -111,6 +111,8 @@ sub get_by_gid {
 
 sub _new_from_response {
     my ($response) = @_;
+    return undef if keys %$response == 0;
+
     my %data = %{ $response->{data} };
     return MusicBrainz::Server::Entity::Work->new(
         name => $data{name},

commit dfc166add78ceae744371d17248c697b3e656f0b
Author: Oliver Charles <[email protected]>
Date:   Fri Jan 18 12:05:13 2013 +0000

    When creating works, submit an edit note

diff --git a/lib/MusicBrainz/Server/Data/EditNote.pm b/lib/MusicBrainz/Server/Data/EditNote.pm
index 3ae226f..efe1da5 100644
--- a/lib/MusicBrainz/Server/Data/EditNote.pm
+++ b/lib/MusicBrainz/Server/Data/EditNote.pm
@@ -12,6 +12,8 @@ use MusicBrainz::Server::Data::Utils qw(
 
 extends 'MusicBrainz::Server::Data::Entity';
 
+with 'MusicBrainz::Server::Data::Role::NES';
+
 sub _table
 {
     return 'edit_note';
@@ -60,14 +62,13 @@ sub load_for_edits
 sub insert
 {
     my ($self, $edit_id, $note_hash) = @_;
-    my $mapping = $self->_column_mapping;
-    my %r = map {
-        my $key = $mapping->{$_} || $_;
-        $key => $note_hash->{$_};
-    } keys %$note_hash;
-    $r{edit} = $edit_id;
-    $self->sql->auto_commit;
-    $self->sql->insert_row('edit_note', \%r);
+    $self->request(
+        '/edit/add-note', {
+            edit => $edit_id,
+            editor => $note_hash->{editor_id},
+            text => $note_hash->{text}
+        }
+    );
 }
 
 sub add_note
@@ -75,33 +76,34 @@ sub add_note
     my ($self, $edit_id, $note_hash) = @_;
     $self->insert($edit_id, $note_hash);
 
-    my $email_data = MusicBrainz::Server::Email->new( c => $self->c );
-    my $edit = $self->c->model('Edit')->get_by_id($edit_id) or die "Edit $edit_id does not exist!";
-    $self->c->model('EditNote')->load_for_edits($edit);
-    $self->c->model('Vote')->load_for_edits($edit);
-    my $editors = $self->c->model('Editor')->get_by_ids($edit->editor_id,
-        $note_hash->{editor_id},
-        (map { $_->editor_id } @{ $edit->votes }),
-        (map { $_->editor_id } @{ $edit->edit_notes }));
-    $self->c->model('Editor')->load_preferences(values %$editors);
-
-    my @to_email = grep { $_ != $note_hash->{editor_id} }
-        map { $_->id } grep { $_->preferences->email_on_notes }
-        map { $editors->{$_->editor_id} }
-            @{ $edit->edit_notes },
-            @{ $edit->votes },
-            $edit;
-
-    my $from = $editors->{ $note_hash->{editor_id} };
-    for my $editor_id (uniq @to_email) {
-        my $editor = $editors->{ $editor_id };
-        $email_data->send_edit_note(
-            from_editor => $from,
-            editor => $editor,
-            note_text => $note_hash->{text},
-            edit_id => $edit_id,
-            own_edit => $edit->editor_id == $editor->id);
-    }
+    # NES
+    # my $email_data = MusicBrainz::Server::Email->new( c => $self->c );
+    # my $edit = $self->c->model('Edit')->get_by_id($edit_id) or die "Edit $edit_id does not exist!";
+    # $self->c->model('EditNote')->load_for_edits($edit);
+    # $self->c->model('Vote')->load_for_edits($edit);
+    # my $editors = $self->c->model('Editor')->get_by_ids($edit->editor_id,
+    #     $note_hash->{editor_id},
+    #     (map { $_->editor_id } @{ $edit->votes }),
+    #     (map { $_->editor_id } @{ $edit->edit_notes }));
+    # $self->c->model('Editor')->load_preferences(values %$editors);
+
+    # my @to_email = grep { $_ != $note_hash->{editor_id} }
+    #     map { $_->id } grep { $_->preferences->email_on_notes }
+    #     map { $editors->{$_->editor_id} }
+    #         @{ $edit->edit_notes },
+    #         @{ $edit->votes },
+    #         $edit;
+
+    # my $from = $editors->{ $note_hash->{editor_id} };
+    # for my $editor_id (uniq @to_email) {
+    #     my $editor = $editors->{ $editor_id };
+    #     $email_data->send_edit_note(
+    #         from_editor => $from,
+    #         editor => $editor,
+    #         note_text => $note_hash->{text},
+    #         edit_id => $edit_id,
+    #         own_edit => $edit->editor_id == $editor->id);
+    # }
 }
 
 no Moose;
diff --git a/lib/MusicBrainz/Server/NES/Controller/Utils.pm b/lib/MusicBrainz/Server/NES/Controller/Utils.pm
index fe16de7..c5ce003 100644
--- a/lib/MusicBrainz/Server/NES/Controller/Utils.pm
+++ b/lib/MusicBrainz/Server/NES/Controller/Utils.pm
@@ -28,10 +28,20 @@ sub create_edit {
     };
 
     if ($c->form_posted && $form->submitted_and_valid($c->req->body_params)) {
-        my $work = do {
-            my $edit = $c->model('NES::Edit')->open;
-            $opts{on_post}->($form->values, $edit);
-        };
+        my $values = $form->values;
+        my $edit = $c->model('NES::Edit')->open;
+
+        my $work = $opts{on_post}->($values, $edit);
+
+        if ($values->{edit_note}) {
+            $c->model('EditNote')->add_note(
+                $edit->id,
+                {
+                    editor_id => $c->user->id,
+                    text => $values->{edit_note}
+                }
+            );
+        }
 
         # NES:
         # my $privs = $c->user->privileges;

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


hooks/post-receive
-- 
mb_server