- Changeset.transaction do
- while p.read == 1
- break if p.node_type == 15 # end element
- next unless p.node_type == 1 # element
-
- case p.name
- when 'create':
- while p.read == 1
- break if p.node_type == 15 # end element
- next unless p.node_type == 1 # element
-
- case p.name
- when 'node':
- elem = XML::Node.new 'node'
- node = Node.from_xml_node(p.expand, true)
- elem['old_id'] = p.expand['id']
- create_prim node_ids, node, p.expand
- elem['new_id'] = node.id.to_s
- elem['new_version'] = node.version.to_s
- root << elem
- when 'way':
- elem = XML::Node.new 'way'
- way = Way.from_xml_node(p.expand, true)
- elem['old_id'] = p.expand['id']
- fix_way(way, node_ids)
- raise OSM::APIPreconditionFailedError.new if !way.preconditions_ok?
- create_prim way_ids, way, p.expand
- elem['new_id'] = way.id.to_s
- elem['new_version'] = way.version.to_s
- root << elem
- when 'relation':
- elem = XML::Node.new 'relation'
- relation = Relation.from_xml_node(p.expand, true)
- elem['old_id'] = p.expand['id']
- fix_rel(relation, ids)
- raise OSM::APIPreconditionFailedError.new if !relation.preconditions_ok?
- create_prim rel_ids, relation, p.expand
- elem['new_id'] = relation.id.to_s
- elem['new_version'] = relation.version.to_s
- root << elem
- end
- end
- when 'modify':
- while p.read == 1
- break if p.node_type == 15 # end element
- next unless p.node_type == 1 # element
-
- case p.name
- when 'node':
- elem = XML::Node.new 'node'
- new_node = Node.from_xml_node(p.expand)
- node = Node.find(new_node.id)
- node.update_from new_node, @user
- elem['old_id'] = elem['new_id'] = node.id.to_s
- elem['new_version'] = node.version.to_s
- root << elem
- when 'way':
- elem = XML::Node.new 'way'
- new_way = Way.from_xml_node(p.expand)
- way = Way.find(new_way.id)
- way.update_from new_way, @user
- elem['old_id'] = elem['new_id'] = way.id.to_s
- elem['new_version'] = way.version.to_s
- root << elem
- when 'relation':
- elem = XML::Node.new 'relation'
- new_relation = Relation.from_xml_node(p.expand)
- relation = Relation.find(new_relation.id)
- relation.update_from new_relation, @user
- elem['old_id'] = elem['new_id'] = relation.id.to_s
- elem['new_version'] = relation.version.to_s
- root << elem
- end
- end
- when 'delete':
- while p.read == 1
- break if p.node_type == 15 # end element
- next unless p.node_type == 1 # element
-
- case p.name
- when 'node':
- elem = XML::Node.new 'node'
- node = Node.find(p.expand['id'])
- node.delete_with_history(@user)
- elem['old_id'] = elem['new_id'] = node.id.to_s
- elem['new_version'] = node.version.to_s
- root << elem
- when 'way':
- elem = XML::Node.new 'way'
- way = Way.find(p.expand['id'])
- way.delete_with_history(@user)
- elem['old_id'] = elem['new_id'] = way.id.to_s
- elem['new_version'] = way.version.to_s
- root << elem
- when 'relation':
- elem = XML::Node.new 'relation'
- relation = Relation.find(p.expand['id'])
- relation.delete_with_history(@user)
- elem['old_id'] = elem['new_id'] = relation.id.to_s
- elem['new_version'] = relation.version.to_s
- root << elem
- end
- end
- end
+ # should be able to get changesets of public users only, or
+ # our own changesets regardless of public-ness.
+ unless u.data_public?
+ # get optional user auth stuff so that users can see their own
+ # changesets if they're non-public
+ setup_user_auth
+
+ raise OSM::APINotFoundError if @user.nil? or @user.id != u.id
+ end
+ return ['user_id = ?', u.id]
+ else
+ return nil
+ end
+ end
+
+ ##
+ # restrict changes to those closed during a particular time period
+ def conditions_time(time)
+ unless time.nil?
+ # if there is a range, i.e: comma separated, then the first is
+ # low, second is high - same as with bounding boxes.
+ if time.count(',') == 1
+ # check that we actually have 2 elements in the array
+ times = time.split(/,/)
+ raise OSM::APIBadUserInput.new("bad time range") if times.size != 2
+
+ from, to = times.collect { |t| DateTime.parse(t) }
+ return ['closed_at >= ? and created_at <= ?', from, to]
+ else
+ # if there is no comma, assume its a lower limit on time
+ return ['closed_at >= ?', DateTime.parse(time)]