Commit b5f420caefaed8b13d7fba7893a66919836220f8

Authored by Rodrigo Souto
1 parent 5c02a6e4

theme: allow multi-level inheritance on approved_themes owner_type

Showing 2 changed files with 22 additions and 2 deletions   Show diff stats
app/models/theme.rb
... ... @@ -49,7 +49,10 @@ class Theme
49 49  
50 50 approved = config['public']
51 51 unless approved
52   - approved = config['owner_type'] == owner.class.base_class.name || config['owner_type'] == owner.class.name
  52 + begin
  53 + approved = owner.kind_of?(config['owner_type'].constantize)
  54 + rescue
  55 + end
53 56 approved &&= config['owner_id'] == owner.id if config['owner_id'].present?
54 57 end
55 58  
... ... @@ -58,7 +61,6 @@ class Theme
58 61 new id, config
59 62 end
60 63 end
61   -
62 64 end
63 65  
64 66 class DuplicatedIdentifier < Exception; end
... ...
test/unit/theme_test.rb
... ... @@ -191,4 +191,22 @@ class ThemeTest &lt; ActiveSupport::TestCase
191 191 assert ! Theme.new('test').public
192 192 end
193 193  
  194 + should 'not crash with nil or invalid owner_type' do
  195 + profile = fast_create(Profile)
  196 + Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR)
  197 +
  198 + t1 = Theme.new('t1').save
  199 + t1.send(:write_config)
  200 + t2 = Theme.new('t2', {:owner_type => nil}).save
  201 + t2.send(:write_config)
  202 + t3 = Theme.new('t3', {:owner_type => 'InvalidClass'}).save
  203 + t3.send(:write_config)
  204 +
  205 + assert_nothing_raised do
  206 + themes = Theme.approved_themes(profile)
  207 + assert_not_includes themes, t1
  208 + assert_not_includes themes, t2
  209 + assert_not_includes themes, t3
  210 + end
  211 + end
194 212 end
... ...