Description:
assigns users to a unique contest, small styling on contest title
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r281:ddf493b045db - - 4 files changed: 22 inserted, 12 deleted

@@ -91,213 +91,215
91 91 end
92 92
93 93 def edit
94 94 @user = User.find(params[:id])
95 95 end
96 96
97 97 def update
98 98 @user = User.find(params[:id])
99 99 if @user.update_attributes(params[:user])
100 100 flash[:notice] = 'User was successfully updated.'
101 101 redirect_to :action => 'show', :id => @user
102 102 else
103 103 render :action => 'edit'
104 104 end
105 105 end
106 106
107 107 def destroy
108 108 User.find(params[:id]).destroy
109 109 redirect_to :action => 'list'
110 110 end
111 111
112 112 def user_stat
113 113 @problems = Problem.find_available_problems
114 114 @users = User.find(:all)
115 115 @scorearray = Array.new
116 116 @users.each do |u|
117 117 ustat = Array.new
118 118 ustat[0] = u
119 119 @problems.each do |p|
120 120 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
121 121 if (sub!=nil) and (sub.points!=nil)
122 122 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
123 123 else
124 124 ustat << [0,false]
125 125 end
126 126 end
127 127 @scorearray << ustat
128 128 end
129 129 end
130 130
131 131 def import
132 132 if params[:file]==''
133 133 flash[:notice] = 'Error importing no file'
134 134 redirect_to :action => 'list' and return
135 135 end
136 136 import_from_file(params[:file])
137 137 end
138 138
139 139 def random_all_passwords
140 140 users = User.find(:all)
141 141 @prefix = params[:prefix] || ''
142 142 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
143 143 @changed = false
144 144 if request.request_method == :post
145 145 @non_admin_users.each do |user|
146 146 password = random_password
147 147 user.password = password
148 148 user.password_confirmation = password
149 149 user.save
150 150 end
151 151 @changed = true
152 152 end
153 153 end
154 154
155 155 # contest management
156 156
157 157 def add_to_contest
158 158 user = User.find(params[:id])
159 159 contest = Contest.find(params[:contest_id])
160 160 if user and contest
161 161 user.contests << contest
162 162 end
163 163 redirect_to :action => 'list'
164 164 end
165 165
166 166 def remove_from_contest
167 167 user = User.find(params[:id])
168 168 contest = Contest.find(params[:contest_id])
169 169 if user and contest
170 170 user.contests.delete(contest)
171 171 end
172 172 redirect_to :action => 'list'
173 173 end
174 174
175 175 def contest_management
176 176 end
177 177
178 178 def manage_contest
179 179 contest = Contest.find(params[:contest][:id])
180 180 if !contest
181 181 flash[:notice] = 'You did not choose the contest.'
182 182 redirect_to :action => 'contest_management' and return
183 183 end
184 184
185 185 operation = params[:operation]
186 186
187 - if operation!='add' and operation!='remove'
187 + if not ['add','remove','assign'].include? operation
188 188 flash[:notice] = 'You did not choose the operation to perform.'
189 189 redirect_to :action => 'contest_management' and return
190 190 end
191 191
192 192 lines = params[:login_list]
193 193 if !lines or lines.blank?
194 194 flash[:notice] = 'You entered an empty list.'
195 195 redirect_to :action => 'contest_management' and return
196 196 end
197 197
198 198 note = []
199 199 lines.split("\n").each do |line|
200 200 puts line
201 201 user = User.find_by_login(line.chomp)
202 202 puts user
203 203 if user
204 204 if operation=='add'
205 205 user.contests << contest
206 + elsif operation=='remove'
207 + user.contests.delete(contest)
206 208 else
207 - user.contests.delete(contest)
209 + user.contests = [contest]
208 210 end
209 211 note << user.login
210 212 end
211 213 end
212 214 flash[:notice] = 'User(s) ' + note.join(', ') +
213 215 ' were successfully modified. '
214 216 redirect_to :action => 'contest_management'
215 217 end
216 218
217 219 # admin management
218 220
219 221 def admin
220 222 @admins = User.find(:all).find_all {|user| user.admin? }
221 223 end
222 224
223 225 def grant_admin
224 226 login = params[:login]
225 227 user = User.find_by_login(login)
226 228 if user!=nil
227 229 admin_role = Role.find_by_name('admin')
228 230 user.roles << admin_role
229 231 else
230 232 flash[:notice] = 'Unknown user'
231 233 end
232 234 flash[:notice] = 'User added as admins'
233 235 redirect_to :action => 'admin'
234 236 end
235 237
236 238 def revoke_admin
237 239 user = User.find(params[:id])
238 240 if user==nil
239 241 flash[:notice] = 'Unknown user'
240 242 redirect_to :action => 'admin' and return
241 243 elsif user.login == 'root'
242 244 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
243 245 redirect_to :action => 'admin' and return
244 246 end
245 247
246 248 admin_role = Role.find_by_name('admin')
247 249 user.roles.delete(admin_role)
248 250 flash[:notice] = 'User permission revoked'
249 251 redirect_to :action => 'admin'
250 252 end
251 253
252 254 protected
253 255
254 256 def random_password(length=5)
255 257 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
256 258 newpass = ""
257 259 length.times { newpass << chars[rand(chars.size-1)] }
258 260 return newpass
259 261 end
260 262
261 263 def import_from_file(f)
262 264 data_hash = YAML.load(f)
263 265 @import_log = ""
264 266
265 267 country_data = data_hash[:countries]
266 268 site_data = data_hash[:sites]
267 269 user_data = data_hash[:users]
268 270
269 271 # import country
270 272 countries = {}
271 273 country_data.each_pair do |id,country|
272 274 c = Country.find_by_name(country[:name])
273 275 if c!=nil
274 276 countries[id] = c
275 277 @import_log << "Found #{country[:name]}\n"
276 278 else
277 279 countries[id] = Country.new(:name => country[:name])
278 280 countries[id].save
279 281 @import_log << "Created #{country[:name]}\n"
280 282 end
281 283 end
282 284
283 285 # import sites
284 286 sites = {}
285 287 site_data.each_pair do |id,site|
286 288 s = Site.find_by_name(site[:name])
287 289 if s!=nil
288 290 @import_log << "Found #{site[:name]}\n"
289 291 else
290 292 s = Site.new(:name => site[:name])
291 293 @import_log << "Created #{site[:name]}\n"
292 294 end
293 295 s.password = site[:password]
294 296 s.country = countries[site[:country_id]]
295 297 s.save
296 298 sites[id] = s
297 299 end
298 300
299 301 # import users
300 302 user_data.each_pair do |id,user|
301 303 u = User.find_by_login(user[:login])
302 304 if u!=nil
303 305 @import_log << "Found #{user[:login]}\n"
@@ -1,16 +1,16
1 1 %h1 Bulk edit users in contests
2 2
3 3 - form_tag :action => 'manage_contest' do
4 4 List users' login below; one per line.
5 5 %br/
6 6 = text_area_tag 'login_list', nil, :rows => 25, :cols => 80
7 7 %br/
8 8 You want to
9 - = select(nil,"operation",[['add users to','add'],['remove users from','remove']])
9 + = select(nil,"operation",[['assign users to','assign'],['add users to','add'],['remove users from','remove']])
10 10 contest
11 11 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
12 12 &nbsp;&nbsp;&nbsp;&nbsp;
13 13 = submit_tag "Perform action", :confirm => 'Are you sure?'
14 14
15 15 %hr/
16 16 = link_to '[go back to index]', :action => 'index'
@@ -67,171 +67,176
67 67 padding: 0 0.5em; }
68 68 table.info td {
69 69 border-left: 1px solid #666666;
70 70 border-right: 1px solid #666666;
71 71 line-height: 1.5em;
72 72 padding: 0 0.5em; }
73 73
74 74 tr.info-head {
75 75 background: #777777;
76 76 color: white; }
77 77 tr.info-odd {
78 78 background: #eeeeee; }
79 79 tr.info-even {
80 80 background: #f9f9f9; }
81 81
82 82 .infobox {
83 83 background: #eeeeff;
84 84 border: 1px dotted #99aaee;
85 85 padding: 5px;
86 86 margin: 10px 0px;
87 87 color: black;
88 88 font-size: 13px; }
89 89
90 90 .submitbox {
91 91 background: #eeeeff;
92 92 border: 1px dotted #99aaee;
93 93 padding: 5px;
94 94 margin: 10px 0px;
95 95 color: black;
96 96 font-size: 13px; }
97 97
98 98 .errorExplanation {
99 99 border: 1px dotted gray;
100 100 color: #bb2222;
101 101 padding: 5px 15px 5px 15px;
102 102 margin-bottom: 5px;
103 103 background-color: white;
104 104 font-weight: normal; }
105 105 .errorExplanation h2 {
106 106 color: #cc1111;
107 107 font-weight: bold; }
108 108
109 109 table.uinfo {
110 110 border-collapse: collapse;
111 111 border: 1px solid black;
112 112 font-size: 13px; }
113 113
114 114 td.uinfo {
115 115 vertical-align: top;
116 116 border: 1px solid black;
117 117 padding: 5px; }
118 118
119 119 th.uinfo {
120 120 background: lightgreen;
121 121 vertical-align: top;
122 122 text-align: right;
123 123 border: 1px solid black;
124 124 padding: 5px; }
125 125
126 126 div.compilermsgbody {
127 127 font-family: monospace; }
128 128 div.task-menu {
129 129 text-align: center;
130 130 font-size: 13px;
131 131 line-height: 1.75em;
132 132 font-weight: bold;
133 133 border-top: 1px dashed gray;
134 134 border-bottom: 1px dashed gray;
135 135 margin-top: 2px;
136 136 margin-bottom: 4px; }
137 137
138 138 table.taskdesc {
139 139 border: 2px solid #dddddd;
140 140 border-collapse: collapse;
141 141 margin: 10px auto;
142 142 width: 90%;
143 143 font-size: 13px; }
144 144 table.taskdesc p {
145 145 font-size: 13px; }
146 146 table.taskdesc tr.name {
147 147 border: 2px solid #dddddd;
148 148 background: #dddddd;
149 149 color: #333333;
150 150 font-weight: bold;
151 151 font-size: 14px;
152 152 line-height: 1.5em;
153 153 text-align: center; }
154 154 table.taskdesc td.desc-odd {
155 155 padding: 5px;
156 156 padding-left: 20px;
157 157 background: #fefeee; }
158 158 table.taskdesc td.desc-even {
159 159 padding: 5px;
160 160 padding-left: 20px;
161 161 background: #feeefe; }
162 162
163 - div.announcementbox {
163 + .announcementbox {
164 164 margin: 10px 0px;
165 165 background: #bbddee;
166 166 padding: 1px; }
167 - div.announcementbox span.title {
167 + .announcementbox span.title {
168 168 font-weight: bold;
169 169 color: #224455;
170 170 padding-left: 10px;
171 171 line-height: 1.6em; }
172 - div.announcement {
172 +
173 + .announcement {
173 174 margin: 2px;
174 175 background: white;
175 176 padding: 1px;
176 177 padding-left: 10px;
177 178 padding-right: 10px;
178 179 padding-top: 5px;
179 180 padding-bottom: 5px; }
180 181
181 182 .announcement p {
182 183 font-size: 12px;
183 184 margin: 2px; }
184 185
185 - div.pub-info {
186 + .pub-info {
186 187 text-align: right;
187 188 font-style: italic;
188 189 font-size: 9px; }
189 - div.pub-info p {
190 + .pub-info p {
190 191 text-align: right;
191 192 font-style: italic;
192 193 font-size: 9px; }
193 194
194 195 .announcement .toggles {
195 196 font-weight: normal;
196 197 float: right;
197 198 font-size: 80%; }
198 199 .announcement .announcement-title {
199 200 font-weight: bold; }
200 201
201 202 div.message {
202 203 margin: 10px 0 0; }
203 204 div.message div.message {
204 205 margin: 0 0 0 30px; }
205 206 div.message div.body {
206 207 border: 2px solid #dddddd;
207 208 background: #fff8f8;
208 209 padding-left: 5px; }
209 210 div.message div.reply-body {
210 211 border: 2px solid #bbbbbb;
211 212 background: #fffff8;
212 213 padding-left: 5px; }
213 214 div.message div.stat {
214 215 font-size: 10px;
215 216 line-height: 1.75em;
216 217 padding: 0 5px;
217 218 color: #333333;
218 219 background: #dddddd;
219 220 font-weight: bold; }
220 221 div.message div.message div.stat {
221 222 font-size: 10px;
222 223 line-height: 1.75em;
223 224 padding: 0 5px;
224 225 color: #444444;
225 226 background: #bbbbbb;
226 227 font-weight: bold; }
227 228 div.contest-title {
228 229 color: white;
229 230 text-align: center;
230 231 line-height: 2em; }
231 232 div.registration-desc, div.test-desc {
232 233 border: 1px dotted gray;
233 234 background: #f5f5f5;
234 235 padding: 5px;
235 236 margin: 10px 0;
236 237 font-size: 12px;
237 238 line-height: 1.5em; }
239 +
240 + h2.contest-title {
241 + margin-top: 5px;
242 + margin-bottom: 5px; }
@@ -101,190 +101,193
101 101 &.info-even
102 102 background: #f9f9f9
103 103
104 104 =basicbox
105 105 background: #eeeeff
106 106 border: 1px dotted #99aaee
107 107 padding: 5px
108 108 margin: 10px 0px
109 109 color: black
110 110 font-size: 13px
111 111
112 112 .infobox
113 113 +basicbox
114 114
115 115 .submitbox
116 116 +basicbox
117 117
118 118 .errorExplanation
119 119 border: 1px dotted gray
120 120 color: #bb2222
121 121 padding: 5px 15px 5px 15px
122 122 margin-bottom: 5px
123 123 background-color: white
124 124 font-weight: normal
125 125
126 126 h2
127 127 color: #cc1111
128 128 font-weight: bold
129 129
130 130
131 131 table.uinfo
132 132 border-collapse: collapse
133 133 border: 1px solid black
134 134 font-size: 13px
135 135
136 136
137 137 td.uinfo
138 138 vertical-align: top
139 139 border: 1px solid black
140 140 padding: 5px
141 141
142 142
143 143 th.uinfo
144 144 background: lightgreen
145 145 vertical-align: top
146 146 text-align: right
147 147 border: 1px solid black
148 148 padding: 5px
149 149
150 150
151 151 div
152 152 &.compilermsgbody
153 153 font-family: monospace
154 154
155 155 &.task-menu
156 156 text-align: center
157 157 font-size: 13px
158 158 line-height: 1.75em
159 159 font-weight: bold
160 160 border-top: 1px dashed gray
161 161 border-bottom: 1px dashed gray
162 162 margin-top: 2px
163 163 margin-bottom: 4px
164 164
165 165
166 166 table.taskdesc
167 167 border: 2px solid #dddddd
168 168 border-collapse: collapse
169 169 margin: 10px auto
170 170 width: 90%
171 171 font-size: 13px
172 172
173 173 p
174 174 font-size: 13px
175 175
176 176 tr.name
177 177 border: 2px solid #dddddd
178 178 background: #dddddd
179 179 color: #333333
180 180 font-weight: bold
181 181 font-size: 14px
182 182 line-height: 1.5em
183 183 text-align: center
184 184
185 185 td
186 186 &.desc-odd
187 187 padding: 5px
188 188 padding-left: 20px
189 189 background: #fefeee
190 190
191 191 &.desc-even
192 192 padding: 5px
193 193 padding-left: 20px
194 194 background: #feeefe
195 195
196 196
197 - div
198 - &.announcementbox
197 + .announcementbox
199 198 margin: 10px 0px
200 199 background: #bbddee
201 200 padding: 1px
202 201
203 202 span.title
204 203 font-weight: bold
205 204 color: #224455
206 205 padding-left: 10px
207 206 line-height: 1.6em
208 207
209 - &.announcement
208 + .announcement
210 209 margin: 2px
211 210 background: white
212 211 padding: 1px
213 212 padding-left: 10px
214 213 padding-right: 10px
215 214 padding-top: 5px
216 215 padding-bottom: 5px
217 216
218 217
219 218 .announcement p
220 219 font-size: 12px
221 220 margin: 2px
222 221
223 222
224 - div.pub-info
223 + .pub-info
225 224 text-align: right
226 225 font-style: italic
227 226 font-size: 9px
228 227
229 228 p
230 229 text-align: right
231 230 font-style: italic
232 231 font-size: 9px
233 232
234 233
235 234 .announcement
236 235 .toggles
237 236 font-weight: normal
238 237 float: right
239 238 font-size: 80%
240 239
241 240 .announcement-title
242 241 font-weight: bold
243 242
244 243
245 244 div
246 245 &.message
247 246 margin: 10px 0 0
248 247
249 248 div
250 249 &.message
251 250 margin: 0 0 0 30px
252 251
253 252 &.body
254 253 border: 2px solid #dddddd
255 254 background: #fff8f8
256 255 padding-left: 5px
257 256
258 257 &.reply-body
259 258 border: 2px solid #bbbbbb
260 259 background: #fffff8
261 260 padding-left: 5px
262 261
263 262 &.stat
264 263 font-size: 10px
265 264 line-height: 1.75em
266 265 padding: 0 5px
267 266 color: #333333
268 267 background: #dddddd
269 268 font-weight: bold
270 269
271 270 &.message div.stat
272 271 font-size: 10px
273 272 line-height: 1.75em
274 273 padding: 0 5px
275 274 color: #444444
276 275 background: #bbbbbb
277 276 font-weight: bold
278 277
279 278 &.contest-title
280 279 color: white
281 280 text-align: center
282 281 line-height: 2em
283 282
284 283 &.registration-desc, &.test-desc
285 284 border: 1px dotted gray
286 285 background: #f5f5f5
287 286 padding: 5px
288 287 margin: 10px 0
289 288 font-size: 12px
290 289 line-height: 1.5em
290 +
291 + h2.contest-title
292 + margin-top: 5px
293 + margin-bottom: 5px No newline at end of file
You need to be logged in to leave comments. Login now