app/models/table.rb
# Core validation method that is automatically called before create and save
Core validation method that is automatically called before create and save
Core validation method that is automatically called before create and save
def validate
    super
    validates_unique [:name, :user_id], :message => 'is already taken'
    errors.add(:user_id, "can't be blank") if user_id.blank?
    errors.add(
      :name, "is a reserved keyword, please choose a different one"
    ) if self.name == 'layergroup'
    errors.add(:privacy, 'has an invalid value') if privacy != PRIVATE && privacy != PUBLIC
    if !self.owner.try(:private_tables_enabled)
      if self.new? && privacy == PRIVATE
        errors.add(:privacy, 'unauthorized to create private tables')
      end
      if !self.new? && privacy == PRIVATE && self.changed_columns.include?(:privacy)
        errors.add(:privacy, 'unauthorized to modify privacy status to private')
      end
    end
  end
def validate super validates_unique [ :name , :user_id ] , :message => 'is already taken' errors . add ( :user_id , "can't be blank" ) if user_id . blank? errors . add ( :name , "is a reserved keyword, please choose a different one" ) if self . name == 'layergroup' errors . add ( :privacy , 'has an invalid value' ) if privacy != PRIVATE && privacy != PUBLIC if ! self . owner . try ( :private_tables_enabled ) if self . new? && privacy == PRIVATE errors . add ( :privacy , 'unauthorized to create private tables' ) end if ! self . new? && privacy == PRIVATE && self . changed_columns . include? ( :privacy ) errors . add ( :privacy , 'unauthorized to modify privacy status to private' ) end end end
Core validation method that is automatically called before create and save
Core validation method that is automatically called before create and save
## SANITY CHECKS # userid and table name tuple must be unique # tables must have a user # privacy setting must be a sane value # Branch if owner dows not have private table privileges # If it's a new table and the user is trying to make it private # if the table exists, is private, but the owner no longer has private privalidges # basically, this should never happen.