mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 04:33:37 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
38 lines
812 B
Ruby
38 lines
812 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Admin::PermalinksController < Admin::AdminController
|
|
|
|
before_action :fetch_permalink, only: [:destroy]
|
|
|
|
def index
|
|
url = params[:filter]
|
|
permalinks = Permalink.filter_by(url)
|
|
render_serialized(permalinks, PermalinkSerializer)
|
|
end
|
|
|
|
def create
|
|
params.require(:url)
|
|
params.require(:permalink_type)
|
|
params.require(:permalink_type_value)
|
|
|
|
permalink = Permalink.new(:url => params[:url], params[:permalink_type] => params[:permalink_type_value])
|
|
if permalink.save
|
|
render_serialized(permalink, PermalinkSerializer)
|
|
else
|
|
render_json_error(permalink)
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@permalink.destroy
|
|
render json: success_json
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_permalink
|
|
@permalink = Permalink.find(params[:id])
|
|
end
|
|
|
|
end
|