gary (owner)

Revisions

gist: 38036 Download_button fork
public
Public Clone URL: git://gist.github.com/38036.git
Embed All Files: show embed
bootstrap.rake #
1
2
3
4
5
6
7
8
9
10
11
12
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace :db do
 
  desc "Bootstrap the application, readying it for use."
  task :bootstrap => ['db:schema:load',
                      'db:users:create_admin',
                      'db:users:create_user'] do
    puts "* #{configatron.name} bootstrap process complete."
  end
 
  namespace :users do
    task :create_admin => :environment do
      unless User.exists?(:login => 'ccadmin')
        do_anything = Right.create(:name => 'su',
                                   :action => '.*',
                                   :controller => '.*'
                                   )
 
        su = Role.create(:name => 'Super User')
        su.rights << do_anything
        su.save
 
        admin = User.create(:login => 'ccadmin',
                            :first_name => configatron.name,
                            :last_name => 'Administrator',
                            :email => "webmaster@#{URI.parse(configatron.url).host}",
                            :password => 'password',
                            :password_confirmation => 'password'
                            )
        admin.roles << su
        admin.save
 
        admin_name = "#{admin.first_name} #{admin.last_name}"
        puts "* #{admin_name}, Super User role and rights created."
      else
        puts '* Adminstrator already exists!'
      end
    end
 
    task :create_user => :environment do
      unless Role.exists?(:name => 'User')
        content_access = Right.create(:name => 'Access Conference Content',
                                      :controller => '(?:organization|conference|(?:purchased_)?video)s',
                                      :action => '(?:show|index)'
                                      )
 
        use_cart = Right.create(:name => 'Use Shopping Cart',
                                :controller => 'store',
                                :action => '(?:add_to|remove_from|empty)cart'
                                )
 
        make_payments = Right.create(:name => 'Make Payments',
                                     :controller => 'payments',
                                     :action => '.*'
                                     )
 
        user = Role.create(:name => 'User')
        [content_access,
         use_cart,
         make_payments].each { |action| user.rights << action }
        user.save
 
        puts '* User role and associated rights created.'
      else
        puts '* User role/rights already exist!'
      end
    end
 
  end
 
end