Description:
- more test on user admin and authorization
- fix more routing
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r754:4cbf294c126c - - 8 files changed: 140 inserted, 79 deleted
@@ -15,49 +15,53 | |||
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | if (!GraderConfiguration['right.bypass_agreement']) and (!params[:accept_agree]) and !user.admin? |
|
18 | 18 | flash[:notice] = 'You must accept the agreement before logging in' |
|
19 | 19 | redirect_to :controller => 'main', :action => 'login' |
|
20 | 20 | return |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | #process logging in |
|
24 | 24 | session[:user_id] = user.id |
|
25 | 25 | session[:admin] = user.admin? |
|
26 | 26 | |
|
27 | 27 | # clear forced logout flag for multicontests contest change |
|
28 | 28 | if GraderConfiguration.multicontests? |
|
29 | 29 | contest_stat = user.contest_stat |
|
30 | 30 | if contest_stat.respond_to? :forced_logout |
|
31 | 31 | if contest_stat.forced_logout |
|
32 | 32 | contest_stat.forced_logout = false |
|
33 | 33 | contest_stat.save |
|
34 | 34 | end |
|
35 | 35 | end |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | #save login information |
|
39 | 39 | Login.create(user_id: user.id, ip_address: request.remote_ip) |
|
40 | 40 | |
|
41 | 41 | redirect_to :controller => 'main', :action => 'list' |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def site_login |
|
45 | 45 | begin |
|
46 | 46 | site = Site.find(params[:login][:site_id]) |
|
47 | 47 | rescue ActiveRecord::RecordNotFound |
|
48 | 48 | site = nil |
|
49 | 49 | end |
|
50 | 50 | if site==nil |
|
51 | 51 | flash[:notice] = 'Wrong site' |
|
52 | 52 | redirect_to :controller => 'main', :action => 'login' and return |
|
53 | 53 | end |
|
54 | 54 | if (site.password) and (site.password == params[:login][:password]) |
|
55 | 55 | session[:site_id] = site.id |
|
56 | 56 | redirect_to :controller => 'site', :action => 'index' |
|
57 | 57 | else |
|
58 | 58 | flash[:notice] = 'Wrong site password' |
|
59 | 59 | redirect_to :controller => 'site', :action => 'login' |
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | + def logout | |
|
64 | + redirect_to root_path | |
|
63 | 65 | end |
|
66 | + | |
|
67 | + end |
@@ -1,90 +1,96 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_action :authenticate, :except => [:index, :login] |
|
4 | 4 | before_action :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | 6 | append_before_action :confirm_and_update_start_time, |
|
7 | 7 | :except => [:index, |
|
8 | 8 | :login, |
|
9 | 9 | :confirm_contest_start] |
|
10 | 10 | |
|
11 | 11 | # to prevent log in box to be shown when user logged out of the |
|
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 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
19 | 19 | # assigned action login as a default action. |
|
20 | 20 | def index |
|
21 | 21 | redirect_to :action => 'login' |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | + #reset login, clear session | |
|
24 | 25 | def login |
|
25 | 26 | saved_notice = flash[:notice] |
|
26 | 27 | reset_session |
|
27 | 28 | flash.now[:notice] = saved_notice |
|
28 | 29 | |
|
29 | 30 | # EXPERIMENT: |
|
30 | 31 | # Hide login if in single user mode and the url does not |
|
31 | 32 | # explicitly specify /login |
|
32 | 33 | # |
|
33 | 34 | # logger.info "PATH: #{request.path}" |
|
34 | 35 | # if GraderConfiguration['system.single_user_mode'] and |
|
35 | 36 | # request.path!='/main/login' |
|
36 | 37 | # @hidelogin = true |
|
37 | 38 | # end |
|
38 | 39 | |
|
39 | 40 | @announcements = Announcement.frontpage |
|
40 | 41 | render :action => 'login', :layout => 'empty' |
|
41 | 42 | end |
|
42 | 43 | |
|
44 | + def logout | |
|
45 | + reset_session | |
|
46 | + redirect_to root_path | |
|
47 | + end | |
|
48 | + | |
|
43 | 49 | def list |
|
44 | 50 | prepare_list_information |
|
45 | 51 | end |
|
46 | 52 | |
|
47 | 53 | def help |
|
48 | 54 | @user = User.find(session[:user_id]) |
|
49 | 55 | end |
|
50 | 56 | |
|
51 | 57 | def submit |
|
52 | 58 | user = User.find(session[:user_id]) |
|
53 | 59 | |
|
54 | 60 | @submission = Submission.new |
|
55 | 61 | @submission.problem_id = params[:submission][:problem_id] |
|
56 | 62 | @submission.user = user |
|
57 | 63 | @submission.language_id = 0 |
|
58 | 64 | if (params['file']) and (params['file']!='') |
|
59 | 65 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
60 | 66 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
61 | 67 | @submission.source_filename = params['file'].original_filename |
|
62 | 68 | end |
|
63 | 69 | |
|
64 | 70 | if (params[:editor_text]) |
|
65 | 71 | language = Language.find_by_id(params[:language_id]) |
|
66 | 72 | @submission.source = params[:editor_text] |
|
67 | 73 | @submission.source_filename = "live_edit.#{language.ext}" |
|
68 | 74 | @submission.language = language |
|
69 | 75 | end |
|
70 | 76 | |
|
71 | 77 | @submission.submitted_at = Time.new.gmtime |
|
72 | 78 | @submission.ip_address = request.remote_ip |
|
73 | 79 | |
|
74 | 80 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
75 | 81 | @submission.errors.add(:base,"The contest is over.") |
|
76 | 82 | prepare_list_information |
|
77 | 83 | render :action => 'list' and return |
|
78 | 84 | end |
|
79 | 85 | |
|
80 | 86 | if @submission.valid?(@current_user) |
|
81 | 87 | if @submission.save == false |
|
82 | 88 | flash[:notice] = 'Error saving your submission' |
|
83 | 89 | elsif Task.create(:submission_id => @submission.id, |
|
84 | 90 | :status => Task::STATUS_INQUEUE) == false |
|
85 | 91 | flash[:notice] = 'Error adding your submission to task queue' |
|
86 | 92 | end |
|
87 | 93 | else |
|
88 | 94 | prepare_list_information |
|
89 | 95 | render :action => 'list' and return |
|
90 | 96 | end |
@@ -1,29 +1,29 | |||
|
1 | 1 | |
|
2 | 2 | - if submission.nil? |
|
3 | 3 | = "-" |
|
4 | 4 | - else |
|
5 | 5 | - unless submission.graded_at |
|
6 | 6 | = t 'main.submitted_at' |
|
7 | 7 | = format_short_time(submission.submitted_at.localtime) |
|
8 | 8 | - else |
|
9 | 9 | %strong= t 'main.graded_at' |
|
10 | 10 | = "#{format_short_time(submission.graded_at.localtime)} " |
|
11 | 11 | %br |
|
12 | 12 | - if GraderConfiguration['ui.show_score'] |
|
13 | 13 | %strong=t 'main.score' |
|
14 | 14 | = "#{(submission.points*100/submission.problem.full_score).to_i} " |
|
15 | 15 | = " [" |
|
16 | 16 | %tt.grader-comment |
|
17 | 17 | = submission.grader_comment |
|
18 | 18 | = "]" |
|
19 | 19 | %br |
|
20 | 20 | %strong View: |
|
21 | 21 | - if GraderConfiguration.show_grading_result |
|
22 | 22 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
23 | 23 | /= link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} |
|
24 |
- = link_to "#{t 'main.cmp_msg'}", compiler_msg_submission_path(submission |
|
|
25 |
- = link_to "#{t 'main.src_link'}", |
|
|
24 | + = link_to "#{t 'main.cmp_msg'}", compiler_msg_submission_path(submission), {popup: true,remote: true,class: 'btn btn-xs btn-info'} | |
|
25 | + = link_to "#{t 'main.src_link'}",download_submission_path(submission), class: 'btn btn-xs btn-info' | |
|
26 | 26 | = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' |
|
27 | 27 | - if GraderConfiguration.show_testcase |
|
28 | 28 | = link_to "testcases", show_problem_testcases_path(problem_id), class: 'btn btn-xs btn-info' |
|
29 | 29 |
@@ -1,25 +1,25 | |||
|
1 | 1 | %h1 Administrators |
|
2 | 2 | |
|
3 | 3 | %table{:class => 'info'} |
|
4 | 4 | %tr{:class => 'info-head'} |
|
5 | 5 | %th # |
|
6 | 6 | %th Login |
|
7 | 7 | %th Full name |
|
8 | 8 | %th |
|
9 | 9 | - @admins.each_with_index do |user, i| |
|
10 | 10 | %tr |
|
11 | 11 | %td= i+1 |
|
12 | 12 | %td= user.login |
|
13 | 13 | %td= user.full_name |
|
14 | 14 | %td |
|
15 | 15 | - if user.login!='root' |
|
16 | 16 | = link_to '[revoke]', :action => 'revoke_admin', :id => user.id |
|
17 | 17 | %hr |
|
18 | 18 | |
|
19 | 19 | = form_tag :action => 'grant_admin' do |
|
20 | - Grant admin permission to: | |
|
21 | - = text_field_tag 'login' | |
|
22 | - = submit_tag 'Grant' | |
|
20 | + = label_tag :login, 'Grant admin permission to:' | |
|
21 | + = text_field_tag 'login',nil, class: 'input-field' | |
|
22 | + = submit_tag 'Grant', class: 'btn btn-primary' | |
|
23 | 23 | |
|
24 | 24 | %hr/ |
|
25 | 25 | = link_to '[go back to index]', :action => 'index' |
@@ -1,174 +1,174 | |||
|
1 | 1 | Rails.application.routes.draw do |
|
2 | 2 | resources :tags |
|
3 | 3 | get "sources/direct_edit" |
|
4 | 4 | |
|
5 | 5 | root :to => 'main#login' |
|
6 | 6 | |
|
7 | 7 | #logins |
|
8 | 8 | match 'login/login', to: 'login#login', via: [:get,:post] |
|
9 | 9 | |
|
10 | - | |
|
11 | 10 | resources :contests |
|
12 | - | |
|
13 | 11 | resources :sites |
|
14 | - | |
|
15 | 12 | resources :test |
|
16 | 13 | |
|
17 | 14 | resources :messages do |
|
18 | 15 | collection do |
|
19 | 16 | get 'console' |
|
20 | 17 | end |
|
21 | 18 | end |
|
22 | 19 | |
|
23 | 20 | resources :announcements do |
|
24 | 21 | member do |
|
25 | 22 | get 'toggle','toggle_front' |
|
26 | 23 | end |
|
27 | 24 | end |
|
28 | 25 | |
|
29 | 26 | resources :problems do |
|
30 | 27 | member do |
|
31 | 28 | get 'toggle' |
|
32 | 29 | get 'toggle_test' |
|
33 | 30 | get 'toggle_view_testcase' |
|
34 | 31 | get 'stat' |
|
35 | 32 | end |
|
36 | 33 | collection do |
|
37 | 34 | get 'turn_all_off' |
|
38 | 35 | get 'turn_all_on' |
|
39 | 36 | get 'import' |
|
40 | 37 | get 'manage' |
|
41 | 38 | get 'quick_create' |
|
42 | 39 | post 'do_manage' |
|
43 | 40 | post 'do_import' |
|
44 | 41 | end |
|
45 | 42 | end |
|
46 | 43 | |
|
47 | 44 | resources :groups do |
|
48 | 45 | member do |
|
49 | 46 | post 'add_user', to: 'groups#add_user', as: 'add_user' |
|
50 | 47 | delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user' |
|
51 | 48 | delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user' |
|
52 | 49 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
53 | 50 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
54 | 51 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
55 | 52 | end |
|
56 | 53 | collection do |
|
57 | 54 | |
|
58 | 55 | end |
|
59 | 56 | end |
|
60 | 57 | |
|
61 | 58 | resources :testcases, only: [] do |
|
62 | 59 | member do |
|
63 | 60 | get 'download_input' |
|
64 | 61 | get 'download_sol' |
|
65 | 62 | end |
|
66 | 63 | collection do |
|
67 | 64 | get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem' |
|
68 | 65 | end |
|
69 | 66 | end |
|
70 | 67 | |
|
71 | 68 | resources :grader_configuration, controller: 'configurations' |
|
72 | 69 | |
|
73 | 70 | resources :users do |
|
74 | 71 | member do |
|
75 | 72 | get 'toggle_activate', 'toggle_enable' |
|
76 | 73 | get 'stat' |
|
77 | 74 | end |
|
78 | 75 | end |
|
79 | 76 | |
|
80 | 77 | resources :submissions do |
|
81 | 78 | member do |
|
82 | 79 | get 'download' |
|
83 | 80 | get 'compiler_msg' |
|
84 | 81 | get 'rejudge' |
|
85 | 82 | get 'source' |
|
86 | 83 | end |
|
87 | 84 | collection do |
|
88 | 85 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
89 | 86 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
90 | 87 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
91 | 88 | end |
|
92 | 89 | end |
|
93 | 90 | |
|
94 | 91 | |
|
95 | 92 | #user admin |
|
96 | 93 | resources :user_admin do |
|
97 | 94 | collection do |
|
98 | 95 | match 'bulk_manage', via: [:get, :post] |
|
99 | 96 | get 'bulk_mail' |
|
100 | 97 | get 'user_stat' |
|
101 | 98 | get 'import' |
|
102 | 99 | get 'new_list' |
|
103 | 100 | get 'admin' |
|
104 | 101 | get 'active' |
|
105 | 102 | get 'mass_mailing' |
|
103 | + get 'revoke_admin' | |
|
106 | 104 | post 'grant_admin' |
|
107 | 105 | match 'create_from_list', via: [:get, :post] |
|
108 | 106 | match 'random_all_passwords', via: [:get, :post] |
|
109 | 107 | end |
|
110 | 108 | member do |
|
111 | 109 | get 'clear_last_ip' |
|
112 | 110 | end |
|
113 | 111 | end |
|
114 | 112 | |
|
115 | 113 | resources :contest_management, only: [:index] do |
|
116 | 114 | collection do |
|
117 | 115 | get 'user_stat' |
|
118 | 116 | get 'clear_stat' |
|
119 | 117 | get 'clear_all_stat' |
|
120 | 118 | get 'change_contest_mode' |
|
121 | 119 | end |
|
122 | 120 | end |
|
123 | 121 | |
|
124 | 122 | #get 'user_admin', to: 'user_admin#index' |
|
125 | 123 | #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
126 | 124 | #post 'user_admin', to: 'user_admin#create' |
|
127 | 125 | #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
128 | 126 | |
|
129 | 127 | #singular resource |
|
130 | 128 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
131 | 129 | #report |
|
132 | 130 | resource :report, only: [], controller: 'report' do |
|
133 | 131 | get 'login' |
|
134 | 132 | get 'multiple_login' |
|
135 | 133 | get 'problem_hof/:id', action: 'problem_hof' |
|
136 | 134 | get 'current_score' |
|
137 | 135 | get 'max_score' |
|
138 | 136 | post 'show_max_score' |
|
139 | 137 | end |
|
140 | 138 | #get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
141 | 139 | #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
142 | 140 | #get "report/login" |
|
143 | 141 | #get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
144 | 142 | #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
145 | 143 | |
|
146 | 144 | resource :main, only: [], controller: 'main' do |
|
145 | + get 'login' | |
|
146 | + get 'logout' | |
|
147 | 147 | get 'list' |
|
148 | 148 | get 'submission(/:id)', action: 'submission', as: 'main_submission' |
|
149 | - post 'submit' | |
|
150 | 149 | get 'announcements' |
|
151 | 150 | get 'help' |
|
151 | + post 'submit' | |
|
152 | 152 | end |
|
153 | 153 | #main |
|
154 | 154 | #get "main/list" |
|
155 | 155 | #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' |
|
156 | 156 | #post 'main/submit', to: 'main#submit' |
|
157 | 157 | #get 'main/announcements', to: 'main#announcements' |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | # |
|
161 | 161 | get 'tasks/view/:file.:ext' => 'tasks#view' |
|
162 | 162 | get 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
163 | 163 | get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
164 | 164 | |
|
165 | 165 | #grader |
|
166 | 166 | get 'graders/list', to: 'graders#list', as: 'grader_list' |
|
167 | 167 | |
|
168 | 168 | |
|
169 | 169 | # See how all your routes lay out with "rake routes" |
|
170 | 170 | |
|
171 | 171 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
172 | 172 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
173 | 173 | # match ':controller(/:action(/:id))(.:format)', via: [:get, :post] |
|
174 | 174 | end |
@@ -1,5 +1,5 | |||
|
1 | - class ChangeSubmissionSourceSize < ActiveRecord::Migration | |
|
1 | + class ChangeSubmissionSourceSize < ActiveRecord::Migration[4.2] | |
|
2 | 2 | def change |
|
3 | 3 | change_column :submissions, :source, :text, :limit => 1.megabyte |
|
4 | 4 | end |
|
5 | 5 | end |
@@ -1,307 +1,306 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead |
|
2 | 2 | # of editing this file, please use the migrations feature of Active Record to |
|
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 | - ActiveRecord::Schema.define(version: 20180612102327) do | |
|
13 | + ActiveRecord::Schema.define(version: 2018_06_12_102327) do | |
|
14 | 14 | |
|
15 |
- create_table "announcements", |
|
|
15 | + create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
16 | 16 |
t.string |
|
17 | - t.text "body", limit: 65535 | |
|
17 | + t.text "body" | |
|
18 | 18 |
t.boolean |
|
19 | 19 | t.datetime "created_at" |
|
20 | 20 | t.datetime "updated_at" |
|
21 | 21 |
t.boolean |
|
22 | 22 |
t.boolean |
|
23 | 23 |
t.string |
|
24 | 24 |
t.string |
|
25 | 25 | end |
|
26 | 26 | |
|
27 |
- create_table "contests", |
|
|
27 | + create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
28 | 28 |
t.string |
|
29 | 29 |
t.boolean |
|
30 | 30 | t.datetime "created_at" |
|
31 | 31 | t.datetime "updated_at" |
|
32 | 32 |
t.string |
|
33 | 33 | end |
|
34 | 34 | |
|
35 |
- create_table "contests_problems", id: false, force: :cascade |
|
|
35 | + create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", 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, force: :cascade |
|
|
40 | + create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", 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", |
|
|
45 | + create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
46 | 46 |
t.string |
|
47 | 47 | t.datetime "created_at" |
|
48 | 48 | t.datetime "updated_at" |
|
49 | 49 | end |
|
50 | 50 | |
|
51 |
- create_table "descriptions", |
|
|
52 | - t.text "body", limit: 65535 | |
|
51 | + create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
52 | + t.text "body" | |
|
53 | 53 |
t.boolean |
|
54 | 54 | t.datetime "created_at" |
|
55 | 55 | t.datetime "updated_at" |
|
56 | 56 | end |
|
57 | 57 | |
|
58 |
- create_table "grader_configurations", |
|
|
58 | + create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
59 | 59 |
t.string |
|
60 | 60 |
t.string |
|
61 | 61 |
t.string |
|
62 | 62 | t.datetime "created_at" |
|
63 | 63 | t.datetime "updated_at" |
|
64 |
- t.text |
|
|
64 | + t.text "description" | |
|
65 | 65 | end |
|
66 | 66 | |
|
67 |
- create_table "grader_processes", |
|
|
67 | + create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
68 | 68 |
t.string |
|
69 | 69 |
t.integer |
|
70 | 70 |
t.string |
|
71 | 71 |
t.boolean |
|
72 | 72 | t.datetime "created_at" |
|
73 | 73 | t.datetime "updated_at" |
|
74 | 74 |
t.integer |
|
75 | 75 |
t.string |
|
76 | 76 |
t.boolean |
|
77 |
- t.index ["host", "pid"], name: "index_grader_processes_on_ |
|
|
77 | + t.index ["host", "pid"], name: "index_grader_processes_on_ip_and_pid" | |
|
78 | 78 | end |
|
79 | 79 | |
|
80 |
- create_table "groups", |
|
|
80 | + create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", 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, force: :cascade |
|
|
85 | + create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| | |
|
86 | 86 | t.integer "problem_id", null: false |
|
87 | 87 |
t.integer "group_id", |
|
88 |
- t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id" |
|
|
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, force: :cascade |
|
|
91 | + create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| | |
|
92 | 92 | t.integer "group_id", null: false |
|
93 | 93 |
t.integer "user_id", |
|
94 |
- t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" |
|
|
94 | + t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" | |
|
95 | 95 | end |
|
96 | 96 | |
|
97 |
- create_table "heart_beats", |
|
|
97 | + create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
98 | 98 |
t.integer |
|
99 | 99 |
t.string |
|
100 | - t.datetime "created_at" | |
|
101 | - t.datetime "updated_at" | |
|
100 | + t.datetime "created_at", null: false | |
|
101 | + t.datetime "updated_at", null: false | |
|
102 | 102 |
t.string |
|
103 |
- t.index ["updated_at"], name: "index_heart_beats_on_updated_at" |
|
|
103 | + t.index ["updated_at"], name: "index_heart_beats_on_updated_at" | |
|
104 | 104 | end |
|
105 | 105 | |
|
106 |
- create_table "languages", |
|
|
106 | + create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
107 | 107 |
t.string "name", |
|
108 | 108 | t.string "pretty_name" |
|
109 | 109 |
t.string "ext", |
|
110 | 110 | t.string "common_ext" |
|
111 | 111 | end |
|
112 | 112 | |
|
113 |
- create_table "logins", |
|
|
113 | + create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
114 | 114 |
t.integer |
|
115 | 115 |
t.string |
|
116 | - t.datetime "created_at" | |
|
117 | - t.datetime "updated_at" | |
|
116 | + t.datetime "created_at", null: false | |
|
117 | + t.datetime "updated_at", null: false | |
|
118 | 118 | end |
|
119 | 119 | |
|
120 |
- create_table "messages", |
|
|
120 | + create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
121 | 121 |
t.integer |
|
122 | 122 |
t.integer |
|
123 | 123 |
t.integer |
|
124 | - t.text "body", limit: 65535 | |
|
124 | + t.text "body" | |
|
125 | 125 |
t.boolean |
|
126 | 126 | t.datetime "created_at" |
|
127 | 127 | t.datetime "updated_at" |
|
128 | 128 | end |
|
129 | 129 | |
|
130 |
- create_table "problems", |
|
|
130 | + create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
131 | 131 |
t.string |
|
132 | 132 |
t.string |
|
133 | 133 | t.integer "full_score" |
|
134 | 134 |
t.date |
|
135 | 135 | t.boolean "available" |
|
136 | 136 |
t.string |
|
137 | 137 | t.integer "description_id" |
|
138 | 138 | t.boolean "test_allowed" |
|
139 | 139 | t.boolean "output_only" |
|
140 | 140 |
t.string |
|
141 | 141 | t.boolean "view_testcase" |
|
142 | 142 | end |
|
143 | 143 | |
|
144 |
- create_table "problems_tags", |
|
|
144 | + create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| | |
|
145 | 145 | t.integer "problem_id" |
|
146 | 146 | t.integer "tag_id" |
|
147 |
- t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true |
|
|
148 |
- t.index ["problem_id"], name: "index_problems_tags_on_problem_id" |
|
|
149 |
- t.index ["tag_id"], name: "index_problems_tags_on_tag_id" |
|
|
147 | + t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true | |
|
148 | + t.index ["problem_id"], name: "index_problems_tags_on_problem_id" | |
|
149 | + t.index ["tag_id"], name: "index_problems_tags_on_tag_id" | |
|
150 | 150 | end |
|
151 | 151 | |
|
152 |
- create_table "rights", |
|
|
152 | + create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", 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, force: :cascade |
|
|
158 | + create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
159 | 159 | t.integer "right_id" |
|
160 | 160 | t.integer "role_id" |
|
161 |
- t.index ["role_id"], name: "index_rights_roles_on_role_id" |
|
|
161 | + t.index ["role_id"], name: "index_rights_roles_on_role_id" | |
|
162 | 162 | end |
|
163 | 163 | |
|
164 |
- create_table "roles", |
|
|
164 | + create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
165 | 165 | t.string "name" |
|
166 | 166 | end |
|
167 | 167 | |
|
168 |
- create_table "roles_users", id: false, force: :cascade |
|
|
168 | + create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
169 | 169 | t.integer "role_id" |
|
170 | 170 | t.integer "user_id" |
|
171 |
- t.index ["user_id"], name: "index_roles_users_on_user_id" |
|
|
171 | + t.index ["user_id"], name: "index_roles_users_on_user_id" | |
|
172 | 172 | end |
|
173 | 173 | |
|
174 |
- create_table "sessions", |
|
|
174 | + create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
175 | 175 |
t.string |
|
176 | - t.text "data", limit: 65535 | |
|
176 | + t.text "data" | |
|
177 | 177 | t.datetime "updated_at" |
|
178 |
- t.index ["session_id"], name: "index_sessions_on_session_id" |
|
|
179 |
- t.index ["updated_at"], name: "index_sessions_on_updated_at" |
|
|
178 | + t.index ["session_id"], name: "index_sessions_on_session_id" | |
|
179 | + t.index ["updated_at"], name: "index_sessions_on_updated_at" | |
|
180 | 180 | end |
|
181 | 181 | |
|
182 |
- create_table "sites", |
|
|
182 | + create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
183 | 183 |
t.string |
|
184 | 184 |
t.boolean |
|
185 | 185 | t.datetime "start_time" |
|
186 | 186 | t.datetime "created_at" |
|
187 | 187 | t.datetime "updated_at" |
|
188 | 188 |
t.integer |
|
189 | 189 |
t.string |
|
190 | 190 | end |
|
191 | 191 | |
|
192 |
- create_table "submission_view_logs", |
|
|
192 | + create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
193 | 193 |
t.integer |
|
194 | 194 |
t.integer |
|
195 | - t.datetime "created_at" | |
|
196 | - t.datetime "updated_at" | |
|
195 | + t.datetime "created_at", null: false | |
|
196 | + t.datetime "updated_at", null: false | |
|
197 | 197 | end |
|
198 | 198 | |
|
199 |
- create_table "submissions", |
|
|
199 | + create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
200 | 200 |
t.integer |
|
201 | 201 |
t.integer |
|
202 | 202 |
t.integer |
|
203 | 203 |
t.text |
|
204 | - t.binary "binary", limit: 65535 | |
|
204 | + t.binary "binary" | |
|
205 | 205 | t.datetime "submitted_at" |
|
206 | 206 | t.datetime "compiled_at" |
|
207 |
- t.text |
|
|
207 | + t.text "compiler_message" | |
|
208 | 208 | t.datetime "graded_at" |
|
209 | 209 |
t.integer |
|
210 |
- t.text |
|
|
210 | + t.text "grader_comment" | |
|
211 | 211 |
t.integer |
|
212 | 212 |
t.string |
|
213 |
- t.float |
|
|
213 | + t.float "max_runtime" | |
|
214 | 214 |
t.integer |
|
215 | 215 |
t.integer |
|
216 | 216 |
t.string |
|
217 |
- t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true |
|
|
218 |
- t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id" |
|
|
217 | + t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true | |
|
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", |
|
|
221 | + create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| | |
|
222 | 222 |
t.string |
|
223 |
- t.text |
|
|
223 | + t.text "description" | |
|
224 | 224 |
t.boolean |
|
225 | 225 |
t.datetime "created_at", |
|
226 | 226 |
t.datetime "updated_at", |
|
227 | 227 | end |
|
228 | 228 | |
|
229 |
- create_table "tasks", |
|
|
229 | + create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
230 | 230 |
t.integer |
|
231 | 231 | t.datetime "created_at" |
|
232 | 232 |
t.integer |
|
233 | 233 | t.datetime "updated_at" |
|
234 |
- t.index ["submission_id"], name: "index_tasks_on_submission_id" |
|
|
234 | + t.index ["submission_id"], name: "index_tasks_on_submission_id" | |
|
235 | 235 | end |
|
236 | 236 | |
|
237 |
- create_table "test_pairs", |
|
|
237 | + create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
238 | 238 |
t.integer |
|
239 | 239 |
t.text |
|
240 | 240 |
t.text |
|
241 | 241 | t.datetime "created_at" |
|
242 | 242 | t.datetime "updated_at" |
|
243 | 243 | end |
|
244 | 244 | |
|
245 |
- create_table "test_requests", |
|
|
245 | + create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
246 | 246 |
t.integer |
|
247 | 247 |
t.integer |
|
248 | 248 |
t.integer |
|
249 | 249 |
t.string |
|
250 | 250 |
t.string |
|
251 | 251 |
t.string |
|
252 | 252 |
t.integer |
|
253 | 253 | t.datetime "updated_at" |
|
254 | 254 | t.datetime "submitted_at" |
|
255 | 255 | t.datetime "compiled_at" |
|
256 |
- t.text |
|
|
256 | + t.text "compiler_message" | |
|
257 | 257 | t.datetime "graded_at" |
|
258 | 258 |
t.string |
|
259 | 259 | t.datetime "created_at" |
|
260 |
- t.float |
|
|
260 | + t.float "running_time" | |
|
261 | 261 |
t.string |
|
262 | 262 |
t.integer |
|
263 |
- t.index ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id" |
|
|
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", |
|
|
266 | + create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| | |
|
267 | 267 |
t.integer |
|
268 | 268 |
t.integer |
|
269 | 269 |
t.integer |
|
270 | 270 |
t.integer |
|
271 | 271 |
t.text |
|
272 | 272 |
t.text |
|
273 | 273 | t.datetime "created_at" |
|
274 | 274 | t.datetime "updated_at" |
|
275 |
- t.index ["problem_id"], name: "index_testcases_on_problem_id" |
|
|
275 | + t.index ["problem_id"], name: "index_testcases_on_problem_id" | |
|
276 | 276 | end |
|
277 | 277 | |
|
278 |
- create_table "user_contest_stats", |
|
|
278 | + create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
279 | 279 |
t.integer |
|
280 | 280 | t.datetime "started_at" |
|
281 | 281 | t.datetime "created_at" |
|
282 | 282 | t.datetime "updated_at" |
|
283 | - t.boolean "forced_logout" | |
|
284 | 283 | end |
|
285 | 284 | |
|
286 |
- create_table "users", |
|
|
285 | + create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| | |
|
287 | 286 |
t.string |
|
288 | 287 |
t.string |
|
289 | 288 |
t.string |
|
290 | 289 |
t.string |
|
291 | 290 |
t.string |
|
292 | 291 |
t.string |
|
293 | 292 |
t.integer |
|
294 | 293 |
t.integer |
|
295 | 294 |
t.boolean |
|
296 | 295 | t.datetime "created_at" |
|
297 | 296 | t.datetime "updated_at" |
|
298 | 297 |
t.string |
|
299 | 298 |
t.boolean |
|
300 | 299 |
t.string |
|
301 | 300 |
t.string |
|
302 |
- t.index ["login"], name: "index_users_on_login", unique: true |
|
|
301 | + t.index ["login"], name: "index_users_on_login", unique: true | |
|
303 | 302 | end |
|
304 | 303 | |
|
305 | 304 | add_foreign_key "problems_tags", "problems" |
|
306 | 305 | add_foreign_key "problems_tags", "tags" |
|
307 | 306 | end |
@@ -1,50 +1,102 | |||
|
1 | 1 | require "application_system_test_case" |
|
2 | 2 | |
|
3 | 3 | class UsersTest < ApplicationSystemTestCase |
|
4 | 4 | # test "visiting the index" do |
|
5 | 5 | # visit users_url |
|
6 | 6 | # |
|
7 | 7 | # assert_selector "h1", text: "User" |
|
8 | 8 | # end |
|
9 | 9 | |
|
10 | 10 | test "add new user and edit" do |
|
11 | 11 | login('admin','admin') |
|
12 | 12 | within 'header' do |
|
13 | 13 | click_on 'Manage' |
|
14 | 14 | click_on 'Users', match: :first |
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | assert_text "Users" |
|
18 | 18 | assert_text "New user" |
|
19 | 19 | |
|
20 | 20 | click_on "New user", match: :first |
|
21 | 21 | fill_in 'Login', with: 'test1' |
|
22 | 22 | fill_in 'Full name', with: 'test1 McTestface' |
|
23 | 23 | fill_in 'e-mail', with: 'a@a.com' |
|
24 | 24 | fill_in 'Password', with: 'abcdef' |
|
25 | 25 | fill_in 'Password confirmation', with: 'abcdef' |
|
26 | 26 | |
|
27 | 27 | click_on 'Create' |
|
28 | 28 | |
|
29 | 29 | assert_text 'User was successfully created' |
|
30 | 30 | assert_text 'a@a.com' |
|
31 | 31 | assert_text 'test1 McTestface' |
|
32 | 32 | |
|
33 | 33 | within('tr', text: 'McTestface') do |
|
34 | 34 | click_on 'Edit' |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | fill_in 'Alias', with: 'hahaha' |
|
38 | 38 | fill_in 'Remark', with: 'section 2' |
|
39 | 39 | click_on 'Update User' |
|
40 | 40 | |
|
41 | 41 | assert_text 'section 2' |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | + test "add multiple users" do | |
|
45 | + login 'admin', 'admin' | |
|
46 | + within 'header' do | |
|
47 | + click_on 'Manage' | |
|
48 | + click_on 'Users', match: :first | |
|
49 | + end | |
|
50 | + | |
|
51 | + click_on 'New list of users', match: :first | |
|
52 | + find(:css, 'textarea').fill_in with:"abc1,Boaty McBoatface,abcdef,alias1,remark1,\nabc2,Boaty2 McSecond,acbdef123,aias2,remark2" | |
|
53 | + click_on 'create users' | |
|
54 | + | |
|
55 | + assert_text('remark1') | |
|
56 | + assert_text('remark2') | |
|
57 | + end | |
|
58 | + | |
|
59 | + test "grant admin right" do | |
|
60 | + login 'admin', 'admin' | |
|
61 | + within 'header' do | |
|
62 | + click_on 'Manage' | |
|
63 | + click_on 'Users', match: :first | |
|
64 | + end | |
|
65 | + | |
|
66 | + click_on "View administrator" | |
|
67 | + fill_in 'login', with: 'john' | |
|
68 | + click_on "Grant" | |
|
69 | + | |
|
70 | + visit logout_main_path | |
|
71 | + login 'john','hello' | |
|
72 | + within 'header' do | |
|
73 | + click_on 'Manage' | |
|
74 | + click_on 'Problem', match: :first | |
|
75 | + end | |
|
76 | + assert_text "Turn off all problems" | |
|
77 | + end | |
|
78 | + | |
|
79 | + test "try using admin from normal user" do | |
|
80 | + login 'admin','admin' | |
|
81 | + visit bulk_manage_user_admin_index_path | |
|
82 | + assert_current_path bulk_manage_user_admin_index_path | |
|
83 | + visit logout_main_path | |
|
84 | + | |
|
85 | + login 'jack','morning' | |
|
86 | + visit bulk_manage_user_admin_index_path | |
|
87 | + assert_current_path root_path | |
|
88 | + assert_text 'You are not authorized' | |
|
89 | + | |
|
90 | + login 'james','morning' | |
|
91 | + visit new_list_user_admin_index_path | |
|
92 | + assert_current_path root_path | |
|
93 | + assert_text 'You are not authorized' | |
|
94 | + end | |
|
95 | + | |
|
44 | 96 | def login(username,password) |
|
45 | 97 | visit root_path |
|
46 | 98 | fill_in "Login", with: username |
|
47 | 99 | fill_in "Password", with: password |
|
48 | 100 | click_on "Login" |
|
49 | 101 | end |
|
50 | 102 | end |
You need to be logged in to leave comments.
Login now