Skip to content

Commit

Permalink
Lots of bugs fixes and small improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Aug 30, 2012
1 parent d374b5e commit 285d33d
Show file tree
Hide file tree
Showing 35 changed files with 403 additions and 167 deletions.
3 changes: 2 additions & 1 deletion app/models/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def safe_method_type(signature, receiver = nil)
end

def authorize?(base_node, params, request)
res = Node.find_by_sql(eval(make_query(base_node, params, request).to_s))
res = Node.find_by_sql(eval(make_query(base_node, params, request).to_s)) rescue nil
if res.empty?
nil
else
Expand Down Expand Up @@ -97,6 +97,7 @@ def make_query(node, params = {}, request = nil)
nil
rescue RubyLess::SyntaxError => err
errors.add(:query, err.message.strip)
nil
rescue => err
errors.add(:query, err.message.strip)
nil
Expand Down
9 changes: 7 additions & 2 deletions app/models/cached_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def expire_old
end

# Remove cached pages related to the given node.
def expire_with(node)
expire(node.cached_pages)
def expire_with(node, filter = nil)
if filter
list = CachedPage.find(:all, :conditions => filter[:conditions], :joins => "INNER JOIN cached_pages_nodes AS cpn ON cpn.cached_page_id = cached_pages.id AND cpn.node_id = #{node.id}")
else
list = node.cached_pages
end
expire(list)
end

private
Expand Down
13 changes: 2 additions & 11 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,7 @@ def can_comment?
visitor.commentator? && discussion && discussion.open?
end

# TODO: test
def sweep_cache
def sweep_cache(filter = nil)
return true if current_site.being_created?

# Clear element cache
Expand All @@ -1366,7 +1365,7 @@ def sweep_cache
# FIXME: use self + modified relations instead of parent/project
[self, self.real_project(false), self.real_section(false), self.parent(false)].compact.uniq.each do |obj|
# destroy all pages in project, parent and section !
CachedPage.expire_with(obj)
CachedPage.expire_with(obj, filter)
end

# clear assets
Expand Down Expand Up @@ -1713,14 +1712,6 @@ def after_publish
def after_auto_publish
sweep_cache
end

# Called after a node is published
def after_publish
if !@new_record_before_save
sync_documents(:publish)
end
sweep_cache
end

# Publish, refuse, propose the Documents of a redaction
def sync_documents(action)
Expand Down
3 changes: 2 additions & 1 deletion app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def select_classes

def export_keys
h = super
h[:dates].merge!('log_at' => log_at, 'event_at' => event_at)
h[:dates].merge!('log_at' => log_at) unless log_at.blank?
h[:dates].merge!('event_at' => event_at) unless event_at.blank?
h
end

Expand Down
3 changes: 3 additions & 0 deletions app/models/skin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# A skin is a container for templates and css to render a full site or sectioon
# of a site.
class Skin < Section
def skin_name
title.to_filename
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
TODO: when a user is 'destroyed', pass everything he owns to another user or just mark the user as 'deleted'...
=end
class User < ActiveRecord::Base
attr_accessor :zafu_cache

include Property
RESCUE_SKIN_ID = -1
ANY_SKIN_ID = 0
Expand Down
3 changes: 2 additions & 1 deletion app/views/nodes/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</head>

<body style='font-family:Helvetica, Arial, sans-serif;'>
<div style='display:table; margin:50px auto; background:#aaa; height:200px; width:600px; border:1px solid black;'>
<!-- The zena_error500 is used we running automated tests. Do not change -->
<div id='zena_error500' style='display:table; margin:50px auto; background:#aaa; height:200px; width:600px; border:1px solid black;'>
<h2 style='font-size:18px; text-align:center; margin-top:20px; border:1px solid red; border-width:1px 0; background:#faa; padding:10px;'>Sorry... An error prevented the requested page from rendering</h2>
<p style='text-align:center; text-style:italic;'>This problem has been logged and will be acted upon.</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion bricks/acls/lib/bricks/acls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.included(base)
def template_path_from_template_url_with_acls(suffix='', template_url=params[:t_url], build=true)
if visitor.exec_acl && skin = visitor.exec_acl.exec_skin
# Make sure t_url is using templates in the allowed Skin
skin_name = skin.title.to_filename
skin_name = skin.skin_name
unless template_url[0..skin_name.size] == skin_name + '/'
# Wrong Skin !
Node.logger.warn "Bad t_url used in ACL context (#{template_url}). Visitor = #{visitor.id} // #{visitor.login}"
Expand Down
1 change: 0 additions & 1 deletion bricks/acls/zena/test/unit/acl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def mock_request(method = :get, params = {}, port = 0)
@group_ids = self.group_ids + [erebus_id]
end
assert !subject.update_attributes(:query => "nodes in site")
err subject
assert_equal 'parse error on value ["in", 1] (kIN)', subject.errors[:query]
end
end # saving an acl with asset_host in query
Expand Down
20 changes: 14 additions & 6 deletions bricks/static/lib/bricks/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_template_text_with_static(path, section_id = nil, opts = {})
elsif !(path =~ %r{^(/|\$)}) && section_id.nil? && @static_brick_name && @static_skin_name
Skin.text_from_static(@static_brick_name, @static_skin_name, path, opts)
else
get_template_text_without_static(path, section_id, opts)
return *get_template_text_without_static(path, section_id, opts)
end
end

Expand Down Expand Up @@ -62,12 +62,16 @@ def get_best_template_with_static(kpaths, format, mode, skin)

module SkinMethods
def self.included(base)
base.property do |p|
p.string 'z_static'
end

base.safe_property 'z_static'
base.validate :validate_z_static
base.class_eval do
property do |p|
p.string 'z_static'
end

safe_property 'z_static'
validate :validate_z_static
alias_method_chain :skin_name, :static
end

# We move this method here so that we do not need to reference
# Bricks::Static in I18n when static brick is disabled.
Expand Down Expand Up @@ -95,6 +99,10 @@ def base.text_from_static(brick_name, skin_name, path, opts)
end
end
end

def skin_name_with_static
z_static ? ('$' + z_static) : skin_name_without_static
end

private
def validate_z_static
Expand Down
2 changes: 0 additions & 2 deletions config/bricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ development:
grid: ON
acls: ON
static: ON
gefo: ON
sphinx:
switch: OFF
activate_if:
Expand Down Expand Up @@ -76,7 +75,6 @@ production:
grid: ON
acls: ON
static: ON
gefo: ON
single: OFF
sphinx:
switch: OFF
Expand Down
2 changes: 1 addition & 1 deletion config/gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem_plugin: # upload progress
simple_xlsx_writer: # spreadsheet
lib: 'simple_xlsx'

querybuilder: '= 1.1.1'
querybuilder: '= 1.1.2'
yamltest: '= 0.7.0'
rubyless: '= 0.8.6'
property: '= 2.3.2'
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/zena.rake
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,16 @@ namespace :zena do
end

sites.each do |site|
Thread.current[:visitor] = site.any_admin

if ENV['WORKER'] == 'false' || RAILS_ENV == 'test'
# We avoid SiteWorker by passing nodes.
Thread.current[:visitor] = site.any_admin
nodes = Node.find(:all,
:conditions => ['site_id = ?', site.id]
)
site.rebuild_index(secure_result(nodes))
else
# We try to use the site worker.
Thread.current[:visitor] = site.any_admin
site.rebuild_index
end
end
Expand Down
14 changes: 12 additions & 2 deletions lib/zafu/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def new_with_url(path, opts={})
# Retrieve the template text in the current folder or as an absolute path.
# This method is used when 'including' text
def get_template_text(path, helper, base_path=nil, opts={})
res = helper.send(:get_template_text, path, base_path, opts)
return [parser_error("template '#{path}' not found", 'include'), nil, nil] unless res
cache = (visitor.zafu_cache ||= {})
unless res = cache[path]
res = helper.send(:get_template_text, path, base_path, opts)
res = [parser_error("template '#{path}' not found", 'include'), nil, nil] unless res
cache[path] = res
end
res
end

Expand Down Expand Up @@ -177,6 +181,12 @@ def initialize(text, opts={})
@text = text
else
@text = before_parse(text)
if part = opts[:part]
# Optimization: try to find part from id
if @text =~ /^(.*?)<[^<>]+id='#{part}'/m
eat $1
end
end
end

start(mode)
Expand Down
20 changes: 4 additions & 16 deletions lib/zafu/process/ruby_less_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_method_type(signature, added_options = false)
node = self.node

if type = node_context_from_signature(signature)
# Resolve self, @page, @node
# Resolve this, @page, @node
type
elsif type = get_var_from_signature(signature)
# Resolved stored set_xxx='something' in context.
Expand Down Expand Up @@ -251,10 +251,8 @@ def rubyless_expand(res)
expand_if(res)
elsif @blocks.empty?
out "<%= #{res} %>"
elsif res.could_be_nil?
expand_with_finder(:method => res, :class => res.klass, :nil => true)
else
expand_with_finder(:method => res, :class => res.klass)
expand_with_finder(:method => res, :class => res.klass, :query => res.opts[:query], :nil => res.could_be_nil?)
end
end

Expand Down Expand Up @@ -287,17 +285,7 @@ def node_context_from_signature(signature)
return nil unless signature.size == 1
ivar = signature.first
if ivar == 'this'
if node.list_context?
# Find single element up
if single_node = node(node.klass.first)
single_node.opts.merge(:class => single_node.klass, :method => single_node.to_s)
else
out parser_error("In [#{node.klass.first}], could resolve 'this'.")
nil
end
else
node.opts.merge(:class => node.klass, :method => node.name)
end
node.opts.merge(:class => node.klass, :method => node.name)
elsif ivar[0..0] == '@' && klass = get_class(ivar[1..-1].capitalize)
if node = self.node(klass)
node.opts.merge(:class => node.klass, :method => node.name)
Expand All @@ -313,7 +301,7 @@ def node_context_from_signature(signature)
def get_var_from_signature(signature)
return nil unless signature.size == 1
if var = get_context_var('set_var', signature.first)
{:method => var, :class => var.klass, :nil => var.could_be_nil?}
{:method => var, :class => var.klass, :nil => var.could_be_nil?, :query => var.opts[:query]}
else
nil
end
Expand Down
15 changes: 15 additions & 0 deletions lib/zena/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,20 @@ def foreach(pseudo_sql, opts = {})
end
nil
end

def profile(node_id)
require 'ruby-prof'
ctrl = NodesController.new
ctrl.request = Struct.new(:format).new(Mime::HTML)
ctrl.instance_variable_set(:@node, nodes(node_id))
start = Time.now
result = RubyProf.profile do
yield(ctrl)
end
puts(Time.now - start)
File.open('grind.log', 'wb') do |f|
RubyProf::CallTreePrinter.new(result).print(f)
end
end
end # Console
end # Zena
14 changes: 13 additions & 1 deletion lib/zena/core_ext/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ class << FileUtils
class << FileUtils
alias symlink_or_copy cp_r
end
end
end

=begin
class << FileUtils
def symlink_or_copy(from, to)
if File.directory?(from)
cp_r(from, to)
else
ln(from, to)
end
end
end
=end
3 changes: 2 additions & 1 deletion lib/zena/use/ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def r_filter
with_context(:node => base_node.dup) do
node.dom_prefix = dom_name
dom_id = node.dom_id(:erb => false)


# TODO: add 'encode_params' and x='"foobar"' to add any value in the request
out %Q{<%= form_remote_tag(:url => zafu_node_path(#{node}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %>
<div class='hidden'>
<input type='hidden' name='t_url' value='#{template_url(upd)}'/>
Expand Down

0 comments on commit 285d33d

Please sign in to comment.