Description:
sends mass emails
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r309:5760cdcf6707 - - 3 files changed: 63 inserted, 1 deleted
@@ -0,0 +1,19 | |||||
|
|
1 | + %h1 Send mass e-mails | ||
|
|
2 | + | ||
|
|
3 | + - form_tag :action => 'bulk_mail' do | ||
|
|
4 | + %b List recipients' login below; one per line. | ||
|
|
5 | + %br/ | ||
|
|
6 | + = text_area_tag 'login_list', nil, :rows => 7, :cols => 80 | ||
|
|
7 | + %br/ | ||
|
|
8 | + %b Subject: | ||
|
|
9 | + = text_field_tag 'subject', '', :size => 60 | ||
|
|
10 | + %br/ | ||
|
|
11 | + %b Email body: | ||
|
|
12 | + %br/ | ||
|
|
13 | + = text_area_tag 'email_body', nil, :rows => 11, :cols => 80 | ||
|
|
14 | + %br/ | ||
|
|
15 | + | ||
|
|
16 | + = submit_tag "Send mails", :confirm => 'Are you sure?' | ||
|
|
17 | + | ||
|
|
18 | + %hr/ | ||
|
|
19 | + = link_to '[go back to index]', :action => 'index' |
@@ -1,63 +1,66 | |||||
|
1 | class UserAdminController < ApplicationController |
|
1 | class UserAdminController < ApplicationController |
|
2 |
|
2 | ||
|
3 | include MailHelperMethods |
|
3 | include MailHelperMethods |
|
4 |
|
4 | ||
|
5 | before_filter :admin_authorization |
|
5 | before_filter :admin_authorization |
|
6 |
|
6 | ||
|
7 | def index |
|
7 | def index |
|
8 | list |
|
8 | list |
|
9 | render :action => 'list' |
|
9 | render :action => 'list' |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
12 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
13 | verify :method => :post, :only => [ :destroy, |
|
13 | verify :method => :post, :only => [ :destroy, |
|
14 | :create, :create_from_list, |
|
14 | :create, :create_from_list, |
|
15 |
- :update |
|
15 | + :update, |
|
|
16 | + :manage_contest, | ||
|
|
17 | + :bulk_mail | ||
|
|
18 | + ], | ||
|
16 | :redirect_to => { :action => :list } |
|
19 | :redirect_to => { :action => :list } |
|
17 |
|
20 | ||
|
18 | def list |
|
21 | def list |
|
19 | @user_count = User.count |
|
22 | @user_count = User.count |
|
20 | if params[:page] == 'all' |
|
23 | if params[:page] == 'all' |
|
21 | @users = User.all |
|
24 | @users = User.all |
|
22 | @paginated = false |
|
25 | @paginated = false |
|
23 | else |
|
26 | else |
|
24 | @users = User.paginate :page => params[:page] |
|
27 | @users = User.paginate :page => params[:page] |
|
25 | @paginated = true |
|
28 | @paginated = true |
|
26 | end |
|
29 | end |
|
27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
30 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | @contests = Contest.enabled |
|
31 | @contests = Contest.enabled |
|
29 | end |
|
32 | end |
|
30 |
|
33 | ||
|
31 | def active |
|
34 | def active |
|
32 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
35 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
33 | @users = [] |
|
36 | @users = [] |
|
34 | sessions.each do |session| |
|
37 | sessions.each do |session| |
|
35 | if session.data[:user_id] |
|
38 | if session.data[:user_id] |
|
36 | @users << User.find(session.data[:user_id]) |
|
39 | @users << User.find(session.data[:user_id]) |
|
37 | end |
|
40 | end |
|
38 | end |
|
41 | end |
|
39 | end |
|
42 | end |
|
40 |
|
43 | ||
|
41 | def show |
|
44 | def show |
|
42 | @user = User.find(params[:id]) |
|
45 | @user = User.find(params[:id]) |
|
43 | end |
|
46 | end |
|
44 |
|
47 | ||
|
45 | def new |
|
48 | def new |
|
46 | @user = User.new |
|
49 | @user = User.new |
|
47 | end |
|
50 | end |
|
48 |
|
51 | ||
|
49 | def create |
|
52 | def create |
|
50 | @user = User.new(params[:user]) |
|
53 | @user = User.new(params[:user]) |
|
51 | @user.activated = true |
|
54 | @user.activated = true |
|
52 | if @user.save |
|
55 | if @user.save |
|
53 | flash[:notice] = 'User was successfully created.' |
|
56 | flash[:notice] = 'User was successfully created.' |
|
54 | redirect_to :action => 'list' |
|
57 | redirect_to :action => 'list' |
|
55 | else |
|
58 | else |
|
56 | render :action => 'new' |
|
59 | render :action => 'new' |
|
57 | end |
|
60 | end |
|
58 | end |
|
61 | end |
|
59 |
|
62 | ||
|
60 | def create_from_list |
|
63 | def create_from_list |
|
61 | lines = params[:user_list] |
|
64 | lines = params[:user_list] |
|
62 |
|
65 | ||
|
63 | note = [] |
|
66 | note = [] |
@@ -256,96 +259,135 | |||||
|
256 | users << user |
|
259 | users << user |
|
257 | end |
|
260 | end |
|
258 | end |
|
261 | end |
|
259 |
|
262 | ||
|
260 | if params[:reset_timer] |
|
263 | if params[:reset_timer] |
|
261 | logout_users(users) |
|
264 | logout_users(users) |
|
262 | end |
|
265 | end |
|
263 |
|
266 | ||
|
264 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
267 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
265 | ' were successfully modified. ' |
|
268 | ' were successfully modified. ' |
|
266 | redirect_to :action => 'contest_management' |
|
269 | redirect_to :action => 'contest_management' |
|
267 | end |
|
270 | end |
|
268 |
|
271 | ||
|
269 | # admin management |
|
272 | # admin management |
|
270 |
|
273 | ||
|
271 | def admin |
|
274 | def admin |
|
272 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
275 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
273 | end |
|
276 | end |
|
274 |
|
277 | ||
|
275 | def grant_admin |
|
278 | def grant_admin |
|
276 | login = params[:login] |
|
279 | login = params[:login] |
|
277 | user = User.find_by_login(login) |
|
280 | user = User.find_by_login(login) |
|
278 | if user!=nil |
|
281 | if user!=nil |
|
279 | admin_role = Role.find_by_name('admin') |
|
282 | admin_role = Role.find_by_name('admin') |
|
280 | user.roles << admin_role |
|
283 | user.roles << admin_role |
|
281 | else |
|
284 | else |
|
282 | flash[:notice] = 'Unknown user' |
|
285 | flash[:notice] = 'Unknown user' |
|
283 | end |
|
286 | end |
|
284 | flash[:notice] = 'User added as admins' |
|
287 | flash[:notice] = 'User added as admins' |
|
285 | redirect_to :action => 'admin' |
|
288 | redirect_to :action => 'admin' |
|
286 | end |
|
289 | end |
|
287 |
|
290 | ||
|
288 | def revoke_admin |
|
291 | def revoke_admin |
|
289 | user = User.find(params[:id]) |
|
292 | user = User.find(params[:id]) |
|
290 | if user==nil |
|
293 | if user==nil |
|
291 | flash[:notice] = 'Unknown user' |
|
294 | flash[:notice] = 'Unknown user' |
|
292 | redirect_to :action => 'admin' and return |
|
295 | redirect_to :action => 'admin' and return |
|
293 | elsif user.login == 'root' |
|
296 | elsif user.login == 'root' |
|
294 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
297 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
295 | redirect_to :action => 'admin' and return |
|
298 | redirect_to :action => 'admin' and return |
|
296 | end |
|
299 | end |
|
297 |
|
300 | ||
|
298 | admin_role = Role.find_by_name('admin') |
|
301 | admin_role = Role.find_by_name('admin') |
|
299 | user.roles.delete(admin_role) |
|
302 | user.roles.delete(admin_role) |
|
300 | flash[:notice] = 'User permission revoked' |
|
303 | flash[:notice] = 'User permission revoked' |
|
301 | redirect_to :action => 'admin' |
|
304 | redirect_to :action => 'admin' |
|
302 | end |
|
305 | end |
|
303 |
|
306 | ||
|
|
307 | + # mass mailing | ||
|
|
308 | + | ||
|
|
309 | + def mass_mailing | ||
|
|
310 | + end | ||
|
|
311 | + | ||
|
|
312 | + def bulk_mail | ||
|
|
313 | + lines = params[:login_list] | ||
|
|
314 | + if !lines or lines.blank? | ||
|
|
315 | + flash[:notice] = 'You entered an empty list.' | ||
|
|
316 | + redirect_to :action => 'mass_mailing' and return | ||
|
|
317 | + end | ||
|
|
318 | + | ||
|
|
319 | + subject = params[:subject] | ||
|
|
320 | + if !subject or subject.blank? | ||
|
|
321 | + flash[:notice] = 'You entered an empty mail subject.' | ||
|
|
322 | + redirect_to :action => 'mass_mailing' and return | ||
|
|
323 | + end | ||
|
|
324 | + | ||
|
|
325 | + body = params[:email_body] | ||
|
|
326 | + if !body or body.blank? | ||
|
|
327 | + flash[:notice] = 'You entered an empty mail body.' | ||
|
|
328 | + redirect_to :action => 'mass_mailing' and return | ||
|
|
329 | + end | ||
|
|
330 | + | ||
|
|
331 | + note = [] | ||
|
|
332 | + users = [] | ||
|
|
333 | + lines.split("\n").each do |line| | ||
|
|
334 | + user = User.find_by_login(line.chomp) | ||
|
|
335 | + if user | ||
|
|
336 | + send_mail(user.email, subject, body) | ||
|
|
337 | + note << user.login | ||
|
|
338 | + end | ||
|
|
339 | + end | ||
|
|
340 | + | ||
|
|
341 | + flash[:notice] = 'User(s) ' + note.join(', ') + | ||
|
|
342 | + ' were successfully modified. ' | ||
|
|
343 | + redirect_to :action => 'mass_mailing' | ||
|
|
344 | + end | ||
|
|
345 | + | ||
|
304 | protected |
|
346 | protected |
|
305 |
|
347 | ||
|
306 | def random_password(length=5) |
|
348 | def random_password(length=5) |
|
307 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
349 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
308 | newpass = "" |
|
350 | newpass = "" |
|
309 | length.times { newpass << chars[rand(chars.size-1)] } |
|
351 | length.times { newpass << chars[rand(chars.size-1)] } |
|
310 | return newpass |
|
352 | return newpass |
|
311 | end |
|
353 | end |
|
312 |
|
354 | ||
|
313 | def import_from_file(f) |
|
355 | def import_from_file(f) |
|
314 | data_hash = YAML.load(f) |
|
356 | data_hash = YAML.load(f) |
|
315 | @import_log = "" |
|
357 | @import_log = "" |
|
316 |
|
358 | ||
|
317 | country_data = data_hash[:countries] |
|
359 | country_data = data_hash[:countries] |
|
318 | site_data = data_hash[:sites] |
|
360 | site_data = data_hash[:sites] |
|
319 | user_data = data_hash[:users] |
|
361 | user_data = data_hash[:users] |
|
320 |
|
362 | ||
|
321 | # import country |
|
363 | # import country |
|
322 | countries = {} |
|
364 | countries = {} |
|
323 | country_data.each_pair do |id,country| |
|
365 | country_data.each_pair do |id,country| |
|
324 | c = Country.find_by_name(country[:name]) |
|
366 | c = Country.find_by_name(country[:name]) |
|
325 | if c!=nil |
|
367 | if c!=nil |
|
326 | countries[id] = c |
|
368 | countries[id] = c |
|
327 | @import_log << "Found #{country[:name]}\n" |
|
369 | @import_log << "Found #{country[:name]}\n" |
|
328 | else |
|
370 | else |
|
329 | countries[id] = Country.new(:name => country[:name]) |
|
371 | countries[id] = Country.new(:name => country[:name]) |
|
330 | countries[id].save |
|
372 | countries[id].save |
|
331 | @import_log << "Created #{country[:name]}\n" |
|
373 | @import_log << "Created #{country[:name]}\n" |
|
332 | end |
|
374 | end |
|
333 | end |
|
375 | end |
|
334 |
|
376 | ||
|
335 | # import sites |
|
377 | # import sites |
|
336 | sites = {} |
|
378 | sites = {} |
|
337 | site_data.each_pair do |id,site| |
|
379 | site_data.each_pair do |id,site| |
|
338 | s = Site.find_by_name(site[:name]) |
|
380 | s = Site.find_by_name(site[:name]) |
|
339 | if s!=nil |
|
381 | if s!=nil |
|
340 | @import_log << "Found #{site[:name]}\n" |
|
382 | @import_log << "Found #{site[:name]}\n" |
|
341 | else |
|
383 | else |
|
342 | s = Site.new(:name => site[:name]) |
|
384 | s = Site.new(:name => site[:name]) |
|
343 | @import_log << "Created #{site[:name]}\n" |
|
385 | @import_log << "Created #{site[:name]}\n" |
|
344 | end |
|
386 | end |
|
345 | s.password = site[:password] |
|
387 | s.password = site[:password] |
|
346 | s.country = countries[site[:country_id]] |
|
388 | s.country = countries[site[:country_id]] |
|
347 | s.save |
|
389 | s.save |
|
348 | sites[id] = s |
|
390 | sites[id] = s |
|
349 | end |
|
391 | end |
|
350 |
|
392 | ||
|
351 | # import users |
|
393 | # import users |
@@ -1,83 +1,84 | |||||
|
1 | <h1>Listing users</h1> |
|
1 | <h1>Listing users</h1> |
|
2 |
|
2 | ||
|
3 | <div class="submitbox"> |
|
3 | <div class="submitbox"> |
|
4 | <b>Quick add</b> |
|
4 | <b>Quick add</b> |
|
5 | <% form_tag :action => 'create' do %> |
|
5 | <% form_tag :action => 'create' do %> |
|
6 | <table border="0"> |
|
6 | <table border="0"> |
|
7 | <tr> |
|
7 | <tr> |
|
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> |
|
21 | </tr> |
|
22 | </table> |
|
22 | </table> |
|
23 | <% end %> |
|
23 | <% end %> |
|
24 | <br/> |
|
24 | <br/> |
|
25 | <b>Import from site management</b> |
|
25 | <b>Import from site management</b> |
|
26 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
26 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
27 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
27 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
28 | <% end %> |
|
28 | <% end %> |
|
29 | <br/> |
|
29 | <br/> |
|
30 | <b>What else: </b> |
|
30 | <b>What else: </b> |
|
31 | <%= link_to '[New user]', :action => 'new' %> |
|
31 | <%= link_to '[New user]', :action => 'new' %> |
|
32 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
32 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
33 | <%= link_to '[View administrators]', :action => 'admin' %> |
|
33 | <%= link_to '[View administrators]', :action => 'admin' %> |
|
34 | <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> |
|
34 | <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> |
|
35 | <%= link_to '[View active users]', :action => 'active' %> |
|
35 | <%= link_to '[View active users]', :action => 'active' %> |
|
|
36 | + <%= link_to '[Mass mailing]', :action => 'mass_mailing' %> | ||
|
36 | <% if Configuration.multicontests? %> |
|
37 | <% if Configuration.multicontests? %> |
|
37 | <br/><b>Multi-contest:</b> |
|
38 | <br/><b>Multi-contest:</b> |
|
38 | <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> |
|
39 | <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> |
|
39 | View users in: |
|
40 | View users in: |
|
40 | <% @contests.each do |contest| %> |
|
41 | <% @contests.each do |contest| %> |
|
41 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
42 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
42 | <% end %> |
|
43 | <% end %> |
|
43 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
44 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
44 | <% end %> |
|
45 | <% end %> |
|
45 | </div> |
|
46 | </div> |
|
46 |
|
47 | ||
|
47 | Total <%= @user_count %> users | |
|
48 | Total <%= @user_count %> users | |
|
48 | <% if !@paginated %> |
|
49 | <% if !@paginated %> |
|
49 | Display all users. |
|
50 | Display all users. |
|
50 | <%= link_to '[show in pages]', :action => 'list', :page => '1' %> |
|
51 | <%= link_to '[show in pages]', :action => 'list', :page => '1' %> |
|
51 | <% else %> |
|
52 | <% else %> |
|
52 | Display in pages. |
|
53 | Display in pages. |
|
53 | <%= link_to '[display all]', :action => 'list', :page => 'all' %> | |
|
54 | <%= link_to '[display all]', :action => 'list', :page => 'all' %> | |
|
54 | <%= will_paginate @users, :container => false %> |
|
55 | <%= will_paginate @users, :container => false %> |
|
55 | <% end %> |
|
56 | <% end %> |
|
56 | <table class="info"> |
|
57 | <table class="info"> |
|
57 | <tr class="info-head"> |
|
58 | <tr class="info-head"> |
|
58 | <% for column in User.content_columns %> |
|
59 | <% for column in User.content_columns %> |
|
59 | <% if !@hidden_columns.index(column.name) %> |
|
60 | <% if !@hidden_columns.index(column.name) %> |
|
60 | <th><%= column.human_name %></th> |
|
61 | <th><%= column.human_name %></th> |
|
61 | <% end %> |
|
62 | <% end %> |
|
62 | <% end %> |
|
63 | <% end %> |
|
63 | <th></th> |
|
64 | <th></th> |
|
64 | <th></th> |
|
65 | <th></th> |
|
65 | <th></th> |
|
66 | <th></th> |
|
66 | </tr> |
|
67 | </tr> |
|
67 |
|
68 | ||
|
68 | <% for user in @users %> |
|
69 | <% for user in @users %> |
|
69 | <tr class="info-<%= cycle("odd","even") %>"> |
|
70 | <tr class="info-<%= cycle("odd","even") %>"> |
|
70 | <% for column in User.content_columns %> |
|
71 | <% for column in User.content_columns %> |
|
71 | <% if !@hidden_columns.index(column.name) %> |
|
72 | <% if !@hidden_columns.index(column.name) %> |
|
72 | <td><%=h user.send(column.name) %></td> |
|
73 | <td><%=h user.send(column.name) %></td> |
|
73 | <% end %> |
|
74 | <% end %> |
|
74 | <% end %> |
|
75 | <% end %> |
|
75 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
76 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
76 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
77 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
77 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
78 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
78 | </tr> |
|
79 | </tr> |
|
79 | <% end %> |
|
80 | <% end %> |
|
80 | </table> |
|
81 | </table> |
|
81 |
|
82 | ||
|
82 | <br /> |
|
83 | <br /> |
|
83 |
|
84 |
You need to be logged in to leave comments.
Login now