Commit 40cccd7802ca14873a9a78d7593a04241bca450a
Committed by
Daniela Feitosa
1 parent
77019ebd
Exists in
master
and in
23 other branches
Allow environment admin add RawHTMLBlock to profiles
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
| @@ -37,6 +37,10 @@ class ProfileDesignController < BoxOrganizerController | @@ -37,6 +37,10 @@ class ProfileDesignController < BoxOrganizerController | ||
| 37 | blocks << BlogArchivesBlock | 37 | blocks << BlogArchivesBlock |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | + if user.is_admin?(profile.environment) | ||
| 41 | + blocks << RawHTMLBlock | ||
| 42 | + end | ||
| 43 | + | ||
| 40 | blocks | 44 | blocks |
| 41 | end | 45 | end |
| 42 | 46 |
test/functional/profile_design_controller_test.rb
| @@ -342,10 +342,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -342,10 +342,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 342 | profile.stubs(:person?).returns(true) | 342 | profile.stubs(:person?).returns(true) |
| 343 | profile.stubs(:enterprise?).returns(false) | 343 | profile.stubs(:enterprise?).returns(false) |
| 344 | profile.stubs(:has_blog?).returns(false) | 344 | profile.stubs(:has_blog?).returns(false) |
| 345 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 345 | environment = mock | 346 | environment = mock |
| 346 | profile.stubs(:environment).returns(environment) | 347 | profile.stubs(:environment).returns(environment) |
| 347 | environment.stubs(:enabled?).returns(false) | 348 | environment.stubs(:enabled?).returns(false) |
| 348 | @controller.stubs(:profile).returns(profile) | 349 | @controller.stubs(:profile).returns(profile) |
| 350 | + @controller.stubs(:user).returns(profile) | ||
| 349 | assert_equal PERSON_BLOCKS, @controller.available_blocks | 351 | assert_equal PERSON_BLOCKS, @controller.available_blocks |
| 350 | end | 352 | end |
| 351 | 353 | ||
| @@ -355,10 +357,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -355,10 +357,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 355 | profile.stubs(:person?).returns(true) | 357 | profile.stubs(:person?).returns(true) |
| 356 | profile.stubs(:enterprise?).returns(false) | 358 | profile.stubs(:enterprise?).returns(false) |
| 357 | profile.stubs(:has_blog?).returns(false) | 359 | profile.stubs(:has_blog?).returns(false) |
| 360 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 358 | environment = mock | 361 | environment = mock |
| 359 | profile.stubs(:environment).returns(environment) | 362 | profile.stubs(:environment).returns(environment) |
| 360 | environment.stubs(:enabled?).returns(false) | 363 | environment.stubs(:enabled?).returns(false) |
| 361 | @controller.stubs(:profile).returns(profile) | 364 | @controller.stubs(:profile).returns(profile) |
| 365 | + @controller.stubs(:user).returns(profile) | ||
| 362 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS | 366 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS |
| 363 | end | 367 | end |
| 364 | 368 | ||
| @@ -368,10 +372,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -368,10 +372,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 368 | profile.stubs(:person?).returns(true) | 372 | profile.stubs(:person?).returns(true) |
| 369 | profile.stubs(:enterprise?).returns(false) | 373 | profile.stubs(:enterprise?).returns(false) |
| 370 | profile.stubs(:has_blog?).returns(true) | 374 | profile.stubs(:has_blog?).returns(true) |
| 375 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 371 | environment = mock | 376 | environment = mock |
| 372 | profile.stubs(:environment).returns(environment) | 377 | profile.stubs(:environment).returns(environment) |
| 373 | environment.stubs(:enabled?).returns(false) | 378 | environment.stubs(:enabled?).returns(false) |
| 374 | @controller.stubs(:profile).returns(profile) | 379 | @controller.stubs(:profile).returns(profile) |
| 380 | + @controller.stubs(:user).returns(profile) | ||
| 375 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG | 381 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG |
| 376 | end | 382 | end |
| 377 | 383 | ||
| @@ -381,10 +387,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -381,10 +387,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 381 | profile.stubs(:person?).returns(false) | 387 | profile.stubs(:person?).returns(false) |
| 382 | profile.stubs(:enterprise?).returns(true) | 388 | profile.stubs(:enterprise?).returns(true) |
| 383 | profile.stubs(:has_blog?).returns(false) | 389 | profile.stubs(:has_blog?).returns(false) |
| 390 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 384 | environment = mock | 391 | environment = mock |
| 385 | profile.stubs(:environment).returns(environment) | 392 | profile.stubs(:environment).returns(environment) |
| 386 | environment.stubs(:enabled?).returns(true) | 393 | environment.stubs(:enabled?).returns(true) |
| 387 | @controller.stubs(:profile).returns(profile) | 394 | @controller.stubs(:profile).returns(profile) |
| 395 | + @controller.stubs(:user).returns(profile) | ||
| 388 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS | 396 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS |
| 389 | end | 397 | end |
| 390 | 398 | ||
| @@ -394,11 +402,27 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -394,11 +402,27 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 394 | profile.stubs(:person?).returns(false) | 402 | profile.stubs(:person?).returns(false) |
| 395 | profile.stubs(:enterprise?).returns(true) | 403 | profile.stubs(:enterprise?).returns(true) |
| 396 | profile.stubs(:has_blog?).returns(false) | 404 | profile.stubs(:has_blog?).returns(false) |
| 405 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 397 | environment = mock | 406 | environment = mock |
| 398 | profile.stubs(:environment).returns(environment) | 407 | profile.stubs(:environment).returns(environment) |
| 399 | environment.stubs(:enabled?).returns(false) | 408 | environment.stubs(:enabled?).returns(false) |
| 400 | @controller.stubs(:profile).returns(profile) | 409 | @controller.stubs(:profile).returns(profile) |
| 410 | + @controller.stubs(:user).returns(profile) | ||
| 401 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE | 411 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE |
| 402 | end | 412 | end |
| 403 | 413 | ||
| 414 | + should 'allow admins to add RawHTMLBlock' do | ||
| 415 | + profile.stubs(:is_admin?).with(anything).returns(true) | ||
| 416 | + @controller.stubs(:user).returns(profile) | ||
| 417 | + get :add_block, :profile => 'designtestuser' | ||
| 418 | + assert_tag :tag => 'input', :attributes => { :id => 'type_rawhtmlblock', :value => 'RawHTMLBlock' } | ||
| 419 | + end | ||
| 420 | + | ||
| 421 | + should 'not allow normal users to add RawHTMLBlock' do | ||
| 422 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
| 423 | + @controller.stubs(:user).returns(profile) | ||
| 424 | + get :add_block, :profile => 'designtestuser' | ||
| 425 | + assert_no_tag :tag => 'input', :attributes => { :id => 'type_rawhtmlblock', :value => 'RawHTMLBlock' } | ||
| 426 | + end | ||
| 427 | + | ||
| 404 | end | 428 | end |