def read
begin
node = Node.find(params[:id])
- if node.visible
+ if node.visible?
response.headers['Last-Modified'] = node.timestamp.rfc822
render :text => node.to_xml.to_s, :content_type => "text/xml"
else
if !relation.preconditions_ok?
render :text => "", :status => :precondition_failed
else
- relation.version = 0
- relation.user_id = @user.id
+ relation.version = 0
+ #relation.user_id = @user.id
relation.save_with_history!
- render :text => relation.id.to_s, :content_type => "text/plain"
+ render :text => relation.id.to_s, :content_type => "text/plain"
end
else
render :nothing => true, :status => :bad_request
new_relation = Relation.from_xml(request.raw_post)
if new_relation and new_relation.id == relation.id
- relation.update_from new_relation, user
+ relation.update_from new_relation, @user
render :text => relation.version.to_s, :content_type => "text/plain"
else
render :nothing => true, :status => :bad_request
has_many :old_relations
validates_presence_of :user_id, :created_at, :open
+ validates_inclusion_of :open, :in => [ true, false ]
# Use a method like this, so that we can easily change how we
# determine whether a changeset is open, without breaking code in at
include GeoRecord
set_table_name 'current_nodes'
-
+
validates_presence_of :changeset_id, :timestamp
validates_inclusion_of :visible, :in => [ true, false ]
validates_numericality_of :latitude, :longitude
el1['id'] = self.id.to_s
el1['lat'] = self.lat.to_s
el1['lon'] = self.lon.to_s
-
+ el1['version'] = self.version.to_s
+ el1['changeset'] = self.changeset_id.to_s
+
user_display_name_cache = {} if user_display_name_cache.nil?
if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
def self.from_relation(relation)
old_relation = OldRelation.new
old_relation.visible = relation.visible
- old_relation.user_id = relation.user_id
+ old_relation.changeset_id = relation.changeset_id
old_relation.timestamp = relation.timestamp
old_relation.id = relation.id
old_relation.version = relation.version
el1['timestamp'] = self.timestamp.xmlschema
el1['user'] = self.user.display_name if self.user.data_public?
el1['version'] = self.version.to_s
+ el1['changeset'] = self.changeset_id.to_s
self.old_members.each do |member|
e = XML::Node.new 'member'
end
relation.version = pt['version']
+ relation.changeset_id = pt['changeset']
if create
relation.timestamp = Time.now
relation.visible = true
else
if pt['timestamp']
- relation.timestamp = Time.parse(pt['timestamp'])
+ relation.timestamp = Time.parse(pt['timestamp'])
end
end
el1['visible'] = self.visible.to_s
el1['timestamp'] = self.timestamp.xmlschema
el1['version'] = self.version.to_s
+ el1['changeset'] = self.changeset_id.to_s
user_display_name_cache = {} if user_display_name_cache.nil?
- if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+ if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
# use the cache if available
elsif self.user.data_public?
- user_display_name_cache[self.user_id] = self.user.display_name
+ user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
else
- user_display_name_cache[self.user_id] = nil
+ user_display_name_cache[self.changeset.user_id] = nil
end
- el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+ el1['user'] = user_display_name_cache[self.changeset.user_id] unless user_display_name_cache[self.changeset.user_id].nil?
self.relation_members.each do |member|
p=0
def delete_with_history(user)
if self.visible
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='relation' and member_id=?", self.id ])
- raise OSM::APIPreconditionFailedError.new
+ raise OSM::APIPreconditionFailedError.new
else
- self.user_id = user.id
- self.tags = []
- self.members = []
- self.visible = false
- save_with_history!
+ #self.user_id = user.id
+ # FIXME we need to deal with changeset here, which is probably already dealt with
+ self.tags = []
+ self.members = []
+ self.visible = false
+ save_with_history!
end
else
raise OSM::APIAlreadyDeletedError.new
raise OSM::APIPreconditionFailedError.new
elsif new_relation.version != version
raise OSM::APIVersionMismatchError.new(new_relation.version, version)
+ elsif new_relation.changeset.user_id != user.id
+ raise OSM::APIUserChangesetMismatchError.new
+ elsif not new_relation.changeset.open?
+ raise OSM::APIChangesetAlreadyClosedError.new
else
- self.user_id = user.id
+ # FIXME need to deal with changeset etc
+ #self.user_id = user.id
+ self.changeset = new_relation.changeset
self.tags = new_relation.tags
self.members = new_relation.members
self.visible = true
el1['visible'] = self.visible.to_s
el1['timestamp'] = self.timestamp.xmlschema
el1['version'] = self.version.to_s
+ el1['changeset'] = self.changeset_id.to_s
user_display_name_cache = {} if user_display_name_cache.nil?
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
- #database: openstreetmap
- #username: openstreetmap
- #password: openstreetmap
- database: osm_test
- username: osm_test
- password: osm_test
+ database: openstreetmap
+ username: openstreetmap
+ password: openstreetmap
host: localhost
# Warning: The database defined as 'test' will be erased and
end
end
+ # Raised when the user logged in isn't the same as the changeset
+ class APIUserChangesetMismatchError < APIError
+ def render_opts
+ { :text => "The user doesn't own that changeset", :status => :conflict }
+ end
+ end
+
+ # Raised when the changeset provided is already closed
+ class APIChangesetAlreadyClosedError < APIError
+ def render_opts
+ { :text => "The supplied changeset has already been closed", :status => :conflict }
+ end
+ end
+
# Raised when the provided version is not equal to the latest in the db.
class APIVersionMismatchError < APIError
def initialize(provided, latest)