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' |
@@ -3,25 +3,28 | |||
|
3 | 3 | include MailHelperMethods |
|
4 | 4 | |
|
5 | 5 | before_filter :admin_authorization |
|
6 | 6 | |
|
7 | 7 | def index |
|
8 | 8 | list |
|
9 | 9 | render :action => 'list' |
|
10 | 10 | end |
|
11 | 11 | |
|
12 | 12 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
13 | 13 | verify :method => :post, :only => [ :destroy, |
|
14 | 14 | :create, :create_from_list, |
|
15 |
- :update |
|
|
15 | + :update, | |
|
16 | + :manage_contest, | |
|
17 | + :bulk_mail | |
|
18 | + ], | |
|
16 | 19 | :redirect_to => { :action => :list } |
|
17 | 20 | |
|
18 | 21 | def list |
|
19 | 22 | @user_count = User.count |
|
20 | 23 | if params[:page] == 'all' |
|
21 | 24 | @users = User.all |
|
22 | 25 | @paginated = false |
|
23 | 26 | else |
|
24 | 27 | @users = User.paginate :page => params[:page] |
|
25 | 28 | @paginated = true |
|
26 | 29 | end |
|
27 | 30 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
@@ -292,24 +295,63 | |||
|
292 | 295 | redirect_to :action => 'admin' and return |
|
293 | 296 | elsif user.login == 'root' |
|
294 | 297 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
295 | 298 | redirect_to :action => 'admin' and return |
|
296 | 299 | end |
|
297 | 300 | |
|
298 | 301 | admin_role = Role.find_by_name('admin') |
|
299 | 302 | user.roles.delete(admin_role) |
|
300 | 303 | flash[:notice] = 'User permission revoked' |
|
301 | 304 | redirect_to :action => 'admin' |
|
302 | 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 | 346 | protected |
|
305 | 347 | |
|
306 | 348 | def random_password(length=5) |
|
307 | 349 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
308 | 350 | newpass = "" |
|
309 | 351 | length.times { newpass << chars[rand(chars.size-1)] } |
|
310 | 352 | return newpass |
|
311 | 353 | end |
|
312 | 354 | |
|
313 | 355 | def import_from_file(f) |
|
314 | 356 | data_hash = YAML.load(f) |
|
315 | 357 | @import_log = "" |
@@ -24,24 +24,25 | |||
|
24 | 24 | <br/> |
|
25 | 25 | <b>Import from site management</b> |
|
26 | 26 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
27 | 27 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
28 | 28 | <% end %> |
|
29 | 29 | <br/> |
|
30 | 30 | <b>What else: </b> |
|
31 | 31 | <%= link_to '[New user]', :action => 'new' %> |
|
32 | 32 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
33 | 33 | <%= link_to '[View administrators]', :action => 'admin' %> |
|
34 | 34 | <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> |
|
35 | 35 | <%= link_to '[View active users]', :action => 'active' %> |
|
36 | + <%= link_to '[Mass mailing]', :action => 'mass_mailing' %> | |
|
36 | 37 | <% if Configuration.multicontests? %> |
|
37 | 38 | <br/><b>Multi-contest:</b> |
|
38 | 39 | <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> |
|
39 | 40 | View users in: |
|
40 | 41 | <% @contests.each do |contest| %> |
|
41 | 42 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
42 | 43 | <% end %> |
|
43 | 44 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
44 | 45 | <% end %> |
|
45 | 46 | </div> |
|
46 | 47 | |
|
47 | 48 | Total <%= @user_count %> users | |
You need to be logged in to leave comments.
Login now