]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
adding changeset stuff for the data browser
[rails.git] / app / models / relation.rb
index c8ee89d374aa63a69a282dd1d2806c0ea1ee1090..436c1e32ef8693bf068429743000b38cfe8f4546 100644 (file)
@@ -1,6 +1,8 @@
 class Relation < ActiveRecord::Base
   require 'xml/libxml'
   
+  include ConsistencyValidations
+  
   set_table_name 'current_relations'
 
   belongs_to :changeset
@@ -75,7 +77,7 @@ class Relation < ActiveRecord::Base
     
     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?
+    elsif self.changeset.user.data_public?
       user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
     else
       user_display_name_cache[self.changeset.user_id] = nil
@@ -180,6 +182,11 @@ class Relation < ActiveRecord::Base
 
   def add_tag_keyval(k, v)
     @tags = Hash.new unless @tags
+
+    # duplicate tags are now forbidden, so we can't allow values
+    # in the hash to be overwritten.
+    raise OSM::APIDuplicateTagsError.new if @tags.include? k
+
     @tags[k] = v
   end
 
@@ -249,6 +256,16 @@ class Relation < ActiveRecord::Base
     self.visible = true
     save_with_history!
   end
+  
+  def create_with_history(user)
+    check_create_consistency(self, user)
+    if !self.preconditions_ok?
+      raise OSM::APIPreconditionFailedError.new
+    end
+    self.version = 0
+    self.visible = true
+    save_with_history!
+  end
 
   def preconditions_ok?
     # These are hastables that store an id in the index of all