From a527f5c27ff92d2ee7e2d5e78dc20b6d1d982aa0 Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzegorz.bizon@ntsn.pl>
Date: Wed, 2 Dec 2015 10:51:46 +0100
Subject: [PATCH] Notify user when award-emoji comment is invalid

---
 app/assets/javascripts/notes.js.coffee       | 4 ++++
 app/controllers/projects/notes_controller.rb | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee
index 797234e6d9c..af0d62c8495 100644
--- a/app/assets/javascripts/notes.js.coffee
+++ b/app/assets/javascripts/notes.js.coffee
@@ -111,6 +111,10 @@ class @Notes
   Note: for rendering inline notes use renderDiscussionNote
   ###
   renderNote: (note) ->
+    unless note.valid
+      alert('You have already used this award emoji !') if note.award
+      return
+
     # render note if it not present in loaded list
     # or skip if rendered
     if @isNewNote(note) && !note.award
diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb
index a7ff5fcd09a..88b949a27ab 100644
--- a/app/controllers/projects/notes_controller.rb
+++ b/app/controllers/projects/notes_controller.rb
@@ -133,6 +133,7 @@ class Projects::NotesController < Projects::ApplicationController
   def render_note_json(note)
     if note.valid?
       render json: {
+        valid: true,
         id: note.id,
         discussion_id: note.discussion_id,
         html: note_to_html(note),
@@ -143,7 +144,11 @@ class Projects::NotesController < Projects::ApplicationController
         discussion_with_diff_html: note_to_discussion_with_diff_html(note)
       }
     else
-      render json: { invalid: true, errors: note.errors }
+      render json: {
+        valid: false,
+        award: note.is_award,
+        errors: note.errors
+      }
     end
   end
 
-- 
GitLab