Class: Ixtlan::Rails::Migrations

Inherits:
Object
  • Object
show all
Defined in:
lib/ixtlan/rails/migrations.rb

Constant Summary collapse

USER =

assume no namespaces !!!

Object.const_get(Ixtlan::Models::USER.sub(/^::/, ''))
GROUP =
Object.const_get(Ixtlan::Models::GROUP.sub(/^::/, ''))
LOCALE =
Object.const_get(Ixtlan::Models::LOCALE.sub(/^::/, ''))
DOMAIN =
Object.const_get(Ixtlan::Models::DOMAIN.sub(/^::/, ''))
CONFIGURATION =
Object.const_get(Ixtlan::Models::CONFIGURATION.sub(/^::/, ''))
TEXT =
Object.const_get(Ixtlan::Models::TEXT.sub(/^::/, ''))

Class Method Summary collapse

Class Method Details

.create_auditObject



79
80
81
# File 'lib/ixtlan/rails/migrations.rb', line 79

def self.create_audit
  Object.const_get(Ixtlan::Models::AUDIT.sub(/^::/, '')).auto_migrate! if Ixtlan::Models::AUDIT
end

.create_configurationObject



50
51
52
53
54
# File 'lib/ixtlan/rails/migrations.rb', line 50

def self.create_configuration
  Ixtlan::Models::ConfigurationLocale.auto_migrate!
  CONFIGURATION.auto_migrate!
  CONFIGURATION.create(:session_idle_timeout => 10, :keep_audit_logs => 3, :current_user => USER.first)
end

.create_domainObject



67
68
69
70
71
72
73
# File 'lib/ixtlan/rails/migrations.rb', line 67

def self.create_domain
  DOMAIN.auto_migrate!
  # get/create "every" domain
  DOMAIN.create(:name => DOMAIN::ALL, :current_user => User.first)
  
  Ixtlan::Models::DomainGroupUser.create(:group => Group.first, :user => USER.first, :domain => DOMAIN.every)
end

.create_localeObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/ixtlan/rails/migrations.rb', line 56

def self.create_locale
  LOCALE.auto_migrate!
  # get/create default locale
  LOCALE.create(:code => LOCALE::DEFAULT, :current_user => USER.first)
  # get/create "every" locale
  LOCALE.create(:code => LOCALE::ALL, :current_user => USER.first)
  
  # root user has access to ALL locales
  Ixtlan::Models::GroupLocaleUser.create(:group => Group.first, :user => USER.first, :locale => LOCALE.every)
end

.create_textObject



75
76
77
# File 'lib/ixtlan/rails/migrations.rb', line 75

def self.create_text
  TEXT.auto_migrate!
end

.create_userObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ixtlan/rails/migrations.rb', line 13

def self.create_user
  USER.auto_migrate!
  LOCALE.auto_migrate!
  GROUP.auto_migrate!
  Ixtlan::Models::GroupUser.auto_migrate!
  Ixtlan::Models::GroupLocaleUser.auto_migrate!
  Ixtlan::Models::DomainGroupUser.auto_migrate!

  u = USER.first
  if u.nil?
    u = USER.new(:login => 'root', :email => '[email protected]', :name => 'Superuser', :id => 1)
    u.created_at = DateTime.now
    u.updated_at = u.created_at
    u.created_by_id = 1
    u.updated_by_id = 1
    u.save!
  end
  u.reset_password
  u.current_user = u
  u.save

  g = GROUP.create(:name => 'root', :current_user => u)
  u.groups << g
  u.save
  
  a = USER.create(:login => 'admin', :email => '[email protected]', :name => 'Administrator', :id => 2, :current_user => u)
  a.reset_password
  a.save!      
  a.groups << GROUP.create(:name => 'admin', :current_user => u)
  a.save
 
  users = GROUP.create(:name => 'users', :current_user => u)
  locales = GROUP.create(:name => 'locales', :current_user => u)
  domains = GROUP.create(:name => 'domains', :current_user => u)
  File.open("root_#{RAILS_ENV}", 'w') { |f| f.puts "root\n#{u.password}\n\nadmin\n#{a.password}\n\n" }
end