Module: NotesActions
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize, RendersNotes
- Included in:
- Projects::NotesController, Snippets::NotesController
- Defined in:
- app/controllers/concerns/notes_actions.rb
Constant Summary collapse
- MICROSECOND =
last_fetched_at is an integer number of microseconds, which is the same precision as PostgreSQL “timestamp” fields.
1_000_000
Instance Method Summary collapse
-
#create ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
-
#destroy ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables.
- #index ⇒ Object
-
#update ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
Methods included from RendersNotes
Instance Method Details
#create ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/concerns/notes_actions.rb', line 40 def create @note = Notes::CreateService.new(note_project, current_user, create_note_params).execute respond_to do |format| format.json do json = { commands_changes: @note.commands_changes&.slice(:emoji_award, :time_estimate, :spend_time), command_names: @note.command_names } if @note.persisted? && return_discussion? json[:valid] = true discussion = @note.discussion prepare_notes_for_rendering(discussion.notes) json[:discussion] = discussion_serializer.represent(discussion, context: self) else prepare_notes_for_rendering([@note]) json.merge!(note_json(@note)) end if @note.errors.present? && @note.errors.attribute_names != [:commands_only, :command_names] render json: { errors: errors_on_create(@note.errors) }, status: :unprocessable_entity else render json: json end end format.html { redirect_back_or_default } end end |
#destroy ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables
96 97 98 99 100 101 102 |
# File 'app/controllers/concerns/notes_actions.rb', line 96 def destroy Notes::DestroyService.new(project, current_user).execute(note) if note.editable? respond_to do |format| format.js { head :ok } end end |
#index ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/concerns/notes_actions.rb', line 25 def index notes, = gather_all_notes notes = prepare_notes_for_rendering(notes) notes = notes.select { |n| n.readable_by?(current_user) } notes = if use_note_serializer? note_serializer.represent(notes) else notes.map { |note| note_json(note) } end render json: .merge(notes: notes) end |
#update ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/concerns/notes_actions.rb', line 74 def update @note = Notes::UpdateService.new(project, current_user, update_note_params).execute(note) if @note.destroyed? head :gone return end respond_to do |format| format.json do if @note.errors.present? render json: { errors: @note.errors..to_sentence }, status: :unprocessable_entity else prepare_notes_for_rendering([@note]) render json: note_json(@note) end end format.html { redirect_back_or_default } end end |