# HG changeset patch # User Nattee Niparnan # Date 2020-08-25 17:30:55 # Node ID 46ce575fc05116fc2581d0f6c777e9b7b20129fb # Parent ebe6e5beb7c47199e52957ea373c3a847ab2042c better user import 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 @@ -65,7 +65,8 @@ ok_user = [] lines.split("\n").each do |line| - items = line.chomp.split(',') + #split with large limit, this will cause consecutive ',' to be result in a blank + items = line.chomp.split(',',1000) if items.length>=2 login = items[0] full_name = items[1] @@ -73,8 +74,12 @@ user_alias = '' added_random_password = false - if items.length >= 3 and items[2].chomp(" ").length > 0; - password = items[2].chomp(" ") + added_password = false + if items.length >= 3 + if items[2].chomp(" ").length > 0 + password = items[2].chomp(" ") + added_password = true + end else password = random_password added_random_password=true; @@ -86,16 +91,21 @@ user_alias = login end + + has_remark = false if items.length>=5 remark = items[4].strip; + has_remark = true end user = User.find_by_login(login) if (user) user.full_name = full_name - user.password = password - user.remark = remark + user.remark = remark if has_remark + user.password = password if added_password || added_random_password else + #create a random password if none are given + password = random_password unless password user = User.new({:login => login, :full_name => full_name, :password => password, diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -182,9 +182,6 @@ #{header} -#{user.full_name}
-#{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} -#{time_left}
#{contest_name} diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -1,17 +1,11 @@ module MainHelper - def link_to_description_if_any(name, problem, options={}) + def link_to_description_if_any(name, problem) if !problem.url.blank? - return link_to name, problem.url, options + return link_to name, problem.url elsif !problem.description_filename.blank? - #build a link to a problem (via task controller) basename, ext = problem.description_filename.split('.') - options[:controller] = 'tasks' - options[:action] = 'download' - options[:id] = problem.id - options[:file] = basename - options[:ext] = ext - return link_to name, options + return link_to name, download_task_path(problem.id,basename,ext), target: '_blank' else return '' end diff --git a/app/views/submissions/show.html.haml b/app/views/submissions/show.html.haml --- a/app/views/submissions/show.html.haml +++ b/app/views/submissions/show.html.haml @@ -42,6 +42,7 @@ - if @submission.problem!=nil = link_to "[#{@submission.problem.name}]", stat_problem_path(@submission.problem) = @submission.problem.full_name + = link_to_description_if_any "[download] ".html_safe, @submission.problem - else = "(n/a)" %tr diff --git a/app/views/user_admin/new_list.html.haml b/app/views/user_admin/new_list.html.haml --- a/app/views/user_admin/new_list.html.haml +++ b/app/views/user_admin/new_list.html.haml @@ -26,6 +26,15 @@ is empty, the original value will be used instead. %li If the users with the same user_id already exists, existing information will be overwritten. + Example: + %ol + %li + %pre user1,Somchai Jaidee + will create (or update) a user with login "user1" and setting the fullname to "Somchai Jaidee", also setting a random password. + %li + %pre user1,Somchai Jaidee, + 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. + .row .col-md-6 diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -177,7 +177,7 @@ # get 'tasks/view/:file.:ext' => 'tasks#view' - get 'tasks/download/:id/:file.:ext' => 'tasks#download' + get 'tasks/download/:id/:file.:ext' => 'tasks#download', as: 'download_task' get 'heartbeat/:id/edit' => 'heartbeat#edit' #grader