Description:
merge with algo-bm
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r787:6a311ff47066 - - 13 files changed: 81 inserted, 75 deleted

@@ -1,22 +1,22
1 1 require 'ipaddr'
2 2
3 3 class ApplicationController < ActionController::Base
4 4 protect_from_forgery
5 5
6 6 before_action :current_user
7 7
8 8 SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
9 9 MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login'
10 - ALLOW_WHITELIST_IP_ONLY_CONF_KEY = 'right.allow_whitelist_ip_only'
10 + WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore'
11 11 WHITELIST_IP_CONF_KEY = 'right.whitelist_ip'
12 12
13 13 #report and redirect for unauthorized activities
14 14 def unauthorized_redirect(notice = 'You are not authorized to view the page you requested')
15 15 flash[:notice] = notice
16 16 redirect_to login_main_path
17 17 end
18 18
19 19 # Returns the current logged-in user (if any).
20 20 def current_user
21 21 return nil unless session[:user_id]
22 22 @current_user ||= User.find(session[:user_id])
@@ -72,55 +72,53
72 72 unauthorized_redirect('You cannot log in at this time')
73 73 return false
74 74 end
75 75 end
76 76
77 77 # check if the user is enabled
78 78 unless @current_user.enabled? || @current_user.admin?
79 79 unauthorized_redirect 'Your account is disabled'
80 80 return false
81 81 end
82 82
83 83 # check if user ip is allowed
84 - unless @current_user.admin? || !GraderConfiguration[ALLOW_WHITELIST_IP_ONLY_CONF_KEY]
84 + unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
85 85 unless is_request_ip_allowed?
86 - unauthorized_redirect 'Your IP is not allowed'
86 + unauthorized_redirect 'Your IP is not allowed to login at this time.'
87 87 return false
88 88 end
89 89 end
90 90
91 91 if GraderConfiguration.multicontests?
92 92 return true if @current_user.admin?
93 93 begin
94 94 if @current_user.contest_stat(true).forced_logout
95 95 flash[:notice] = 'You have been automatically logged out.'
96 96 redirect_to :controller => 'main', :action => 'index'
97 97 end
98 98 rescue
99 99 end
100 100 end
101 101 return true
102 102 end
103 103
104 104 #redirect to root (and also force logout)
105 105 #if the user use different ip from the previous connection
106 106 # only applicable when MULTIPLE_IP_LOGIN options is false only
107 107 def authenticate_by_ip_address
108 108 #this assume that we have already authenticate normally
109 109 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
110 110 user = User.find(session[:user_id])
111 - puts "User admin #{user.admin?}"
112 111 if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip)
113 112 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
114 - puts "hahaha"
115 113 redirect_to :controller => 'main', :action => 'login'
116 114 return false
117 115 end
118 116 unless user.last_ip
119 117 user.last_ip = request.remote_ip
120 118 user.save
121 119 end
122 120 end
123 121 return true
124 122 end
125 123
126 124 def authorization
@@ -143,25 +141,27
143 141 return true if session[:user_id]==nil
144 142 user = User.find(session[:user_id], :include => :site)
145 143 return true if user==nil || user.site == nil
146 144 if user.contest_finished?
147 145 flash[:notice] = 'Error: the contest you are participating is over.'
148 146 redirect_to :back
149 147 return false
150 148 end
151 149 return true
152 150 end
153 151
154 152 def is_request_ip_allowed?
155 - if GraderConfiguration[ALLOW_WHITELIST_IP_ONLY_CONF_KEY]
153 + unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
156 154 user_ip = IPAddr.new(request.remote_ip)
157 - GraderConfiguration[WHITELIST_IP_LIST_CONF_KEY].delete(' ').split(',').each do |ips|
155 +
156 + GraderConfiguration[WHITELIST_IP_CONF_KEY].delete(' ').split(',').each do |ips|
158 157 allow_ips = IPAddr.new(ips)
159 - unless allow_ips.includes(user_ip)
160 - return false
158 + if allow_ips.include?(user_ip)
159 + return true
161 160 end
162 161 end
162 + return false
163 163 end
164 164 return true
165 165 end
166 166
167 167 end
@@ -12,24 +12,25
12 12 # system only in some tab
13 13 prepend_before_action :reject_announcement_refresh_when_logged_out,
14 14 :only => [:announcements]
15 15
16 16 before_action :authenticate_by_ip_address, :only => [:list]
17 17
18 18 #reset login, clear session
19 19 #front page
20 20 def login
21 21 saved_notice = flash[:notice]
22 22 reset_session
23 23 flash.now[:notice] = saved_notice
24 + @remote_ip = request.remote_ip
24 25
25 26 # EXPERIMENT:
26 27 # Hide login if in single user mode and the url does not
27 28 # explicitly specify /login
28 29 #
29 30 # logger.info "PATH: #{request.path}"
30 31 # if GraderConfiguration['system.single_user_mode'] and
31 32 # request.path!='/main/login'
32 33 # @hidelogin = true
33 34 # end
34 35
35 36 @announcements = Announcement.frontpage
@@ -456,24 +456,25
456 456 p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
457 457 @logs = Submission.joins(:problem).find_by_sql(p)
458 458
459 459
460 460
461 461
462 462
463 463 end
464 464
465 465 protected
466 466
467 467 def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
468 + #scorearray[i] = user #i's user stat where i is the index (not id)
468 469 scorearray = Array.new
469 470 users.each do |u|
470 471 ustat = Array.new
471 472 ustat[0] = u
472 473 problems.each do |p|
473 474 unless get_last_score
474 475 #get max score
475 476 max_points = 0
476 477 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
477 478 max_points = sub.points if sub and sub.points and (sub.points > max_points)
478 479 end
479 480 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
@@ -66,27 +66,24
66 66 # GET /submissions/1/edit
67 67 def edit
68 68 @submission = Submission.find(params[:id])
69 69 @source = @submission.source.to_s
70 70 @problem = @submission.problem
71 71 @lang_id = @submission.language.id
72 72 end
73 73
74 74
75 75 def get_latest_submission_status
76 76 @problem = Problem.find(params[:pid])
77 77 @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid])
78 - puts User.find(params[:uid]).login
79 - puts Problem.find(params[:pid]).name
80 - puts 'nil' unless @submission
81 78 respond_to do |format|
82 79 format.js
83 80 end
84 81 end
85 82
86 83 # GET /submissions/:id/rejudge
87 84 def rejudge
88 85 @submission = Submission.find(params[:id])
89 86 @task = @submission.task
90 87 @task.status_inqueue! if @task
91 88 respond_to do |format|
92 89 format.js
@@ -52,95 +52,99
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 + error_msg = nil
64 65 ok_user = []
65 66
66 67 lines.split("\n").each do |line|
67 68 items = line.chomp.split(',')
68 69 if items.length>=2
69 70 login = items[0]
70 71 full_name = items[1]
71 72 remark =''
72 73 user_alias = ''
73 74
74 75 added_random_password = false
75 76 if items.length >= 3 and items[2].chomp(" ").length > 0;
76 77 password = items[2].chomp(" ")
77 78 else
78 79 password = random_password
79 - add_random_password=true;
80 + added_random_password=true;
80 81 end
81 82
82 83 if items.length>= 4 and items[3].chomp(" ").length > 0;
83 84 user_alias = items[3].chomp(" ")
84 85 else
85 86 user_alias = login
86 87 end
87 88
88 89 if items.length>=5
89 90 remark = items[4].strip;
90 91 end
91 92
92 93 user = User.find_by_login(login)
93 94 if (user)
94 95 user.full_name = full_name
95 96 user.password = password
96 97 user.remark = remark
97 98 else
98 99 user = User.new({:login => login,
99 - :full_name => full_name,
100 - :password => password,
101 - :password_confirmation => password,
102 - :alias => user_alias,
103 - :remark => remark})
100 + :full_name => full_name,
101 + :password => password,
102 + :password_confirmation => password,
103 + :alias => user_alias,
104 + :remark => remark})
104 105 end
105 106 user.activated = true
106 107
107 108 if user.save
108 109 if added_random_password
109 110 note << "'#{login}' (+)"
110 111 else
111 112 note << login
112 113 end
113 114 ok_user << user
114 115 else
115 - error_note << "#{login}"
116 + error_note << "'#{login}'"
117 + error_msg = user.errors.full_messages.to_sentence unless error_msg
116 118 end
117 119
118 120 end
119 121 end
120 122
121 123 #add to group
122 124 if params[:add_to_group]
123 125 group = Group.where(id: params[:group_id]).first
124 126 if group
125 127 group.users << ok_user
126 128 end
127 129 end
128 130
129 131 # show flash
130 - flash[:success] = 'User(s) ' + note.join(', ') +
131 - ' were successfully created. ' +
132 - '( (+) - created with random passwords.)'
132 + if note.size > 0
133 + flash[:success] = 'User(s) ' + note.join(', ') +
134 + ' were successfully created. ' +
135 + '( (+) - created with random passwords.)'
136 + end
133 137 if error_note.size > 0
134 - flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ')
138 + flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') + ". The error of the first failed one are: " + error_msg;
135 139 end
136 140 redirect_to :action => 'index'
137 141 end
138 142
139 143 def edit
140 144 @user = User.find(params[:id])
141 145 end
142 146
143 147 def update
144 148 @user = User.find(params[:id])
145 149 if @user.update_attributes(user_params)
146 150 flash[:notice] = 'User was successfully updated.'
@@ -12,29 +12,31
12 12 .col-md-12
13 13 %h1 Group details
14 14 .row
15 15 .col-md-6
16 16 .panel.panel-default
17 17 .panel-heading
18 18 .panel-title Users in this group
19 19 .panel-body
20 20 %ul
21 21 %li
22 22 If you want to add several users to a group, it may be easier to just re-import those users in
23 23 = link_to 'New list of users', new_list_user_admin_index_path
24 - page
24 + page. You can also use
25 + = link_to 'Bulk Manage User', bulk_manage_user_admin_index_path
26 + page.
25 27 =form_tag add_user_group_path(@group), class: 'form-inline' do
26 28 .form-group
27 29 =label_tag :user_id, "User"
28 - =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2'
30 + =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2', style: 'width: 10em';
29 31 =submit_tag "Add",class: 'btn btn-primary'
30 32
31 33
32 34 %table.table.table-hover
33 35 %thead
34 36 %tr
35 37 %th Login
36 38 %th Full name
37 39 %th Remark
38 40 %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm'
39 41
40 42 %tbody
@@ -43,30 +45,30
43 45 %td= user.login
44 46 %td= user.full_name
45 47 %td= user.remark
46 48 %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm'
47 49 .col-md-6
48 50 .panel.panel-default
49 51 .panel-heading
50 52 .panel-title Problems
51 53 .panel-body
52 54 %ul
53 55 %li
54 56 If you want to add several problem to a group, it may be easier to bulk manage them in the
55 - = link_to 'Bulk Manage', manage_problems_path
57 + = link_to 'Bulk Manage Problems', manage_problems_path
56 58 page
57 59 =form_tag add_problem_group_path(@group), class: 'form-inline' do
58 60 .form-group
59 61 =label_tag :problem_id, "Problem"
60 - =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2'
62 + =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2', style: 'width: 10em';
61 63 =submit_tag "Add",class: 'btn btn-primary'
62 64
63 65
64 66 %table.table.table-hover
65 67 %thead
66 68 %tr
67 69 %th name
68 70 %th Full name
69 71 %th Full score
70 72 %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm'
71 73
72 74 %tbody
@@ -1,11 +1,12
1 1 %h1= GraderConfiguration['ui.front.title']
2 2
3 3 .row
4 4 .col-md-6
5 5 - if @announcements.length!=0
6 6 .announcementbox{:style => 'margin-top: 0px'}
7 7 %span{:class => 'title'}
8 8 Announcements
9 9 = render :partial => 'announcement', :collection => @announcements
10 10 .col-md-4{style: "padding-left: 20px;"}
11 11 = render :partial => 'login_box'
12 + = "current ip is #{@remote_ip}"
@@ -3,27 +3,27
3 3 %tr
4 4 %th Login
5 5 %th Name
6 6 / %th Activated?
7 7 / %th Logged_in
8 8 / %th Contest(s)
9 9 %th Remark
10 10 - @problems.each do |p|
11 11 %th.text-right= p.name.gsub('_',' ')
12 12 %th.text-right Total
13 13 %th.text-right Passed
14 14 %tbody
15 - - sum = Array.new(@scorearray[0].count,0)
16 - - nonzero = Array.new(@scorearray[0].count,0)
17 - - full = Array.new(@scorearray[0].count,0)
15 + - sum = Array.new(@problems.count+1,0)
16 + - nonzero = Array.new(@problems.count+1,0)
17 + - full = Array.new(@problems.count+1,0)
18 18 - @scorearray.each do |sc|
19 19 %tr
20 20 - total,num_passed = 0,0
21 21 - sc.each_index do |i|
22 22 - if i == 0
23 23 %td= link_to sc[i].login, stat_user_path(sc[i])
24 24 %td= sc[i].full_name
25 25 / %td= sc[i].activated
26 26 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
27 27 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
28 28 %td= sc[i].remark
29 29 - else
@@ -1,11 +1,11
1 1 .container-fluid
2 2 %h1 Current Score
3 3 = form_tag current_score_report_path, method: 'get' do
4 4 Show only users from this group
5 - = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
5 + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em';
6 6 = submit_tag 'Apply',class: 'btn btn-default'
7 7
8 8 %br
9 9
10 10
11 11 = render "score_table"
@@ -138,25 +138,24
138 138 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
139 139
140 140 #singular resource
141 141 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
142 142 #report
143 143 resource :report, only: [], controller: 'report' do
144 144 get 'login'
145 145 get 'multiple_login'
146 146 get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof'
147 147 get 'current_score(/:group_id)', action: 'current_score', as: 'current_score'
148 148 get 'max_score'
149 149 post 'show_max_score'
150 - get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof'
151 150 get 'stuck'
152 151 get 'cheat_report'
153 152 post 'cheat_report'
154 153 get 'cheat_scruntinize'
155 154 post 'cheat_scruntinize'
156 155 end
157 156 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
158 157 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
159 158 #get "report/login"
160 159 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
161 160 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
162 161
@@ -3,295 +3,296
3 3 # incrementally modify your database, and then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your
6 6 # database schema. If you need to create the application database on another
7 7 # system, you should be using db:schema:load, not running all the migrations
8 8 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 9 # you'll amass, the slower it'll run and the greater likelihood for issues).
10 10 #
11 11 # It's strongly recommended that you check this file into your version control system.
12 12
13 13 ActiveRecord::Schema.define(version: 2018_06_12_102327) do
14 14
15 - create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
15 + create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
16 16 t.string "author"
17 17 t.text "body"
18 18 t.boolean "published"
19 19 t.datetime "created_at"
20 20 t.datetime "updated_at"
21 21 t.boolean "frontpage", default: false
22 22 t.boolean "contest_only", default: false
23 23 t.string "title"
24 24 t.string "notes"
25 25 end
26 26
27 - create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
27 + create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
28 28 t.string "title"
29 29 t.boolean "enabled"
30 30 t.datetime "created_at"
31 31 t.datetime "updated_at"
32 32 t.string "name"
33 33 end
34 34
35 - create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
35 + create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
36 36 t.integer "contest_id"
37 37 t.integer "problem_id"
38 38 end
39 39
40 - create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
40 + create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
41 41 t.integer "contest_id"
42 42 t.integer "user_id"
43 43 end
44 44
45 - create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
45 + create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
46 46 t.string "name"
47 47 t.datetime "created_at"
48 48 t.datetime "updated_at"
49 49 end
50 50
51 - create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
51 + create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
52 52 t.text "body"
53 53 t.boolean "markdowned"
54 54 t.datetime "created_at"
55 55 t.datetime "updated_at"
56 56 end
57 57
58 - create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
58 + create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
59 59 t.string "key"
60 60 t.string "value_type"
61 61 t.string "value"
62 62 t.datetime "created_at"
63 63 t.datetime "updated_at"
64 64 t.text "description"
65 65 end
66 66
67 - create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
67 + create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
68 68 t.string "host"
69 69 t.integer "pid"
70 70 t.string "mode"
71 71 t.boolean "active"
72 72 t.datetime "created_at"
73 73 t.datetime "updated_at"
74 74 t.integer "task_id"
75 75 t.string "task_type"
76 76 t.boolean "terminated"
77 - t.index ["host", "pid"], name: "index_grader_processes_on_ip_and_pid"
77 + t.index ["host", "pid"], name: "index_grader_processes_on_host_and_pid"
78 78 end
79 79
80 - create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
80 + create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
81 81 t.string "name"
82 82 t.string "description"
83 83 end
84 84
85 - create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
85 + create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
86 86 t.integer "problem_id", null: false
87 87 t.integer "group_id", null: false
88 88 t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id"
89 89 end
90 90
91 - create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
91 + create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
92 92 t.integer "group_id", null: false
93 93 t.integer "user_id", null: false
94 94 t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id"
95 95 end
96 96
97 97 create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
98 98 t.integer "user_id"
99 99 t.string "ip_address"
100 - t.datetime "created_at", null: false
101 - t.datetime "updated_at", null: false
100 + t.datetime "created_at"
101 + t.datetime "updated_at"
102 102 t.string "status"
103 103 t.index ["updated_at"], name: "index_heart_beats_on_updated_at"
104 104 end
105 105
106 - create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
106 + create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
107 107 t.string "name", limit: 10
108 108 t.string "pretty_name"
109 109 t.string "ext", limit: 10
110 110 t.string "common_ext"
111 111 end
112 112
113 113 create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
114 114 t.integer "user_id"
115 115 t.string "ip_address"
116 - t.datetime "created_at", null: false
117 - t.datetime "updated_at", null: false
116 + t.datetime "created_at"
117 + t.datetime "updated_at"
118 118 end
119 119
120 - create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
120 + create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
121 121 t.integer "sender_id"
122 122 t.integer "receiver_id"
123 123 t.integer "replying_message_id"
124 124 t.text "body"
125 125 t.boolean "replied"
126 126 t.datetime "created_at"
127 127 t.datetime "updated_at"
128 128 end
129 129
130 - create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
130 + create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
131 131 t.string "name", limit: 30
132 132 t.string "full_name"
133 133 t.integer "full_score"
134 134 t.date "date_added"
135 135 t.boolean "available"
136 136 t.string "url"
137 137 t.integer "description_id"
138 138 t.boolean "test_allowed"
139 139 t.boolean "output_only"
140 140 t.string "description_filename"
141 141 t.boolean "view_testcase"
142 142 end
143 143
144 - create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
144 + create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
145 145 t.integer "problem_id"
146 146 t.integer "tag_id"
147 147 t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true
148 148 t.index ["problem_id"], name: "index_problems_tags_on_problem_id"
149 149 t.index ["tag_id"], name: "index_problems_tags_on_tag_id"
150 150 end
151 151
152 - create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
152 + create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
153 153 t.string "name"
154 154 t.string "controller"
155 155 t.string "action"
156 156 end
157 157
158 - create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
158 + create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
159 159 t.integer "right_id"
160 160 t.integer "role_id"
161 161 t.index ["role_id"], name: "index_rights_roles_on_role_id"
162 162 end
163 163
164 - create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
164 + create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
165 165 t.string "name"
166 166 end
167 167
168 - create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
168 + create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
169 169 t.integer "role_id"
170 170 t.integer "user_id"
171 171 t.index ["user_id"], name: "index_roles_users_on_user_id"
172 172 end
173 173
174 - create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
174 + create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
175 175 t.string "session_id"
176 176 t.text "data"
177 177 t.datetime "updated_at"
178 178 t.index ["session_id"], name: "index_sessions_on_session_id"
179 179 t.index ["updated_at"], name: "index_sessions_on_updated_at"
180 180 end
181 181
182 - create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
182 + create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
183 183 t.string "name"
184 184 t.boolean "started"
185 185 t.datetime "start_time"
186 186 t.datetime "created_at"
187 187 t.datetime "updated_at"
188 188 t.integer "country_id"
189 189 t.string "password"
190 190 end
191 191
192 192 create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
193 193 t.integer "user_id"
194 194 t.integer "submission_id"
195 - t.datetime "created_at", null: false
196 - t.datetime "updated_at", null: false
195 + t.datetime "created_at"
196 + t.datetime "updated_at"
197 197 end
198 198
199 - create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
199 + create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
200 200 t.integer "user_id"
201 201 t.integer "problem_id"
202 202 t.integer "language_id"
203 203 t.text "source", limit: 16777215
204 204 t.binary "binary"
205 205 t.datetime "submitted_at"
206 206 t.datetime "compiled_at"
207 207 t.text "compiler_message"
208 208 t.datetime "graded_at"
209 209 t.integer "points"
210 210 t.text "grader_comment"
211 211 t.integer "number"
212 212 t.string "source_filename"
213 213 t.float "max_runtime"
214 214 t.integer "peak_memory"
215 215 t.integer "effective_code_length"
216 216 t.string "ip_address"
217 217 t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true
218 218 t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id"
219 219 end
220 220
221 - create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
221 + create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
222 222 t.string "name", null: false
223 223 t.text "description"
224 224 t.boolean "public"
225 225 t.datetime "created_at", null: false
226 226 t.datetime "updated_at", null: false
227 227 end
228 228
229 - create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
229 + create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
230 230 t.integer "submission_id"
231 231 t.datetime "created_at"
232 232 t.integer "status"
233 233 t.datetime "updated_at"
234 234 t.index ["submission_id"], name: "index_tasks_on_submission_id"
235 235 end
236 236
237 - create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
237 + create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
238 238 t.integer "problem_id"
239 239 t.text "input", limit: 16777215
240 240 t.text "solution", limit: 16777215
241 241 t.datetime "created_at"
242 242 t.datetime "updated_at"
243 243 end
244 244
245 - create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
245 + create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
246 246 t.integer "user_id"
247 247 t.integer "problem_id"
248 248 t.integer "submission_id"
249 249 t.string "input_file_name"
250 250 t.string "output_file_name"
251 251 t.string "running_stat"
252 252 t.integer "status"
253 253 t.datetime "updated_at"
254 254 t.datetime "submitted_at"
255 255 t.datetime "compiled_at"
256 256 t.text "compiler_message"
257 257 t.datetime "graded_at"
258 258 t.string "grader_comment"
259 259 t.datetime "created_at"
260 260 t.float "running_time"
261 261 t.string "exit_status"
262 262 t.integer "memory_usage"
263 263 t.index ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id"
264 264 end
265 265
266 - create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
266 + create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
267 267 t.integer "problem_id"
268 268 t.integer "num"
269 269 t.integer "group"
270 270 t.integer "score"
271 271 t.text "input", limit: 4294967295
272 272 t.text "sol", limit: 4294967295
273 273 t.datetime "created_at"
274 274 t.datetime "updated_at"
275 275 t.index ["problem_id"], name: "index_testcases_on_problem_id"
276 276 end
277 277
278 - create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
278 + create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
279 279 t.integer "user_id"
280 280 t.datetime "started_at"
281 281 t.datetime "created_at"
282 282 t.datetime "updated_at"
283 + t.boolean "forced_logout"
283 284 end
284 285
285 - create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
286 + create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
286 287 t.string "login", limit: 50
287 288 t.string "full_name"
288 289 t.string "hashed_password"
289 290 t.string "salt", limit: 5
290 291 t.string "alias"
291 292 t.string "email"
292 293 t.integer "site_id"
293 294 t.integer "country_id"
294 295 t.boolean "activated", default: false
295 296 t.datetime "created_at"
296 297 t.datetime "updated_at"
297 298 t.string "section"
@@ -91,25 +91,25
91 91
92 92 {
93 93 :key => 'right.heartbeat_response_full',
94 94 :value_type => 'string',
95 95 :default_value => 'OK',
96 96 :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)'
97 97 },
98 98
99 99 {
100 100 :key => 'right.view_testcase',
101 101 :value_type => 'boolean',
102 102 :default_value => 'false',
103 - :description => 'When true, any user can view/download test data'
103 + :description => 'If true, any user can view/download test data'
104 104 },
105 105
106 106 {
107 107 :key => 'system.online_registration',
108 108 :value_type => 'boolean',
109 109 :default_value => 'false',
110 110 :description => 'This option enables online registration.'
111 111 },
112 112
113 113 # If Configuration['system.online_registration'] is true, the
114 114 # system allows online registration, and will use these
115 115 # information for sending confirmation emails.
@@ -173,35 +173,35
173 173 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
174 174 },
175 175
176 176 {
177 177 :key => 'system.use_problem_group',
178 178 :value_type => 'boolean',
179 179 :default_value => 'false',
180 180 :description => "If true, available problem to the user will be only ones associated with the group of the user."
181 181 },
182 182
183 183
184 184 {
185 - :key => 'right.whitelist_ip_only',
185 + :key => 'right.whitelist_ignore',
186 186 :value_type => 'boolean',
187 - :default_value => 'false',
188 - :description => "If true, non-admin user will be able to use the system only when their ip is in the 'whitelist_ip'."
187 + :default_value => 'true',
188 + :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login."
189 189 },
190 190
191 191 {
192 192 :key => 'right.whitelist_ip',
193 193 :value_type => 'string',
194 194 :default_value => '0.0.0.0/0',
195 - :description => "list of whitelist ip, given in comma separated CIDR notation. For example '161.200.92.0/23, 161.200.80.1/32'"
195 + :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'"
196 196 },
197 197
198 198 ]
199 199
200 200
201 201 def create_configuration_key(key,
202 202 value_type,
203 203 default_value,
204 204 description='')
205 205 conf = (GraderConfiguration.find_by_key(key) ||
206 206 GraderConfiguration.new(:key => key,
207 207 :value_type => value_type,
@@ -265,24 +265,24
265 265 root.roles << Role.find_by_name('admin')
266 266
267 267 root.activated = true
268 268 root.save
269 269 end
270 270
271 271 def seed_users_and_roles
272 272 seed_roles
273 273 seed_root
274 274 end
275 275
276 276 def seed_more_languages
277 - Language.delete_all
277 + #Language.delete_all
278 278 Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
279 279 Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
280 280 Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
281 281 Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
282 282 Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
283 283 Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
284 284 end
285 285
286 286 seed_config
287 287 seed_users_and_roles
288 288 seed_more_languages
@@ -41,25 +41,25
41 41 assert_text 'section 2'
42 42 end
43 43
44 44 test "add multiple users" do
45 45 login 'admin', 'admin'
46 46 within 'header' do
47 47 click_on 'Manage'
48 48 click_on 'Users', match: :first
49 49 end
50 50
51 51 click_on 'New list of users', match: :first
52 52 find(:css, 'textarea').fill_in with:"abc1,Boaty McBoatface,abcdef,alias1,remark1,\nabc2,Boaty2 McSecond,acbdef123,aias2,remark2"
53 - click_on 'create users'
53 + click_on 'Create following users'
54 54
55 55 assert_text('remark1')
56 56 assert_text('remark2')
57 57 end
58 58
59 59 test "grant admin right" do
60 60 login 'admin', 'admin'
61 61 within 'header' do
62 62 click_on 'Manage'
63 63 click_on 'Users', match: :first
64 64 end
65 65
You need to be logged in to leave comments. Login now