Description:
assigns all users from on contest list to another
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r298:e6c044028e60 - - 2 files changed: 40 inserted, 15 deleted
@@ -136,59 +136,69 | |||||
|
136 | redirect_to :action => 'list' and return |
|
136 | redirect_to :action => 'list' and return |
|
137 | end |
|
137 | end |
|
138 | import_from_file(params[:file]) |
|
138 | import_from_file(params[:file]) |
|
139 | end |
|
139 | end |
|
140 |
|
140 | ||
|
141 | def random_all_passwords |
|
141 | def random_all_passwords |
|
142 | users = User.find(:all) |
|
142 | users = User.find(:all) |
|
143 | @prefix = params[:prefix] || '' |
|
143 | @prefix = params[:prefix] || '' |
|
144 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
144 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
145 | @changed = false |
|
145 | @changed = false |
|
146 | if request.request_method == :post |
|
146 | if request.request_method == :post |
|
147 | @non_admin_users.each do |user| |
|
147 | @non_admin_users.each do |user| |
|
148 | password = random_password |
|
148 | password = random_password |
|
149 | user.password = password |
|
149 | user.password = password |
|
150 | user.password_confirmation = password |
|
150 | user.password_confirmation = password |
|
151 | user.save |
|
151 | user.save |
|
152 | end |
|
152 | end |
|
153 | @changed = true |
|
153 | @changed = true |
|
154 | end |
|
154 | end |
|
155 | end |
|
155 | end |
|
156 |
|
156 | ||
|
157 | # contest management |
|
157 | # contest management |
|
158 |
|
158 | ||
|
159 | def contests |
|
159 | def contests |
|
160 | - if params[:id]!='none' |
|
160 | + @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
161 |
- |
|
161 | + @contests = Contest.enabled |
|
162 | - else |
|
162 | + end |
|
163 | - @contest = nil |
|
163 | + |
|
|
164 | + def assign_from_list | ||
|
|
165 | + contest_id = params[:users_contest_id] | ||
|
|
166 | + org_contest, users = find_contest_and_user_from_contest_id(contest_id) | ||
|
|
167 | + contest = Contest.find(params[:new_contest][:id]) | ||
|
|
168 | + if !contest | ||
|
|
169 | + flash[:notice] = 'Error: no contest' | ||
|
|
170 | + redirect_to :action => 'contests', :id =>contest_id | ||
|
164 | end |
|
171 | end |
|
165 | - if @contest |
|
172 | + |
|
166 | - @users = @contest.users |
|
173 | + note = [] |
|
167 | - else |
|
174 | + users.each do |u| |
|
168 | - @users = User.find_users_with_no_contest |
|
175 | + u.contests = [contest] |
|
|
176 | + note << u.login | ||
|
169 | end |
|
177 | end |
|
170 | - @contests = Contest.enabled |
|
178 | + flash[:notice] = 'User(s) ' + note.join(', ') + |
|
|
179 | + " were successfully reassigned to #{contest.title}." | ||
|
|
180 | + redirect_to :action => 'contests', :id =>contest.id | ||
|
171 | end |
|
181 | end |
|
172 |
|
182 | ||
|
173 | def add_to_contest |
|
183 | def add_to_contest |
|
174 | user = User.find(params[:id]) |
|
184 | user = User.find(params[:id]) |
|
175 | contest = Contest.find(params[:contest_id]) |
|
185 | contest = Contest.find(params[:contest_id]) |
|
176 | if user and contest |
|
186 | if user and contest |
|
177 | user.contests << contest |
|
187 | user.contests << contest |
|
178 | end |
|
188 | end |
|
179 | redirect_to :action => 'list' |
|
189 | redirect_to :action => 'list' |
|
180 | end |
|
190 | end |
|
181 |
|
191 | ||
|
182 | def remove_from_contest |
|
192 | def remove_from_contest |
|
183 | user = User.find(params[:id]) |
|
193 | user = User.find(params[:id]) |
|
184 | contest = Contest.find(params[:contest_id]) |
|
194 | contest = Contest.find(params[:contest_id]) |
|
185 | if user and contest |
|
195 | if user and contest |
|
186 | user.contests.delete(contest) |
|
196 | user.contests.delete(contest) |
|
187 | end |
|
197 | end |
|
188 | redirect_to :action => 'list' |
|
198 | redirect_to :action => 'list' |
|
189 | end |
|
199 | end |
|
190 |
|
200 | ||
|
191 | def contest_management |
|
201 | def contest_management |
|
192 | end |
|
202 | end |
|
193 |
|
203 | ||
|
194 | def manage_contest |
|
204 | def manage_contest |
@@ -358,25 +368,39 | |||||
|
358 | users.each do |user| |
|
368 | users.each do |user| |
|
359 | contest_stat = user.contest_stat(true) |
|
369 | contest_stat = user.contest_stat(true) |
|
360 | if contest_stat and !contest_stat.forced_logout |
|
370 | if contest_stat and !contest_stat.forced_logout |
|
361 | contest_stat.forced_logout = true |
|
371 | contest_stat.forced_logout = true |
|
362 | contest_stat.save |
|
372 | contest_stat.save |
|
363 | end |
|
373 | end |
|
364 | end |
|
374 | end |
|
365 | end |
|
375 | end |
|
366 |
|
376 | ||
|
367 | def send_contest_update_notification_email(user, contest) |
|
377 | def send_contest_update_notification_email(user, contest) |
|
368 | contest_title_name = Configuration['contest.name'] |
|
378 | contest_title_name = Configuration['contest.name'] |
|
369 | contest_name = contest.name |
|
379 | contest_name = contest.name |
|
370 | subject = t('contest.notification.email_subject', { |
|
380 | subject = t('contest.notification.email_subject', { |
|
371 | :contest_title_name => contest_title_name, |
|
381 | :contest_title_name => contest_title_name, |
|
372 | :contest_name => contest_name }) |
|
382 | :contest_name => contest_name }) |
|
373 | body = t('contest.notification.email_body', { |
|
383 | body = t('contest.notification.email_body', { |
|
374 | :full_name => user.full_name, |
|
384 | :full_name => user.full_name, |
|
375 | :contest_title_name => contest_title_name, |
|
385 | :contest_title_name => contest_title_name, |
|
376 | :contest_name => contest.name, |
|
386 | :contest_name => contest.name, |
|
377 | }) |
|
387 | }) |
|
378 |
|
388 | ||
|
379 | logger.info body |
|
389 | logger.info body |
|
380 | send_mail(user.email, subject, body) |
|
390 | send_mail(user.email, subject, body) |
|
381 | end |
|
391 | end |
|
|
392 | + | ||
|
|
393 | + def find_contest_and_user_from_contest_id(id) | ||
|
|
394 | + if id!='none' | ||
|
|
395 | + @contest = Contest.find(id) | ||
|
|
396 | + else | ||
|
|
397 | + @contest = nil | ||
|
|
398 | + end | ||
|
|
399 | + if @contest | ||
|
|
400 | + @users = @contest.users | ||
|
|
401 | + else | ||
|
|
402 | + @users = User.find_users_with_no_contest | ||
|
|
403 | + end | ||
|
|
404 | + return [@contest, @users] | ||
|
|
405 | + end | ||
|
382 | end |
|
406 | end |
@@ -1,65 +1,66 | |||||
|
1 | <h1> |
|
1 | <h1> |
|
2 | List users in <% if @contest %><%= @contest.title %> |
|
2 | List users in <% if @contest %><%= @contest.title %> |
|
3 | <% else %>Users not in any contests<% end %> |
|
3 | <% else %>Users not in any contests<% end %> |
|
4 | </h1> |
|
4 | </h1> |
|
5 |
|
5 | ||
|
6 | <div class="submitbox"> |
|
6 | <div class="submitbox"> |
|
7 | <%= link_to '[View all users]', :action => 'list' %> |
|
7 | <%= link_to '[View all users]', :action => 'list' %> |
|
8 | <% if Configuration.multicontests? %> |
|
8 | <% if Configuration.multicontests? %> |
|
9 | <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> |
|
9 | <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> |
|
10 | <br/> |
|
10 | <br/> |
|
11 | View users in: |
|
11 | View users in: |
|
12 | <% @contests.each do |contest| %> |
|
12 | <% @contests.each do |contest| %> |
|
13 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
13 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
14 | <% end %> |
|
14 | <% end %> |
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
16 | <% end %> |
|
16 | <% end %> |
|
|
17 | + <br/> | ||
|
|
18 | + <% form_tag :action => 'assign_from_list' do %> | ||
|
|
19 | + <%= hidden_field_tag 'users_contest_id', (@contest ? @contest.id : 'none') %> | ||
|
|
20 | + Assign all to | ||
|
|
21 | + <%= select("new_contest","id",Contest.all.collect {|c| [c.title, c.id]}) %> | ||
|
|
22 | + <%= submit_tag "Assign", :confirm => 'Are you sure?' %> | ||
|
|
23 | + <% end %> | ||
|
17 | </div> |
|
24 | </div> |
|
18 |
|
25 | ||
|
19 | <table class="info"> |
|
26 | <table class="info"> |
|
20 | <tr class="info-head"> |
|
27 | <tr class="info-head"> |
|
21 | <th>Login</th> |
|
28 | <th>Login</th> |
|
22 | <th>Full name</th> |
|
29 | <th>Full name</th> |
|
23 | <th>Email</th> |
|
30 | <th>Email</th> |
|
24 | <th>Activated?</th> |
|
31 | <th>Activated?</th> |
|
25 | <th></th> |
|
32 | <th></th> |
|
26 | <th></th> |
|
33 | <th></th> |
|
27 | <th></th> |
|
34 | <th></th> |
|
28 | <% if Configuration.multicontests? %> |
|
35 | <% if Configuration.multicontests? %> |
|
29 | <th>Contests</th> |
|
36 | <th>Contests</th> |
|
30 | <th>Other enabled contests</th> |
|
37 | <th>Other enabled contests</th> |
|
31 | <% end %> |
|
38 | <% end %> |
|
32 | </tr> |
|
39 | </tr> |
|
33 |
|
40 | ||
|
34 | <% for user in @users %> |
|
41 | <% for user in @users %> |
|
35 | <tr class="info-<%= cycle("odd","even") %>"> |
|
42 | <tr class="info-<%= cycle("odd","even") %>"> |
|
36 | <td><%=h user.login %></td> |
|
43 | <td><%=h user.login %></td> |
|
37 | <td><%=h user.full_name %></td> |
|
44 | <td><%=h user.full_name %></td> |
|
38 | <td><%=h user.email %></td> |
|
45 | <td><%=h user.email %></td> |
|
39 | <td><%=h user.activated %></td> |
|
46 | <td><%=h user.activated %></td> |
|
40 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
47 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
41 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
48 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
42 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
49 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
43 | <% if Configuration.multicontests? %> |
|
50 | <% if Configuration.multicontests? %> |
|
44 | <td> |
|
51 | <td> |
|
45 | <% user.contests.each do |contest| %> |
|
52 | <% user.contests.each do |contest| %> |
|
46 | <%= contest.name %> [<%= link_to 'x', :action => 'remove_from_contest', :id => user.id, :contest_id => contest.id %>] |
|
53 | <%= contest.name %> [<%= link_to 'x', :action => 'remove_from_contest', :id => user.id, :contest_id => contest.id %>] |
|
47 | <% end %> |
|
54 | <% end %> |
|
48 | </td> |
|
55 | </td> |
|
49 | <td> |
|
56 | <td> |
|
50 | <% @contests.each do |contest| %> |
|
57 | <% @contests.each do |contest| %> |
|
51 | <% if not user.contests.all.find {|c| c.id==contest.id } %> |
|
58 | <% if not user.contests.all.find {|c| c.id==contest.id } %> |
|
52 | <%= contest.name %> [<%= link_to '+', :action => 'add_to_contest', :id => user.id, :contest_id => contest.id %>] |
|
59 | <%= contest.name %> [<%= link_to '+', :action => 'add_to_contest', :id => user.id, :contest_id => contest.id %>] |
|
53 | <% end %> |
|
60 | <% end %> |
|
54 | <% end %> |
|
61 | <% end %> |
|
55 | </td> |
|
62 | </td> |
|
56 | <% end %> |
|
63 | <% end %> |
|
57 | </tr> |
|
64 | </tr> |
|
58 | <% end %> |
|
65 | <% end %> |
|
59 | </table> |
|
66 | </table> |
|
60 | - |
|
||
|
61 | - |
|
||
|
62 | - <br /> |
|
||
|
63 | - |
|
||
|
64 | - <%= link_to 'New user', :action => 'new' %> |
|
||
|
65 | - <%= link_to 'New list of users', :action => 'new_list' %> |
|
You need to be logged in to leave comments.
Login now