Description:
sends mass emails
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

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,39 +1,42
1 1 class UserAdminController < ApplicationController
2 2
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']
28 31 @contests = Contest.enabled
29 32 end
30 33
31 34 def active
32 35 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
33 36 @users = []
34 37 sessions.each do |session|
35 38 if session.data[:user_id]
36 39 @users << User.find(session.data[:user_id])
37 40 end
38 41 end
39 42 end
@@ -280,48 +283,87
280 283 user.roles << admin_role
281 284 else
282 285 flash[:notice] = 'Unknown user'
283 286 end
284 287 flash[:notice] = 'User added as admins'
285 288 redirect_to :action => 'admin'
286 289 end
287 290
288 291 def revoke_admin
289 292 user = User.find(params[:id])
290 293 if user==nil
291 294 flash[:notice] = 'Unknown user'
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 = ""
316 358
317 359 country_data = data_hash[:countries]
318 360 site_data = data_hash[:sites]
319 361 user_data = data_hash[:users]
320 362
321 363 # import country
322 364 countries = {}
323 365 country_data.each_pair do |id,country|
324 366 c = Country.find_by_name(country[:name])
325 367 if c!=nil
326 368 countries[id] = c
327 369 @import_log << "Found #{country[:name]}\n"
@@ -12,48 +12,49
12 12 <td><label for="user_email">Email</label></td>
13 13 </tr>
14 14 <tr>
15 15 <td><%= text_field 'user', 'login', :size => 10 %></td>
16 16 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
17 17 <td><%= password_field 'user', 'password', :size => 10 %></td>
18 18 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
19 19 <td><%= text_field 'user', 'email', :size => 15 %></td>
20 20 <td><%= submit_tag "Create" %></td>
21 21 </tr>
22 22 </table>
23 23 <% end %>
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 |
48 49 <% if !@paginated %>
49 50 Display all users.
50 51 <%= link_to '[show in pages]', :action => 'list', :page => '1' %>
51 52 <% else %>
52 53 Display in pages.
53 54 <%= link_to '[display all]', :action => 'list', :page => 'all' %> |
54 55 <%= will_paginate @users, :container => false %>
55 56 <% end %>
56 57 <table class="info">
57 58 <tr class="info-head">
58 59 <% for column in User.content_columns %>
59 60 <% if !@hidden_columns.index(column.name) %>
You need to be logged in to leave comments. Login now