Commit 5f5d537055ba930fc37fbfd065083d76a0fc1faa
1 parent
b2efc64b
Exists in
master
and in
29 other branches
ActionItem789: Adding method to make user_themes public/not public
* Adding method public_themes to find user_themes that can be used for others * Adding attribute accessors for public * On creation of a new theme, making it not public by default
Showing
4 changed files
with
49 additions
and
2 deletions
Show diff stats
app/controllers/my_profile/themes_controller.rb
@@ -9,7 +9,7 @@ class ThemesController < MyProfileController | @@ -9,7 +9,7 @@ class ThemesController < MyProfileController | ||
9 | end | 9 | end |
10 | 10 | ||
11 | def index | 11 | def index |
12 | - @themes = Theme.system_themes | 12 | + @themes = Theme.system_themes + Theme.public_themes |
13 | @current_theme = profile.theme | 13 | @current_theme = profile.theme |
14 | 14 | ||
15 | @layout_templates = LayoutTemplate.all | 15 | @layout_templates = LayoutTemplate.all |
@@ -19,7 +19,7 @@ class ThemesController < MyProfileController | @@ -19,7 +19,7 @@ class ThemesController < MyProfileController | ||
19 | def new | 19 | def new |
20 | if !request.xhr? | 20 | if !request.xhr? |
21 | id = params[:name].to_slug | 21 | id = params[:name].to_slug |
22 | - t = Theme.new(id, :name => params[:name], :owner => profile) | 22 | + t = Theme.new(id, :name => params[:name], :owner => profile, :public => false) |
23 | t.save | 23 | t.save |
24 | redirect_to :action => 'index' | 24 | redirect_to :action => 'index' |
25 | else | 25 | else |
app/models/theme.rb
@@ -37,6 +37,15 @@ class Theme | @@ -37,6 +37,15 @@ class Theme | ||
37 | end | 37 | end |
38 | end | 38 | end |
39 | 39 | ||
40 | + def public_themes | ||
41 | + Dir.glob(File.join(user_themes_dir, '*', 'theme.yml')).select do |desc| | ||
42 | + config = YAML.load_file(desc) | ||
43 | + config['public'] | ||
44 | + end.map do |desc| | ||
45 | + Theme.find(File.basename(File.dirname(desc))) | ||
46 | + end | ||
47 | + end | ||
48 | + | ||
40 | end | 49 | end |
41 | 50 | ||
42 | class DuplicatedIdentifier < Exception; end | 51 | class DuplicatedIdentifier < Exception; end |
@@ -60,6 +69,14 @@ class Theme | @@ -60,6 +69,14 @@ class Theme | ||
60 | config['name'] = value | 69 | config['name'] = value |
61 | end | 70 | end |
62 | 71 | ||
72 | + def public | ||
73 | + config['public'] || false | ||
74 | + end | ||
75 | + | ||
76 | + def public=(value) | ||
77 | + config['public'] = value | ||
78 | + end | ||
79 | + | ||
63 | def ==(other) | 80 | def ==(other) |
64 | other.is_a?(self.class) && (other.id == self.id) | 81 | other.is_a?(self.class) && (other.id == self.id) |
65 | end | 82 | end |
test/functional/themes_controller_test.rb
@@ -33,6 +33,15 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -33,6 +33,15 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
33 | end | 33 | end |
34 | end | 34 | end |
35 | 35 | ||
36 | + should 'not display themes for selection if it is not public' do | ||
37 | + Theme.create('first', :owner => profile, :public => true) | ||
38 | + Theme.create('second', :owner => profile, :public => false) | ||
39 | + get :index, :profile => 'testinguser' | ||
40 | + | ||
41 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/first" } | ||
42 | + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/second" } | ||
43 | + end | ||
44 | + | ||
36 | should 'highlight current theme' do | 45 | should 'highlight current theme' do |
37 | profile.update_attributes(:theme => 'first') | 46 | profile.update_attributes(:theme => 'first') |
38 | Theme.expects(:system_themes).returns([Theme.new('first'), Theme.new('second')]) | 47 | Theme.expects(:system_themes).returns([Theme.new('first'), Theme.new('second')]) |
test/unit/theme_test.rb
@@ -149,5 +149,26 @@ class ThemeTest < ActiveSupport::TestCase | @@ -149,5 +149,26 @@ class ThemeTest < ActiveSupport::TestCase | ||
149 | assert_equivalent [ 'one.png', 'two.png' ], theme.image_files | 149 | assert_equivalent [ 'one.png', 'two.png' ], theme.image_files |
150 | end | 150 | end |
151 | 151 | ||
152 | + should 'be able to find public themes' do | ||
153 | + profile = create_user('testinguser').person | ||
154 | + t1 = Theme.create('mytheme', :owner => profile, :public => false) | ||
155 | + t2 = Theme.create('mytheme2', :owner => profile, :public => true) | ||
156 | + | ||
157 | + assert_equal [t2], Theme.public_themes | ||
158 | + end | ||
159 | + | ||
160 | + should 'set theme to public' do | ||
161 | + t = Theme.new('mytheme') | ||
162 | + t.public = true | ||
163 | + t.save | ||
164 | + | ||
165 | + t = Theme.find('mytheme') | ||
166 | + assert t.public | ||
167 | + end | ||
168 | + | ||
169 | + should 'not be public by default' do | ||
170 | + assert ! Theme.new('test').public | ||
171 | + end | ||
172 | + | ||
152 | end | 173 | end |
153 | 174 |