Changeset 302

Show
Ignore:
Timestamp:
2007-02-22 23:50:41 (2 years ago)
Author:
gaspard
Message:

Better parsing of 'zafu params' (everything before zafu= is considered html, everything after are params)
Implemented the 'do' meta param : <z:each do='link'/>
Fixed some translations and added a group_site image
Added a site wide group for all users except anon : id = 3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/group_controller.rb

    r220 r302  
    3636  def update 
    3737    render :nothing=>true if 1 == params[:id] 
    38     if params[:users] 
     38    if params[:users] && params[:id] != 3 
    3939      params[:group][:user_ids] = params[:users].values.map {|v| v.to_i} 
    4040    end 
  • trunk/app/controllers/user_controller.rb

    r220 r302  
    3434    @user = User.find(params[:id]) 
    3535    @user.password = nil 
    36     @groups = Group.find(:all, :order=>'id') 
     36    if 1 == @user[:id] 
     37      @groups = Group.find(:all, :conditions=>"id <> 1", :order=>'id') 
     38    else 
     39      @groups = Group.find(:all, :order=>'id') 
     40    end 
    3741    render :partial=>'user/form' 
    3842  end 
  • trunk/app/helpers/application_helper.rb

    r285 r302  
    370370   
    371371  # Hierachical menu. (same on all pages) 
    372   def menu(opts={}) 
     372  def show_menu(opts={}) 
    373373    Cache.with(visitor.id, visitor.group_ids, Page.kpath, 'show_menu') do 
    374374      if ZENA_ENV[:menu_tag_id] !=nil 
  • trunk/app/models/user.rb

    r245 r302  
    1616  belongs_to              :contact 
    1717  validate                :valid_user 
    18   after_create            :add_public_group 
     18  before_create           :add_default_groups 
    1919  before_destroy          :dont_destroy_su_or_anon 
    2020   
     
    8484    res = res.map{|g| g[:id]} 
    8585    res << 1 unless res.include?(1) 
     86    res << 3 unless res.include?(3) || id == 1 # all logged in users are in the 'site' group except 'anon' 
    8687    @group_ids = res 
    8788  end 
     
    149150      self[:login] = nil 
    150151      self[:password] = nil 
    151     elsif new_record? 
    152       # validate uniqueness of 'login' 
    153       if User.find(:first, :conditions=>["login = ?", self[:login]]) 
    154         errors.add(:login, 'has already been taken') 
     152    else 
     153      if new_record? 
     154        # validate uniqueness of 'login' 
     155        if User.find(:first, :conditions=>["login = ?", self[:login]]) 
     156          errors.add(:login, 'has already been taken') 
     157        end 
     158        # validate uniqueness of 'login' 
     159        if User.find(:first, :conditions=>["login = ?", self[:login]]) 
     160          errors.add(:login, 'has already been taken') 
     161        end 
     162      else 
     163        # get old password 
     164        old = User.find(self[:id]) 
     165        self[:password] = old[:password] if self[:password].nil? || self[:password] == "" 
     166        # validate uniqueness of 'login' 
     167        if User.find(:first, :conditions=>["login = ? AND id <> ?", self[:login], self[:id]]) 
     168          errors.add(:login, 'has already been taken') 
     169        end 
     170        errors.add(:login, 'too short') unless self[:login] == old[:login] || (self[:login] && self[:login].length > 3) 
    155171      end 
    156     else 
    157       # get old password 
    158       old = User.find(self[:id]) 
    159       self[:password] = old[:password] if self[:password].nil? || self[:password] == "" 
    160       # validate uniqueness of 'login' 
    161       if User.find(:first, :conditions=>["login = ? AND id <> ?", self[:login], self[:id]]) 
    162         errors.add(:login, 'has already been taken') 
    163       end 
    164       errors.add(:login, 'too short') unless self[:login] == old[:login] || (self[:login] && self[:login].length > 3) 
    165172      errors.add(:password, 'too short') unless self[:password] && self[:password].length > 4 
    166173    end 
    167174  end 
    168175   
    169   # Make sure all users are in the _public_ group. This method is called +after_create+. 
    170   def add_public_group #:doc: 
    171     unless groups.map{|g| g[:id]}.include?(1) 
    172       groups << Group.find(1) 
    173     end 
     176  # Make sure all users are in the _public_ and _site_ groups. This method is called +after_create+. 
     177  def add_default_groups #:doc: 
     178    g_ids = groups.map{|g| g[:id]} 
     179    groups << Group.find(1) unless g_ids.include?(1) 
     180    groups << Group.find(3) unless g_ids.include?(3) || id == 1 
    174181  end 
    175182   
     
    178185    raise Zena::AccessViolation, "su and Anonymous users cannot be destroyed !" if [1,2].include?(id) 
    179186  end 
     187   
     188  def old 
     189    @old ||= self.class.find(self[:id]) 
     190  end 
    180191end 
  • trunk/app/views/group/_form.rhtml

    r212 r302  
    1717      <tr><td class='label'><%= trans('name')%>       </td><td><%= text_field('group', 'name',        :size=>15 ) %></td></tr> 
    1818      <tr><td class='label'><%= trans('users')%>      </td><td><%= @users.inject([]) do |list, u| 
    19         unless 1 == u[:id] || 2 == u[:id] 
    20           list << "<input type='checkbox' name='users[#{u.id}]' value='#{u.id}' class='box' #{(@group && @group.user_ids.include?(u[:id])) ? "checked='1'" : ''}/>#{u.login}" 
     19        unless u[:id] == 1 || u[:id] == 2 
     20          if @group && @group[:id] == 3 
     21            list << "<input type='checkbox' name='users[#{u.id}]' value='#{u.id}' class='box' checked='1' disabled='1'/>#{u.login}" 
     22          else 
     23            list << "<input type='checkbox' name='users[#{u.id}]' value='#{u.id}' class='box' #{(@group && @group.user_ids.include?(u[:id])) ? "checked='1'" : ''}/>#{u.login}" 
     24          end 
    2125        end 
    2226        list 
  • trunk/app/views/group/_li.rhtml

    r135 r302  
    11<% icon = 'group' 
    2 if 1 == li[:id] 
     2if li[:id] == 1 
    33  icon += '_pub' 
    4 elsif 2 == li[:id] 
     4elsif li[:id] == 2 
    55  icon += '_admin' 
     6elsif li[:id] == 3 
     7  icon += '_site' 
    68end %> 
    79<tr id='group<%= li[:id] %>'> 
  • trunk/app/views/layouts/admin.rhtml

    r213 r302  
    2020  </div> 
    2121 
    22   <%= show_menu      %
    23   <%= logo Time.now.utc  %
     22  <div id='menu'><%= show_menu %></div
     23  <div id='logo'><a href='/'><img src='img/logo.png' width='220' height='100'/></a></div
    2424  <%= flash_messages %> 
    2525   
  • trunk/app/views/login/login.rhtml

    r274 r302  
    1717  </div> 
    1818 
    19   <%= logo Time.now.utc  %
     19  <div id='logo'><a href='/'><img src='img/logo.png' width='220' height='100'/></a></div
    2020  <%= flash_messages %> 
    2121 
  • trunk/app/views/user/_form.rhtml

    r212 r302  
    3535    <tr><td class='label'><%= trans("groups")%>     </td><td> 
    3636    <%= @groups.inject([]) do |list, g| 
    37           if 1 == g[:id] 
     37          if g[:id] == 1 || g[:id] == 3 
    3838            list << "<input type='checkbox' name='groups[#{g.id}]' value='#{g.id}' class='box' checked='1' disabled='1' />#{g.name}" 
    3939          else 
  • trunk/config/zena.rb

    r299 r302  
    22AUTHENTICATED_PREFIX = "oo" 
    33ZENA_ENV = { 
    4   :site_name => 'cvd', 
     4  :site_name => 'zena', 
    55  :root_id => 1, 
    66  :authorize => false, 
  • trunk/db/initialize/zena/base.yml

    r244 r302  
    2323    name:           admin 
    2424 
     25  - id:             3 
     26    name:           site 
     27 
    2528groups_users: 
    2629  - group_id:       2 
     30    user_id:        3 
     31     
     32  - group_id:       3 
    2733    user_id:        3 
    2834 
  • trunk/db/initialize/zena/images.yml

    r213 r302  
    167167    lang:      en 
    168168    value:     "<img src='/images/home.png'/>" 
     169     
     170  - phrase_id:    99 
     171    lang:      en 
     172    value:     "<img src='/images/group.png'/>" 
     173 
     174  - phrase_id:    100 
     175    lang:      en 
     176    value:     "<img src='/images/group_site.png'/>" 
  • trunk/db/initialize/zena/init.rb

    r132 r302  
    5555    elsif :nodes == tbl && record[:log_at] == 'today' 
    5656      record[:log_at] = Time.now 
     57    elsif :groups == tbl && record[:id] == 3 
     58      record[:name] = ZENA_ENV[:site_name] 
    5759    end 
    5860    unless Loader.create(record) 
  • trunk/db/initialize/zena/trans_phrases.yml

    r213 r302  
    293293  - id:   98 
    294294    phrase:  'img_home' 
     295 
     296  - id:   99 
     297    phrase:  'img_group' 
     298 
     299  - id:   100 
     300    phrase:  'img_group_site' 
  • trunk/lib/parser/lib/rules/zafu.rb

    r283 r302  
    1313      res = super 
    1414      if @zafu_tag && !@zafu_tag_done 
     15        if res =~ /\A\[(\w+)(.*)\/\]\Z/ 
     16          res = "[#{$1}#{$2}]<#{tag}/>[/#{$1}]" 
     17        elsif res =~ /\A\[([^\]]+)\](.*)\[\/(\w+)\]\Z/ 
     18          res = "[#{$1}]#{render_zafu_tag($2)}[/#{$3}]" 
     19        end 
    1520        @zafu_tag_done = true 
    16         if res =~ /\A\[(\w+)(.*)\/\]\Z/ 
    17           "[#{$1}#{$2}]<#{tag}/>[/#{$1}]" 
    18         elsif res =~ /\A\[([^\]]+)\](.*)\[\/(\w+)\]\Z/ 
    19           "[#{$1}]#{render_zafu_tag($2)}[/#{$3}]" 
    20         end 
    21       else 
    22         res 
    23       end 
     21      end 
     22      res 
    2423    end 
    2524     
     
    7069      if @zafu_tag = @options[:zafu_tag] 
    7170        @options.delete(:zafu_tag) 
    72         @zafu_tag_params = {} 
    73         [:id, :class].each do |param| 
    74           @zafu_tag_params[param] = @params[param] if @params[param] 
    75           @params.delete(param) 
    76         end 
     71        @zafu_tag_params = @options[:zafu_tag_params] || {} 
     72        @options.delete(:zafu_tag_params) 
     73        @zafu_tag_count = 1 
     74      elsif @zafu_tag = @options[:eat_zafu] 
     75        @eat_zafu = true 
     76        @options.delete(:eat_zafu) 
    7777        @zafu_tag_count = 1 
    7878      else 
     
    8181      if @method == 'include' 
    8282        include_template 
     83      elsif @options[:do] 
     84        opts = {:method=>@options[:do]} 
     85         
     86        # the matching zafu tag will be parsed by the last 'do', we must inform it to halt properly : 
     87        opts[:eat_zafu] = @zafu_tag if @zafu_tag 
     88         
     89        all_params = @options[:do_params] 
     90        if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 
     91          # we have a sub 'do' 
     92          match = $~ 
     93          opts[:do] = $3 
     94          opts[:do_params] = $4 
     95          opts[:params] = parse_params($1) 
     96        else 
     97          @options.delete(:do_params) 
     98          @options.delete(:do) 
     99          opts[:params] = parse_params(all_params) 
     100        end 
     101        make(:void, opts) 
    83102      else 
    84103        if mode == :tag 
     
    87106          enter(mode) 
    88107        end 
     108      end 
     109      if @eat_zafu 
     110        @zafu_tag = nil 
    89111      end 
    90112    end 
     
    165187      if @text =~ /\A<z:(\w+)([^>]*?)(\/?)>/ 
    166188        # puts "ZTAG:[#{$&}]}" # ztag 
    167         method = $1 
    168189        closed = ($3 != '') 
    169190        eat $& 
    170         params = parse_params($2) 
     191        all_params = $2 
     192        opts = {:method=>$1} 
     193        if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 
     194          # we have a 'do' 
     195          match = $~ 
     196          opts[:do] = $3 
     197          opts[:do_params] = $4 
     198          opts[:params] = parse_params($1) 
     199        else 
     200          opts[:params] = parse_params(all_params) 
     201        end 
    171202        if closed 
    172           make(:void, :params=>params, :method=>method, :text=>''
    173         else 
    174           make(:void, :params=>params, :method=>method
    175         end 
    176       elsif @text =~ /\A<(\w+)([^>]*?)zafu\s*=([^>]*?)(\/?)>/ 
     203          make(:void, opts.merge(:text=>'')
     204        else   
     205          make(:void, opts
     206        end 
     207      elsif @text =~ /\A<(\w+)([^>]*?)zafu\s*=('|")([^\3]*?[^\\])\3([^>]*?)(\/?)>/ 
    177208        # puts "ZAFU:[#{$&}]}" # zafu param tag 
    178209        eat $& 
    179         zafu_tag = $1 
    180         closed = ($4 != '') 
    181         params = parse_params($2+"zafu="+$3) 
    182         method = params[:zafu] 
    183         params.delete(:zafu) 
     210        match = $~ 
     211        all_params = match[5] 
     212        closed = (match[6] != '') 
     213        opts = {:method=>match[4], :zafu_tag=>match[1], :zafu_tag_params=>parse_params(match[2])} 
     214        if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 
     215          # we have a 'do' 
     216          match = $~ 
     217          opts[:do] = $3 
     218          opts[:do_params] = $4 
     219          opts[:params] = parse_params($1) 
     220        else 
     221          opts[:params] = parse_params(all_params) 
     222        end 
    184223        if closed 
    185           make(:void, :zafu_tag=>zafu_tag, :params=>params, :method=>method, :text=>''
     224          make(:void, opts.merge(:text=>'')
    186225        else   
    187           make(:void, :zafu_tag=>zafu_tag, :params=>params, :method=>method
     226          make(:void, opts
    188227        end 
    189228      elsif @zafu_tag && @text =~ /\A<#{@zafu_tag}([^>]*?)(\/?)>/ 
  • trunk/lib/parser/lib/rules/zena.rb

    r301 r302  
    188188    end 
    189189     
     190    # TODO: add parent_id into the form ! 
    190191    def r_form 
    191192      @pass[:form] = self 
     
    283284        out res 
    284285        out "<% end -%>" 
    285       else   
     286      else 
    286287        res = expand_with 
    287288        if @context[:template_url] && @pass[:edit] 
     
    497498        if order = @params[:order] 
    498499          if order == 'random' 
    499             erb_params[k] = 'RAND()' 
     500            erb_params[:order] = 'RAND()' 
    500501          elsif order =~ /\A(\w+)( ASC| DESC|)\Z/ 
    501             erb_params[k] = order 
     502            erb_params[:order] = order 
    502503          else 
    503504            # ignore 
  • trunk/lib/parser/test/parser_test.rb

    r283 r302  
    2222  testfile :zafu, :zafu_asset, :zafu_insight 
    2323  def test_single 
    24     do_test('zafu', 'html_zafu_comment') 
     24    do_test('zafu', 'zafu_tag_closed') 
    2525  end 
    2626  make_tests 
  • trunk/lib/parser/test/zafu.yml

    r283 r302  
    6464 
    6565zafu_keep_params: 
    66   src: "I love <div zafu='test' class='truc' id='machin' depth='3'>my wife</div>" 
     66  src: "I love <div class='truc' id='machin' zafu='test' depth='3'>my wife</div>" 
    6767  res: "I love [test {= :depth=>'3'}]<div class='truc' id='machin'>my wife</div>[/test]" 
    6868 
     
    175175  src: "<z:test><z:hello/><!--|this is not a comment <z:hello/>  --></z:test>" 
    176176  res: "[test][hello/]this is not a comment [hello/]  [/test]" 
     177 
     178do_simple: 
     179  src: "<z:test do='hello'/>" 
     180  res: "[test][hello/][/test]" 
     181   
     182do_zafu: 
     183  src: "<p zafu='test' param='yo' do='hello' param='hey'>some thing</p>" 
     184  res: "[test {= :param=>'yo'}]<p>[hello {= :param=>'hey'}]some thing[/hello]</p>[/test]" 
     185   
     186do_multiple: 
     187  src: "<z:test param='1' do='test' param='2' do='hello' param='3'/>" 
     188  res: "[test {= :param=>'1'}][test {= :param=>'2'}][hello {= :param=>'3'}/][/test][/test]" 
     189 
     190do_multiple_with_zafu: 
     191  src: "" 
     192  res: "" 
  • trunk/test/fixtures/groups.yml

    r1 r302  
    1010  updated_at:     2006-03-12 
    1111  name:           admin 
    12  
    13 workers
     12   
     13site
    1414  id:             3 
    1515  created_at:     2006-03-10 
  • trunk/test/fixtures/groups_users.yml

    r1 r302  
    1313 
    1414 
    15  
    16  
    17 ant_in_workers: 
     15ant_in_site: 
    1816  user_id:    3 
    1917  group_id:   3 
    2018 
    21 tiger_in_workers
     19tiger_in_site
    2220  user_id:    4 
    2321  group_id:   3 
    24    
     22 
     23lion_in_site: 
     24  user_id:    5 
     25  group_id:   3 
    2526 
    2627 
  • trunk/test/fixtures/trans_phrases.yml

    r213 r302  
    390390  id:   98 
    391391  phrase:  'img_home' 
     392   
     39399: 
     394  id:   99 
     395  phrase:  'img_group' 
     396   
     397100: 
     398  id:   100 
     399  phrase:  'img_group_site' 
  • trunk/test/fixtures/trans_values.yml

    r213 r302  
    916916  lang:      en 
    917917  value:     "<img src='/images/home.png'/>" 
     918 
     919171: 
     920  id:        171 
     921  phrase_id:    99 
     922  lang:      en 
     923  value:     "<img src='/images/group.png'/>" 
     924 
     925172: 
     926  id:        172 
     927  phrase_id:    100 
     928  lang:      en 
     929  value:     "<img src='/images/group_site.png'/>" 
  • trunk/test/fixtures/versions.yml

    r281 r302  
    105105  user_id:        4 
    106106  comment:        no comment yet 
    107   title:          no title ye
     107  title:          projects lis
    108108  summary:        no summary yet 
    109109  text:           nothing written yet 
  • trunk/test/helpers/basic.yml

    r299 r302  
    126126node_id: 
    127127  src: "I (<z:show attr='name'/>) know: <z:node node_id='2'><z:show attr='name'/> with <z:children><span zafu='each' join=', '><z:show attr='name'>child</z:show></span></z:children></z:node>" 
    128   res: "I (status) know: people with <span>ant</span>, <span>tiger</span>, <span>lion</span>" 
     128  res: "I (status) know: people with <span>ant</span>, <span>lion</span>, <span>tiger</span>" 
    129129 
    130130node_path: 
     
    280280  tem: "<%= 'children'.pluralize %>" 
    281281  res: "children" 
     282 
     283each_do: 
     284  context: 
     285    node: 'wiki' 
     286  src: "<z:children><z:each join=', ' do='show' attr='name'/></z:children>" 
     287  res: "bird, flower" 
     288   
     289parent_do: 
     290  context: 
     291    node: 'wiki' 
     292  src: "<z:parent do='link'/>" 
     293  res: "<a href=\"/oo/page8.html\">projects list</a>" 
     294 
     295do_each: 
     296  src: "<z:children do='each'><z:link/></z:children>" 
     297  res: "" 
     298 
     299do_with_inner: 
     300  src: "<ul zafu='children' do='each' tag='li'><z:show attr='name'/></ul>" 
     301  res: "<ul><li>...</li><li>...</li>" 
  • trunk/test/helpers/relations.yml

    r301 r302  
    6969  src: "<z:children store='project' limit='1'><z:each><z:pages from='site' project='stored' limit='5'><z:each join=', '><z:show attr='name'/></z:each></z:pages></z:each></z:children>" 
    7070  res: "ant, art, collections, lion, menu" 
     71 
     72author_visitor: 
     73  src: "<z:pages from='site' author='visitor'><z:each do='link'/></z:pages>" 
     74  res: "ant, art, collections, lion, menu" 
  • trunk/test/helpers/test_all.rb

    r301 r302  
    44  testfile :relations, :basic 
    55  def test_single 
    6     do_test('relations', 'store_context') 
     6    do_test('basic', 'do_each') 
    77  end 
    88  make_tests 
  • trunk/test/unit/multiversion_test.rb

    r275 r302  
    417417    node = secure(Node) { nodes(:lake)  } # reload 
    418418    assert_equal 2, node.editions.size, "English and french editions" 
    419     assert_equal ["en", "fr"], node.traductions.sort 
     419    assert_equal ["en"], node.traductions.map{|t| t[:lang]}.sort 
    420420  end 
    421421   
     
    484484    node = secure(Node) { nodes(:wiki) } 
    485485    trad = node.traductions 
    486     assert_equal 0, trad.size 
     486    assert_nil trad, 'no traductions' 
    487487  end 
    488488     
  • trunk/test/unit/secure_test.rb

    r299 r302  
    330330    wiki = nodes(:wiki) 
    331331    attrs[:parent_id] = wiki[:id] 
    332     # ant is in 'workers', all should be ok 
    333     attrs[:pgroup_id] = groups_id(:workers
    334     z = secure(Note) { Note.create(attrs) } 
    335      
     332    # ant is in the 'site' group, all should be ok 
     333    attrs[:pgroup_id] = groups_id(:site
     334    z = secure(Note) { Note.create(attrs) } 
     335    err z 
    336336    assert ! z.new_record? , "Not a new record" 
    337337    assert z.errors.empty? , "No errors" 
    338338    assert_equal wiki[:rgroup_id], z[:rgroup_id] , "Same rgroup as parent" 
    339339    assert_equal wiki[:wgroup_id], z[:wgroup_id] , "Same wgroup as parent" 
    340     assert_equal groups_id(:workers), z[:pgroup_id] , "New pgroup set" 
     340    assert_equal groups_id(:site), z[:pgroup_id] , "New pgroup set" 
    341341  end 
    342342   
  • trunk/test/unit/user_test.rb

    r186 r302  
    2626    user = User.new("login"=>"john", "password"=>"isjjna78a9h", "group_ids"=>["1", "2"]) 
    2727    assert user.save 
    28     assert_equal 2, user.groups.size 
     28    assert_equal 3, user.groups.size 
    2929  end 
    3030   
     
    3333    assert_kind_of User, user 
    3434    assert !user.new_record?, "Not a new record" 
    35     assert_equal 1, user.groups.size 
     35    assert_equal 2, user.groups.size 
    3636    assert_equal 'public', user.groups[0].name 
    3737  end 
     
    6565    bob = User.new 
    6666    bob.login = 'bob' 
     67    bob.save 
    6768    assert ! bob.save 
    6869    assert_not_nil bob.errors[:password] 
     
    100101  end 
    101102   
     103   
    102104  # TODO: finish tests for User 
    103105  # groups