Description:
test interface upload
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@81 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r36:a3144ce1a174 - - 13 files changed: 269 inserted, 20 deleted
@@ -0,0 +1,64 | |||
|
1 | + require 'fileutils' | |
|
2 | + | |
|
3 | + class TestRequest < Task | |
|
4 | + | |
|
5 | + set_table_name "test_requests" | |
|
6 | + | |
|
7 | + belongs_to :user | |
|
8 | + belongs_to :problem | |
|
9 | + belongs_to :submission | |
|
10 | + | |
|
11 | + def self.get_inqueue_and_change_status(status) | |
|
12 | + # since there will be only one grader grading TestRequest | |
|
13 | + # we do not need locking (hopefully) | |
|
14 | + | |
|
15 | + task = Task.find(:first, | |
|
16 | + :order => "created_at", | |
|
17 | + :conditions => {:status=> Task::STATUS_INQUEUE}) | |
|
18 | + if task!=nil | |
|
19 | + task.status = status | |
|
20 | + task.save! | |
|
21 | + end | |
|
22 | + | |
|
23 | + task | |
|
24 | + end | |
|
25 | + | |
|
26 | + # interfacing with form | |
|
27 | + def self.new_from_form_params(user,params) | |
|
28 | + test_request = TestRequest.new | |
|
29 | + test_request.user = user | |
|
30 | + problem = Problem.find(params[:problem_id]) | |
|
31 | + test_request.problem = problem | |
|
32 | + test_request.submission = | |
|
33 | + Submission.find_by_user_problem_number(user.id, | |
|
34 | + problem.id, | |
|
35 | + params[:submission_number]) | |
|
36 | + test_request.input_file_name = save_input_file(params[:input_file], user, problem) | |
|
37 | + test_request.submitted_at = Time.new | |
|
38 | + test_request.status_inqueue | |
|
39 | + test_request | |
|
40 | + end | |
|
41 | + | |
|
42 | + protected | |
|
43 | + def self.input_file_name(user,problem) | |
|
44 | + begin | |
|
45 | + tmpname = UPLOADED_INPUT_FILE_DIR + "/#{user.login}/#{problem.name}/#{rand(10000)}" | |
|
46 | + end while File.exists?(tmpname) | |
|
47 | + tmpname | |
|
48 | + end | |
|
49 | + | |
|
50 | + def self.save_input_file(tempfile, user, problem) | |
|
51 | + new_file_name = input_file_name(user,problem) | |
|
52 | + dirname = File.dirname(new_file_name) | |
|
53 | + FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) | |
|
54 | + if tempfile.instance_of?(Tempfile) | |
|
55 | + tempfile.close | |
|
56 | + FileUtils.move(tempfile.path,new_file_name) | |
|
57 | + else | |
|
58 | + File.open(new_file_name, "wb") do |f| | |
|
59 | + f.write(tempfile.read) | |
|
60 | + end | |
|
61 | + end | |
|
62 | + new_file_name | |
|
63 | + end | |
|
64 | + end |
@@ -0,0 +1,5 | |||
|
1 | + %tr.test-request | |
|
2 | + %td= test_request_counter +1 | |
|
3 | + %td= test_request.problem.full_name | |
|
4 | + %td= test_request.submission_id | |
|
5 | + %td= test_request.status_str |
@@ -0,0 +1,67 | |||
|
1 | + <h2>Test Interface</h2> | |
|
2 | + | |
|
3 | + <% if @problems.length==0 %> | |
|
4 | + "There is no submission" | |
|
5 | + <% return %> | |
|
6 | + <% end %> | |
|
7 | + | |
|
8 | + <script type="text/javascript"> | |
|
9 | + var submissionCount = { | |
|
10 | + <% @submissions.each do |submission| %> | |
|
11 | + <%= submission.problem_id %> : <%= submission.number %>, | |
|
12 | + <% end %> | |
|
13 | + }; | |
|
14 | + function updateSubmissionList() { | |
|
15 | + currentProb = document.getElementById("test_request_problem_id").value; | |
|
16 | + count = submissionCount[currentProb]; | |
|
17 | + submissionSelect = document.getElementById("test_request_submission_number"); | |
|
18 | + submissionSelect.options.length = 0; | |
|
19 | + for(i=0; i<count; i++) { | |
|
20 | + submissionSelect.options[i] = new Option(""+(i+1),""+(i+1),false,false); | |
|
21 | + } | |
|
22 | + } | |
|
23 | + </script> | |
|
24 | + | |
|
25 | + <% form_for :test_request, nil, | |
|
26 | + :url => { :action => 'test_submit'}, | |
|
27 | + :html => { :multipart => true } do |f| %> | |
|
28 | + <table> | |
|
29 | + <tr> | |
|
30 | + <td>Task:</td> | |
|
31 | + <td> | |
|
32 | + <%= select(:test_request, | |
|
33 | + :problem_id, | |
|
34 | + @problems.collect {|p| [p.name, p.id]}, {}, | |
|
35 | + { :onclick => "updateSubmissionList();" }) %> | |
|
36 | + </td> | |
|
37 | + </tr> | |
|
38 | + <tr> | |
|
39 | + <td>Submission:</td> | |
|
40 | + <td> | |
|
41 | + <%= select(:test_request, | |
|
42 | + :submission_number, | |
|
43 | + (1..@submissions[0].number).collect {|n| [n,n]}) %> | |
|
44 | + </td> | |
|
45 | + </tr> | |
|
46 | + <tr> | |
|
47 | + <td>Input data:</td> | |
|
48 | + <td><%= f.file_field :input_file %></td> | |
|
49 | + <tr> | |
|
50 | + <td colspan="2"> | |
|
51 | + <%= submit_tag 'submit' %> | |
|
52 | + </td> | |
|
53 | + </tr> | |
|
54 | + </table> | |
|
55 | + <% end %> | |
|
56 | + | |
|
57 | + <h3>Previous requests</h3> | |
|
58 | + | |
|
59 | + <table border="1"> | |
|
60 | + <tr> | |
|
61 | + <th></td> | |
|
62 | + <th>problem</th> | |
|
63 | + <th>#</th> | |
|
64 | + <th>status</th> | |
|
65 | + </tr> | |
|
66 | + <%= render :partial => 'test_request', :collection => @user.test_requests %> | |
|
67 | + </table> |
@@ -0,0 +1,30 | |||
|
1 | + class CreateTestRequests < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + create_table :test_requests do |t| | |
|
4 | + t.column :user_id, :integer | |
|
5 | + t.column :problem_id, :integer | |
|
6 | + t.column :submission_id, :integer | |
|
7 | + t.column :input_file_name, :string | |
|
8 | + t.column :output_file_name, :string | |
|
9 | + t.column :running_stat, :string | |
|
10 | + | |
|
11 | + # these are similar to tasks | |
|
12 | + t.column :status, :integer | |
|
13 | + t.column :updated_at, :datetime | |
|
14 | + | |
|
15 | + # these are intentionally similar to submissions | |
|
16 | + t.column :submitted_at, :datetime | |
|
17 | + t.column :compiled_at, :datetime | |
|
18 | + t.column :compiler_message, :string | |
|
19 | + t.column :graded_at, :datetime | |
|
20 | + t.column :grader_comment, :string | |
|
21 | + t.timestamps | |
|
22 | + end | |
|
23 | + add_index :test_requests, [:user_id, :problem_id] | |
|
24 | + end | |
|
25 | + | |
|
26 | + def self.down | |
|
27 | + remove_index :test_requests, :column => [:user_id, :problem_id] | |
|
28 | + drop_table :test_requests | |
|
29 | + end | |
|
30 | + end |
@@ -0,0 +1,7 | |||
|
1 | + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | |
|
2 | + | |
|
3 | + # one: | |
|
4 | + # column: value | |
|
5 | + # | |
|
6 | + # two: | |
|
7 | + # column: value |
@@ -0,0 +1,8 | |||
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | |
|
2 | + | |
|
3 | + class TestRequestTest < ActiveSupport::TestCase | |
|
4 | + # Replace this with your real tests. | |
|
5 | + def test_truth | |
|
6 | + assert true | |
|
7 | + end | |
|
8 | + end |
@@ -1,70 +1,87 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | 4 | |
|
5 | 5 | verify :method => :post, :only => [:submit], |
|
6 | 6 | :redirect_to => { :action => :index } |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | def index |
|
10 | 10 | redirect_to :action => 'login' |
|
11 | 11 | end |
|
12 | 12 | |
|
13 | 13 | def login |
|
14 | 14 | reset_session |
|
15 | 15 | render :action => 'login', :layout => 'empty' |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def list |
|
19 | 19 | prepare_list_information |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def submit |
|
23 | 23 | @submission = Submission.new(params[:submission]) |
|
24 | 24 | @submission.user_id = session[:user_id] |
|
25 | 25 | @submission.language_id = 0 |
|
26 | 26 | @submission.source = params['file'].read if params['file']!='' |
|
27 | 27 | @submission.submitted_at = Time.new |
|
28 | 28 | if @submission.valid? |
|
29 | 29 | if @submission.save == false |
|
30 | 30 | flash[:notice] = 'Error saving your submission' |
|
31 | 31 | elsif Task.create(:submission_id => @submission.id, |
|
32 | 32 | :status => Task::STATUS_INQUEUE) == false |
|
33 | 33 | flash[:notice] = 'Error adding your submission to task queue' |
|
34 | 34 | end |
|
35 | 35 | else |
|
36 | 36 | prepare_list_information |
|
37 | 37 | render :action => 'list' and return |
|
38 | 38 | end |
|
39 | 39 | redirect_to :action => 'list' |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def get_source |
|
43 | 43 | submission = Submission.find(params[:id]) |
|
44 | 44 | if submission.user_id == session[:user_id] |
|
45 | 45 | fname = submission.problem.name + '.' + submission.language.ext |
|
46 | 46 | send_data(submission.source, |
|
47 | 47 | {:filename => fname, |
|
48 | 48 | :type => 'text/plain'}) |
|
49 | 49 | else |
|
50 | 50 | flash[:notice] = 'Error viewing source' |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | + def test | |
|
55 | + @user = User.find(session[:user_id]) | |
|
56 | + @submissions = Submission.find_last_for_all_available_problems(@user.id) | |
|
57 | + @problems = @submissions.collect { |submission| submission.problem } | |
|
58 | + end | |
|
59 | + | |
|
60 | + def test_submit | |
|
61 | + @user = User.find(session[:user_id]) | |
|
62 | + test_request = TestRequest.new_from_form_params(@user,params[:test_request]) | |
|
63 | + if test_request.save | |
|
64 | + redirect_to :action => 'test' | |
|
65 | + else | |
|
66 | + flash[:notice] = 'Error saving your test submission' | |
|
67 | + render :action => 'test' | |
|
68 | + end | |
|
69 | + end | |
|
70 | + | |
|
54 | 71 | protected |
|
55 | 72 | def prepare_list_information |
|
56 | 73 | @problems = Problem.find_available_problems |
|
57 | 74 | @prob_submissions = Array.new |
|
58 | 75 | @user = User.find(session[:user_id]) |
|
59 | 76 | @problems.each do |p| |
|
60 | 77 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
61 | 78 | if sub!=nil |
|
62 | 79 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
63 | 80 | else |
|
64 | 81 | @prob_submissions << { :count => 0, :submission => nil } |
|
65 | 82 | end |
|
66 | 83 | end |
|
67 | 84 | end |
|
68 | 85 | |
|
69 | 86 | end |
|
70 | 87 |
@@ -1,35 +1,33 | |||
|
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | 2 | module ApplicationHelper |
|
3 | 3 | |
|
4 | 4 | def user_header |
|
5 |
- |
|
|
5 | + menu_items = '' | |
|
6 | 6 | user = User.find(session[:user_id]) |
|
7 | 7 | |
|
8 | 8 | # main page |
|
9 | - options += link_to_unless_current '[Main]', | |
|
10 | - :controller => 'main', :action => 'list' | |
|
11 | - options += ' ' | |
|
9 | + append_to menu_items, '[Main]', 'main', 'list' | |
|
10 | + append_to menu_items, '[Test]', 'main', 'test' | |
|
12 | 11 | |
|
13 | 12 | # admin menu |
|
14 | 13 | if (user!=nil) and (user.admin?) |
|
15 | - options += | |
|
16 | - (link_to_unless_current '[Problem admin]', | |
|
17 | - :controller => 'problems', :action => 'index') + ' ' | |
|
18 | - options += | |
|
19 | - (link_to_unless_current '[User admin]', | |
|
20 | - :controller => 'user_admin', :action => 'index') + ' ' | |
|
21 | - options += | |
|
22 | - (link_to_unless_current '[User stat]', | |
|
23 | - :controller => 'user_admin', :action => 'user_stat') + ' ' | |
|
14 | + append_to menu_items, '[Problem admin]', 'problems', 'index' | |
|
15 | + append_to menu_items, '[User admin]', 'user_admin', 'index' | |
|
16 | + append_to menu_items, '[User stat]', 'user_admin', 'user_stat' | |
|
24 | 17 | end |
|
25 | 18 | |
|
26 | 19 | # general options |
|
27 | - options += link_to_unless_current '[Settings]', | |
|
28 | - :controller => 'users', :action => 'index' | |
|
29 | - options += ' ' | |
|
30 | - options += | |
|
31 | - link_to('[Log out]', {:controller => 'main', :action => 'login'}) | |
|
32 | - options | |
|
20 | + append_to menu_items, '[Settings]', 'users', 'index' | |
|
21 | + append_to menu_items, '[Log out]', 'main', 'login' | |
|
22 | + | |
|
23 | + menu_items | |
|
24 | + end | |
|
25 | + | |
|
26 | + def append_to(option,label, controller, action) | |
|
27 | + option << ' ' if option!='' | |
|
28 | + option << link_to_unless_current(label, | |
|
29 | + :controller => controller, | |
|
30 | + :action => action) | |
|
33 | 31 | end |
|
34 | 32 | |
|
35 | 33 | end |
@@ -1,100 +1,119 | |||
|
1 | 1 | class Submission < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :language |
|
4 | 4 | belongs_to :problem |
|
5 | 5 | belongs_to :user |
|
6 | 6 | |
|
7 | 7 | validates_presence_of :source |
|
8 | 8 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
9 | 9 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
10 | 10 | validate :must_specify_language |
|
11 | 11 | validate :must_have_valid_problem |
|
12 | 12 | |
|
13 | 13 | before_save :assign_latest_number |
|
14 | 14 | |
|
15 | 15 | def self.find_last_by_user_and_problem(user_id, problem_id) |
|
16 | 16 | last_sub = find(:first, |
|
17 | 17 | :conditions => {:user_id => user_id, |
|
18 | 18 | :problem_id => problem_id}, |
|
19 | 19 | :order => 'submitted_at DESC') |
|
20 | 20 | return last_sub |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | def self.find_all_last_by_problem(problem_id) |
|
24 | 24 | # need to put in SQL command, maybe there's a better way |
|
25 | 25 | Submission.find_by_sql("SELECT * FROM submissions " + |
|
26 | 26 | "WHERE id = " + |
|
27 | 27 | "(SELECT MAX(id) FROM submissions AS subs " + |
|
28 | 28 | "WHERE subs.user_id = submissions.user_id AND " + |
|
29 | 29 | "problem_id = " + problem_id.to_s + " " + |
|
30 | 30 | "GROUP BY user_id)") |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | + def self.find_last_for_all_available_problems(user_id) | |
|
34 | + submissions = Array.new | |
|
35 | + problems = Problem.find_available_problems | |
|
36 | + problems.each do |problem| | |
|
37 | + sub = Submission.find_last_by_user_and_problem(user_id, problem.id) | |
|
38 | + submissions << sub if sub!=nil | |
|
39 | + end | |
|
40 | + submissions | |
|
41 | + end | |
|
42 | + | |
|
43 | + def self.find_by_user_problem_number(user_id, problem_id, number) | |
|
44 | + Submission.find(:first, | |
|
45 | + :conditions => { | |
|
46 | + :user_id => user_id, | |
|
47 | + :problem_id => problem_id, | |
|
48 | + :number => number | |
|
49 | + }) | |
|
50 | + end | |
|
51 | + | |
|
33 | 52 | protected |
|
34 | 53 | |
|
35 | 54 | def self.find_option_in_source(option, source) |
|
36 | 55 | if source==nil |
|
37 | 56 | return nil |
|
38 | 57 | end |
|
39 | 58 | i = 0 |
|
40 | 59 | source.each_line do |s| |
|
41 | 60 | if s =~ option |
|
42 | 61 | words = s.split |
|
43 | 62 | return words[1] |
|
44 | 63 | end |
|
45 | 64 | i = i + 1 |
|
46 | 65 | if i==10 |
|
47 | 66 | return nil |
|
48 | 67 | end |
|
49 | 68 | end |
|
50 | 69 | return nil |
|
51 | 70 | end |
|
52 | 71 | |
|
53 | 72 | def self.find_language_in_source(source) |
|
54 | 73 | langopt = find_option_in_source(/^LANG:/,source) |
|
55 | 74 | if language = Language.find_by_name(langopt) |
|
56 | 75 | return language |
|
57 | 76 | elsif language = Language.find_by_pretty_name(langopt) |
|
58 | 77 | return language |
|
59 | 78 | else |
|
60 | 79 | return nil |
|
61 | 80 | end |
|
62 | 81 | end |
|
63 | 82 | |
|
64 | 83 | def self.find_problem_in_source(source) |
|
65 | 84 | prob_opt = find_option_in_source(/^TASK:/,source) |
|
66 | 85 | if problem = Problem.find_by_name(prob_opt) |
|
67 | 86 | return problem |
|
68 | 87 | else |
|
69 | 88 | return nil |
|
70 | 89 | end |
|
71 | 90 | end |
|
72 | 91 | |
|
73 | 92 | # validation codes |
|
74 | 93 | def must_specify_language |
|
75 | 94 | return if self.source==nil |
|
76 | 95 | self.language = Submission.find_language_in_source(self.source) |
|
77 | 96 | errors.add_to_base("must specify programming language") unless self.language!=nil |
|
78 | 97 | end |
|
79 | 98 | |
|
80 | 99 | def must_have_valid_problem |
|
81 | 100 | return if self.source==nil |
|
82 | 101 | if self.problem_id!=-1 |
|
83 | 102 | problem = Problem.find(self.problem_id) |
|
84 | 103 | else |
|
85 | 104 | problem = Submission.find_problem_in_source(self.source) |
|
86 | 105 | end |
|
87 | 106 | if problem==nil |
|
88 | 107 | errors.add_to_base("must specify problem") |
|
89 | 108 | elsif !problem.available |
|
90 | 109 | errors.add_to_base("must specify valid problem") |
|
91 | 110 | end |
|
92 | 111 | end |
|
93 | 112 | |
|
94 | 113 | # callbacks |
|
95 | 114 | def assign_latest_number |
|
96 | 115 | latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id) |
|
97 | 116 | self.number = (latest==nil) ? 1 : latest.number + 1; |
|
98 | 117 | end |
|
99 | 118 | |
|
100 | 119 | end |
@@ -1,55 +1,66 | |||
|
1 | 1 | class Task < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | STATUS_GRADING = 0 |
|
4 | 4 | STATUS_INQUEUE = 1 |
|
5 | 5 | STATUS_COMPLETE = 2 |
|
6 | 6 | |
|
7 | 7 | def status_inqueue |
|
8 | 8 | self.status = Task::STATUS_INQUEUE |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | def status_inqueue! |
|
12 | 12 | status_inqueue |
|
13 | 13 | self.save |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | def status_grading |
|
17 | 17 | self.status = Task::STATUS_GRADING |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def status_grading! |
|
21 | 21 | status_grading |
|
22 | 22 | self.save |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def status_complete |
|
26 | 26 | self.status = Task::STATUS_COMPLETE |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def status_complete! |
|
30 | 30 | status_complete |
|
31 | 31 | self.save |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | + def status_str | |
|
35 | + case self.status | |
|
36 | + when Task::STATUS_INQUEUE | |
|
37 | + "inqueue" | |
|
38 | + when Task::STATUS_GRADING | |
|
39 | + "grading" | |
|
40 | + when Task::STATUS_COMPLETE | |
|
41 | + "complete" | |
|
42 | + end | |
|
43 | + end | |
|
44 | + | |
|
34 | 45 | def self.get_inqueue_and_change_status(status) |
|
35 | 46 | task = nil |
|
36 | 47 | begin |
|
37 | 48 | Task.transaction do |
|
38 | 49 | task = Task.find(:first, |
|
39 | 50 | :order => "created_at", |
|
40 | 51 | :conditions => {:status=> Task::STATUS_INQUEUE}, |
|
41 | 52 | :lock => true) |
|
42 | 53 | if task!=nil |
|
43 | 54 | task.status = status |
|
44 | 55 | task.save! |
|
45 | 56 | end |
|
46 | 57 | end |
|
47 | 58 | |
|
48 | 59 | rescue |
|
49 | 60 | task = nil |
|
50 | 61 | |
|
51 | 62 | end |
|
52 | 63 | task |
|
53 | 64 | end |
|
54 | 65 | |
|
55 | 66 | end |
@@ -1,74 +1,76 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | 2 | |
|
3 | 3 | class User < ActiveRecord::Base |
|
4 | 4 | |
|
5 | 5 | has_and_belongs_to_many :roles |
|
6 | 6 | |
|
7 | + has_many :test_requests, :order => "problem_id" | |
|
8 | + | |
|
7 | 9 | validates_presence_of :login |
|
8 | 10 | validates_presence_of :full_name |
|
9 | 11 | validates_length_of :full_name, :minimum => 1 |
|
10 | 12 | |
|
11 | 13 | validates_presence_of :password, :if => :password_required? |
|
12 | 14 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
13 | 15 | validates_confirmation_of :password, :if => :password_required? |
|
14 | 16 | |
|
15 | 17 | attr_accessor :password |
|
16 | 18 | |
|
17 | 19 | before_save :encrypt_new_password |
|
18 | 20 | |
|
19 | 21 | def self.authenticate(login, password) |
|
20 | 22 | user = find_by_login(login) |
|
21 | 23 | return user if user && user.authenticated?(password) |
|
22 | 24 | end |
|
23 | 25 | |
|
24 | 26 | def authenticated?(password) |
|
25 | 27 | hashed_password == encrypt(password,salt) |
|
26 | 28 | end |
|
27 | 29 | |
|
28 | 30 | def admin? |
|
29 | 31 | self.roles.detect {|r| r.name == 'admin' } |
|
30 | 32 | end |
|
31 | 33 | |
|
32 | 34 | def email_for_editing |
|
33 | 35 | if self.email==nil |
|
34 | 36 | "(unknown)" |
|
35 | 37 | elsif self.email=='' |
|
36 | 38 | "(blank)" |
|
37 | 39 | else |
|
38 | 40 | self.email |
|
39 | 41 | end |
|
40 | 42 | end |
|
41 | 43 | |
|
42 | 44 | def email_for_editing=(e) |
|
43 | 45 | self.email=e |
|
44 | 46 | end |
|
45 | 47 | |
|
46 | 48 | def alias_for_editing |
|
47 | 49 | if self.alias==nil |
|
48 | 50 | "(unknown)" |
|
49 | 51 | elsif self.alias=='' |
|
50 | 52 | "(blank)" |
|
51 | 53 | else |
|
52 | 54 | self.alias |
|
53 | 55 | end |
|
54 | 56 | end |
|
55 | 57 | |
|
56 | 58 | def alias_for_editing=(e) |
|
57 | 59 | self.alias=e |
|
58 | 60 | end |
|
59 | 61 | |
|
60 | 62 | protected |
|
61 | 63 | def encrypt_new_password |
|
62 | 64 | return if password.blank? |
|
63 | 65 | self.salt = (10+rand(90)).to_s |
|
64 | 66 | self.hashed_password = encrypt(password,salt) |
|
65 | 67 | end |
|
66 | 68 | |
|
67 | 69 | def password_required? |
|
68 | 70 | hashed_password.blank? || !password.blank? |
|
69 | 71 | end |
|
70 | 72 | |
|
71 | 73 | def encrypt(string,salt) |
|
72 | 74 | Digest::SHA1.hexdigest(salt + string) |
|
73 | 75 | end |
|
74 | 76 | end |
@@ -1,60 +1,62 | |||
|
1 | 1 | # Be sure to restart your web server when you modify this file. |
|
2 | 2 | |
|
3 | 3 | # Uncomment below to force Rails into production mode when |
|
4 | 4 | # you don't control web/app server and can't set it the proper way |
|
5 | 5 | # ENV['RAILS_ENV'] ||= 'production' |
|
6 | 6 | |
|
7 | 7 | # Specifies gem version of Rails to use when vendor/rails is not present |
|
8 | 8 | RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION |
|
9 | 9 | |
|
10 | 10 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
11 | 11 | require File.join(File.dirname(__FILE__), 'boot') |
|
12 | 12 | |
|
13 | 13 | Rails::Initializer.run do |config| |
|
14 | 14 | # Settings in config/environments/* take precedence over those specified here |
|
15 | 15 | |
|
16 | 16 | # Skip frameworks you're not going to use (only works if using vendor/rails) |
|
17 | 17 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
18 | 18 | |
|
19 | 19 | # Only load the plugins named here, by default all plugins in vendor/plugins are loaded |
|
20 | 20 | # config.plugins = %W( exception_notification ssl_requirement ) |
|
21 | 21 | |
|
22 | 22 | # Add additional load paths for your own custom dirs |
|
23 | 23 | # config.load_paths += %W( #{RAILS_ROOT}/extras ) |
|
24 | 24 | |
|
25 | 25 | # Force all environments to use the same logger level |
|
26 | 26 | # (by default production uses :info, the others :debug) |
|
27 | 27 | # config.log_level = :debug |
|
28 | 28 | |
|
29 | 29 | # Use the database for sessions instead of the file system |
|
30 | 30 | # (create the session table with 'rake db:sessions:create') |
|
31 | 31 | config.action_controller.session_store = :active_record_store |
|
32 | 32 | |
|
33 | 33 | # Use SQL instead of Active Record's schema dumper when creating the test database. |
|
34 | 34 | # This is necessary if your schema can't be completely dumped by the schema dumper, |
|
35 | 35 | # like if you have constraints or database-specific column types |
|
36 | 36 | # config.active_record.schema_format = :sql |
|
37 | 37 | |
|
38 | 38 | # Activate observers that should always be running |
|
39 | 39 | # config.active_record.observers = :cacher, :garbage_collector |
|
40 | 40 | |
|
41 | 41 | # Make Active Record use UTC-base instead of local time |
|
42 | 42 | config.active_record.default_timezone = :utc |
|
43 | 43 | |
|
44 | 44 | # See Rails::Configuration for more options |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | # Add new inflection rules using the following format |
|
48 | 48 | # (all these examples are active by default): |
|
49 | 49 | # Inflector.inflections do |inflect| |
|
50 | 50 | # inflect.plural /^(ox)$/i, '\1en' |
|
51 | 51 | # inflect.singular /^(ox)en/i, '\1' |
|
52 | 52 | # inflect.irregular 'person', 'people' |
|
53 | 53 | # inflect.uncountable %w( fish sheep ) |
|
54 | 54 | # end |
|
55 | 55 | |
|
56 | 56 | # Add new mime types for use in respond_to blocks: |
|
57 | 57 | # Mime::Type.register "text/richtext", :rtf |
|
58 | 58 | # Mime::Type.register "application/x-mobile", :mobile |
|
59 | 59 | |
|
60 | 60 | # Include your application configuration below |
|
61 | + | |
|
62 | + UPLOADED_INPUT_FILE_DIR = '/home/jittat/web_grader/upload/' |
@@ -1,110 +1,129 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | 2 | # please use the migrations feature of ActiveRecord to incrementally modify your database, and |
|
3 | 3 | # then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
6 | 6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | 7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | 8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 1 |
|
|
12 | + ActiveRecord::Schema.define(:version => 19) do | |
|
13 | 13 | |
|
14 | 14 | create_table "grader_processes", :force => true do |t| |
|
15 | 15 | t.string "host", :limit => 20 |
|
16 | 16 | t.integer "pid" |
|
17 | 17 | t.string "mode" |
|
18 | 18 | t.boolean "active" |
|
19 | 19 | t.datetime "created_at" |
|
20 | 20 | t.datetime "updated_at" |
|
21 | 21 | t.integer "task_id" |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | 24 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
25 | 25 | |
|
26 | 26 | create_table "languages", :force => true do |t| |
|
27 | 27 | t.string "name", :limit => 10 |
|
28 | 28 | t.string "pretty_name" |
|
29 | 29 | t.string "ext", :limit => 10 |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | create_table "problems", :force => true do |t| |
|
33 | 33 | t.string "name", :limit => 30 |
|
34 | 34 | t.string "full_name" |
|
35 | 35 | t.integer "full_score" |
|
36 | 36 | t.date "date_added" |
|
37 | 37 | t.boolean "available" |
|
38 | 38 | t.string "url" |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | create_table "rights", :force => true do |t| |
|
42 | 42 | t.string "name" |
|
43 | 43 | t.string "controller" |
|
44 | 44 | t.string "action" |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | create_table "rights_roles", :id => false, :force => true do |t| |
|
48 | 48 | t.integer "right_id" |
|
49 | 49 | t.integer "role_id" |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
53 | 53 | |
|
54 | 54 | create_table "roles", :force => true do |t| |
|
55 | 55 | t.string "name" |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | create_table "roles_users", :id => false, :force => true do |t| |
|
59 | 59 | t.integer "role_id" |
|
60 | 60 | t.integer "user_id" |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
64 | 64 | |
|
65 | 65 | create_table "sessions", :force => true do |t| |
|
66 | 66 | t.string "session_id" |
|
67 | 67 | t.text "data" |
|
68 | 68 | t.datetime "updated_at" |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
72 | 72 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
73 | 73 | |
|
74 | 74 | create_table "submissions", :force => true do |t| |
|
75 | 75 | t.integer "user_id" |
|
76 | 76 | t.integer "problem_id" |
|
77 | 77 | t.integer "language_id" |
|
78 | 78 | t.text "source" |
|
79 | 79 | t.binary "binary" |
|
80 | 80 | t.datetime "submitted_at" |
|
81 | 81 | t.datetime "compiled_at" |
|
82 | 82 | t.text "compiler_message" |
|
83 | 83 | t.datetime "graded_at" |
|
84 | 84 | t.integer "points" |
|
85 | 85 | t.text "grader_comment" |
|
86 | 86 | t.integer "number" |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
90 | 90 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
91 | 91 | |
|
92 | 92 | create_table "tasks", :force => true do |t| |
|
93 | 93 | t.integer "submission_id" |
|
94 | 94 | t.datetime "created_at" |
|
95 | 95 | t.integer "status" |
|
96 | 96 | t.datetime "updated_at" |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | + create_table "test_requests", :force => true do |t| | |
|
100 | + t.integer "user_id" | |
|
101 | + t.integer "problem_id" | |
|
102 | + t.integer "submission_id" | |
|
103 | + t.string "input_file_name" | |
|
104 | + t.string "output_file_name" | |
|
105 | + t.string "running_stat" | |
|
106 | + t.integer "status" | |
|
107 | + t.datetime "updated_at" | |
|
108 | + t.datetime "submitted_at" | |
|
109 | + t.datetime "compiled_at" | |
|
110 | + t.string "compiler_message" | |
|
111 | + t.datetime "graded_at" | |
|
112 | + t.string "grader_comment" | |
|
113 | + t.datetime "created_at" | |
|
114 | + end | |
|
115 | + | |
|
116 | + add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" | |
|
117 | + | |
|
99 | 118 | create_table "users", :force => true do |t| |
|
100 | 119 | t.string "login", :limit => 10 |
|
101 | 120 | t.string "full_name" |
|
102 | 121 | t.string "hashed_password" |
|
103 | 122 | t.string "salt", :limit => 5 |
|
104 | 123 | t.string "alias" |
|
105 | 124 | t.string "email" |
|
106 | 125 | end |
|
107 | 126 | |
|
108 | 127 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
109 | 128 | |
|
110 | 129 | end |
You need to be logged in to leave comments.
Login now