Skip to content

Commit

Permalink
Added forced skin setting for sites (overwrites all but ACL skin sett…
Browse files Browse the repository at this point in the history
…ings).
  • Loading branch information
gaspard committed Nov 5, 2013
1 parent b65031d commit 727e50b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -7,6 +7,7 @@
* Added login retry wait delay on failures.
* Added support for 'in home' or 'from home' in sqliss.
* Added support for any scope with 'in sub_nodes' (uses fullpath field).
* Added forced skin setting for sites (overwrites all but ACL skin settings). <== TODO: Document

* Minor changes
* Fixed gemspec to not include TextMate helper and selenium plugin.
Expand Down
33 changes: 31 additions & 2 deletions app/models/site.rb
Expand Up @@ -62,7 +62,7 @@ class Site < ActiveRecord::Base

validate :valid_site
validates_uniqueness_of :host
attr_accessible :name, :languages, :default_lang, :authentication, :http_auth, :ssl_on_auth, :auto_publish, :redit_time, :api_group_id, :home_zip
attr_accessible :name, :languages, :default_lang, :authentication, :http_auth, :ssl_on_auth, :auto_publish, :redit_time, :api_group_id, :home_zip, :skin_zip
has_many :groups, :order => "name"
has_many :nodes
has_many :users
Expand Down Expand Up @@ -405,6 +405,30 @@ def home_zip=(zip)
@home_zip_error = _('could not be found')
end
end

def skin_zip
skin ? skin.zip : nil
end

def skin_zip=(zip)
if zip.blank?
self[:skin_id] = nil
else
if id = secure(Node) { Node.translate_pseudo_id(zip) }
self[:skin_id] = id
else
@skin_zip_error = _('could not be found')
end
end
end

def skin
secure(Skin) { Skin.find_by_id(skin_id) }
end

def skin_id
@alias && @alias[:skin_id] || self[:skin_id]
end

def create_alias(hostname)
raise "Hostname '#{hostname}' already exists" if Site.find_by_host(hostname)
Expand Down Expand Up @@ -604,9 +628,14 @@ def valid_site
end

if @home_zip_error
errors.add('root_id', @home_zip_error)
errors.add('root_zip', @home_zip_error)
@home_zip_error = nil
end

if @skin_zip_error
errors.add('skin_zip', @skin_zip_error)
@skin_zip_error = nil
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -339,7 +339,7 @@ def get_skin(node)
nil
when ANY_SKIN_ID
# normal skin
node.skin || (node.parent ? node.parent.skin : nil)
current_site.skin || node.skin || (node.parent ? node.parent.skin : nil)
else
# find skin from zip
secure(Skin) { Skin.find_by_zip(skin_zip)}
Expand Down
1 change: 1 addition & 0 deletions app/views/sites/_form.erb
Expand Up @@ -15,6 +15,7 @@
<table cellspacing='0' class='edit_site'>
<tr><td class='label'><%= _('host') %></td><td><%= @site[:host] %></td></tr>
<tr><td class='label'><%= _('home') %></td><td><%= text_field('site', :home_zip, :size=>15, :value => @site.home_zip) %></td></tr>
<tr><td class='label'><%= _('skin') %></td><td><%= text_field('site', :skin_zip, :size=>15, :value => @site.skin_zip) %></td></tr>
<% Site.attributes_for_form(@site.is_alias?)[:text].each do |name| -%>
<tr><td class='label'><%= _(name) %></td><td><%= text_field('site', name, :size=>nil) %></td></tr>
<% end -%>
Expand Down
@@ -0,0 +1,11 @@
class AddModelFlagAndSkinId < ActiveRecord::Migration
def self.up
add_column :users, :is_model, :boolean
add_column :sites, :skin_id, :integer
end

def self.down
remove_column :users, :is_model
remove_column :sites, :skin_id
end
end
1 change: 1 addition & 0 deletions test/sites/zena/sites.yml
Expand Up @@ -22,6 +22,7 @@ alias:
host: alias.host
root: zena
home: wiki
skin: wikiSkin
anon: anon
public_group: public
site_group: workers
Expand Down
1 change: 1 addition & 0 deletions test/sites/zena/users.yml
Expand Up @@ -15,6 +15,7 @@ ant:
groups: public, workers
status: user
lang: fr
is_model: true

tiger:
login: tiger
Expand Down
22 changes: 22 additions & 0 deletions test/unit/site_test.rb
Expand Up @@ -406,6 +406,10 @@ def test_rebuild_fullpath
should 'return alias home node' do
assert_equal nodes_id(:wiki), subject.home_id
end

should 'return alias skin node' do
assert_equal nodes_id(:wikiSkin), subject.skin_id
end
end

context 'Creating a site alias' do
Expand Down Expand Up @@ -434,6 +438,24 @@ def test_rebuild_fullpath
end
end

context 'Editing a site alias skin' do
subject do
secure(Site) { sites(:alias) }
end

should 'allow setting skin' do
assert_equal nodes_id(:wikiSkin), subject.skin_id
assert subject.update_attributes(:skin_zip => nodes_zip(:default))
assert_equal nodes_id(:default), sites(:alias).skin.id
end

should 'allow setting skin to nil' do
assert_equal nodes_id(:wikiSkin), subject.skin_id
assert subject.update_attributes(:skin_zip => '')
assert_nil sites(:alias).skin_id
end
end

private
def fullpath(*args)
args.map {|sym| nodes_zip(sym).to_s}.join('/')
Expand Down
4 changes: 4 additions & 0 deletions test/unit/zena/use/rendering_test.rb
Expand Up @@ -63,6 +63,10 @@ class RenderingTest < Zena::View::TestCase
should 'find site alias on visitor site' do
assert_equal 'alias.host', visitor.site.host
end

should 'find forced skin on any node' do
assert_equal 'wiki skin', visitor.get_skin(nodes(:zena)).title
end
end

should 'return a fullpath on fullpath_from_template_url' do
Expand Down

0 comments on commit 727e50b

Please sign in to comment.