Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r836:36fbb20457ec - - 8 files changed: 105 inserted, 71 deleted
@@ -94,9 +94,8 | |||
|
94 | 94 | |
|
95 | 95 | def submission_authorization |
|
96 | 96 | #admin always has privileged |
|
97 | - if @current_user.admin? | |
|
98 | - return true | |
|
99 | - end | |
|
97 | + return true if @current_user.admin? | |
|
98 | + return true if @current_user.has_role?('TA') && (['show','download'].include? action_name) | |
|
100 | 99 | |
|
101 | 100 | sub = Submission.find(params[:id]) |
|
102 | 101 | if @current_user.available_problems.include? sub.problem |
@@ -355,36 +355,33 | |||
|
355 | 355 | # admin management |
|
356 | 356 | |
|
357 | 357 | def admin |
|
358 | - @admins = User.all.find_all {|user| user.admin? } | |
|
358 | + @admins = Role.where(name: 'admin').take.users | |
|
359 | + @tas = Role.where(name: 'ta').take.users | |
|
359 | 360 | end |
|
360 | 361 | |
|
361 | - def grant_admin | |
|
362 |
- |
|
|
363 | - user = User.find_by_login(login) | |
|
364 | - if user!=nil | |
|
365 | - admin_role = Role.find_by_name('admin') | |
|
366 | - user.roles << admin_role | |
|
367 | - else | |
|
368 | - flash[:notice] = 'Unknown user' | |
|
362 | + def modify_role | |
|
363 | + user = User.find_by_login(params[:login]) | |
|
364 | + role = Role.find_by_name(params[:role]) | |
|
365 | + unless user && role | |
|
366 | + flash[:error] = 'Unknown user or role' | |
|
367 | + redirect_to admin_user_admin_index_path | |
|
368 | + return | |
|
369 | 369 | end |
|
370 | - flash[:notice] = 'User added as admins' | |
|
371 | - redirect_to :action => 'admin' | |
|
372 | - end | |
|
373 | - | |
|
374 | - def revoke_admin | |
|
375 | - user = User.find(params[:id]) | |
|
376 | - if user==nil | |
|
377 | - flash[:notice] = 'Unknown user' | |
|
378 | - redirect_to :action => 'admin' and return | |
|
379 | - elsif user.login == 'root' | |
|
380 | - flash[:notice] = 'You cannot revoke admisnistrator permission from root.' | |
|
381 | - redirect_to :action => 'admin' and return | |
|
370 | + if params[:commit] == 'Grant' | |
|
371 | + #grant role | |
|
372 | + user.roles << role | |
|
373 | + flash[:notice] = "User '#{user.login}' has been granted the role '#{role.name}'" | |
|
374 | + else | |
|
375 | + #revoke role | |
|
376 | + if user.login == 'root' && role.name == 'admin' | |
|
377 | + flash[:error] = 'You cannot revoke admisnistrator permission from root.' | |
|
378 | + redirect_to admin_user_admin_index_path | |
|
379 | + return | |
|
380 | + end | |
|
381 | + user.roles.delete(role) | |
|
382 | + flash[:notice] = "The role '#{role.name}' has been revoked from User '#{user.login}'" | |
|
382 | 383 | end |
|
383 | - | |
|
384 | - admin_role = Role.find_by_name('admin') | |
|
385 | - user.roles.delete(admin_role) | |
|
386 | - flash[:notice] = 'User permission revoked' | |
|
387 | - redirect_to :action => 'admin' | |
|
384 | + redirect_to admin_user_admin_index_path | |
|
388 | 385 | end |
|
389 | 386 | |
|
390 | 387 | # mass mailing |
@@ -124,7 +124,11 | |||
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def admin? |
|
127 | - self.roles.where(name: 'admin').count > 0 | |
|
127 | + has_role?('admin') | |
|
128 | + end | |
|
129 | + | |
|
130 | + def has_role?(role) | |
|
131 | + self.roles.where(name: role).count > 0 | |
|
128 | 132 | end |
|
129 | 133 | |
|
130 | 134 | def email_for_editing |
@@ -68,7 +68,7 | |||
|
68 | 68 | = add_menu( 'Login Report', 'report', 'login') |
|
69 | 69 | - if (ungraded = Submission.where('graded_at is null').where('submitted_at < ?', 1.minutes.ago).count) > 0 |
|
70 | 70 | =link_to "#{ungraded} backlogs!", |
|
71 | - grader_list_path, | |
|
71 | + graders_list_path, | |
|
72 | 72 | class: 'navbar-btn btn btn-default btn-warning', data: {toggle: 'tooltip'},title: 'Number of ungraded submission' |
|
73 | 73 | |
|
74 | 74 | %ul.nav.navbar-nav.navbar-right |
@@ -6,19 +6,23 | |||
|
6 | 6 | %h1 Problem stat: #{@problem.name} |
|
7 | 7 | %h2 Overview |
|
8 | 8 | |
|
9 | + .row | |
|
10 | + .col-md-2 | |
|
11 | + %strong Name: | |
|
12 | + .col-md-10 | |
|
13 | + = @problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 | |
|
14 | + = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, @problem | |
|
15 | + .row | |
|
16 | + .col-md-2.strong | |
|
17 | + %strong Submissions: | |
|
18 | + .col-md-10 | |
|
19 | + = @submissions.count | |
|
20 | + .row | |
|
21 | + .col-md-2.strong | |
|
22 | + %strong Solved/Attemped User | |
|
23 | + .col-md-10 | |
|
24 | + #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | |
|
9 | 25 | |
|
10 | - %table.info | |
|
11 | - %thead | |
|
12 | - %tr.info-head | |
|
13 | - %th Stat | |
|
14 | - %th Value | |
|
15 | - %tbody | |
|
16 | - %tr{class: cycle('info-even','info-odd')} | |
|
17 | - %td Submissions | |
|
18 | - %td= @submissions.count | |
|
19 | - %tr{class: cycle('info-even','info-odd')} | |
|
20 | - %td Solved/Attempted User | |
|
21 | - %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | |
|
22 | 26 | |
|
23 | 27 | %h2 Submissions Count |
|
24 | 28 | = render partial: 'application/bar_graph', locals: { histogram: @histogram } |
@@ -1,25 +1,54 | |||
|
1 | - %h1 Administrators | |
|
1 | + %h1 Modify Role | |
|
2 | + .row | |
|
3 | + .col-md-6 | |
|
4 | + %h4 Administrators | |
|
5 | + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do | |
|
6 | + = hidden_field_tag :role, 'admin' | |
|
7 | + .form-group | |
|
8 | + = label_tag :login, 'Grant admin role to:' | |
|
9 | + = text_field_tag 'login',nil, class: 'form-control' | |
|
10 | + .form-group | |
|
11 | + = submit_tag 'Grant', class: 'btn btn-primary' | |
|
12 | + %br | |
|
13 | + %table.table.table-condense.table-hover.table-striped.table-bordered | |
|
14 | + %thead{:class => 'info-head'} | |
|
15 | + %th # | |
|
16 | + %th Login | |
|
17 | + %th Full name | |
|
18 | + %th | |
|
19 | + - @admins.each_with_index do |user, i| | |
|
20 | + %tr | |
|
21 | + %td= i+1 | |
|
22 | + %td= user.login | |
|
23 | + %td= user.full_name | |
|
24 | + %td | |
|
25 | + - if user.login!='root' | |
|
26 | + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'admin', commit: 'revoke') | |
|
27 | + .col-md-6 | |
|
28 | + %h4 Teacher Assistants (TA) | |
|
29 | + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do | |
|
30 | + = hidden_field_tag :role, 'TA' | |
|
31 | + .form-group | |
|
32 | + = label_tag :login, 'Grant TA role to:' | |
|
33 | + = text_field_tag 'login',nil, class: 'form-control' | |
|
34 | + .form-group | |
|
35 | + = submit_tag 'Grant', class: 'btn btn-primary' | |
|
36 | + %br | |
|
37 | + %table.table.table-condense.table-hover.table-striped.table-bordered | |
|
38 | + %thead{:class => 'info-head'} | |
|
39 | + %th # | |
|
40 | + %th Login | |
|
41 | + %th Full name | |
|
42 | + %th | |
|
43 | + - @tas.each_with_index do |user, i| | |
|
44 | + %tr | |
|
45 | + %td= i+1 | |
|
46 | + %td= user.login | |
|
47 | + %td= user.full_name | |
|
48 | + %td | |
|
49 | + - if user.login!='root' | |
|
50 | + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'TA', commit: 'revoke') | |
|
2 | 51 | |
|
3 | - %table{:class => 'info'} | |
|
4 | - %tr{:class => 'info-head'} | |
|
5 | - %th # | |
|
6 | - %th Login | |
|
7 | - %th Full name | |
|
8 | - %th | |
|
9 | - - @admins.each_with_index do |user, i| | |
|
10 | - %tr | |
|
11 | - %td= i+1 | |
|
12 | - %td= user.login | |
|
13 | - %td= user.full_name | |
|
14 | - %td | |
|
15 | - - if user.login!='root' | |
|
16 | - = link_to '[revoke]', :action => 'revoke_admin', :id => user.id | |
|
17 | - %hr | |
|
18 | - | |
|
19 | - = form_tag :action => 'grant_admin' do | |
|
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 | 52 | |
|
24 | 53 | %hr/ |
|
25 | 54 | = link_to '[go back to index]', :action => 'index' |
@@ -113,8 +113,7 | |||
|
113 | 113 | get 'admin' |
|
114 | 114 | get 'active' |
|
115 | 115 | get 'mass_mailing' |
|
116 | - get 'revoke_admin' | |
|
117 | - post 'grant_admin' | |
|
116 | + match 'modify_role', via: [:get, :post] | |
|
118 | 117 | match 'create_from_list', via: [:get, :post] |
|
119 | 118 | match 'random_all_passwords', via: [:get, :post] |
|
120 | 119 | end |
@@ -188,18 +187,19 | |||
|
188 | 187 | get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
189 | 188 | |
|
190 | 189 | #grader |
|
191 | - get 'graders/list', to: 'graders#list', as: 'grader_list' | |
|
190 | + #get 'graders/list', to: 'graders#list', as: 'grader_list' | |
|
192 | 191 | namespace :graders do |
|
193 | 192 | get 'task/:id/:type', action: 'task', as: 'task' |
|
194 | 193 | get 'view/:id/:type', action: 'view', as: 'view' |
|
195 | 194 | get 'clear/:id', action: 'clear', as: 'clear' |
|
196 | - get 'stop' | |
|
197 | - get 'stop_all' | |
|
198 | - get 'clear_all' | |
|
199 | - get 'clear_terminated' | |
|
200 | 195 | get 'start_grading' |
|
201 | 196 | get 'start_exam' |
|
197 | + get 'clear_all' | |
|
198 | + get 'stop_all' | |
|
202 | 199 | |
|
200 | + get 'stop' | |
|
201 | + get 'clear_terminated' | |
|
202 | + get 'list' | |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 |
You need to be logged in to leave comments.
Login now