Browse Source

validate domain ownership

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
d8b89042b4
  1. 9
      app/models/domain.rb
  2. 5
      db/migrate/20111014194447_index_domains_user_id.rb

9
app/models/domain.rb

@ -34,6 +34,15 @@ class Domain < ActiveRecord::Base
:minimum => 2, :maximum => 10, :message => "must have be at least 2, at most 10"}
validates_associated :records
validates :user_id, :presence => true
validate do # domain ownership
segments = name.split('.')
if segments.size > 2
parent = segments[1..-1].join('.')
unless Domain.exists?(:name => parent, :user_id => user_id)
errors.add :name, "issue, must create the domain named `#{parent}` first"
end
end
end
def slave?; self.type == 'SLAVE' end

5
db/migrate/20111014194447_index_domains_user_id.rb

@ -0,0 +1,5 @@
class IndexDomainsUserId < ActiveRecord::Migration
def change
add_index :domains, :user_id
end
end
Loading…
Cancel
Save