Skip to content

Commit

Permalink
Fixed root class resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 30, 2011
1 parent 0411c99 commit 2ab8d42
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 28 deletions.
22 changes: 13 additions & 9 deletions app/controllers/columns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ class ColumnsController < ApplicationController
def index
roles = {}
secure(Column) do
@columns = Column.paginate(:all, :order => 'role_id ASC, name ASC', :per_page => 200, :page => params[:page]).sort! do |a, b|
role_a = (roles[a.role_id] ||= a.role).kpath
role_b = (roles[b.role_id] ||= b.role).kpath

if role_a == role_b
a.name <=> b.name
else
role_a <=> role_b
end
@columns = Column.paginate(:all, :order => 'role_id ASC, name ASC', :per_page => 200, :page => params[:page])
end

@columns.sort! do |a, b|
role_a = (roles[a.role_id] ||= a.role)
role_b = (roles[b.role_id] ||= b.role)

if role_a == role_b
a.name <=> b.name
elsif role_a.kpath == role_a.kpath
role_a.name <=> role_b.name
else
role_a.kpath <=> role_a.kpath
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Site < ActiveRecord::Base
ACTIONS = %w{clear_cache rebuild_index}
include RubyLess
safe_method :host => String, :lang_list => [String]
safe_context :root => {:class => 'Node', :method => 'root_node'}
safe_context :root => {:class => 'Project', :enroll => true, :method => 'root_node'}

validate :valid_site
validates_uniqueness_of :host
Expand Down
9 changes: 5 additions & 4 deletions app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ def real_class?
# explicitely declared as safe are safe. If the VirtualClass reflects a virtual
# class, all properties are considered safe.
def safe_method_type(signature, receiver = nil)

if signature.size == 1
if type = real_class.safe_method_type(signature, receiver)
return type
elsif signature.size == 1
method = signature.first
if receiver && (query = receiver.opts[:query])
if query.select_keys.include?(method)
Expand All @@ -348,9 +349,9 @@ def safe_method_type(signature, receiver = nil)
if type = safe_column_types[method]
return type
end
else
nil
end

real_class.safe_method_type(signature, receiver)
end

# Return safe columns including super class's safe columns
Expand Down
8 changes: 4 additions & 4 deletions app/views/columns/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<table id='column_list' class='admin' cellspacing="0">
<tr><th class='nav' colspan='3'><%= will_paginate @columns %></th></tr>
<% role = nil; @columns.each do |col| -%>
<% if col.role != role; role = col.role -%>
<% role_id = nil; @columns.each do |col| -%>
<% if col.role_id != role_id; role_id = col.role_id -%>
<tr>
<th class='nav sub <%= role.class %>' colspan='3'>
<span class='kpath'><%= role.kpath %></span> <%= role.name %>
<th class='nav sub <%= col.role.class %>' colspan='3'>
<span class='kpath'><%= col.role.kpath %></span> <%= col.role.name %>
</th>
</tr>
<% end -%>
Expand Down
2 changes: 1 addition & 1 deletion config/gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ httparty: '= 0.6.1'

querybuilder: '= 1.0.0'
yamltest: '= 0.7.0'
rubyless: '= 0.8.2'
rubyless: '= 0.8.3'
property: '= 2.1.2'
versions: '= 0.3.1'
zafu: '= 0.7.9'
Expand Down
1 change: 1 addition & 0 deletions lib/zena/db_helper/abstract_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def delete(table, opts)
# Insert a list of values (multicolumn insert). The values should be properly escaped before
# being passed to this method.
def insert_many(table, columns, values)
return if values.empty?
values = values.compact.uniq.map do |list|
list.map {|e| quote(e)}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.visitor_node_proc
safe_method :visitor => User
safe_method :visitor_node => visitor_node_proc
safe_method :main => Proc.new {|h, r, s| {:method => '@node', :class => VirtualClass['Node']}}
safe_method :root => Proc.new {|h, r, s| {:method => 'visitor.site.root_node', :class => VirtualClass['Node'], :nil => true}}
safe_method :root => {:method => 'visitor.site.root_node', :class => 'Project', :enroll => true, :nil => true}
safe_method :site => {:class => Site, :method => 'visitor.site'}

# Group an array of records by key.
Expand Down
9 changes: 7 additions & 2 deletions lib/zena/use/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def zen_path(node, options={})
pre = opts.delete(:prefix) || (visitor.is_anon? && opts.delete(:lang)) || prefix
mode = opts.delete(:mode)
host = opts.delete(:host)
abs_url_prefix = host ? "#{http_protocol}://#{host}" : ''
if ssl = opts.delete(:ssl)
http = 'https'
else
http = http_protocol
end
abs_url_prefix = host ? "#{http}://#{host}" : ''

if node.kind_of?(Document) && format == node.ext
if node.public? && !visitor.site.authentication?
Expand Down Expand Up @@ -182,7 +187,7 @@ def append_query_params(path, opts)
# Url for a node. Options are 'mode' and 'format'
# ex 'http://test.host/en/document34_print.html'
def zen_url(node, opts={})
zen_path(node,opts.merge(:host => host_with_port))
zen_path(node,{:host => host_with_port}.merge(opts))
end

# Return the path to a document's data
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ table.admin td:first-child { border-left: 1px solid #999; }
.admin .btn_validate { float:right; margin-right:30px; }
.admin .label {width:150px; line-height:1.9em;}
.admin th { background:#999; color:#222; font-weight:bold;}
.admin .Role { color:#ccc;}
.admin .Role { color:#eee;}
.admin .name { font-weight:bold;}
.admin .blank { text-align:center; background:none; padding-top:2em;}
.admin th .kpath {font-weight:normal; font-family:Monaco, monospace; color:#ccc;}
Expand Down
4 changes: 4 additions & 0 deletions test/integration/zafu_compiler/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ root:
tem: "<% if var1 = visitor.site.root_node %><%= var1.prop['title'] %><% end %>"
res: 'Zena the wild CMS'

root_should_be_a_project:
src: "<r:root do='hot' do='title'/>"
tem: "/root_node.*SELECT.*var2\.prop\['title'\]/"

notes:
context:
node: 'cleanWater'
Expand Down
4 changes: 4 additions & 0 deletions test/integration/zafu_compiler/urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ r_url_with_hash:
src: "<r:url mode='back' f='x'/>"
res: "/page22_back.html\?f=x/"

url_with_ssl:
src: "<a href='#{url(this, :host =&gt; \"some.host:445\", :ssl =&gt; true)}' do='title'/>"
res: "<a href='https://some.host:445/oo/projects-list/Clean-Water-project/page22.html'>status title</a>"

path:
src: "<a href='#{path}'>blah</a>"
res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>blah</a>"
Expand Down
7 changes: 6 additions & 1 deletion test/unit/image_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ImageTest < Zena::Unit::TestCase
should 'build filepath from title' do
assert_match /birdy.jpg/, subject.filepath
end

should 'save default text' do
node = secure(Node) { Node.find(subject.id) }
assert_equal "!#{subject.zip}!", node.text
Expand Down Expand Up @@ -101,6 +101,11 @@ class ImageTest < Zena::Unit::TestCase
assert_kind_of ExifData, subject.prop['exif']
end

should 'declare exif as safe prop' do
type = subject.safe_method_type(['exif'])
assert_equal Hash[:class => ExifData, :method => 'exif'], type
end

should 'parse time values' do
assert_equal Time.parse("1998-01-01 00:00:00"), subject.exif.date_time
end
Expand Down
8 changes: 4 additions & 4 deletions zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2011-05-27}
s.date = %q{2011-05-28}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down Expand Up @@ -2238,7 +2238,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<tzinfo>, ["= 0.3.26"])
s.add_runtime_dependency(%q<rails>, ["= 2.3.11"])
s.add_runtime_dependency(%q<httparty>, ["= 0.6.1"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.2"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.3"])
s.add_runtime_dependency(%q<property>, ["= 2.1.2"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.3"])
Expand All @@ -2261,7 +2261,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<tzinfo>, ["= 0.3.26"])
s.add_dependency(%q<rails>, ["= 2.3.11"])
s.add_dependency(%q<httparty>, ["= 0.6.1"])
s.add_dependency(%q<rubyless>, ["= 0.8.2"])
s.add_dependency(%q<rubyless>, ["= 0.8.3"])
s.add_dependency(%q<property>, ["= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
Expand All @@ -2285,7 +2285,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<tzinfo>, ["= 0.3.26"])
s.add_dependency(%q<rails>, ["= 2.3.11"])
s.add_dependency(%q<httparty>, ["= 0.6.1"])
s.add_dependency(%q<rubyless>, ["= 0.8.2"])
s.add_dependency(%q<rubyless>, ["= 0.8.3"])
s.add_dependency(%q<property>, ["= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
Expand Down

0 comments on commit 2ab8d42

Please sign in to comment.