Description:
added admin users management
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r233:ebadb70a03ab - - 3 files changed: 61 inserted, 0 deleted
@@ -0,0 +1,25 | |||||
|
|
1 | + %h1 Administrators | ||
|
|
2 | + | ||
|
|
3 | + %table | ||
|
|
4 | + %tr | ||
|
|
5 | + %th # | ||
|
|
6 | + %th Login | ||
|
|
7 | + %th Full name | ||
|
|
8 | + %th | ||
|
|
9 | + - @admins.each_with_index do |user, i| | ||
|
|
10 | + %tr | ||
|
|
11 | + %td= i+1 | ||
|
|
12 | + %td= user.login | ||
|
|
13 | + %td= user.full_name | ||
|
|
14 | + %td | ||
|
|
15 | + - if user.login!='root' | ||
|
|
16 | + = link_to '[revoke]', :action => 'revoke_admin', :id => user.id | ||
|
|
17 | + %hr | ||
|
|
18 | + | ||
|
|
19 | + - form_tag :action => 'grant_admin' do | ||
|
|
20 | + Grant admin permission to: | ||
|
|
21 | + = text_field_tag 'login' | ||
|
|
22 | + = submit_tag 'Grant' | ||
|
|
23 | + | ||
|
|
24 | + %hr/ | ||
|
|
25 | + = link_to '[go back to index]', :action => 'index' |
@@ -130,48 +130,83 | |||||
|
130 | def import |
|
130 | def import |
|
131 | if params[:file]=='' |
|
131 | if params[:file]=='' |
|
132 | flash[:notice] = 'Error importing no file' |
|
132 | flash[:notice] = 'Error importing no file' |
|
133 | redirect_to :action => 'list' and return |
|
133 | redirect_to :action => 'list' and return |
|
134 | end |
|
134 | end |
|
135 | import_from_file(params[:file]) |
|
135 | import_from_file(params[:file]) |
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | def random_all_passwords |
|
138 | def random_all_passwords |
|
139 | users = User.find(:all) |
|
139 | users = User.find(:all) |
|
140 | @prefix = params[:prefix] || '' |
|
140 | @prefix = params[:prefix] || '' |
|
141 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
141 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
142 | @changed = false |
|
142 | @changed = false |
|
143 | if request.request_method == :post |
|
143 | if request.request_method == :post |
|
144 | @non_admin_users.each do |user| |
|
144 | @non_admin_users.each do |user| |
|
145 | password = random_password |
|
145 | password = random_password |
|
146 | user.password = password |
|
146 | user.password = password |
|
147 | user.password_confirmation = password |
|
147 | user.password_confirmation = password |
|
148 | user.save |
|
148 | user.save |
|
149 | end |
|
149 | end |
|
150 | @changed = true |
|
150 | @changed = true |
|
151 | end |
|
151 | end |
|
152 | end |
|
152 | end |
|
153 |
|
153 | ||
|
|
154 | + # admin management | ||
|
|
155 | + | ||
|
|
156 | + def admin | ||
|
|
157 | + @admins = User.find(:all).find_all {|user| user.admin? } | ||
|
|
158 | + end | ||
|
|
159 | + | ||
|
|
160 | + def grant_admin | ||
|
|
161 | + login = params[:login] | ||
|
|
162 | + user = User.find_by_login(login) | ||
|
|
163 | + if user!=nil | ||
|
|
164 | + admin_role = Role.find_by_name('admin') | ||
|
|
165 | + user.roles << admin_role | ||
|
|
166 | + else | ||
|
|
167 | + flash[:notice] = 'Unknown user' | ||
|
|
168 | + end | ||
|
|
169 | + flash[:notice] = 'User added as admins' | ||
|
|
170 | + redirect_to :action => 'admin' | ||
|
|
171 | + end | ||
|
|
172 | + | ||
|
|
173 | + def revoke_admin | ||
|
|
174 | + user = User.find(params[:id]) | ||
|
|
175 | + if user==nil | ||
|
|
176 | + flash[:notice] = 'Unknown user' | ||
|
|
177 | + redirect_to :action => 'admin' and return | ||
|
|
178 | + elsif user.login == 'root' | ||
|
|
179 | + flash[:notice] = 'You cannot revoke admisnistrator permission from root.' | ||
|
|
180 | + redirect_to :action => 'admin' and return | ||
|
|
181 | + end | ||
|
|
182 | + | ||
|
|
183 | + admin_role = Role.find_by_name('admin') | ||
|
|
184 | + user.roles.delete(admin_role) | ||
|
|
185 | + flash[:notice] = 'User permission revoked' | ||
|
|
186 | + redirect_to :action => 'admin' | ||
|
|
187 | + end | ||
|
|
188 | + | ||
|
154 | protected |
|
189 | protected |
|
155 |
|
190 | ||
|
156 | def random_password(length=5) |
|
191 | def random_password(length=5) |
|
157 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
192 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
158 | newpass = "" |
|
193 | newpass = "" |
|
159 | length.times { newpass << chars[rand(chars.size-1)] } |
|
194 | length.times { newpass << chars[rand(chars.size-1)] } |
|
160 | return newpass |
|
195 | return newpass |
|
161 | end |
|
196 | end |
|
162 |
|
197 | ||
|
163 | def import_from_file(f) |
|
198 | def import_from_file(f) |
|
164 | data_hash = YAML.load(f) |
|
199 | data_hash = YAML.load(f) |
|
165 | @import_log = "" |
|
200 | @import_log = "" |
|
166 |
|
201 | ||
|
167 | country_data = data_hash[:countries] |
|
202 | country_data = data_hash[:countries] |
|
168 | site_data = data_hash[:sites] |
|
203 | site_data = data_hash[:sites] |
|
169 | user_data = data_hash[:users] |
|
204 | user_data = data_hash[:users] |
|
170 |
|
205 | ||
|
171 | # import country |
|
206 | # import country |
|
172 | countries = {} |
|
207 | countries = {} |
|
173 | country_data.each_pair do |id,country| |
|
208 | country_data.each_pair do |id,country| |
|
174 | c = Country.find_by_name(country[:name]) |
|
209 | c = Country.find_by_name(country[:name]) |
|
175 | if c!=nil |
|
210 | if c!=nil |
|
176 | countries[id] = c |
|
211 | countries[id] = c |
|
177 | @import_log << "Found #{country[:name]}\n" |
|
212 | @import_log << "Found #{country[:name]}\n" |
@@ -8,48 +8,49 | |||||
|
8 | <td><label for="user_login">Login</label></td> |
|
8 | <td><label for="user_login">Login</label></td> |
|
9 | <td><label for="user_full_name">Full name</label></td> |
|
9 | <td><label for="user_full_name">Full name</label></td> |
|
10 | <td><label for="user_password">Password</label></td> |
|
10 | <td><label for="user_password">Password</label></td> |
|
11 | <td><label for="user_password_confirmation">Confirm</label></td> |
|
11 | <td><label for="user_password_confirmation">Confirm</label></td> |
|
12 | <td><label for="user_email">Email</label></td> |
|
12 | <td><label for="user_email">Email</label></td> |
|
13 | </tr> |
|
13 | </tr> |
|
14 | <tr> |
|
14 | <tr> |
|
15 | <td><%= text_field 'user', 'login', :size => 10 %></td> |
|
15 | <td><%= text_field 'user', 'login', :size => 10 %></td> |
|
16 | <td><%= text_field 'user', 'full_name', :size => 30 %></td> |
|
16 | <td><%= text_field 'user', 'full_name', :size => 30 %></td> |
|
17 | <td><%= password_field 'user', 'password', :size => 10 %></td> |
|
17 | <td><%= password_field 'user', 'password', :size => 10 %></td> |
|
18 | <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td> |
|
18 | <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td> |
|
19 | <td><%= text_field 'user', 'email', :size => 15 %></td> |
|
19 | <td><%= text_field 'user', 'email', :size => 15 %></td> |
|
20 | <td><%= submit_tag "Create" %></td> |
|
20 | <td><%= submit_tag "Create" %></td> |
|
21 | </tr></table> |
|
21 | </tr></table> |
|
22 | <% end %> |
|
22 | <% end %> |
|
23 | <br/> |
|
23 | <br/> |
|
24 | <b>Import from site management</b> |
|
24 | <b>Import from site management</b> |
|
25 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
25 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
26 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
26 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
27 | <% end %> |
|
27 | <% end %> |
|
28 | <br/> |
|
28 | <br/> |
|
29 | <b>What else: </b> |
|
29 | <b>What else: </b> |
|
30 | <%= link_to '[New user]', :action => 'new' %> |
|
30 | <%= link_to '[New user]', :action => 'new' %> |
|
31 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
31 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
|
32 | + <%= link_to '[View administrators]', :action => 'admin' %> | ||
|
32 | <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> |
|
33 | <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> |
|
33 | <%= link_to '[View active users]', :action => 'active' %> |
|
34 | <%= link_to '[View active users]', :action => 'active' %> |
|
34 |
|
35 | ||
|
35 | </div> |
|
36 | </div> |
|
36 |
|
37 | ||
|
37 | <table> |
|
38 | <table> |
|
38 | <tr> |
|
39 | <tr> |
|
39 | <% for column in User.content_columns %> |
|
40 | <% for column in User.content_columns %> |
|
40 | <% if !@hidden_columns.index(column.name) %> |
|
41 | <% if !@hidden_columns.index(column.name) %> |
|
41 | <th><%= column.human_name %></th> |
|
42 | <th><%= column.human_name %></th> |
|
42 | <% end %> |
|
43 | <% end %> |
|
43 | <% end %> |
|
44 | <% end %> |
|
44 | </tr> |
|
45 | </tr> |
|
45 |
|
46 | ||
|
46 | <% for user in @users %> |
|
47 | <% for user in @users %> |
|
47 | <tr> |
|
48 | <tr> |
|
48 | <% for column in User.content_columns %> |
|
49 | <% for column in User.content_columns %> |
|
49 | <% if !@hidden_columns.index(column.name) %> |
|
50 | <% if !@hidden_columns.index(column.name) %> |
|
50 | <td><%=h user.send(column.name) %></td> |
|
51 | <td><%=h user.send(column.name) %></td> |
|
51 | <% end %> |
|
52 | <% end %> |
|
52 | <% end %> |
|
53 | <% end %> |
|
53 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
54 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
54 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
55 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
55 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
56 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
You need to be logged in to leave comments.
Login now