Add changeset comment search api with filtering by author and time
This commit is contained in:
parent
bd278a07fe
commit
1f59507e78
8 changed files with 91 additions and 14 deletions
|
@ -11,6 +11,7 @@ class ApiAbility
|
|||
can :create, Note unless user
|
||||
|
||||
can [:read, :download], Changeset
|
||||
can :read, ChangesetComment
|
||||
can :read, Tracepoint
|
||||
can :read, User
|
||||
can :read, [Node, Way, Relation, OldNode, OldWay, OldRelation]
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
module Api
|
||||
class ChangesetCommentsController < ApiController
|
||||
before_action :check_api_writable
|
||||
before_action :authorize
|
||||
include QueryMethods
|
||||
|
||||
before_action :check_api_writable, :except => [:index]
|
||||
before_action :authorize, :except => [:index]
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
@ -9,6 +11,15 @@ module Api
|
|||
|
||||
before_action :set_request_formats
|
||||
|
||||
##
|
||||
# show all comments or search for a subset
|
||||
def index
|
||||
@comments = ChangesetComment.includes(:author).where(:visible => true).order("created_at DESC")
|
||||
@comments = query_conditions_time(@comments)
|
||||
@comments = query_conditions_user(@comments, :author)
|
||||
@comments = query_limit(@comments)
|
||||
end
|
||||
|
||||
##
|
||||
# Add a comment to a changeset
|
||||
def create
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
cattrs = {
|
||||
"id" => changeset_comment.id,
|
||||
"date" => changeset_comment.created_at.xmlschema,
|
||||
"visible" => changeset_comment.visible
|
||||
}
|
||||
if changeset_comment.author.data_public?
|
||||
cattrs["uid"] = changeset_comment.author.id
|
||||
cattrs["user"] = changeset_comment.author.display_name
|
||||
end
|
||||
xml.comment(cattrs) do |comment_xml_node|
|
||||
comment_xml_node.text(changeset_comment.body)
|
||||
end
|
7
app/views/api/changeset_comments/index.xml.builder
Normal file
7
app/views/api/changeset_comments/index.xml.builder
Normal file
|
@ -0,0 +1,7 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
|
||||
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||
@comments.includes(:author).each do |comment|
|
||||
osm << render(comment)
|
||||
end
|
||||
end
|
|
@ -27,18 +27,7 @@ xml.changeset(attrs) do |changeset_xml_node|
|
|||
if @comments
|
||||
changeset_xml_node.discussion do |discussion_xml_node|
|
||||
@comments.each do |comment|
|
||||
cattrs = {
|
||||
"id" => comment.id,
|
||||
"date" => comment.created_at.xmlschema,
|
||||
"visible" => comment.visible
|
||||
}
|
||||
if comment.author.data_public?
|
||||
cattrs["uid"] = comment.author.id
|
||||
cattrs["user"] = comment.author.display_name
|
||||
end
|
||||
discussion_xml_node.comment(cattrs) do |comment_xml_node|
|
||||
comment_xml_node.text(comment.body)
|
||||
end
|
||||
discussion_xml_node << render(comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue