Commit 089515d808a5c0b7183fedb204cbc1c7decbf026
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/121' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/121
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
app/models/theme.rb
| ... | ... | @@ -43,8 +43,13 @@ class Theme |
| 43 | 43 | |
| 44 | 44 | def approved_themes(owner) |
| 45 | 45 | Dir.glob(File.join(system_themes_dir, '*')).select do |item| |
| 46 | - config = YAML.load_file(File.join(item, 'theme.yml')) | |
| 47 | - (config['owner_type'] == owner.class.base_class.name) && (config['owner_id'] == owner.id) || config['public'] | |
| 46 | + if File.exists?( File.join(item, 'theme.yml') ) | |
| 47 | + config = YAML.load_file(File.join(item, 'theme.yml')) | |
| 48 | + (config['owner_type'] == owner.class.base_class.name) && | |
| 49 | + (config['owner_id'] == owner.id) || config['public'] | |
| 50 | + else | |
| 51 | + false | |
| 52 | + end | |
| 48 | 53 | end.map do |desc| |
| 49 | 54 | new(File.basename(desc)) |
| 50 | 55 | end | ... | ... |
test/unit/theme_test.rb
| ... | ... | @@ -170,6 +170,14 @@ class ThemeTest < ActiveSupport::TestCase |
| 170 | 170 | assert ! Theme.approved_themes(profile).include?(Theme.find(t3.id)) |
| 171 | 171 | end |
| 172 | 172 | |
| 173 | + should 'not list non theme files or dirs inside themes dir' do | |
| 174 | + Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) | |
| 175 | + Dir.mkdir(TMP_THEMES_DIR) | |
| 176 | + Dir.mkdir(TMP_THEMES_DIR+'/empty-dir') | |
| 177 | + File.new(TMP_THEMES_DIR+'/my-logo.png', File::CREAT) | |
| 178 | + assert Theme.approved_themes(Environment.default).empty? | |
| 179 | + end | |
| 180 | + | |
| 173 | 181 | should 'set theme to public' do |
| 174 | 182 | t = Theme.new('mytheme') |
| 175 | 183 | t.public = true | ... | ... |