Description:
manages users in contests
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r280:f8e3b2e72e4a - - 7 files changed: 111 inserted, 7 deleted
@@ -0,0 +1,16 | |||||
|
|
1 | + %h1 Bulk edit users in contests | ||
|
|
2 | + | ||
|
|
3 | + - form_tag :action => 'manage_contest' do | ||
|
|
4 | + List users' login below; one per line. | ||
|
|
5 | + %br/ | ||
|
|
6 | + = text_area_tag 'login_list', nil, :rows => 25, :cols => 80 | ||
|
|
7 | + %br/ | ||
|
|
8 | + You want to | ||
|
|
9 | + = select(nil,"operation",[['add users to','add'],['remove users from','remove']]) | ||
|
|
10 | + contest | ||
|
|
11 | + = select("contest","id",Contest.all.collect {|c| [c.title, c.id]}) | ||
|
|
12 | + | ||
|
|
13 | + = submit_tag "Perform action", :confirm => 'Are you sure?' | ||
|
|
14 | + | ||
|
|
15 | + %hr/ | ||
|
|
16 | + = link_to '[go back to index]', :action => 'index' |
@@ -7,24 +7,25 | |||||
|
7 | render :action => 'list' |
|
7 | render :action => 'list' |
|
8 | end |
|
8 | end |
|
9 |
|
9 | ||
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | verify :method => :post, :only => [ :destroy, |
|
11 | verify :method => :post, :only => [ :destroy, |
|
12 | :create, :create_from_list, |
|
12 | :create, :create_from_list, |
|
13 | :update ], |
|
13 | :update ], |
|
14 | :redirect_to => { :action => :list } |
|
14 | :redirect_to => { :action => :list } |
|
15 |
|
15 | ||
|
16 | def list |
|
16 | def list |
|
17 | @users = User.find(:all) |
|
17 | @users = User.find(:all) |
|
18 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
18 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
|
19 | + @contests = Contest.all(:conditions => {:enabled => true}) | ||
|
19 | end |
|
20 | end |
|
20 |
|
21 | ||
|
21 | def active |
|
22 | def active |
|
22 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
23 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
23 | @users = [] |
|
24 | @users = [] |
|
24 | sessions.each do |session| |
|
25 | sessions.each do |session| |
|
25 | if session.data[:user_id] |
|
26 | if session.data[:user_id] |
|
26 | @users << User.find(session.data[:user_id]) |
|
27 | @users << User.find(session.data[:user_id]) |
|
27 | end |
|
28 | end |
|
28 | end |
|
29 | end |
|
29 | end |
|
30 | end |
|
30 |
|
31 | ||
@@ -142,24 +143,86 | |||||
|
142 | @changed = false |
|
143 | @changed = false |
|
143 | if request.request_method == :post |
|
144 | if request.request_method == :post |
|
144 | @non_admin_users.each do |user| |
|
145 | @non_admin_users.each do |user| |
|
145 | password = random_password |
|
146 | password = random_password |
|
146 | user.password = password |
|
147 | user.password = password |
|
147 | user.password_confirmation = password |
|
148 | user.password_confirmation = password |
|
148 | user.save |
|
149 | user.save |
|
149 | end |
|
150 | end |
|
150 | @changed = true |
|
151 | @changed = true |
|
151 | end |
|
152 | end |
|
152 | end |
|
153 | end |
|
153 |
|
154 | ||
|
|
155 | + # contest management | ||
|
|
156 | + | ||
|
|
157 | + def add_to_contest | ||
|
|
158 | + user = User.find(params[:id]) | ||
|
|
159 | + contest = Contest.find(params[:contest_id]) | ||
|
|
160 | + if user and contest | ||
|
|
161 | + user.contests << contest | ||
|
|
162 | + end | ||
|
|
163 | + redirect_to :action => 'list' | ||
|
|
164 | + end | ||
|
|
165 | + | ||
|
|
166 | + def remove_from_contest | ||
|
|
167 | + user = User.find(params[:id]) | ||
|
|
168 | + contest = Contest.find(params[:contest_id]) | ||
|
|
169 | + if user and contest | ||
|
|
170 | + user.contests.delete(contest) | ||
|
|
171 | + end | ||
|
|
172 | + redirect_to :action => 'list' | ||
|
|
173 | + end | ||
|
|
174 | + | ||
|
|
175 | + def contest_management | ||
|
|
176 | + end | ||
|
|
177 | + | ||
|
|
178 | + def manage_contest | ||
|
|
179 | + contest = Contest.find(params[:contest][:id]) | ||
|
|
180 | + if !contest | ||
|
|
181 | + flash[:notice] = 'You did not choose the contest.' | ||
|
|
182 | + redirect_to :action => 'contest_management' and return | ||
|
|
183 | + end | ||
|
|
184 | + | ||
|
|
185 | + operation = params[:operation] | ||
|
|
186 | + | ||
|
|
187 | + if operation!='add' and operation!='remove' | ||
|
|
188 | + flash[:notice] = 'You did not choose the operation to perform.' | ||
|
|
189 | + redirect_to :action => 'contest_management' and return | ||
|
|
190 | + end | ||
|
|
191 | + | ||
|
|
192 | + lines = params[:login_list] | ||
|
|
193 | + if !lines or lines.blank? | ||
|
|
194 | + flash[:notice] = 'You entered an empty list.' | ||
|
|
195 | + redirect_to :action => 'contest_management' and return | ||
|
|
196 | + end | ||
|
|
197 | + | ||
|
|
198 | + note = [] | ||
|
|
199 | + lines.split("\n").each do |line| | ||
|
|
200 | + puts line | ||
|
|
201 | + user = User.find_by_login(line.chomp) | ||
|
|
202 | + puts user | ||
|
|
203 | + if user | ||
|
|
204 | + if operation=='add' | ||
|
|
205 | + user.contests << contest | ||
|
|
206 | + else | ||
|
|
207 | + user.contests.delete(contest) | ||
|
|
208 | + end | ||
|
|
209 | + note << user.login | ||
|
|
210 | + end | ||
|
|
211 | + end | ||
|
|
212 | + flash[:notice] = 'User(s) ' + note.join(', ') + | ||
|
|
213 | + ' were successfully modified. ' | ||
|
|
214 | + redirect_to :action => 'contest_management' | ||
|
|
215 | + end | ||
|
|
216 | + | ||
|
154 | # admin management |
|
217 | # admin management |
|
155 |
|
218 | ||
|
156 | def admin |
|
219 | def admin |
|
157 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
220 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
158 | end |
|
221 | end |
|
159 |
|
222 | ||
|
160 | def grant_admin |
|
223 | def grant_admin |
|
161 | login = params[:login] |
|
224 | login = params[:login] |
|
162 | user = User.find_by_login(login) |
|
225 | user = User.find_by_login(login) |
|
163 | if user!=nil |
|
226 | if user!=nil |
|
164 | admin_role = Role.find_by_name('admin') |
|
227 | admin_role = Role.find_by_name('admin') |
|
165 | user.roles << admin_role |
|
228 | user.roles << admin_role |
@@ -1,16 +1,16 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
4 | - has_and_belongs_to_many :contests |
|
4 | + has_and_belongs_to_many :contests, :uniq => true |
|
5 | has_many :test_pairs, :dependent => :delete_all |
|
5 | has_many :test_pairs, :dependent => :delete_all |
|
6 |
|
6 | ||
|
7 | validates_presence_of :name |
|
7 | validates_presence_of :name |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
9 | validates_presence_of :full_name |
|
9 | validates_presence_of :full_name |
|
10 |
|
10 | ||
|
11 | named_scope :available, :conditions => {:available => true} |
|
11 | named_scope :available, :conditions => {:available => true} |
|
12 |
|
12 | ||
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 |
|
15 | ||
|
16 | def self.find_available_problems |
|
16 | def self.find_available_problems |
@@ -12,25 +12,25 | |||||
|
12 | :order => 'created_at DESC' |
|
12 | :order => 'created_at DESC' |
|
13 |
|
13 | ||
|
14 | has_many :replied_messages, |
|
14 | has_many :replied_messages, |
|
15 | :class_name => "Message", |
|
15 | :class_name => "Message", |
|
16 | :foreign_key => "receiver_id", |
|
16 | :foreign_key => "receiver_id", |
|
17 | :order => 'created_at DESC' |
|
17 | :order => 'created_at DESC' |
|
18 |
|
18 | ||
|
19 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
19 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
20 |
|
20 | ||
|
21 | belongs_to :site |
|
21 | belongs_to :site |
|
22 | belongs_to :country |
|
22 | belongs_to :country |
|
23 |
|
23 | ||
|
24 | - has_and_belongs_to_many :contests |
|
24 | + has_and_belongs_to_many :contests, :uniq => true |
|
25 |
|
25 | ||
|
26 | named_scope :activated_users, :conditions => {:activated => true} |
|
26 | named_scope :activated_users, :conditions => {:activated => true} |
|
27 |
|
27 | ||
|
28 | validates_presence_of :login |
|
28 | validates_presence_of :login |
|
29 | validates_uniqueness_of :login |
|
29 | validates_uniqueness_of :login |
|
30 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
30 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
31 | validates_length_of :login, :within => 3..30 |
|
31 | validates_length_of :login, :within => 3..30 |
|
32 |
|
32 | ||
|
33 | validates_presence_of :full_name |
|
33 | validates_presence_of :full_name |
|
34 | validates_length_of :full_name, :minimum => 1 |
|
34 | validates_length_of :full_name, :minimum => 1 |
|
35 |
|
35 | ||
|
36 | validates_presence_of :password, :if => :password_required? |
|
36 | validates_presence_of :password, :if => :password_required? |
@@ -23,24 +23,25 | |||||
|
23 |
|
23 | ||
|
24 | - if Configuration.show_tasks_to?(@user) |
|
24 | - if Configuration.show_tasks_to?(@user) |
|
25 | - if not Configuration.multicontests? |
|
25 | - if not Configuration.multicontests? |
|
26 | %table.info |
|
26 | %table.info |
|
27 | %tr.info-head |
|
27 | %tr.info-head |
|
28 | %th |
|
28 | %th |
|
29 | %th Tasks |
|
29 | %th Tasks |
|
30 | %th # of sub(s) |
|
30 | %th # of sub(s) |
|
31 | %th Results |
|
31 | %th Results |
|
32 | = render :partial => 'problem', :collection => @problems |
|
32 | = render :partial => 'problem', :collection => @problems |
|
33 | - else |
|
33 | - else |
|
34 | - @contest_problems.each do |cp| |
|
34 | - @contest_problems.each do |cp| |
|
|
35 | + - if cp[:problems].length > 0 | ||
|
35 | %h2{:class =>'contest-title'} |
|
36 | %h2{:class =>'contest-title'} |
|
36 | = "#{cp[:contest] ? cp[:contest].title : 'Public problems'}" |
|
37 | = "#{cp[:contest] ? cp[:contest].title : 'Public problems'}" |
|
37 | %table.info |
|
38 | %table.info |
|
38 | %tr.info-head |
|
39 | %tr.info-head |
|
39 | %th |
|
40 | %th |
|
40 | %th Tasks |
|
41 | %th Tasks |
|
41 | %th # of sub(s) |
|
42 | %th # of sub(s) |
|
42 | %th Results |
|
43 | %th Results |
|
43 | = render :partial => 'problem', :collection => cp[:problems] |
|
44 | = render :partial => 'problem', :collection => cp[:problems] |
|
44 |
|
45 | ||
|
45 |
|
46 | ||
|
46 | %hr/ |
|
47 | %hr/ |
@@ -1,16 +1,16 | |||||
|
1 | %h1 Administrators |
|
1 | %h1 Administrators |
|
2 |
|
2 | ||
|
3 | - %table |
|
3 | + %table{:class => 'info'} |
|
4 | - %tr |
|
4 | + %tr{:class => 'info-head'} |
|
5 | %th # |
|
5 | %th # |
|
6 | %th Login |
|
6 | %th Login |
|
7 | %th Full name |
|
7 | %th Full name |
|
8 | %th |
|
8 | %th |
|
9 | - @admins.each_with_index do |user, i| |
|
9 | - @admins.each_with_index do |user, i| |
|
10 | %tr |
|
10 | %tr |
|
11 | %td= i+1 |
|
11 | %td= i+1 |
|
12 | %td= user.login |
|
12 | %td= user.login |
|
13 | %td= user.full_name |
|
13 | %td= user.full_name |
|
14 | %td |
|
14 | %td |
|
15 | - if user.login!='root' |
|
15 | - if user.login!='root' |
|
16 | = link_to '[revoke]', :action => 'revoke_admin', :id => user.id |
|
16 | = link_to '[revoke]', :action => 'revoke_admin', :id => user.id |
@@ -24,42 +24,66 | |||||
|
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 | + <% if Configuration.multicontests? %> | ||
|
|
37 | + <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> | ||
|
|
38 | + <% end %> | ||
|
36 | </div> |
|
39 | </div> |
|
37 |
|
40 | ||
|
38 | - <table> |
|
41 | + <table class="info"> |
|
39 | - <tr> |
|
42 | + <tr class="info-head"> |
|
40 | <% for column in User.content_columns %> |
|
43 | <% for column in User.content_columns %> |
|
41 | <% if !@hidden_columns.index(column.name) %> |
|
44 | <% if !@hidden_columns.index(column.name) %> |
|
42 | <th><%= column.human_name %></th> |
|
45 | <th><%= column.human_name %></th> |
|
43 | <% end %> |
|
46 | <% end %> |
|
44 | <% end %> |
|
47 | <% end %> |
|
|
48 | + <th></th> | ||
|
|
49 | + <th></th> | ||
|
|
50 | + <th></th> | ||
|
|
51 | + <% if Configuration.multicontests? %> | ||
|
|
52 | + <th>Contests</th> | ||
|
|
53 | + <th>Other enabled contests</th> | ||
|
|
54 | + <% end %> | ||
|
45 | </tr> |
|
55 | </tr> |
|
46 |
|
56 | ||
|
47 | <% for user in @users %> |
|
57 | <% for user in @users %> |
|
48 | - <tr> |
|
58 | + <tr class="info-<%= cycle("odd","even") %>"> |
|
49 | <% for column in User.content_columns %> |
|
59 | <% for column in User.content_columns %> |
|
50 | <% if !@hidden_columns.index(column.name) %> |
|
60 | <% if !@hidden_columns.index(column.name) %> |
|
51 | <td><%=h user.send(column.name) %></td> |
|
61 | <td><%=h user.send(column.name) %></td> |
|
52 | <% end %> |
|
62 | <% end %> |
|
53 | <% end %> |
|
63 | <% end %> |
|
54 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
64 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
55 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
65 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
56 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
66 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
|
67 | + <% if Configuration.multicontests? %> | ||
|
|
68 | + <td> | ||
|
|
69 | + <% user.contests.each do |contest| %> | ||
|
|
70 | + <%= contest.name %> [<%= link_to 'x', :action => 'remove_from_contest', :id => user.id, :contest_id => contest.id %>] | ||
|
|
71 | + <% end %> | ||
|
|
72 | + </td> | ||
|
|
73 | + <td> | ||
|
|
74 | + <% @contests.each do |contest| %> | ||
|
|
75 | + <% if not user.contests.all.find {|c| c.id==contest.id } %> | ||
|
|
76 | + <%= contest.name %> [<%= link_to '+', :action => 'add_to_contest', :id => user.id, :contest_id => contest.id %>] | ||
|
|
77 | + <% end %> | ||
|
|
78 | + <% end %> | ||
|
|
79 | + </td> | ||
|
|
80 | + <% end %> | ||
|
57 | </tr> |
|
81 | </tr> |
|
58 | <% end %> |
|
82 | <% end %> |
|
59 | </table> |
|
83 | </table> |
|
60 |
|
84 | ||
|
61 |
|
85 | ||
|
62 | <br /> |
|
86 | <br /> |
|
63 |
|
87 | ||
|
64 | <%= link_to 'New user', :action => 'new' %> |
|
88 | <%= link_to 'New user', :action => 'new' %> |
|
65 | <%= link_to 'New list of users', :action => 'new_list' %> |
|
89 | <%= link_to 'New list of users', :action => 'new_list' %> |
You need to be logged in to leave comments.
Login now