Description:
moved root/roles creation from migration to seed.rb
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r276:d30b9a9e9085 - - 3 files changed: 67 inserted, 78 deleted

@@ -1,16 +1,3
1 -
2 - def create_configuration_key(key,
3 - value_type,
4 - default_value,
5 - description='')
6 - conf = (Configuration.find_by_key(key) ||
7 - Configuration.new(:key => key,
8 - :value_type => value_type,
9 - :value => default_value))
10 - conf.description = description
11 - conf.save
12 - end
13 -
14 1 CONFIGURATIONS =
15 2 [
16 3 {
@@ -111,6 +98,20
111 98 }
112 99 ]
113 100
101 +
102 + def create_configuration_key(key,
103 + value_type,
104 + default_value,
105 + description='')
106 + conf = (Configuration.find_by_key(key) ||
107 + Configuration.new(:key => key,
108 + :value_type => value_type,
109 + :value => default_value))
110 + conf.description = description
111 + conf.save
112 + end
113 +
114 + def seed_config
114 115 CONFIGURATIONS.each do |conf|
115 116 if conf.has_key? :description
116 117 desc = conf[:description]
@@ -122,3 +123,56
122 123 conf[:default_value],
123 124 desc)
124 125 end
126 + end
127 +
128 + def seed_roles
129 + return if Role.find_by_name('admin')
130 +
131 + role = Role.create(:name => 'admin')
132 + user_admin_right = Right.create(:name => 'user_admin',
133 + :controller => 'user_admin',
134 + :action => 'all')
135 + problem_admin_right = Right.create(:name=> 'problem_admin',
136 + :controller => 'problems',
137 + :action => 'all')
138 +
139 + graders_right = Right.create(:name => 'graders_admin',
140 + :controller => 'graders',
141 + :action => 'all')
142 +
143 + role.rights << user_admin_right;
144 + role.rights << problem_admin_right;
145 + role.rights << graders_right;
146 + role.save
147 + end
148 +
149 + def seed_root
150 + return if User.find_by_login('root')
151 +
152 + root = User.new(:login => 'root',
153 + :full_name => 'Administrator',
154 + :alias => 'root')
155 + root.password = 'ioionrails';
156 +
157 + class << root
158 + public :encrypt_new_password
159 + def valid?
160 + true
161 + end
162 + end
163 +
164 + root.encrypt_new_password
165 +
166 + root.roles << Role.find_by_name('admin')
167 +
168 + root.activated = true
169 + root.save
170 + end
171 +
172 + def seed_users_and_roles
173 + seed_roles
174 + seed_root
175 + end
176 +
177 + seed_config
178 + seed_users_and_roles
deleted file
deleted file
You need to be logged in to leave comments. Login now