API: remove various associated fields included by default.
Remove various associated fields that were included by default on certain endpoints. API users can use the only param to include the full association if they need these fields. * /artists.json: urls. * /artist_urls.json: artist. * /comments.json: creator_name and updater_name. * /notes.json: creator_name. * /pools.json: creator_name. * /posts.json: uploader_name, children_ids, pixiv_ugoira_frame_data. * /post_appeals.json: is_resolved. * /post_versions.json: updater_name. * /uploads.json: uploader_name.
This commit is contained in:
@@ -4,10 +4,7 @@ class ArtistUrlsController < ApplicationController
|
||||
|
||||
def index
|
||||
@artist_urls = ArtistUrl.paginated_search(params).includes(model_includes(params))
|
||||
respond_with(@artist_urls) do |format|
|
||||
format.json { render json: @artist_urls.to_json(format_params) }
|
||||
format.xml { render xml: @artist_urls.to_xml(format_params) }
|
||||
end
|
||||
respond_with(@artist_urls)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -20,25 +17,12 @@ class ArtistUrlsController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[{artist: [:urls]}]
|
||||
[]
|
||||
else
|
||||
[:artist]
|
||||
end
|
||||
end
|
||||
|
||||
def format_params
|
||||
param_hash = {}
|
||||
if params[:only]
|
||||
param_hash[:only] = params[:only]
|
||||
else
|
||||
param_hash[:include] = [:artist]
|
||||
end
|
||||
if request.format.symbol == :xml
|
||||
param_hash[:root] = "artist-urls"
|
||||
end
|
||||
param_hash
|
||||
end
|
||||
|
||||
def artist_url_params
|
||||
permitted_params = %i[is_active]
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class ArtistsController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[:urls]
|
||||
[]
|
||||
else
|
||||
[:urls, :tag]
|
||||
end
|
||||
|
||||
@@ -76,7 +76,7 @@ class CommentsController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[:creator, :updater]
|
||||
[]
|
||||
elsif params[:format] == "atom"
|
||||
[:creator, :post]
|
||||
else
|
||||
|
||||
@@ -61,7 +61,7 @@ class NotesController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[:creator]
|
||||
[]
|
||||
else
|
||||
[:creator, :post]
|
||||
end
|
||||
|
||||
@@ -100,7 +100,7 @@ class PostsController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml", "atom"].include?(params[:format])
|
||||
[:uploader]
|
||||
[]
|
||||
else
|
||||
(CurrentUser.user.is_moderator? ? [:uploader] : [])
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ class UploadsController < ApplicationController
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[:uploader]
|
||||
[]
|
||||
else
|
||||
[:uploader, {post: [:uploader]}]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user