Description:
add TA roles
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r799:584294790340 - - 6 files changed: 82 inserted, 53 deleted

@@ -73,40 +73,39
73 73
74 74
75 75 def get_latest_submission_status
76 76 @problem = Problem.find(params[:pid])
77 77 @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid])
78 78 respond_to do |format|
79 79 format.js
80 80 end
81 81 end
82 82
83 83 # GET /submissions/:id/rejudge
84 84 def rejudge
85 85 @submission = Submission.find(params[:id])
86 86 @task = @submission.task
87 87 @task.status_inqueue! if @task
88 88 respond_to do |format|
89 89 format.js
90 90 end
91 91 end
92 92
93 93 protected
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
103 102 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
104 103 end
105 104
106 105 #default to NO
107 106 unauthorized_redirect
108 107 return false
109 108 end
110 109
111 110
112 111 end
@@ -341,78 +341,75
341 341 user.contest_stat.reset_timer_and_save
342 342 end
343 343
344 344 if params[:notification_emails]
345 345 send_contest_update_notification_email(user, contest)
346 346 end
347 347
348 348 note << user.login
349 349 users << user
350 350 end
351 351 end
352 352
353 353 if params[:reset_timer]
354 354 logout_users(users)
355 355 end
356 356
357 357 flash[:notice] = 'User(s) ' + note.join(', ') +
358 358 ' were successfully modified. '
359 359 redirect_to :action => 'contest_management'
360 360 end
361 361
362 362 # admin management
363 363
364 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 367 end
367 368
368 - def grant_admin
369 - login = params[:login]
370 - user = User.find_by_login(login)
371 - if user!=nil
372 - admin_role = Role.find_by_name('admin')
373 - user.roles << admin_role
374 - else
375 - flash[:notice] = 'Unknown user'
369 + def modify_role
370 + user = User.find_by_login(params[:login])
371 + role = Role.find_by_name(params[:role])
372 + unless user && role
373 + flash[:error] = 'Unknown user or role'
374 + redirect_to admin_user_admin_index_path
375 + return
376 376 end
377 - flash[:notice] = 'User added as admins'
378 - redirect_to :action => 'admin'
379 - end
380 -
381 - def revoke_admin
382 - user = User.find(params[:id])
383 - if user==nil
384 - flash[:notice] = 'Unknown user'
385 - redirect_to :action => 'admin' and return
386 - elsif user.login == 'root'
387 - flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
388 - redirect_to :action => 'admin' and return
377 + if params[:commit] == 'Grant'
378 + #grant role
379 + user.roles << role
380 + flash[:notice] = "User '#{user.login}' has been granted the role '#{role.name}'"
381 + else
382 + #revoke role
383 + if user.login == 'root' && role.name == 'admin'
384 + flash[:error] = 'You cannot revoke admisnistrator permission from root.'
385 + redirect_to admin_user_admin_index_path
386 + return
387 + end
388 + user.roles.delete(role)
389 + flash[:notice] = "The role '#{role.name}' has been revoked from User '#{user.login}'"
389 390 end
390 -
391 - admin_role = Role.find_by_name('admin')
392 - user.roles.delete(admin_role)
393 - flash[:notice] = 'User permission revoked'
394 - redirect_to :action => 'admin'
391 + redirect_to admin_user_admin_index_path
395 392 end
396 393
397 394 # mass mailing
398 395
399 396 def mass_mailing
400 397 end
401 398
402 399 def bulk_mail
403 400 lines = params[:login_list]
404 401 if !lines or lines.blank?
405 402 flash[:notice] = 'You entered an empty list.'
406 403 redirect_to :action => 'mass_mailing' and return
407 404 end
408 405
409 406 mail_subject = params[:subject]
410 407 if !mail_subject or mail_subject.blank?
411 408 flash[:notice] = 'You entered an empty mail subject.'
412 409 redirect_to :action => 'mass_mailing' and return
413 410 end
414 411
415 412 mail_body = params[:email_body]
416 413 if !mail_body or mail_body.blank?
417 414 flash[:notice] = 'You entered an empty mail body.'
418 415 redirect_to :action => 'mass_mailing' and return
@@ -60,49 +60,53
60 60 before_save :encrypt_new_password
61 61 before_save :assign_default_site
62 62 before_save :assign_default_contest
63 63
64 64 # this is for will_paginate
65 65 cattr_reader :per_page
66 66 @@per_page = 50
67 67
68 68 def self.authenticate(login, password)
69 69 user = find_by_login(login)
70 70 if user
71 71 return user if user.authenticated?(password)
72 72 end
73 73 end
74 74
75 75 def authenticated?(password)
76 76 if self.activated
77 77 hashed_password == User.encrypt(password,self.salt)
78 78 else
79 79 false
80 80 end
81 81 end
82 82
83 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 89 end
86 90
87 91 def email_for_editing
88 92 if self.email==nil
89 93 "(unknown)"
90 94 elsif self.email==''
91 95 "(blank)"
92 96 else
93 97 self.email
94 98 end
95 99 end
96 100
97 101 def email_for_editing=(e)
98 102 self.email=e
99 103 end
100 104
101 105 def alias_for_editing
102 106 if self.alias==nil
103 107 "(unknown)"
104 108 elsif self.alias==''
105 109 "(blank)"
106 110 else
107 111 self.alias
108 112 end
@@ -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'
@@ -92,50 +92,49
92 92 member do
93 93 get 'download'
94 94 get 'compiler_msg'
95 95 get 'rejudge'
96 96 end
97 97 collection do
98 98 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
99 99 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
100 100 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
101 101 end
102 102 end
103 103
104 104
105 105 #user admin
106 106 resources :user_admin do
107 107 collection do
108 108 match 'bulk_manage', via: [:get, :post]
109 109 get 'bulk_mail'
110 110 get 'user_stat'
111 111 get 'import'
112 112 get 'new_list'
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
121 120 member do
122 121 get 'clear_last_ip'
123 122 end
124 123 end
125 124
126 125 resources :contest_management, only: [:index] do
127 126 collection do
128 127 get 'user_stat'
129 128 get 'clear_stat'
130 129 get 'clear_all_stat'
131 130 get 'change_contest_mode'
132 131 end
133 132 end
134 133
135 134 #get 'user_admin', to: 'user_admin#index'
136 135 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
137 136 #post 'user_admin', to: 'user_admin#create'
138 137 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
139 138
140 139 #singular resource
141 140 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
@@ -204,48 +204,49
204 204 description='')
205 205 conf = (GraderConfiguration.find_by_key(key) ||
206 206 GraderConfiguration.new(:key => key,
207 207 :value_type => value_type,
208 208 :value => default_value))
209 209 conf.description = description
210 210 conf.save
211 211 end
212 212
213 213 def seed_config
214 214 CONFIGURATIONS.each do |conf|
215 215 if conf.has_key? :description
216 216 desc = conf[:description]
217 217 else
218 218 desc = ''
219 219 end
220 220 create_configuration_key(conf[:key],
221 221 conf[:value_type],
222 222 conf[:default_value],
223 223 desc)
224 224 end
225 225 end
226 226
227 227 def seed_roles
228 + Role.find_or_create_by(name: 'TA')
228 229 return if Role.find_by_name('admin')
229 230
230 231 role = Role.create(:name => 'admin')
231 232 user_admin_right = Right.create(:name => 'user_admin',
232 233 :controller => 'user_admin',
233 234 :action => 'all')
234 235 problem_admin_right = Right.create(:name=> 'problem_admin',
235 236 :controller => 'problems',
236 237 :action => 'all')
237 238
238 239 graders_right = Right.create(:name => 'graders_admin',
239 240 :controller => 'graders',
240 241 :action => 'all')
241 242
242 243 role.rights << user_admin_right;
243 244 role.rights << problem_admin_right;
244 245 role.rights << graders_right;
245 246 role.save
246 247 end
247 248
248 249 def seed_root
249 250 return if User.find_by_login('root')
250 251
251 252 root = User.new(:login => 'root',
You need to be logged in to leave comments. Login now