Description:
allow ta to view problem stat
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r803:30dd5b343f6b - - 2 files changed: 5 inserted, 3 deleted
@@ -25,26 +25,25 | |||
|
25 | 25 | def admin_authorization |
|
26 | 26 | return false unless check_valid_login |
|
27 | 27 | user = User.includes(:roles).find(session[:user_id]) |
|
28 | 28 | unless user.admin? |
|
29 | 29 | unauthorized_redirect |
|
30 | 30 | return false |
|
31 | 31 | end |
|
32 | 32 | return true |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def authorization_by_roles(allowed_roles) |
|
36 | 36 | return false unless check_valid_login |
|
37 | - user = User.find(session[:user_id]) | |
|
38 | - unless user.roles.detect { |role| allowed_roles.member?(role.name) } | |
|
37 | + unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } | |
|
39 | 38 | unauthorized_redirect |
|
40 | 39 | return false |
|
41 | 40 | end |
|
42 | 41 | end |
|
43 | 42 | |
|
44 | 43 | def testcase_authorization |
|
45 | 44 | #admin always has privileged |
|
46 | 45 | if @current_user.admin? |
|
47 | 46 | return true |
|
48 | 47 | end |
|
49 | 48 | |
|
50 | 49 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
@@ -1,15 +1,18 | |||
|
1 | 1 | class ProblemsController < ApplicationController |
|
2 | 2 | |
|
3 | - before_action :admin_authorization | |
|
3 | + before_action :admin_authorization, except: [:stat] | |
|
4 | + before_action only: [:stat] do | |
|
5 | + authorization_by_roles(['admin','ta']) | |
|
6 | + end | |
|
4 | 7 | |
|
5 | 8 | in_place_edit_for :problem, :name |
|
6 | 9 | in_place_edit_for :problem, :full_name |
|
7 | 10 | in_place_edit_for :problem, :full_score |
|
8 | 11 | |
|
9 | 12 | def index |
|
10 | 13 | @problems = Problem.order(date_added: :desc) |
|
11 | 14 | end |
|
12 | 15 | |
|
13 | 16 | |
|
14 | 17 | def show |
|
15 | 18 | @problem = Problem.find(params[:id]) |
You need to be logged in to leave comments.
Login now