|
297 | 297 | @user1.submissions.map(&:id).should be_include(s3.id) |
298 | 298 | end |
299 | 299 | end |
| 300 | + |
| 301 | + context "permissions" do |
| 302 | + it "should grant become_user to self" do |
| 303 | + @user = user_with_pseudonym(:username => 'nobody1@example.com') |
| 304 | + @user.grants_right?(@user, nil, :become_user).should be_true |
| 305 | + end |
| 306 | + |
| 307 | + it "should not grant become_user to other users" do |
| 308 | + @user1 = user_with_pseudonym(:username => 'nobody1@example.com') |
| 309 | + @user2 = user_with_pseudonym(:username => 'nobody2@example.com') |
| 310 | + @user1.grants_right?(@user2, nil, :become_user).should be_false |
| 311 | + @user2.grants_right?(@user1, nil, :become_user).should be_false |
| 312 | + end |
| 313 | + |
| 314 | + it "should grant become_user to site and account admins" do |
| 315 | + user = user_with_pseudonym(:username => 'nobody1@example.com') |
| 316 | + @admin = user_with_pseudonym(:username => 'nobody2@example.com') |
| 317 | + @site_admin = user_with_pseudonym(:username => 'nobody3@example.com') |
| 318 | + Account.site_admin.add_user(@site_admin) |
| 319 | + Account.default.add_user(@admin) |
| 320 | + user.grants_right?(@site_admin, nil, :become_user).should be_true |
| 321 | + @admin.grants_right?(@site_admin, nil, :become_user).should be_true |
| 322 | + user.grants_right?(@admin, nil, :become_user).should be_true |
| 323 | + @admin.grants_right?(@admin, nil, :become_user).should be_true |
| 324 | + @admin.grants_right?(user, nil, :become_user).should be_false |
| 325 | + @site_admin.grants_right?(@site_admin, nil, :become_user).should be_true |
| 326 | + @site_admin.grants_right?(user, nil, :become_user).should be_false |
| 327 | + @site_admin.grants_right?(@admin, nil, :become_user).should be_false |
| 328 | + end |
| 329 | + |
| 330 | + it "should not grant become_user to other site admins" do |
| 331 | + @site_admin1 = user_with_pseudonym(:username => 'nobody1@example.com') |
| 332 | + @site_admin2 = user_with_pseudonym(:username => 'nobody2@example.com') |
| 333 | + Account.site_admin.add_user(@site_admin1) |
| 334 | + Account.site_admin.add_user(@site_admin2) |
| 335 | + @site_admin1.grants_right?(@site_admin2, nil, :become_user).should be_false |
| 336 | + @site_admin2.grants_right?(@site_admin1, nil, :become_user).should be_false |
| 337 | + end |
| 338 | + |
| 339 | + it "should not grant become_user to other account admins" do |
| 340 | + @admin1 = user_with_pseudonym(:username => 'nobody1@example.com') |
| 341 | + @admin2 = user_with_pseudonym(:username => 'nobody2@example.com') |
| 342 | + Account.default.add_user(@admin1) |
| 343 | + Account.default.add_user(@admin2) |
| 344 | + @admin1.grants_right?(@admin2, nil, :become_user).should be_false |
| 345 | + @admin2.grants_right?(@admin1, nil, :become_user).should be_false |
| 346 | + end |
| 347 | + |
| 348 | + it "should grant become_user for users in multiple accounts to site admins but not account admins" do |
| 349 | + user = user_with_pseudonym(:username => 'nobody1@example.com') |
| 350 | + @account2 = Account.create! |
| 351 | + user.pseudonyms.create!(:unique_id => 'nobodyelse@example.com', :account => @account2) |
| 352 | + @admin = user_with_pseudonym(:username => 'nobody2@example.com') |
| 353 | + @site_admin = user_with_pseudonym(:username => 'nobody3@example.com') |
| 354 | + Account.default.add_user(@admin) |
| 355 | + Account.site_admin.add_user(@site_admin) |
| 356 | + user.grants_right?(@admin, nil, :become_user).should be_false |
| 357 | + user.grants_right?(@site_admin, nil, :become_user).should be_true |
| 358 | + @account2.add_user(@admin) |
| 359 | + user.grants_right?(@admin, nil, :become_user).should be_true |
| 360 | + end |
| 361 | + |
| 362 | + it "should not grant become_user for dis-associated users" do |
| 363 | + @user1 = user_model |
| 364 | + @user2 = user_model |
| 365 | + @user1.grants_right?(@user2, nil, :become_user).should be_false |
| 366 | + @user2.grants_right?(@user1, nil, :become_user).should be_false |
| 367 | + end |
| 368 | + |
| 369 | + it "should grant become_user for dis-associated users to site admins" do |
| 370 | + user = user_model |
| 371 | + @site_admin = user_model |
| 372 | + Account.site_admin.add_user(@site_admin) |
| 373 | + user.grants_right?(@site_admin, nil, :become_user).should be_true |
| 374 | + @site_admin.grants_right?(user, nil, :become_user).should be_false |
| 375 | + end |
| 376 | + end |
300 | 377 | end |
0 commit comments