diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb
--- a/app/controllers/user_admin_controller.rb
+++ b/app/controllers/user_admin_controller.rb
@@ -157,17 +157,27 @@
# contest management
def contests
- if params[:id]!='none'
- @contest = Contest.find(params[:id])
- else
- @contest = nil
+ @contest, @users = find_contest_and_user_from_contest_id(params[:id])
+ @contests = Contest.enabled
+ end
+
+ def assign_from_list
+ contest_id = params[:users_contest_id]
+ org_contest, users = find_contest_and_user_from_contest_id(contest_id)
+ contest = Contest.find(params[:new_contest][:id])
+ if !contest
+ flash[:notice] = 'Error: no contest'
+ redirect_to :action => 'contests', :id =>contest_id
end
- if @contest
- @users = @contest.users
- else
- @users = User.find_users_with_no_contest
+
+ note = []
+ users.each do |u|
+ u.contests = [contest]
+ note << u.login
end
- @contests = Contest.enabled
+ flash[:notice] = 'User(s) ' + note.join(', ') +
+ " were successfully reassigned to #{contest.title}."
+ redirect_to :action => 'contests', :id =>contest.id
end
def add_to_contest
@@ -379,4 +389,18 @@
logger.info body
send_mail(user.email, subject, body)
end
+
+ def find_contest_and_user_from_contest_id(id)
+ if id!='none'
+ @contest = Contest.find(id)
+ else
+ @contest = nil
+ end
+ if @contest
+ @users = @contest.users
+ else
+ @users = User.find_users_with_no_contest
+ end
+ return [@contest, @users]
+ end
end
diff --git a/app/views/user_admin/contests.html.erb b/app/views/user_admin/contests.html.erb
--- a/app/views/user_admin/contests.html.erb
+++ b/app/views/user_admin/contests.html.erb
@@ -14,6 +14,13 @@
<% end %>
<%= link_to "[no contest]", :action => 'contests', :id => 'none' %>
<% end %>
+
+ <% form_tag :action => 'assign_from_list' do %>
+ <%= hidden_field_tag 'users_contest_id', (@contest ? @contest.id : 'none') %>
+ Assign all to
+ <%= select("new_contest","id",Contest.all.collect {|c| [c.title, c.id]}) %>
+ <%= submit_tag "Assign", :confirm => 'Are you sure?' %>
+ <% end %>