Files
danbooru/app/controllers/artist_commentaries_controller.rb
evazion 18c949ff34 Fix #5208: The posts version of create or update artist commentary endpoint does not work without the post ID parameter being passed in the body
Fix /posts/:post_id/artist_commentary/create_or_update not working
without passing `artist_commentary[post_id]` in the form body.
2022-08-25 21:50:33 -05:00

42 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class ArtistCommentariesController < ApplicationController
respond_to :html, :xml, :json, :js
def index
@commentaries = authorize ArtistCommentary.paginated_search(params)
@commentaries = @commentaries.includes(post: [:uploader, :media_asset]) if request.format.html?
respond_with(@commentaries)
end
def search
end
def show
if params[:id]
@commentary = authorize ArtistCommentary.find(params[:id])
else
@commentary = authorize ArtistCommentary.find_by_post_id!(params[:post_id])
end
respond_with(@commentary) do |format|
format.html { redirect_to post_path(@commentary.post) }
end
end
def create_or_update
post_id = params[:artist_commentary].delete(:post_id) || params[:post_id]
@artist_commentary = authorize ArtistCommentary.find_or_initialize_by(post_id: post_id)
@artist_commentary.update(permitted_attributes(@artist_commentary))
respond_with(@artist_commentary)
end
def revert
@artist_commentary = authorize ArtistCommentary.find_by_post_id!(params[:id])
@version = @artist_commentary.versions.find(params[:version_id])
@artist_commentary.revert_to!(@version)
respond_with(@artist_commentary)
end
end