From 8988f9cde85dca995d109ee3b6d333768a0c1222 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 10 May 2017 16:58:40 -0500 Subject: [PATCH 1/2] /forum_topics.json: add `search[id]=` param. --- app/models/forum_topic.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 668e809b9..b6f7c7f3f 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -72,6 +72,10 @@ class ForumTopic < ActiveRecord::Base q = permitted return q if params.blank? + if params[:id].present? + q = q.where(id: params[:id].split(",").map(&:to_i)) + end + if params[:mod_only].present? q = q.where("min_level >= ?", MIN_LEVELS[:Moderator]) end From 02b3622f1236baad7699cf414ee3f7aa0f966322 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 14 May 2017 12:38:39 -0500 Subject: [PATCH 2/2] api: allow search[*_id] params to accept lists of ids in more places. --- app/models/artist_commentary.rb | 2 +- app/models/artist_version.rb | 4 ++-- app/models/note.rb | 4 ++-- app/models/note_version.rb | 6 +++--- app/models/pool.rb | 2 +- app/models/pool_archive.rb | 4 ++-- app/models/post_appeal.rb | 4 ++-- app/models/post_archive.rb | 4 ++-- app/models/post_flag.rb | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index 65901d282..3f60b5c49 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -30,7 +30,7 @@ class ArtistCommentary < ActiveRecord::Base end if params[:post_id].present? - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:original_present] == "yes" diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index c602c3294..becdd27d3 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -26,11 +26,11 @@ class ArtistVersion < ActiveRecord::Base end if params[:updater_id].present? - q = q.for_user(params[:updater_id].to_i) + q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i)) end if params[:artist_id].present? - q = q.where("artist_id = ?", params[:artist_id].to_i) + q = q.where(artist_id: params[:artist_id].split(",").map(&:to_i)) end params[:order] ||= params.delete(:sort) diff --git a/app/models/note.rb b/app/models/note.rb index 57418f6ea..a81d3b125 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -56,7 +56,7 @@ class Note < ActiveRecord::Base end if params[:post_id].present? - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:post_tags_match].present? @@ -68,7 +68,7 @@ class Note < ActiveRecord::Base end if params[:creator_id].present? - q = q.where("creator_id = ?", params[:creator_id].to_i) + q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i)) end q diff --git a/app/models/note_version.rb b/app/models/note_version.rb index ec7283d8f..d30f9d97c 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -9,15 +9,15 @@ class NoteVersion < ActiveRecord::Base params = {} if params.blank? if params[:updater_id] - q = q.where("updater_id = ?", params[:updater_id].to_i) + q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i)) end if params[:post_id] - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:note_id] - q = q.where("note_id = ?", params[:note_id].to_i) + q = q.where(note_id: params[:note_id].split(",").map(&:to_i)) end q diff --git a/app/models/pool.rb b/app/models/pool.rb index d051689d6..e99eb910c 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -71,7 +71,7 @@ class Pool < ActiveRecord::Base end if params[:creator_id].present? - q = q.where("creator_id = ?", params[:creator_id].to_i) + q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i)) end if params[:is_active] == "true" diff --git a/app/models/pool_archive.rb b/app/models/pool_archive.rb index 4bd8ad3ef..7cc654966 100644 --- a/app/models/pool_archive.rb +++ b/app/models/pool_archive.rb @@ -19,7 +19,7 @@ class PoolArchive < ActiveRecord::Base return q if params.blank? if params[:updater_id].present? - q = q.for_user(params[:updater_id].to_i) + q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i)) end if params[:updater_name].present? @@ -27,7 +27,7 @@ class PoolArchive < ActiveRecord::Base end if params[:pool_id].present? - q = q.where("pool_id = ?", params[:pool_id].to_i) + q = q.where(pool_id: params[:pool_id].split(",").map(&:to_i)) end q diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index 611044661..82eaccd3e 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -52,7 +52,7 @@ class PostAppeal < ActiveRecord::Base end if params[:creator_id].present? - q = q.for_user(params[:creator_id].to_i) + q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i)) end if params[:creator_name].present? @@ -60,7 +60,7 @@ class PostAppeal < ActiveRecord::Base end if params[:post_id].present? - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:post_tags_match].present? diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index 559077fc6..b6d3a5154 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -34,11 +34,11 @@ class PostArchive < ActiveRecord::Base end if params[:updater_id].present? - q = q.where("updater_id = ?", params[:updater_id].to_i) + q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i)) end if params[:post_id].present? - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:start_id].present? diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index ef355b23f..8b0e63f24 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -74,7 +74,7 @@ class PostFlag < ActiveRecord::Base end if params[:post_id].present? - q = q.where("post_id = ?", params[:post_id].to_i) + q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end if params[:post_tags_match].present?