Commit 40cccd7802ca14873a9a78d7593a04241bca450a

Authored by Joenio Costa
Committed by Daniela Feitosa
1 parent 77019ebd

Allow environment admin add RawHTMLBlock to profiles

app/controllers/my_profile/profile_design_controller.rb
... ... @@ -37,6 +37,10 @@ class ProfileDesignController < BoxOrganizerController
37 37 blocks << BlogArchivesBlock
38 38 end
39 39  
  40 + if user.is_admin?(profile.environment)
  41 + blocks << RawHTMLBlock
  42 + end
  43 +
40 44 blocks
41 45 end
42 46  
... ...
test/functional/profile_design_controller_test.rb
... ... @@ -342,10 +342,12 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
342 342 profile.stubs(:person?).returns(true)
343 343 profile.stubs(:enterprise?).returns(false)
344 344 profile.stubs(:has_blog?).returns(false)
  345 + profile.stubs(:is_admin?).with(anything).returns(false)
345 346 environment = mock
346 347 profile.stubs(:environment).returns(environment)
347 348 environment.stubs(:enabled?).returns(false)
348 349 @controller.stubs(:profile).returns(profile)
  350 + @controller.stubs(:user).returns(profile)
349 351 assert_equal PERSON_BLOCKS, @controller.available_blocks
350 352 end
351 353  
... ... @@ -355,10 +357,12 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
355 357 profile.stubs(:person?).returns(true)
356 358 profile.stubs(:enterprise?).returns(false)
357 359 profile.stubs(:has_blog?).returns(false)
  360 + profile.stubs(:is_admin?).with(anything).returns(false)
358 361 environment = mock
359 362 profile.stubs(:environment).returns(environment)
360 363 environment.stubs(:enabled?).returns(false)
361 364 @controller.stubs(:profile).returns(profile)
  365 + @controller.stubs(:user).returns(profile)
362 366 assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS
363 367 end
364 368  
... ... @@ -368,10 +372,12 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
368 372 profile.stubs(:person?).returns(true)
369 373 profile.stubs(:enterprise?).returns(false)
370 374 profile.stubs(:has_blog?).returns(true)
  375 + profile.stubs(:is_admin?).with(anything).returns(false)
371 376 environment = mock
372 377 profile.stubs(:environment).returns(environment)
373 378 environment.stubs(:enabled?).returns(false)
374 379 @controller.stubs(:profile).returns(profile)
  380 + @controller.stubs(:user).returns(profile)
375 381 assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG
376 382 end
377 383  
... ... @@ -381,10 +387,12 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
381 387 profile.stubs(:person?).returns(false)
382 388 profile.stubs(:enterprise?).returns(true)
383 389 profile.stubs(:has_blog?).returns(false)
  390 + profile.stubs(:is_admin?).with(anything).returns(false)
384 391 environment = mock
385 392 profile.stubs(:environment).returns(environment)
386 393 environment.stubs(:enabled?).returns(true)
387 394 @controller.stubs(:profile).returns(profile)
  395 + @controller.stubs(:user).returns(profile)
388 396 assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS
389 397 end
390 398  
... ... @@ -394,11 +402,27 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
394 402 profile.stubs(:person?).returns(false)
395 403 profile.stubs(:enterprise?).returns(true)
396 404 profile.stubs(:has_blog?).returns(false)
  405 + profile.stubs(:is_admin?).with(anything).returns(false)
397 406 environment = mock
398 407 profile.stubs(:environment).returns(environment)
399 408 environment.stubs(:enabled?).returns(false)
400 409 @controller.stubs(:profile).returns(profile)
  410 + @controller.stubs(:user).returns(profile)
401 411 assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE
402 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 428 end
... ...