discourse/app/controllers/reviewable_notes_controller.rb
Gary Pendergast 599404de31
DEV: Add a ReviewableNote model, and tie it into the Reviewable model. (#33047)
As part of the review queue refresh, we'll be adding the ability for moderators to make notes on individual reviewable items. As a first step, this change adds the new model and associated backend code.
2025-06-04 09:33:02 +10:00

38 lines
938 B
Ruby

# frozen_string_literal: true
class ReviewableNotesController < ApplicationController
before_action :find_reviewable
def create
note = @reviewable.reviewable_notes.build(note_params)
note.user = current_user
if note.save
# Reload to ensure associations are loaded
note.reload
render json: ReviewableNoteSerializer.new(note, scope: guardian, root: false)
else
render json: { errors: note.errors.full_messages }, status: 422
end
end
def destroy
note = @reviewable.reviewable_notes.find(params[:id])
# Only allow the author or admin to delete notes
raise Discourse::InvalidAccess unless note.user == current_user || current_user.admin?
note.destroy!
render json: success_json
end
private
def find_reviewable
@reviewable = Reviewable.find(params[:reviewable_id])
end
def note_params
params.require(:reviewable_note).permit(:content)
end
end