Description:
better user import
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r798:46ce575fc051 - - 6 files changed: 28 inserted, 17 deleted

@@ -44,79 +44,89
44 44 if @user.save
45 45 flash[:notice] = 'User was successfully created.'
46 46 redirect_to :action => 'index'
47 47 else
48 48 render :action => 'new'
49 49 end
50 50 end
51 51
52 52 def clear_last_ip
53 53 @user = User.find(params[:id])
54 54 @user.last_ip = nil
55 55 @user.save
56 56 redirect_to action: 'index', page: params[:page]
57 57 end
58 58
59 59 def create_from_list
60 60 lines = params[:user_list]
61 61
62 62 note = []
63 63 error_note = []
64 64 error_msg = nil
65 65 ok_user = []
66 66
67 67 lines.split("\n").each do |line|
68 - items = line.chomp.split(',')
68 + #split with large limit, this will cause consecutive ',' to be result in a blank
69 + items = line.chomp.split(',',1000)
69 70 if items.length>=2
70 71 login = items[0]
71 72 full_name = items[1]
72 73 remark =''
73 74 user_alias = ''
74 75
75 76 added_random_password = false
76 - if items.length >= 3 and items[2].chomp(" ").length > 0;
77 + added_password = false
78 + if items.length >= 3
79 + if items[2].chomp(" ").length > 0
77 80 password = items[2].chomp(" ")
81 + added_password = true
82 + end
78 83 else
79 84 password = random_password
80 85 added_random_password=true;
81 86 end
82 87
83 88 if items.length>= 4 and items[3].chomp(" ").length > 0;
84 89 user_alias = items[3].chomp(" ")
85 90 else
86 91 user_alias = login
87 92 end
88 93
94 +
95 + has_remark = false
89 96 if items.length>=5
90 97 remark = items[4].strip;
98 + has_remark = true
91 99 end
92 100
93 101 user = User.find_by_login(login)
94 102 if (user)
95 103 user.full_name = full_name
96 - user.password = password
97 - user.remark = remark
104 + user.remark = remark if has_remark
105 + user.password = password if added_password || added_random_password
98 106 else
107 + #create a random password if none are given
108 + password = random_password unless password
99 109 user = User.new({:login => login,
100 110 :full_name => full_name,
101 111 :password => password,
102 112 :password_confirmation => password,
103 113 :alias => user_alias,
104 114 :remark => remark})
105 115 end
106 116 user.activated = true
107 117
108 118 if user.save
109 119 if added_random_password
110 120 note << "'#{login}' (+)"
111 121 else
112 122 note << login
113 123 end
114 124 ok_user << user
115 125 else
116 126 error_note << "'#{login}'"
117 127 error_msg = user.errors.full_messages.to_sentence unless error_msg
118 128 end
119 129
120 130 end
121 131 end
122 132
@@ -161,51 +161,48
161 161 " #{format_short_duration(user.contest_time_left)}"
162 162 end
163 163 end
164 164
165 165 #
166 166 # if the contest is in the anaysis mode
167 167 if GraderConfiguration.analysis_mode?
168 168 header = <<ANALYSISMODE
169 169 <tr><td colspan="2" align="center">
170 170 <span class="contest-over-msg">ANALYSIS MODE</span>
171 171 </td></tr>
172 172 ANALYSISMODE
173 173 end
174 174
175 175 contest_name = GraderConfiguration['contest.name']
176 176
177 177 #
178 178 # build real title bar
179 179 result = <<TITLEBAR
180 180 <div class="title">
181 181 <table>
182 182 #{header}
183 183 <tr>
184 184 <td class="left-col">
185 - #{user.full_name}<br/>
186 - #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)}
187 - #{time_left}
188 185 <br/>
189 186 </td>
190 187 <td class="right-col">#{contest_name}</td>
191 188 </tr>
192 189 </table>
193 190 </div>
194 191 TITLEBAR
195 192 result.html_safe
196 193 end
197 194
198 195 def markdown(text)
199 196 markdown = RDiscount.new(text)
200 197 markdown.to_html.html_safe
201 198 end
202 199
203 200
204 201 BOOTSTRAP_FLASH_MSG = {
205 202 success: 'alert-success',
206 203 error: 'alert-danger',
207 204 alert: 'alert-danger',
208 205 notice: 'alert-info'
209 206 }
210 207
211 208 def bootstrap_class_for(flash_type)
@@ -1,20 +1,14
1 1 module MainHelper
2 2
3 - def link_to_description_if_any(name, problem, options={})
3 + def link_to_description_if_any(name, problem)
4 4 if !problem.url.blank?
5 - return link_to name, problem.url, options
5 + return link_to name, problem.url
6 6 elsif !problem.description_filename.blank?
7 - #build a link to a problem (via task controller)
8 7 basename, ext = problem.description_filename.split('.')
9 - options[:controller] = 'tasks'
10 - options[:action] = 'download'
11 - options[:id] = problem.id
12 - options[:file] = basename
13 - options[:ext] = ext
14 - return link_to name, options
8 + return link_to name, download_task_path(problem.id,basename,ext), target: '_blank'
15 9 else
16 10 return ''
17 11 end
18 12 end
19 13
20 14 end
@@ -21,48 +21,49
21 21 e = ace.edit("editor")
22 22 e.setOptions({ maxLines: Infinity })
23 23 e.setValue($("#data").text())
24 24 e.gotoLine(1)
25 25 e.getSession().setMode("#{get_ace_mode(@submission.language)}")
26 26 e.setReadOnly(true)
27 27 .col-md-5
28 28 %table.table.table-striped
29 29 %tr
30 30 %td.text-right
31 31 %strong User
32 32 %td
33 33 - if @submission.user
34 34 = link_to "#{@submission.user.login}", stat_user_path(@submission.user)
35 35 = @submission.user.full_name
36 36 - else
37 37 = "(n/a)"
38 38 %tr
39 39 %td.text-right
40 40 %strong Task
41 41 %td
42 42 - if @submission.problem!=nil
43 43 = link_to "[#{@submission.problem.name}]", stat_problem_path(@submission.problem)
44 44 = @submission.problem.full_name
45 + = link_to_description_if_any "[download] <span class='glyphicon glyphicon-file'></span>".html_safe, @submission.problem
45 46 - else
46 47 = "(n/a)"
47 48 %tr
48 49 %td.text-right
49 50 %strong Tries
50 51 %td= @submission.number
51 52 %tr
52 53 %td.text-right
53 54 %strong Language
54 55 %td= @submission.language.pretty_name
55 56 %tr
56 57 %td.text-right
57 58 %strong Submitted
58 59 %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
59 60 %tr
60 61 %td.text-right
61 62 %strong Graded
62 63 - if @submission.graded_at
63 64 %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
64 65 - else
65 66 %td -
66 67 %tr
67 68 %td.text-right
68 69 %strong Points
@@ -5,41 +5,50
5 5 .row
6 6 .col-md-6
7 7 .panel.panel-default
8 8 .panel-heading
9 9 .panel-title Info
10 10 .panel-body
11 11 %ul
12 12 %li
13 13 List of user information in this format:
14 14 %tt user_id,name(,passwd(,alias(,remark)))
15 15 %li
16 16 Note that
17 17 %tt passwd, alias
18 18 and
19 19 %tt remark
20 20 is optional.
21 21 %li
22 22 When
23 23 %tt passwd
24 24 or
25 25 %tt alias
26 26 is empty, the original value will be used instead.
27 27 %li
28 28 If the users with the same user_id already exists, existing information will be overwritten.
29 + Example:
30 + %ol
31 + %li
32 + %pre user1,Somchai Jaidee
33 + will create (or update) a user with login "user1" and setting the fullname to "Somchai Jaidee", also setting a random password.
34 + %li
35 + %pre user1,Somchai Jaidee,
36 + will create (or update) a user with login "user1" and and setting the fullname "Somchai Jaidee". No change is made to the password unless this is a new user. If this is a new user, a random password will be generated.
37 +
29 38
30 39 .row
31 40 .col-md-6
32 41 = form_tag :action => 'create_from_list' do
33 42 .form-group
34 43 = submit_tag 'Create following users',class: 'btn btn-success'
35 44 .form-group
36 45 .div.checkbox
37 46 %label
38 47 = check_box_tag :add_to_group
39 48 Also add these users to the following group
40 49 = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
41 50 .form-group
42 51 = text_area_tag 'user_list', nil, :rows => 50, :cols => 80
43 52 .col-md-6
44 53
45 54
@@ -156,49 +156,49
156 156 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
157 157 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
158 158 #get "report/login"
159 159 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
160 160 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
161 161
162 162 resource :main, only: [], controller: 'main' do
163 163 get 'login'
164 164 get 'logout'
165 165 get 'list'
166 166 get 'submission(/:id)', action: 'submission', as: 'main_submission'
167 167 get 'announcements'
168 168 get 'help'
169 169 post 'submit'
170 170 end
171 171 #main
172 172 #get "main/list"
173 173 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
174 174 #post 'main/submit', to: 'main#submit'
175 175 #get 'main/announcements', to: 'main#announcements'
176 176
177 177
178 178 #
179 179 get 'tasks/view/:file.:ext' => 'tasks#view'
180 - get 'tasks/download/:id/:file.:ext' => 'tasks#download'
180 + get 'tasks/download/:id/:file.:ext' => 'tasks#download', as: 'download_task'
181 181 get 'heartbeat/:id/edit' => 'heartbeat#edit'
182 182
183 183 #grader
184 184 get 'graders/list', to: 'graders#list', as: 'grader_list'
185 185 namespace :graders do
186 186 get 'task/:id/:type', action: 'task', as: 'task'
187 187 get 'view/:id/:type', action: 'view', as: 'view'
188 188 get 'clear/:id', action: 'clear', as: 'clear'
189 189 get 'stop'
190 190 get 'stop_all'
191 191 get 'clear_all'
192 192 get 'clear_terminated'
193 193 get 'start_grading'
194 194 get 'start_exam'
195 195
196 196 end
197 197
198 198
199 199 # See how all your routes lay out with "rake routes"
200 200
201 201 # This is a legacy wild controller route that's not recommended for RESTful applications.
202 202 # Note: This route will make all actions in every controller accessible via GET requests.
203 203 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
204 204 end
You need to be logged in to leave comments. Login now