Description:
add TA roles
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r799:584294790340 - - 6 files changed: 71 inserted, 42 deleted
@@ -94,9 +94,8 | |||||
|
94 |
|
94 | ||
|
95 | def submission_authorization |
|
95 | def submission_authorization |
|
96 | #admin always has privileged |
|
96 | #admin always has privileged |
|
97 | - if @current_user.admin? |
|
97 | + return true if @current_user.admin? |
|
98 | - return true |
|
98 | + return true if @current_user.has_role?('TA') && (['show','download'].include? action_name) |
|
99 | - end |
|
||
|
100 |
|
99 | ||
|
101 | sub = Submission.find(params[:id]) |
|
100 | sub = Submission.find(params[:id]) |
|
102 | if @current_user.available_problems.include? sub.problem |
|
101 | if @current_user.available_problems.include? sub.problem |
@@ -362,36 +362,33 | |||||
|
362 | # admin management |
|
362 | # admin management |
|
363 |
|
363 | ||
|
364 | def admin |
|
364 | def admin |
|
365 | - @admins = User.all.find_all {|user| user.admin? } |
|
365 | + @admins = Role.where(name: 'admin').take.users |
|
|
366 | + @tas = Role.where(name: 'ta').take.users | ||
|
366 | end |
|
367 | end |
|
367 |
|
368 | ||
|
368 | - def grant_admin |
|
369 | + def modify_role |
|
369 |
- |
|
370 | + user = User.find_by_login(params[:login]) |
|
370 | - user = User.find_by_login(login) |
|
371 | + role = Role.find_by_name(params[:role]) |
|
371 | - if user!=nil |
|
372 | + unless user && role |
|
372 | - admin_role = Role.find_by_name('admin') |
|
373 | + flash[:error] = 'Unknown user or role' |
|
373 | - user.roles << admin_role |
|
374 | + redirect_to admin_user_admin_index_path |
|
374 | - else |
|
375 | + return |
|
375 | - flash[:notice] = 'Unknown user' |
|
||
|
376 | - end |
|
||
|
377 | - flash[:notice] = 'User added as admins' |
|
||
|
378 | - redirect_to :action => 'admin' |
|
||
|
379 | end |
|
376 | end |
|
380 | - |
|
377 | + if params[:commit] == 'Grant' |
|
381 | - def revoke_admin |
|
378 | + #grant role |
|
382 | - user = User.find(params[:id]) |
|
379 | + user.roles << role |
|
383 | - if user==nil |
|
380 | + flash[:notice] = "User '#{user.login}' has been granted the role '#{role.name}'" |
|
384 | - flash[:notice] = 'Unknown user' |
|
381 | + else |
|
385 | - redirect_to :action => 'admin' and return |
|
382 | + #revoke role |
|
386 |
- |
|
383 | + if user.login == 'root' && role.name == 'admin' |
|
387 |
- flash[: |
|
384 | + flash[:error] = 'You cannot revoke admisnistrator permission from root.' |
|
388 | - redirect_to :action => 'admin' and return |
|
385 | + redirect_to admin_user_admin_index_path |
|
|
386 | + return | ||
|
389 | end |
|
387 | end |
|
390 | - |
|
388 | + user.roles.delete(role) |
|
391 | - admin_role = Role.find_by_name('admin') |
|
389 | + flash[:notice] = "The role '#{role.name}' has been revoked from User '#{user.login}'" |
|
392 | - user.roles.delete(admin_role) |
|
390 | + end |
|
393 | - flash[:notice] = 'User permission revoked' |
|
391 | + redirect_to admin_user_admin_index_path |
|
394 | - redirect_to :action => 'admin' |
|
||
|
395 | end |
|
392 | end |
|
396 |
|
393 | ||
|
397 | # mass mailing |
|
394 | # mass mailing |
@@ -81,7 +81,11 | |||||
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | def admin? |
|
83 | def admin? |
|
84 | - self.roles.where(name: 'admin').count > 0 |
|
84 | + has_role?('admin') |
|
|
85 | + end | ||
|
|
86 | + | ||
|
|
87 | + def has_role?(role) | ||
|
|
88 | + self.roles.where(name: role).count > 0 | ||
|
85 | end |
|
89 | end |
|
86 |
|
90 | ||
|
87 | def email_for_editing |
|
91 | def email_for_editing |
@@ -1,7 +1,17 | |||||
|
1 | - %h1 Administrators |
|
1 | + %h1 Modify Role |
|
2 | - |
|
2 | + .row |
|
3 | - %table{:class => 'info'} |
|
3 | + .col-md-6 |
|
4 | - %tr{:class => 'info-head'} |
|
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'} | ||
|
5 | %th # |
|
15 | %th # |
|
6 | %th Login |
|
16 | %th Login |
|
7 | %th Full name |
|
17 | %th Full name |
@@ -13,13 +23,32 | |||||
|
13 | %td= user.full_name |
|
23 | %td= user.full_name |
|
14 | %td |
|
24 | %td |
|
15 | - if user.login!='root' |
|
25 | - if user.login!='root' |
|
16 | - = link_to '[revoke]', :action => 'revoke_admin', :id => user.id |
|
26 | + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'admin', commit: 'revoke') |
|
17 | - %hr |
|
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') | ||
|
18 |
|
51 | ||
|
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 | %hr/ |
|
53 | %hr/ |
|
25 | = link_to '[go back to index]', :action => 'index' |
|
54 | = link_to '[go back to index]', :action => 'index' |
@@ -113,8 +113,7 | |||||
|
113 | get 'admin' |
|
113 | get 'admin' |
|
114 | get 'active' |
|
114 | get 'active' |
|
115 | get 'mass_mailing' |
|
115 | get 'mass_mailing' |
|
116 | - get 'revoke_admin' |
|
116 | + match 'modify_role', via: [:get, :post] |
|
117 | - post 'grant_admin' |
|
||
|
118 | match 'create_from_list', via: [:get, :post] |
|
117 | match 'create_from_list', via: [:get, :post] |
|
119 | match 'random_all_passwords', via: [:get, :post] |
|
118 | match 'random_all_passwords', via: [:get, :post] |
|
120 | end |
|
119 | end |
You need to be logged in to leave comments.
Login now