* Add a global /post_events page that shows the history of all approvals, disapprovals, flags, appeals, and replacements on a single page. * Redesign the /posts/:id/events page to show all approval, disapproval, flag, appeal, and replacement events for a single post (before it only showed approvals, flags, and appeals). * Remove the replacement history link from the post show page. Replacements are now included in the post events page (closes #4948: Highlighed replacements). * Add /post_approvals/:id and /post_replacements/:id routes (these are used by the "Details" link on the post events page).
47 lines
1.5 KiB
Ruby
47 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PostReplacementsController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
|
|
def new
|
|
@post_replacement = authorize PostReplacement.new(post_id: params[:post_id], **permitted_attributes(PostReplacement))
|
|
respond_with(@post_replacement)
|
|
end
|
|
|
|
def create
|
|
@post_replacement = authorize PostReplacement.new(creator: CurrentUser.user, post_id: params[:post_id], **permitted_attributes(PostReplacement))
|
|
@post_replacement.save
|
|
|
|
if request.format.html? && @post_replacement.errors.any?
|
|
flash[:notice] = @post_replacement.errors.full_messages.join("; ")
|
|
redirect_to @post_replacement.post
|
|
else
|
|
flash[:notice] = "Post replaced"
|
|
respond_with(@post_replacement, location: @post_replacement.post)
|
|
end
|
|
end
|
|
|
|
def update
|
|
@post_replacement = authorize PostReplacement.find(params[:id])
|
|
@post_replacement.update(permitted_attributes(@post_replacement))
|
|
|
|
respond_with(@post_replacement)
|
|
end
|
|
|
|
def index
|
|
params[:search][:post_id] = params.delete(:post_id) if params.key?(:post_id)
|
|
@post_replacements = authorize PostReplacement.paginated_search(params)
|
|
@post_replacements = @post_replacements.includes(:creator, post: [:uploader, :media_asset]) if request.format.html?
|
|
|
|
respond_with(@post_replacements)
|
|
end
|
|
|
|
def show
|
|
@post_replacement = authorize PostReplacement.find(params[:id])
|
|
|
|
respond_with(@post_replacement) do |format|
|
|
format.html { redirect_to post_replacements_path(search: { id: @post_replacement.id }) }
|
|
end
|
|
end
|
|
end
|