Description:
[web] added mode + access control, when sites started/finished
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@250 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
r122:dfa0387efb1e - - 9 files changed: 121 inserted, 17 deleted
@@ -0,0 +1,17 | |||||
|
|
1 | + class AddModeToConfigurations < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + | ||
|
|
4 | + # Configuration['system.mode']: | ||
|
|
5 | + # * 'standard' mode | ||
|
|
6 | + # * 'contest' mode (check site start time/stop time) | ||
|
|
7 | + # * 'analysis' mode (show results, no new submissions) | ||
|
|
8 | + | ||
|
|
9 | + Configuration.create(:key => 'system.mode', | ||
|
|
10 | + :value_type => 'string', | ||
|
|
11 | + :value => 'standard') | ||
|
|
12 | + end | ||
|
|
13 | + | ||
|
|
14 | + def self.down | ||
|
|
15 | + Configuration.find_by_key('system.mode').destroy | ||
|
|
16 | + end | ||
|
|
17 | + end |
@@ -1,6 +1,9 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
|
3 | + SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
|
|
4 | + | ||
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
5 | before_filter :authenticate, :except => [:index, :login] |
|
|
6 | + before_filter :check_viewability | ||
|
4 |
|
7 | ||
|
5 | # |
|
8 | # |
|
6 | # COMMENT OUT: filter in each action instead |
|
9 | # COMMENT OUT: filter in each action instead |
@@ -43,7 +46,8 | |||||
|
43 | end |
|
46 | end |
|
44 | @submission.submitted_at = Time.new.gmtime |
|
47 | @submission.submitted_at = Time.new.gmtime |
|
45 |
|
48 | ||
|
46 | - if user.site!=nil and user.site.finished? |
|
49 | + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
|
50 | + user.site!=nil and user.site.finished? | ||
|
47 | @submission.errors.add_to_base "The contest is over." |
|
51 | @submission.errors.add_to_base "The contest is over." |
|
48 | prepare_list_information |
|
52 | prepare_list_information |
|
49 | render :action => 'list' and return |
|
53 | render :action => 'list' and return |
@@ -125,5 +129,13 | |||||
|
125 | :order => "created_at DESC") |
|
129 | :order => "created_at DESC") |
|
126 | end |
|
130 | end |
|
127 |
|
131 | ||
|
|
132 | + def check_viewability | ||
|
|
133 | + user = User.find(session[:user_id]) | ||
|
|
134 | + if (!Configuration.show_tasks_to?(user)) and | ||
|
|
135 | + ((action_name=='submission') or (action_name=='submit')) | ||
|
|
136 | + redirect_to :action => 'list' and return | ||
|
|
137 | + end | ||
|
128 | end |
|
138 | end |
|
129 |
|
139 | ||
|
|
140 | + end | ||
|
|
141 | + |
@@ -1,7 +1,6 | |||||
|
1 | class TasksController < ApplicationController |
|
1 | class TasksController < ApplicationController |
|
2 |
|
2 | ||
|
3 | - before_filter :authenticate |
|
3 | + before_filter :authenticate, :check_viewability |
|
4 | - |
|
||
|
5 |
|
4 | ||
|
6 | def index |
|
5 | def index |
|
7 | redirect_to :action => 'list' |
|
6 | redirect_to :action => 'list' |
@@ -12,4 +11,14 | |||||
|
12 | @user = User.find(session[:user_id]) |
|
11 | @user = User.find(session[:user_id]) |
|
13 | end |
|
12 | end |
|
14 |
|
13 | ||
|
|
14 | + protected | ||
|
|
15 | + | ||
|
|
16 | + def check_viewability | ||
|
|
17 | + user = User.find(session[:user_id]) | ||
|
|
18 | + if user==nil or !Configuration.show_tasks_to?(user) | ||
|
|
19 | + redirect_to :controller => 'main', :action => 'list' | ||
|
|
20 | + return false | ||
|
15 | end |
|
21 | end |
|
|
22 | + end | ||
|
|
23 | + | ||
|
|
24 | + end |
@@ -1,6 +1,8 | |||||
|
1 | class TestController < ApplicationController |
|
1 | class TestController < ApplicationController |
|
2 |
|
2 | ||
|
3 | - before_filter :authenticate |
|
3 | + SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
|
4 | + | ||
|
|
5 | + before_filter :authenticate, :check_viewability | ||
|
4 |
|
6 | ||
|
5 | # |
|
7 | # |
|
6 | # COMMENT OUT: filter in each action instead |
|
8 | # COMMENT OUT: filter in each action instead |
@@ -24,7 +26,8 | |||||
|
24 | render :action => 'index' and return |
|
26 | render :action => 'index' and return |
|
25 | end |
|
27 | end |
|
26 |
|
28 | ||
|
27 | - if @user.site!=nil and @user.site.finished? |
|
29 | + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
|
30 | + @user.site!=nil and @user.site.finished? | ||
|
28 | @submitted_test_request.errors.add_to_base('Contest is over.') |
|
31 | @submitted_test_request.errors.add_to_base('Contest is over.') |
|
29 | prepare_index_information |
|
32 | prepare_index_information |
|
30 | render :action => 'index' and return |
|
33 | render :action => 'index' and return |
@@ -92,4 +95,14 | |||||
|
92 | @test_requests = @user.test_requests |
|
95 | @test_requests = @user.test_requests |
|
93 | end |
|
96 | end |
|
94 |
|
97 | ||
|
|
98 | + def check_viewability | ||
|
|
99 | + user = User.find(session[:user_id]) | ||
|
|
100 | + if !Configuration.show_tasks_to?(user) | ||
|
|
101 | + redirect_to :controller => 'main', :action => 'list' | ||
|
95 | end |
|
102 | end |
|
|
103 | + if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit') | ||
|
|
104 | + redirect_to :controller => 'test', :action => 'index' | ||
|
|
105 | + end | ||
|
|
106 | + end | ||
|
|
107 | + | ||
|
|
108 | + end |
@@ -1,6 +1,8 | |||||
|
1 | # Methods added to this helper will be available to all templates in the application. |
|
1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | module ApplicationHelper |
|
2 | module ApplicationHelper |
|
3 |
|
3 | ||
|
|
4 | + SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
|
|
5 | + | ||
|
4 | def user_header |
|
6 | def user_header |
|
5 | menu_items = '' |
|
7 | menu_items = '' |
|
6 | user = User.find(session[:user_id]) |
|
8 | user = User.find(session[:user_id]) |
@@ -21,9 +23,12 | |||||
|
21 | # main page |
|
23 | # main page |
|
22 | append_to menu_items, '[Main]', 'main', 'list' |
|
24 | append_to menu_items, '[Main]', 'main', 'list' |
|
23 | append_to menu_items, '[Messages]', 'messages', 'list' |
|
25 | append_to menu_items, '[Messages]', 'messages', 'list' |
|
|
26 | + | ||
|
|
27 | + if (user!=nil) and (Configuration.show_tasks_to?(user)) | ||
|
24 | append_to menu_items, '[Tasks]', 'tasks', 'list' |
|
28 | append_to menu_items, '[Tasks]', 'tasks', 'list' |
|
25 | append_to menu_items, '[Submissions]', 'main', 'submission' |
|
29 | append_to menu_items, '[Submissions]', 'main', 'submission' |
|
26 | append_to menu_items, '[Test]', 'test', 'index' |
|
30 | append_to menu_items, '[Test]', 'test', 'index' |
|
|
31 | + end | ||
|
27 | append_to menu_items, '[Help]', 'main', 'help' |
|
32 | append_to menu_items, '[Help]', 'main', 'help' |
|
28 | #append_to menu_items, '[Settings]', 'users', 'index' |
|
33 | #append_to menu_items, '[Settings]', 'users', 'index' |
|
29 | append_to menu_items, '[Log out]', 'main', 'login' |
|
34 | append_to menu_items, '[Log out]', 'main', 'login' |
@@ -48,19 +53,44 | |||||
|
48 | st + time.strftime("%X") |
|
53 | st + time.strftime("%X") |
|
49 | end |
|
54 | end |
|
50 |
|
55 | ||
|
|
56 | + def read_textfile(fname,max_size=2048) | ||
|
|
57 | + begin | ||
|
|
58 | + File.open(fname).read(max_size) | ||
|
|
59 | + rescue | ||
|
|
60 | + nil | ||
|
|
61 | + end | ||
|
|
62 | + end | ||
|
51 |
|
63 | ||
|
52 | def user_title_bar(user) |
|
64 | def user_title_bar(user) |
|
53 | - if user.site!=nil and user.site.finished? |
|
65 | + header = '' |
|
54 | - contest_over_string = <<CONTEST_OVER |
|
66 | + |
|
|
67 | + # | ||
|
|
68 | + # if the contest is over | ||
|
|
69 | + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and | ||
|
|
70 | + user.site!=nil and user.site.finished? | ||
|
|
71 | + header = <<CONTEST_OVER | ||
|
55 | <tr><td colspan="2" align="center"> |
|
72 | <tr><td colspan="2" align="center"> |
|
56 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
73 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
57 | </td></tr> |
|
74 | </td></tr> |
|
58 | CONTEST_OVER |
|
75 | CONTEST_OVER |
|
59 | end |
|
76 | end |
|
|
77 | + | ||
|
|
78 | + # | ||
|
|
79 | + # if the contest is in the anaysis mode | ||
|
|
80 | + if Configuration[SYSTEM_MODE_CONF_KEY]=='analysis' | ||
|
|
81 | + header = <<ANALYSISMODE | ||
|
|
82 | + <tr><td colspan="2" align="center"> | ||
|
|
83 | + <span class="contest-over-msg">ANALYSIS MODE</span> | ||
|
|
84 | + </td></tr> | ||
|
|
85 | + ANALYSISMODE | ||
|
|
86 | + end | ||
|
|
87 | + | ||
|
|
88 | + # | ||
|
|
89 | + # build real title bar | ||
|
60 | <<TITLEBAR |
|
90 | <<TITLEBAR |
|
61 | <div class="title"> |
|
91 | <div class="title"> |
|
62 | <table> |
|
92 | <table> |
|
63 | - #{contest_over_string} |
|
93 | + #{header} |
|
64 | <tr> |
|
94 | <tr> |
|
65 | <td class="left-col"> |
|
95 | <td class="left-col"> |
|
66 | #{user.full_name}<br/> |
|
96 | #{user.full_name}<br/> |
@@ -73,12 +103,4 | |||||
|
73 | TITLEBAR |
|
103 | TITLEBAR |
|
74 | end |
|
104 | end |
|
75 |
|
105 | ||
|
76 | - def read_textfile(fname,max_size=2048) |
|
||
|
77 | - begin |
|
||
|
78 | - File.open(fname).read(max_size) |
|
||
|
79 | - rescue |
|
||
|
80 | - nil |
|
||
|
81 |
|
|
106 | end |
|
82 | - end |
|
||
|
83 | - |
|
||
|
84 | - end |
|
@@ -1,5 +1,10 | |||||
|
|
1 | + # | ||
|
|
2 | + # This class also contains various login of the system. | ||
|
|
3 | + # | ||
|
1 | class Configuration < ActiveRecord::Base |
|
4 | class Configuration < ActiveRecord::Base |
|
2 |
|
5 | ||
|
|
6 | + SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
|
|
7 | + | ||
|
3 | @@configurations = nil |
|
8 | @@configurations = nil |
|
4 |
|
9 | ||
|
5 | def self.get(key) |
|
10 | def self.get(key) |
@@ -21,6 +26,28 | |||||
|
21 | @@configurations = nil |
|
26 | @@configurations = nil |
|
22 | end |
|
27 | end |
|
23 |
|
28 | ||
|
|
29 | + # | ||
|
|
30 | + # View decision | ||
|
|
31 | + # | ||
|
|
32 | + def self.show_submitbox_to?(user) | ||
|
|
33 | + mode = get(SYSTEM_MODE_CONF_KEY) | ||
|
|
34 | + return false if mode=='analysis' | ||
|
|
35 | + if (mode=='contest') | ||
|
|
36 | + return false if (user.site!=nil) and | ||
|
|
37 | + ((user.site.started==false) or (user.site.finished?)) | ||
|
|
38 | + end | ||
|
|
39 | + return true | ||
|
|
40 | + end | ||
|
|
41 | + | ||
|
|
42 | + def self.show_tasks_to?(user) | ||
|
|
43 | + mode = get(SYSTEM_MODE_CONF_KEY) | ||
|
|
44 | + if (mode=='contest') | ||
|
|
45 | + return false if (user.site!=nil) and (user.site.started==false) | ||
|
|
46 | + end | ||
|
|
47 | + return true | ||
|
|
48 | + end | ||
|
|
49 | + | ||
|
|
50 | + | ||
|
24 | protected |
|
51 | protected |
|
25 | def self.read_config |
|
52 | def self.read_config |
|
26 | @@configurations = {} |
|
53 | @@configurations = {} |
@@ -6,6 +6,7 | |||||
|
6 | Announcements |
|
6 | Announcements |
|
7 | = render :partial => 'announcement', :collection => @announcements |
|
7 | = render :partial => 'announcement', :collection => @announcements |
|
8 |
|
8 | ||
|
|
9 | + - if Configuration.show_submitbox_to?(@user) | ||
|
9 | .submitbox |
|
10 | .submitbox |
|
10 | = error_messages_for 'submission' |
|
11 | = error_messages_for 'submission' |
|
11 | = render :partial => 'submission_box' |
|
12 | = render :partial => 'submission_box' |
@@ -13,6 +14,7 | |||||
|
13 |
|
14 | ||
|
14 | %hr/ |
|
15 | %hr/ |
|
15 |
|
16 | ||
|
|
17 | + - if Configuration.show_tasks_to?(@user) | ||
|
16 | %table.info |
|
18 | %table.info |
|
17 | %tr.info-head |
|
19 | %tr.info-head |
|
18 | %th |
|
20 | %th |
@@ -30,6 +30,7 | |||||
|
30 | } |
|
30 | } |
|
31 | </script> |
|
31 | </script> |
|
32 |
|
32 | ||
|
|
33 | + <% if Configuration.show_submitbox_to?(@user) %> | ||
|
33 | <div class="submitbox"> |
|
34 | <div class="submitbox"> |
|
34 | <%= error_messages_for 'submitted_test_request' %> |
|
35 | <%= error_messages_for 'submitted_test_request' %> |
|
35 | <% form_for :test_request, nil, |
|
36 | <% form_for :test_request, nil, |
@@ -85,6 +86,7 | |||||
|
85 | </table> |
|
86 | </table> |
|
86 | <% end %> |
|
87 | <% end %> |
|
87 | </div> |
|
88 | </div> |
|
|
89 | + <% end %> | ||
|
88 |
|
90 | ||
|
89 | <h3>Previous requests</h3> |
|
91 | <h3>Previous requests</h3> |
|
90 |
|
92 |
@@ -9,7 +9,7 | |||||
|
9 | # |
|
9 | # |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
11 |
|
11 | ||
|
12 |
- ActiveRecord::Schema.define(:version => 3 |
|
12 | + ActiveRecord::Schema.define(:version => 36) do |
|
13 |
|
13 | ||
|
14 | create_table "announcements", :force => true do |t| |
|
14 | create_table "announcements", :force => true do |t| |
|
15 | t.string "author" |
|
15 | t.string "author" |
You need to be logged in to leave comments.
Login now