Commit 630d23848b60862d3788133d3be2475daacb8fad

Authored by Rodrigo Souto
2 parents 0ce4ec09 a76f7cae

Merge branch 'stable'

AUTHORS
... ... @@ -153,6 +153,7 @@ Leandro Nunes dos Santos <leandronunes@gmail.com>
153 153 Leandro Nunes dos Santos <leandro.santos@serpro.gov.br>
154 154 LinguÁgil 2010 <linguagil.bahia@gmail.com>
155 155 Lucas Melo <lucas@colivre.coop.br>
  156 +Lucas Melo <lucaspradomelo@gmail.com>
156 157 Luis David Aguilar Carlos <ludwig9003@gmail.com>
157 158 Martín Olivera <molivera@solar.org.ar>
158 159 Moises Machado <moises@colivre.coop.br>
... ...
app/helpers/application_helper.rb
... ... @@ -1345,10 +1345,7 @@ module ApplicationHelper
1345 1345 options[:on_ready] ||= 'null'
1346 1346  
1347 1347 result = text_field_tag(name, nil, text_field_options.merge(html_options.merge({:id => element_id})))
1348   - result +=
1349   - "
1350   - <script type='text/javascript'>
1351   - jQuery('##{element_id}')
  1348 + result += javascript_tag("jQuery('##{element_id}')
1352 1349 .tokenInput('#{url_for(search_action)}', {
1353 1350 minChars: #{options[:min_chars].to_json},
1354 1351 prePopulate: #{options[:pre_populate].to_json},
... ... @@ -1364,16 +1361,15 @@ module ApplicationHelper
1364 1361 onAdd: #{options[:on_add]},
1365 1362 onDelete: #{options[:on_delete]},
1366 1363 onReady: #{options[:on_ready]},
1367   - })
1368   - "
1369   - result += options[:focus] ? ".focus();" : ";"
  1364 + });
  1365 + ")
  1366 + result += javascript_tag("jQuery('##{element_id}').focus();") if options[:focus]
1370 1367 if options[:avoid_enter]
1371   - result += "jQuery('#token-input-#{element_id}')
  1368 + result += javascript_tag("jQuery('#token-input-#{element_id}')
1372 1369 .live('keydown', function(event){
1373 1370 if(event.keyCode == '13') return false;
1374   - });"
  1371 + });")
1375 1372 end
1376   - result += "</script>"
1377 1373 result
1378 1374 end
1379 1375  
... ...
app/models/blog.rb
... ... @@ -82,4 +82,8 @@ class Blog &lt; Folder
82 82 posts.empty?
83 83 end
84 84  
  85 + def last_posts(limit=3)
  86 + posts.where("type != 'RssFeed'").order(:updated_at).limit(limit)
  87 + end
  88 +
85 89 end
... ...
app/models/blog_archives_block.rb
... ... @@ -21,18 +21,22 @@ class BlogArchivesBlock &lt; Block
21 21 end
22 22  
23 23 def visible_posts(person)
24   - blog.posts.native_translations.select {|post| post.display_to?(person)}
  24 + #FIXME Performance issues with display_to. Must convert it to a scope.
  25 + # Checkout this page for further information: http://noosfero.org/Development/ActionItem2705
  26 + blog.posts.published.native_translations #.select {|post| post.display_to?(person)}
25 27 end
26 28  
27 29 def content(args={})
28 30 owner_blog = self.blog
29 31 return nil unless owner_blog
30 32 results = ''
31   - visible_posts(args[:person]).group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year|
32   - results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
  33 + posts = visible_posts(args[:person])
  34 + posts.count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count|
  35 + results << content_tag('li', content_tag('strong', "#{year} (#{count})"))
33 36 results << "<ul class='#{year}-archive'>"
34   - results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month|
35   - results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner_blog.url.merge(:year => year, :month => month[0])))
  37 + posts.count(:all, :conditions => ['EXTRACT(YEAR FROM published_at)=?', year], :group => 'EXTRACT(MONTH FROM published_at)').sort_by {|month, count| -month.to_i}.each do |month, count|
  38 + month_name = gettext(MONTHS[month.to_i - 1])
  39 + results << content_tag('li', link_to("#{month_name} (#{count})", owner_blog.url.merge(:year => year, :month => month)))
