Changeset 302
- Timestamp:
- 2007-02-22 23:50:41 (2 years ago)
- Files:
-
- trunk/app/controllers/group_controller.rb (modified) (1 diff)
- trunk/app/controllers/user_controller.rb (modified) (1 diff)
- trunk/app/helpers/application_helper.rb (modified) (1 diff)
- trunk/app/models/user.rb (modified) (4 diffs)
- trunk/app/views/group/_form.rhtml (modified) (1 diff)
- trunk/app/views/group/_li.rhtml (modified) (1 diff)
- trunk/app/views/layouts/admin.rhtml (modified) (1 diff)
- trunk/app/views/login/login.rhtml (modified) (1 diff)
- trunk/app/views/user/_form.rhtml (modified) (1 diff)
- trunk/config/zena.rb (modified) (1 diff)
- trunk/db/initialize/zena/base.yml (modified) (1 diff)
- trunk/db/initialize/zena/images.yml (modified) (1 diff)
- trunk/db/initialize/zena/init.rb (modified) (1 diff)
- trunk/db/initialize/zena/trans_phrases.yml (modified) (1 diff)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (5 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (3 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (2 diffs)
- trunk/public/images/group_site.png (added)
- trunk/test/fixtures/groups.yml (modified) (1 diff)
- trunk/test/fixtures/groups_users.yml (modified) (1 diff)
- trunk/test/fixtures/trans_phrases.yml (modified) (1 diff)
- trunk/test/fixtures/trans_values.yml (modified) (1 diff)
- trunk/test/fixtures/versions.yml (modified) (1 diff)
- trunk/test/helpers/basic.yml (modified) (2 diffs)
- trunk/test/helpers/relations.yml (modified) (1 diff)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
- trunk/test/unit/multiversion_test.rb (modified) (2 diffs)
- trunk/test/unit/secure_test.rb (modified) (1 diff)
- trunk/test/unit/user_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/group_controller.rb
r220 r302 36 36 def update 37 37 render :nothing=>true if 1 == params[:id] 38 if params[:users] 38 if params[:users] && params[:id] != 3 39 39 params[:group][:user_ids] = params[:users].values.map {|v| v.to_i} 40 40 end trunk/app/controllers/user_controller.rb
r220 r302 34 34 @user = User.find(params[:id]) 35 35 @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 37 41 render :partial=>'user/form' 38 42 end trunk/app/helpers/application_helper.rb
r285 r302 370 370 371 371 # Hierachical menu. (same on all pages) 372 def menu(opts={})372 def show_menu(opts={}) 373 373 Cache.with(visitor.id, visitor.group_ids, Page.kpath, 'show_menu') do 374 374 if ZENA_ENV[:menu_tag_id] !=nil trunk/app/models/user.rb
r245 r302 16 16 belongs_to :contact 17 17 validate :valid_user 18 after_create :add_public_group18 before_create :add_default_groups 19 19 before_destroy :dont_destroy_su_or_anon 20 20 … … 84 84 res = res.map{|g| g[:id]} 85 85 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' 86 87 @group_ids = res 87 88 end … … 149 150 self[:login] = nil 150 151 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) 155 171 end 156 else157 # get old password158 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 end164 errors.add(:login, 'too short') unless self[:login] == old[:login] || (self[:login] && self[:login].length > 3)165 172 errors.add(:password, 'too short') unless self[:password] && self[:password].length > 4 166 173 end 167 174 end 168 175 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 end176 # 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 174 181 end 175 182 … … 178 185 raise Zena::AccessViolation, "su and Anonymous users cannot be destroyed !" if [1,2].include?(id) 179 186 end 187 188 def old 189 @old ||= self.class.find(self[:id]) 190 end 180 191 end trunk/app/views/group/_form.rhtml
r212 r302 17 17 <tr><td class='label'><%= trans('name')%> </td><td><%= text_field('group', 'name', :size=>15 ) %></td></tr> 18 18 <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 21 25 end 22 26 list trunk/app/views/group/_li.rhtml
r135 r302 1 1 <% icon = 'group' 2 if 1 == li[:id]2 if li[:id] == 1 3 3 icon += '_pub' 4 elsif 2 == li[:id]4 elsif li[:id] == 2 5 5 icon += '_admin' 6 elsif li[:id] == 3 7 icon += '_site' 6 8 end %> 7 9 <tr id='group<%= li[:id] %>'> trunk/app/views/layouts/admin.rhtml
r213 r302 20 20 </div> 21 21 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> 24 24 <%= flash_messages %> 25 25 trunk/app/views/login/login.rhtml
r274 r302 17 17 </div> 18 18 19 < %= logo Time.now.utc %>19 <div id='logo'><a href='/'><img src='img/logo.png' width='220' height='100'/></a></div> 20 20 <%= flash_messages %> 21 21 trunk/app/views/user/_form.rhtml
r212 r302 35 35 <tr><td class='label'><%= trans("groups")%> </td><td> 36 36 <%= @groups.inject([]) do |list, g| 37 if 1 == g[:id]37 if g[:id] == 1 || g[:id] == 3 38 38 list << "<input type='checkbox' name='groups[#{g.id}]' value='#{g.id}' class='box' checked='1' disabled='1' />#{g.name}" 39 39 else trunk/config/zena.rb
r299 r302 2 2 AUTHENTICATED_PREFIX = "oo" 3 3 ZENA_ENV = { 4 :site_name => ' cvd',4 :site_name => 'zena', 5 5 :root_id => 1, 6 6 :authorize => false, trunk/db/initialize/zena/base.yml
r244 r302 23 23 name: admin 24 24 25 - id: 3 26 name: site 27 25 28 groups_users: 26 29 - group_id: 2 30 user_id: 3 31 32 - group_id: 3 27 33 user_id: 3 28 34 trunk/db/initialize/zena/images.yml
r213 r302 167 167 lang: en 168 168 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 55 55 elsif :nodes == tbl && record[:log_at] == 'today' 56 56 record[:log_at] = Time.now 57 elsif :groups == tbl && record[:id] == 3 58 record[:name] = ZENA_ENV[:site_name] 57 59 end 58 60 unless Loader.create(record) trunk/db/initialize/zena/trans_phrases.yml
r213 r302 293 293 - id: 98 294 294 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 13 13 res = super 14 14 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 15 20 @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 24 23 end 25 24 … … 70 69 if @zafu_tag = @options[:zafu_tag] 71 70 @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) 77 77 @zafu_tag_count = 1 78 78 else … … 81 81 if @method == 'include' 82 82 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) 83 102 else 84 103 if mode == :tag … … 87 106 enter(mode) 88 107 end 108 end 109 if @eat_zafu 110 @zafu_tag = nil 89 111 end 90 112 end … … 165 187 if @text =~ /\A<z:(\w+)([^>]*?)(\/?)>/ 166 188 # puts "ZTAG:[#{$&}]}" # ztag 167 method = $1168 189 closed = ($3 != '') 169 190 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 171 202 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([^>]*?)(\/?)>/ 177 208 # puts "ZAFU:[#{$&}]}" # zafu param tag 178 209 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 184 223 if closed 185 make(:void, :zafu_tag=>zafu_tag, :params=>params, :method=>method, :text=>'')224 make(:void, opts.merge(:text=>'')) 186 225 else 187 make(:void, :zafu_tag=>zafu_tag, :params=>params, :method=>method)226 make(:void, opts) 188 227 end 189 228 elsif @zafu_tag && @text =~ /\A<#{@zafu_tag}([^>]*?)(\/?)>/ trunk/lib/parser/lib/rules/zena.rb
r301 r302 188 188 end 189 189 190 # TODO: add parent_id into the form ! 190 191 def r_form 191 192 @pass[:form] = self … … 283 284 out res 284 285 out "<% end -%>" 285 else 286 else 286 287 res = expand_with 287 288 if @context[:template_url] && @pass[:edit] … … 497 498 if order = @params[:order] 498 499 if order == 'random' 499 erb_params[ k] = 'RAND()'500 erb_params[:order] = 'RAND()' 500 501 elsif order =~ /\A(\w+)( ASC| DESC|)\Z/ 501 erb_params[ k] = order502 erb_params[:order] = order 502 503 else 503 504 # ignore trunk/lib/parser/test/parser_test.rb
r283 r302 22 22 testfile :zafu, :zafu_asset, :zafu_insight 23 23 def test_single 24 do_test('zafu', ' html_zafu_comment')24 do_test('zafu', 'zafu_tag_closed') 25 25 end 26 26 make_tests trunk/lib/parser/test/zafu.yml
r283 r302 64 64 65 65 zafu_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>" 67 67 res: "I love [test {= :depth=>'3'}]<div class='truc' id='machin'>my wife</div>[/test]" 68 68 … … 175 175 src: "<z:test><z:hello/><!--|this is not a comment <z:hello/> --></z:test>" 176 176 res: "[test][hello/]this is not a comment [hello/] [/test]" 177 178 do_simple: 179 src: "<z:test do='hello'/>" 180 res: "[test][hello/][/test]" 181 182 do_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 186 do_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 190 do_multiple_with_zafu: 191 src: "" 192 res: "" trunk/test/fixtures/groups.yml
r1 r302 10 10 updated_at: 2006-03-12 11 11 name: admin 12 13 workers:12 13 site: 14 14 id: 3 15 15 created_at: 2006-03-10 trunk/test/fixtures/groups_users.yml
r1 r302 13 13 14 14 15 16 17 ant_in_workers: 15 ant_in_site: 18 16 user_id: 3 19 17 group_id: 3 20 18 21 tiger_in_ workers:19 tiger_in_site: 22 20 user_id: 4 23 21 group_id: 3 24 22 23 lion_in_site: 24 user_id: 5 25 group_id: 3 25 26 26 27 trunk/test/fixtures/trans_phrases.yml
r213 r302 390 390 id: 98 391 391 phrase: 'img_home' 392 393 99: 394 id: 99 395 phrase: 'img_group' 396 397 100: 398 id: 100 399 phrase: 'img_group_site' trunk/test/fixtures/trans_values.yml
r213 r302 916 916 lang: en 917 917 value: "<img src='/images/home.png'/>" 918 919 171: 920 id: 171 921 phrase_id: 99 922 lang: en 923 value: "<img src='/images/group.png'/>" 924 925 172: 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 105 105 user_id: 4 106 106 comment: no comment yet 107 title: no title yet107 title: projects list 108 108 summary: no summary yet 109 109 text: nothing written yet trunk/test/helpers/basic.yml
r299 r302 126 126 node_id: 127 127 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>" 129 129 130 130 node_path: … … 280 280 tem: "<%= 'children'.pluralize %>" 281 281 res: "children" 282 283 each_do: 284 context: 285 node: 'wiki' 286 src: "<z:children><z:each join=', ' do='show' attr='name'/></z:children>" 287 res: "bird, flower" 288 289 parent_do: 290 context: 291 node: 'wiki' 292 src: "<z:parent do='link'/>" 293 res: "<a href=\"/oo/page8.html\">projects list</a>" 294 295 do_each: 296 src: "<z:children do='each'><z:link/></z:children>" 297 res: "" 298 299 do_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 69 69 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>" 70 70 res: "ant, art, collections, lion, menu" 71 72 author_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 4 4 testfile :relations, :basic 5 5 def test_single 6 do_test(' relations', 'store_context')6 do_test('basic', 'do_each') 7 7 end 8 8 make_tests trunk/test/unit/multiversion_test.rb
r275 r302 417 417 node = secure(Node) { nodes(:lake) } # reload 418 418 assert_equal 2, node.editions.size, "English and french editions" 419 assert_equal ["en" , "fr"], node.traductions.sort419 assert_equal ["en"], node.traductions.map{|t| t[:lang]}.sort 420 420 end 421 421 … … 484 484 node = secure(Node) { nodes(:wiki) } 485 485 trad = node.traductions 486 assert_ equal 0, trad.size486 assert_nil trad, 'no traductions' 487 487 end 488 488 trunk/test/unit/secure_test.rb
r299 r302 330 330 wiki = nodes(:wiki) 331 331 attrs[:parent_id] = wiki[:id] 332 # ant is in 'workers', all should be ok333 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 336 336 assert ! z.new_record? , "Not a new record" 337 337 assert z.errors.empty? , "No errors" 338 338 assert_equal wiki[:rgroup_id], z[:rgroup_id] , "Same rgroup as parent" 339 339 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" 341 341 end 342 342 trunk/test/unit/user_test.rb
r186 r302 26 26 user = User.new("login"=>"john", "password"=>"isjjna78a9h", "group_ids"=>["1", "2"]) 27 27 assert user.save 28 assert_equal 2, user.groups.size28 assert_equal 3, user.groups.size 29 29 end 30 30 … … 33 33 assert_kind_of User, user 34 34 assert !user.new_record?, "Not a new record" 35 assert_equal 1, user.groups.size35 assert_equal 2, user.groups.size 36 36 assert_equal 'public', user.groups[0].name 37 37 end … … 65 65 bob = User.new 66 66 bob.login = 'bob' 67 bob.save 67 68 assert ! bob.save 68 69 assert_not_nil bob.errors[:password] … … 100 101 end 101 102 103 102 104 # TODO: finish tests for User 103 105 # groups
