diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb index 9cfeeb0..4f63eea 100644 --- a/app/controllers/my_profile/themes_controller.rb +++ b/app/controllers/my_profile/themes_controller.rb @@ -9,7 +9,7 @@ class ThemesController < MyProfileController end def index - @themes = Theme.system_themes + @themes = Theme.system_themes + Theme.public_themes @current_theme = profile.theme @layout_templates = LayoutTemplate.all @@ -19,7 +19,7 @@ class ThemesController < MyProfileController def new if !request.xhr? id = params[:name].to_slug - t = Theme.new(id, :name => params[:name], :owner => profile) + t = Theme.new(id, :name => params[:name], :owner => profile, :public => false) t.save redirect_to :action => 'index' else diff --git a/app/models/theme.rb b/app/models/theme.rb index 34bbb2c..f22b8eb 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -37,6 +37,15 @@ class Theme end end + def public_themes + Dir.glob(File.join(user_themes_dir, '*', 'theme.yml')).select do |desc| + config = YAML.load_file(desc) + config['public'] + end.map do |desc| + Theme.find(File.basename(File.dirname(desc))) + end + end + end class DuplicatedIdentifier < Exception; end @@ -60,6 +69,14 @@ class Theme config['name'] = value end + def public + config['public'] || false + end + + def public=(value) + config['public'] = value + end + def ==(other) other.is_a?(self.class) && (other.id == self.id) end diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb index 20d7496..4589f47 100644 --- a/test/functional/themes_controller_test.rb +++ b/test/functional/themes_controller_test.rb @@ -33,6 +33,15 @@ class ThemesControllerTest < Test::Unit::TestCase end end + should 'not display themes for selection if it is not public' do + Theme.create('first', :owner => profile, :public => true) + Theme.create('second', :owner => profile, :public => false) + get :index, :profile => 'testinguser' + + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/first" } + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/second" } + end + should 'highlight current theme' do profile.update_attributes(:theme => 'first') Theme.expects(:system_themes).returns([Theme.new('first'), Theme.new('second')]) diff --git a/test/unit/theme_test.rb b/test/unit/theme_test.rb index 2a77671..8a11a9b 100644 --- a/test/unit/theme_test.rb +++ b/test/unit/theme_test.rb @@ -149,5 +149,26 @@ class ThemeTest < ActiveSupport::TestCase assert_equivalent [ 'one.png', 'two.png' ], theme.image_files end + should 'be able to find public themes' do + profile = create_user('testinguser').person + t1 = Theme.create('mytheme', :owner => profile, :public => false) + t2 = Theme.create('mytheme2', :owner => profile, :public => true) + + assert_equal [t2], Theme.public_themes + end + + should 'set theme to public' do + t = Theme.new('mytheme') + t.public = true + t.save + + t = Theme.find('mytheme') + assert t.public + end + + should 'not be public by default' do + assert ! Theme.new('test').public + end + end -- libgit2 0.21.2