36 40 end
37 41 results << "</ul>"
38 42 end
... ...
app/views/search/_full_blog.html.erb
... ... @@ -7,12 +7,12 @@
7 7 <tr class="search-blog-items">
8 8 <td class="search-field-label"><%= _("Last posts") %></td>
9 9  
10   - <% r = blog.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %>
11   - <td class="<%= "search-field-none" if r.empty? %>">
12   - <% r.each do |a| %>
13   - <%= link_to a.title, a.view_url, :class => 'search-blog-sample-item '+icon_for_article(a) %>
  10 + <% last_posts = blog.last_posts %>
  11 + <td class="<%= "search-field-none" if last_posts.empty? %>">
  12 + <% last_posts.each do |post| %>
  13 + <%= link_to post.title, post.view_url, :class => 'search-blog-sample-item '+icon_for_article(post) %>
14 14 <% end %>
15   - <%= _('None') if r.empty? %>
  15 + <%= _('None') if last_posts.empty? %>
16 16 </td>
17 17 </tr>
18 18  
... ...
debian/changelog
  1 +noosfero (0.43.1) unstable; urgency=low
  2 +
  3 + * Bugfix release
  4 +
  5 + -- Rodrigo Souto <rodrigo@colivre.coop.br> Wed, 17 Jul 2013 01:20:46 -0300
  6 +
1 7 noosfero (0.43.0) unstable; urgency=low
2 8  
3 9 * Solr search converted to a plugin
... ...
lib/noosfero.rb
... ... @@ -3,7 +3,7 @@ require &#39;fast_gettext&#39;
3 3  
4 4 module Noosfero
5 5 PROJECT = 'noosfero'
6   - VERSION = '0.43.0'
  6 + VERSION = '0.43.1'
7 7  
8 8 def self.pattern_for_controllers_in_directory(dir)
9 9 disjunction = controllers_in_directory(dir).join('|')
... ...
plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb
... ... @@ -70,7 +70,8 @@ class CustomFormsPluginMyprofileController &lt; MyProfileController
70 70 private
71 71  
72 72 def new_fields(params)
73   - result = params[:fields].map {|id, hash| hash.has_key?(:real_id) ? nil : hash}.compact
  73 + keys = params[:fields].keys.sort{|a, b| a.to_i <=> b.to_i}
  74 + result = keys.map { |id| (hash = params[:fields][id]).has_key?(:real_id) ? nil : hash}.compact
74 75 result.delete_if {|field| field[:name].blank?}
75 76 result
76 77 end
... ...
plugins/custom_forms/db/migrate/20130702120732_add_position_to_custom_forms_plugin_fields.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class AddPositionToCustomFormsPluginFields < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :custom_forms_plugin_fields do |t|
  4 + t.integer :position, :default => 0
  5 + end
  6 + end
  7 +
  8 + def self.down
  9 + change_table :custom_forms_plugin_fields do |t|
  10 + t.remove :position
  11 + end
  12 + end
  13 +end
... ...
plugins/custom_forms/lib/custom_forms_plugin/field.rb
... ... @@ -12,5 +12,11 @@ class CustomFormsPlugin::Field &lt; ActiveRecord::Base
12 12 before_validation do |field|
13 13 field.slug = field.name.to_slug if field.name.present?
14 14 end
  15 +
  16 + before_create do |field|
  17 + if field.form.fields.exists?
  18 + field.position = field.form.fields.order('position').last.position + 1
  19 + end
  20 + end
15 21 end
16 22  
... ...
plugins/custom_forms/lib/custom_forms_plugin/form.rb
1 1 class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord
2 2 belongs_to :profile
3 3  
4   - has_many :fields, :class_name => 'CustomFormsPlugin::Field', :dependent => :destroy
  4 + has_many :fields, :class_name => 'CustomFormsPlugin::Field', :dependent => :destroy, :order => 'position'
5 5 has_many :submissions, :class_name => 'CustomFormsPlugin::Submission'
6 6  
7 7 serialize :access
... ...
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... ... @@ -40,7 +40,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase
40 40 should 'create a form' do
41 41 format = '%Y-%m-%d %H:%M'
42 42 begining = Time.now.strftime(format)
43   - ending = (Time.now + 1.day).strftime('%Y-%m-%d %H:%M')
  43 + ending = (Time.now + 1.day).strftime(format)
44 44 assert_difference CustomFormsPlugin::Form, :count, 1 do
45 45 post :create, :profile => profile.identifier,
46 46 :form => {
... ... @@ -90,12 +90,42 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase
90 90 assert f2.kind_of?(CustomFormsPlugin::SelectField)
91 91 end
92 92  
  93 + should 'create fields in the order they are sent' do
  94 + format = '%Y-%m-%d %H:%M'
  95 + num_fields = 10
  96 + begining = Time.now.strftime(format)
  97 + ending = (Time.now + 1.day).strftime(format)
  98 + fields = {}
  99 + num_fields.times do |i|
  100 + fields[i.to_s] = {
  101 + :name => i.to_s,
  102 + :default_value => '',
  103 + :type => 'text_field'
  104 + }
  105 + end
  106 + assert_difference CustomFormsPlugin::Form, :count, 1 do
  107 + post :create, :profile => profile.identifier,
  108 + :form => {
  109 + :name => 'My Form',
  110 + :access => 'logged',
  111 + :begining => begining,
  112 + :ending => ending,
  113 + :description => 'Cool form'},
  114 + :fields => fields
  115 + end
  116 + form = CustomFormsPlugin::Form.find_by_name('My Form')
  117 + assert_equal num_fields, form.fields.count
  118 + form.fields.find_each do |f|
  119 + assert_equal f.position, f.name.to_i
  120 + end
  121 + end
  122 +
93 123 should 'edit a form' do
94 124 form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software')
95 125 field = CustomFormsPlugin::TextField.create!(:form => form, :name => 'License')
96 126 format = '%Y-%m-%d %H:%M'
97 127 begining = Time.now.strftime(format)
98   - ending = (Time.now + 1.day).strftime('%Y-%m-%d %H:%M')
  128 + ending = (Time.now + 1.day).strftime(format)
99 129  
100 130 post :edit, :profile => profile.identifier, :id => form.id,
101 131 :form => {:name => 'My Form', :access => 'logged', :begining => begining, :ending => ending, :description => 'Cool form'},
... ...
plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb
... ... @@ -71,5 +71,15 @@ class CustomFormsPlugin::FieldTest &lt; ActiveSupport::TestCase
71 71 end
72 72 assert_equal form.fields, [license_field]
73 73 end
  74 +
  75 + should 'give positions by creation order' do
  76 + form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile))
  77 + field_0 = CustomFormsPlugin::Field.create!(:name => 'License', :form => form)
  78 + field_1 = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form)
  79 + field_2 = CustomFormsPlugin::Field.create!(:name => 'Wiki', :form => form)
  80 + assert_equal 0, field_0.position
  81 + assert_equal 1, field_1.position
  82 + assert_equal 2, field_2.position
  83 + end
74 84 end
75 85  
... ...
public/javascripts/chat.js
... ... @@ -99,6 +99,7 @@ jQuery(function($) {
99 99 },
100 100  
101 101 render_body_message: function(body) {
  102 + body = body.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r?\n/g, '<br>');
102 103 body = $().emoticon(body);
103 104 body = linkify(body, {
104 105 callback: function(text, href) {
... ...
test/unit/blog_archives_block_test.rb
... ... @@ -38,7 +38,7 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
38 38 end
39 39 block = BlogArchivesBlock.new
40 40 block.stubs(:owner).returns(profile)
41   - assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ }
  41 + assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ }
42 42 end
43 43  
44 44 should 'order list of amount posts' do
... ... @@ -131,7 +131,7 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
131 131 end
132 132 block = BlogArchivesBlock.new
133 133 block.stubs(:owner).returns(profile)
134   - assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ }
  134 + assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ }
135 135 end
136 136  
137 137 should 'not try to load a removed blog' do
... ... @@ -157,22 +157,25 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
157 157 end
158 158 end
159 159  
160   - should 'not count articles if the user can\'t see them' do
161   - person = create_user('testuser').person
162   - blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path')
163   - block = fast_create(BlogArchivesBlock)
164   -
165   - feed = mock()
166   - feed.stubs(:url).returns(blog.url)
167   - blog.stubs(:feed).returns(feed)
168   - block.stubs(:blog).returns(blog)
169   - block.stubs(:owner).returns(profile)
170   -
171   - public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan'))
172   - private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan'))
173   -
174   - assert_match /January \(1\)/, block.content({:person => person})
175   - assert_match /January \(1\)/, block.content()
176   - assert_match /January \(2\)/, block.content({:person => profile})
177   - end
  160 +#FIXME Performance issues with display_to. Must convert it to a scope.
  161 +# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705
  162 +#
  163 +# should 'not count articles if the user can\'t see them' do
  164 +# person = create_user('testuser').person
  165 +# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path')
  166 +# block = fast_create(BlogArchivesBlock)
  167 +#
  168 +# feed = mock()
  169 +# feed.stubs(:url).returns(blog.url)
  170 +# blog.stubs(:feed).returns(feed)
  171 +# block.stubs(:blog).returns(blog)
  172 +# block.stubs(:owner).returns(profile)
  173 +#
  174 +# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan'))
  175 +# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan'))
  176 +#
  177 +# assert_match /January \(1\)/, block.content({:person => person})
  178 +# assert_match /January \(1\)/, block.content()
  179 +# assert_match /January \(2\)/, block.content({:person => profile})
  180 +# end
178 181 end
... ...