lib/dcmgr/models/account.rb in wakame-vdc-agents-10.11.0 vs lib/dcmgr/models/account.rb in wakame-vdc-agents-10.12.0

- old
+ new

@@ -1,42 +1,37 @@ # -*- coding: utf-8 -*- module Dcmgr::Models class Account < BaseNew taggable 'a' - with_timestamps - plugin :single_table_inheritance, :uuid, :model_map=>{} - plugin :subclasses - # pk has to be overwritten by the STI subclasses. unrestrict_primary_key DISABLED=0 ENABLED=1 inheritable_schema do String :description, :size=>100 Fixnum :enabled, :default=>ENABLED, :null=>false end + with_timestamps - one_to_many :tags + one_to_many :tags, :dataset=>lambda { Tag.filter(:account_id=>self.canonical_uuid); } + # sti plugin has to be loaded at lower position. + plugin :subclasses + plugin :single_table_inheritance, :uuid, :model_map=>{} + + def disable? self.enabled == DISABLED end def enable? self.enabled == ENABLED end - def to_hash_document - h = self.values.dup - h[:id] = h[:uuid] = self.canonical_uuid - h - end - - # STI class variable setter, getter methods. class << self def default_values @default_values ||= {} end @@ -91,9 +86,21 @@ pk 100 uuid '00000000' description 'datacenter system account' # DatacenterAccount never be disabled + def before_save + super + self.enabled = Account::ENABLED + end + end + + SystemAccount.define_account(:SharedPoolAccount) do + pk 101 + uuid 'shpoolxx' + description 'system account for shared resources' + + # SahredPoolAccount is always enabled. def before_save super self.enabled = Account::ENABLED end end