# frozen_string_literal: true class Posts::LocationsController < ApplicationController before_action :filter_banned_users before_action :load_post before_action :check_auth, except: [:show] before_action :load_location, only: [:update, :destroy] before_action -> { ratelimit 1, 5.seconds, t('booru.errors.metadata_flooding', seconds: 5) }, unless: -> { current_user&.staff? } def show respond_to do |format| format.json { render json: @post.locations } end end def create @location = @post.locations.create!(location_params) flash[:notice] = 'Location successfully created.' redirect_to @post end def update @location = @post.locations.find_by_location(location_params[:location]) @location.update!(id_at_location: location_params[:id_at_location]) flash[:notice] = 'Location successfully updated.' redirect_to @post end def destroy @location.destroy! flash[:notice] = 'Location successfully destroyed.' redirect_to @post end private def location_params params.require(:location).permit(:location, :id_at_location) end def load_post @post = Post.find(params[:port_id]) end def load_location @location = @post.locations.find_by(location: location_params[:location]) end def check_auth authorize! :fuck_up, @post # authorize! :update_metadata, @post end end