Move query notes by user value to mixin
This commit is contained in:
parent
500c1bddf2
commit
bd278a07fe
3 changed files with 37 additions and 13 deletions
|
@ -256,19 +256,8 @@ module Api
|
||||||
@notes = bbox_condition(@notes)
|
@notes = bbox_condition(@notes)
|
||||||
|
|
||||||
# Add any user filter
|
# Add any user filter
|
||||||
if params[:display_name] || params[:user]
|
user = query_conditions_user_value
|
||||||
if params[:display_name]
|
@notes = @notes.joins(:comments).where(:note_comments => { :author_id => user }) if user
|
||||||
@user = User.find_by(:display_name => params[:display_name])
|
|
||||||
|
|
||||||
raise OSM::APIBadUserInput, "User #{params[:display_name]} not known" unless @user
|
|
||||||
else
|
|
||||||
@user = User.find_by(:id => params[:user])
|
|
||||||
|
|
||||||
raise OSM::APIBadUserInput, "User #{params[:user]} not known" unless @user
|
|
||||||
end
|
|
||||||
|
|
||||||
@notes = @notes.joins(:comments).where(:note_comments => { :author_id => @user })
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add any text filter
|
# Add any text filter
|
||||||
if params[:q]
|
if params[:q]
|
||||||
|
|
|
@ -3,6 +3,33 @@ module QueryMethods
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
##
|
||||||
|
# Filter the resulting items by user
|
||||||
|
def query_conditions_user(items, filter_property)
|
||||||
|
user = query_conditions_user_value
|
||||||
|
items = items.where(filter_property => user) if user
|
||||||
|
items
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Get user value for query filtering by user
|
||||||
|
# Raises OSM::APIBadUserInput if user not found like notes api does, changesets api raises OSM::APINotFoundError instead
|
||||||
|
def query_conditions_user_value
|
||||||
|
if params[:display_name] || params[:user]
|
||||||
|
if params[:display_name]
|
||||||
|
user = User.find_by(:display_name => params[:display_name])
|
||||||
|
|
||||||
|
raise OSM::APIBadUserInput, "User #{params[:display_name]} not known" unless user
|
||||||
|
else
|
||||||
|
user = User.find_by(:id => params[:user])
|
||||||
|
|
||||||
|
raise OSM::APIBadUserInput, "User #{params[:user]} not known" unless user
|
||||||
|
end
|
||||||
|
|
||||||
|
user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Restrict the resulting items to those created during a particular time period
|
# Restrict the resulting items to those created during a particular time period
|
||||||
# Using 'to' requires specifying 'from' as well for historical reasons
|
# Using 'to' requires specifying 'from' as well for historical reasons
|
||||||
|
|
|
@ -1066,6 +1066,14 @@ module Api
|
||||||
assert_select "gpx", :count => 1 do
|
assert_select "gpx", :count => 1 do
|
||||||
assert_select "wpt", :count => 1
|
assert_select "wpt", :count => 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user2 = create(:user)
|
||||||
|
get search_api_notes_path(:user => user2.id, :format => "xml")
|
||||||
|
assert_response :success
|
||||||
|
assert_equal "application/xml", @response.media_type
|
||||||
|
assert_select "osm", :count => 1 do
|
||||||
|
assert_select "note", :count => 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_search_by_time_success
|
def test_search_by_time_success
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue