From 3bdc57f0a710b3769381ecad7ea4098223ecff56 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Sat, 16 Apr 2016 21:09:08 +0200 Subject: Create table for award emoji --- app/controllers/projects/notes_controller.rb | 35 ++++++---------------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'app/controllers/projects/notes_controller.rb') diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 707a0d0e5c6..9000e0adf63 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -3,7 +3,7 @@ class Projects::NotesController < Projects::ApplicationController before_action :authorize_read_note! before_action :authorize_create_note!, only: [:create] before_action :authorize_admin_note!, only: [:update, :destroy] - before_action :find_current_user_notes, except: [:destroy, :delete_attachment, :award_toggle] + before_action :find_current_user_notes, only: [:index] def index current_fetched_at = Time.now.to_i @@ -22,8 +22,10 @@ class Projects::NotesController < Projects::ApplicationController def create @note = Notes::CreateService.new(project, current_user, note_params).execute + @note = note.is_a?(AwardEmoji) ? @note.to_note_json : note_json(@note) + respond_to do |format| - format.json { render json: note_json(@note) } + format.json { render json: @note } format.html { redirect_back_or_default } end end @@ -56,35 +58,12 @@ class Projects::NotesController < Projects::ApplicationController end end - def award_toggle - noteable = if note_params[:noteable_type] == "issue" - project.issues.find(note_params[:noteable_id]) - else - project.merge_requests.find(note_params[:noteable_id]) - end - - data = { - author: current_user, - is_award: true, - note: note_params[:note].delete(":") - } - - note = noteable.notes.find_by(data) - - if note - note.destroy - else - Notes::CreateService.new(project, current_user, note_params).execute - end - - render json: { ok: true } - end - private def note @note ||= @project.notes.find(params[:id]) end + alias_method :awardable, :note def note_to_html(note) render_to_string( @@ -137,7 +116,7 @@ class Projects::NotesController < Projects::ApplicationController id: note.id, discussion_id: note.discussion_id, html: note_to_html(note), - award: note.is_award, + award: false, note: note.note, discussion_html: note_to_discussion_html(note), discussion_with_diff_html: note_to_discussion_with_diff_html(note) @@ -145,7 +124,7 @@ class Projects::NotesController < Projects::ApplicationController else { valid: false, - award: note.is_award, + award: false, errors: note.errors } end -- cgit v1.2.1 From dccf8a9fc8d4dde91942944f6b47387bfb13c380 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Mon, 25 Apr 2016 20:10:20 +0200 Subject: Add tests on Awardables and Award Emoji --- app/controllers/projects/notes_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app/controllers/projects/notes_controller.rb') diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 9000e0adf63..eb5137fe999 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -22,7 +22,7 @@ class Projects::NotesController < Projects::ApplicationController def create @note = Notes::CreateService.new(project, current_user, note_params).execute - @note = note.is_a?(AwardEmoji) ? @note.to_note_json : note_json(@note) + @note = @note.is_a?(AwardEmoji) ? @note.to_note_json : note_json(@note) respond_to do |format| format.json { render json: @note } @@ -63,7 +63,6 @@ class Projects::NotesController < Projects::ApplicationController def note @note ||= @project.notes.find(params[:id]) end - alias_method :awardable, :note def note_to_html(note) render_to_string( -- cgit v1.2.1 From e0cabb67d0492907e6cef21bb0ef21a6e953b70b Mon Sep 17 00:00:00 2001 From: ZJ van de Weg Date: Tue, 17 May 2016 12:28:17 -0500 Subject: Fix latests concerns --- app/controllers/projects/notes_controller.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/controllers/projects/notes_controller.rb') diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index eb5137fe999..b097f609c63 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -22,10 +22,8 @@ class Projects::NotesController < Projects::ApplicationController def create @note = Notes::CreateService.new(project, current_user, note_params).execute - @note = @note.is_a?(AwardEmoji) ? @note.to_note_json : note_json(@note) - respond_to do |format| - format.json { render json: @note } + format.json { render json: note_json(@note) } format.html { redirect_back_or_default } end end @@ -109,7 +107,14 @@ class Projects::NotesController < Projects::ApplicationController end def note_json(note) - if note.valid? + if note.is_a?(AwardEmoji) + { + valid: note.valid?, + award: true, + id: note.id, + name: note.name + } + elsif note.valid? { valid: true, id: note.id, -- cgit v1.2.1