Commit 924f3a20f3ac143d19d6138e75b0819837256c20

Authored by Antonio Terceiro
2 parents 3c321efd f442790a

Merge branch 'stable'

app/models/approve_article.rb
@@ -68,6 +68,7 @@ class ApproveArticle < Task @@ -68,6 +68,7 @@ class ApproveArticle < Task
68 end 68 end
69 69
70 def target_notification_message 70 def target_notification_message
  71 + return nil if target.organization? && !target.moderated_articles?
71 description + "\n\n" + 72 description + "\n\n" +
72 _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } 73 _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name }
73 end 74 end
app/models/task.rb
@@ -59,7 +59,7 @@ class Task < ActiveRecord::Base @@ -59,7 +59,7 @@ class Task < ActiveRecord::Base
59 59
60 begin 60 begin
61 target_msg = task.target_notification_message 61 target_msg = task.target_notification_message
62 - TaskMailer.deliver_target_notification(task, target_msg) 62 + TaskMailer.deliver_target_notification(task, target_msg) if target_msg
63 rescue NotImplementedError => ex 63 rescue NotImplementedError => ex
64 RAILS_DEFAULT_LOGGER.info ex.to_s 64 RAILS_DEFAULT_LOGGER.info ex.to_s
65 end 65 end
app/views/cms/media_listing.rhtml
@@ -46,6 +46,17 @@ @@ -46,6 +46,17 @@
46 <% end %> 46 <% end %>
47 </div><!-- id='media-listing-upload' --> 47 </div><!-- id='media-listing-upload' -->
48 <hr/> 48 <hr/>
  49 +
  50 + <script type='text/javascript'>
  51 + document.observe("dom:loaded", function() {
  52 + Event.addBehavior.reassignAfterAjax = true;
  53 + Event.addBehavior({
  54 + 'div#pagination-images .pagination a' : Remote.Link,
  55 + 'div#pagination-documents .pagination a' : Remote.Link
  56 + })
  57 + });
  58 + </script>
  59 +
49 <div id='media-listing'> 60 <div id='media-listing'>
50 <h3><%= _('Folders') %></h3> 61 <h3><%= _('Folders') %></h3>
51 <p><%= _('Drag images and documents to add them to the text. If needed, resize images by clicking the tree icon on editor.') %></p> 62 <p><%= _('Drag images and documents to add them to the text. If needed, resize images by clicking the tree icon on editor.') %></p>
lib/feed_handler.rb
@@ -15,7 +15,12 @@ class FeedHandler @@ -15,7 +15,12 @@ class FeedHandler
15 def fetch(address) 15 def fetch(address)
16 begin 16 begin
17 content = "" 17 content = ""
18 - open(address) do |s| content = s.read end 18 + block = lambda { |s| content = s.read }
  19 + content = if is_web_address?(address)
  20 + open( address, "User-Agent" => "Noosfero/#{Noosfero::VERSION}", &block )
  21 + else
  22 + open_uri_original_open(address, &block)
  23 + end
19 return content 24 return content
20 rescue Exception => ex 25 rescue Exception => ex
21 raise FeedHandler::FetchError, ex.to_s 26 raise FeedHandler::FetchError, ex.to_s
@@ -39,4 +44,14 @@ class FeedHandler @@ -39,4 +44,14 @@ class FeedHandler
39 class ParseError < Exception; end 44 class ParseError < Exception; end
40 class FetchError < Exception; end 45 class FetchError < Exception; end
41 46
  47 + protected
  48 +
  49 + # extracted from the open implementation in the open-uri library
  50 + def is_web_address?(address)
  51 + address.respond_to?(:open) ||
  52 + address.respond_to?(:to_str) &&
  53 + (%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ address) &&
  54 + URI.parse(address).respond_to?(:open)
  55 + end
  56 +
42 end 57 end
public/javascripts/application.js
@@ -45,12 +45,3 @@ function convToValidIdentifier( str, sep ) { @@ -45,12 +45,3 @@ function convToValidIdentifier( str, sep ) {
45 .replace( /ç/g, "c" ) 45 .replace( /ç/g, "c" )
46 .replace( /[^-_a-z0-9.]+/g, sep ) 46 .replace( /[^-_a-z0-9.]+/g, sep )
47 } 47 }
48 -  
49 -document.observe("dom:loaded", function() {  
50 - Event.addBehavior.reassignAfterAjax = true;  
51 - Event.addBehavior({  
52 - 'div#pagination-images .pagination a' : Remote.Link,  
53 - 'div#pagination-documents .pagination a' : Remote.Link  
54 - })  
55 -});  
56 -  
public/javascripts/lightbox.js
@@ -53,7 +53,6 @@ function checkIt(string) { @@ -53,7 +53,6 @@ function checkIt(string) {
53 53
54 Event.observe(window, 'load', initialize, false); 54 Event.observe(window, 'load', initialize, false);
55 Event.observe(window, 'load', getBrowserInfo, false); 55 Event.observe(window, 'load', getBrowserInfo, false);
56 -Event.observe(window, 'unload', Event.unloadCache, false);  
57 56
58 var lightbox = Class.create(); 57 var lightbox = Class.create();
59 58
test/unit/approve_article_test.rb
@@ -2,8 +2,15 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -2,8 +2,15 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2
3 class ApproveArticleTest < ActiveSupport::TestCase 3 class ApproveArticleTest < ActiveSupport::TestCase
4 4
  5 + def setup
  6 + ActionMailer::Base.delivery_method = :test
  7 + ActionMailer::Base.perform_deliveries = true
  8 + ActionMailer::Base.deliveries = []
  9 + @profile = create_user('test_user').person
  10 + end
  11 + attr_reader :profile
  12 +
5 should 'have name, reference article and profile' do 13 should 'have name, reference article and profile' do
6 - profile = create_user('test_user').person  
7 article = profile.articles.create!(:name => 'test article') 14 article = profile.articles.create!(:name => 'test article')
8 15
9 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 16 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
@@ -14,7 +21,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -14,7 +21,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
14 end 21 end
15 22
16 should 'create published article when finished' do 23 should 'create published article when finished' do
17 - profile = create_user('test_user').person  
18 article = profile.articles.create!(:name => 'test article') 24 article = profile.articles.create!(:name => 'test article')
19 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 25 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
20 26
@@ -24,7 +30,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -24,7 +30,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
24 end 30 end
25 31
26 should 'override target notification message method from Task' do 32 should 'override target notification message method from Task' do
27 - p1 = create_user('testuser1').person 33 + p1 = profile
28 p2 = create_user('testuser2').person 34 p2 = create_user('testuser2').person
29 task = AddFriend.new(:person => p1, :friend => p2) 35 task = AddFriend.new(:person => p1, :friend => p2)
30 assert_nothing_raised NotImplementedError do 36 assert_nothing_raised NotImplementedError do
@@ -33,7 +39,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -33,7 +39,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
33 end 39 end
34 40
35 should 'have parent if defined' do 41 should 'have parent if defined' do
36 - profile = create_user('test_user').person  
37 article = profile.articles.create!(:name => 'test article') 42 article = profile.articles.create!(:name => 'test article')
38 folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') 43 folder = profile.articles.create!(:name => 'test folder', :type => 'Folder')
39 44
@@ -43,7 +48,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -43,7 +48,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
43 end 48 end
44 49
45 should 'not have parent if not defined' do 50 should 'not have parent if not defined' do
46 - profile = create_user('test_user').person  
47 article = profile.articles.create!(:name => 'test article') 51 article = profile.articles.create!(:name => 'test article')
48 52
49 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 53 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
@@ -52,7 +56,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -52,7 +56,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
52 end 56 end
53 57
54 should 'alert when reference article is removed' do 58 should 'alert when reference article is removed' do
55 - profile = create_user('test_user').person  
56 article = profile.articles.create!(:name => 'test article') 59 article = profile.articles.create!(:name => 'test article')
57 60
58 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 61 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
@@ -64,7 +67,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -64,7 +67,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
64 end 67 end
65 68
66 should 'preserve article_parent' do 69 should 'preserve article_parent' do
67 - profile = create_user('test_user').person  
68 article = profile.articles.create!(:name => 'test article') 70 article = profile.articles.create!(:name => 'test article')
69 a = ApproveArticle.new(:article_parent => article) 71 a = ApproveArticle.new(:article_parent => article)
70 72
@@ -72,7 +74,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -72,7 +74,6 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
72 end 74 end
73 75
74 should 'handle blank names' do 76 should 'handle blank names' do
75 - profile = create_user('test_user').person  
76 article = profile.articles.create!(:name => 'test article') 77 article = profile.articles.create!(:name => 'test article')
77 community = Community.create!(:name => 'test comm') 78 community = Community.create!(:name => 'test comm')
78 a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) 79 a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
@@ -81,4 +82,19 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -81,4 +82,19 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
81 a.finish 82 a.finish
82 end 83 end
83 end 84 end
  85 +
  86 + should 'notify target if group is moderated' do
  87 + article = profile.articles.create!(:name => 'test article')
  88 + community = Community.create!(:name => 'test comm', :moderated_articles => true)
  89 + a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
  90 + assert !ActionMailer::Base.deliveries.empty?
  91 + end
  92 +
  93 + should 'not notify target if group is not moderated' do
  94 + article = profile.articles.create!(:name => 'test article')
  95 + community = Community.create!(:name => 'test comm', :moderated_articles => false)
  96 + a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
  97 + assert ActionMailer::Base.deliveries.empty?
  98 + end
  99 +
84 end 100 end
test/unit/feed_handler_test.rb
@@ -73,4 +73,10 @@ class FeedHandlerTest &lt; Test::Unit::TestCase @@ -73,4 +73,10 @@ class FeedHandlerTest &lt; Test::Unit::TestCase
73 handler.process(container) 73 handler.process(container)
74 end 74 end
75 75
  76 + should 'identifies itself as noosfero user agent' do
  77 + handler = FeedHandler.new
  78 + handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}"}, anything).returns('bli content')
  79 + assert_equal 'bli content', handler.fetch('http://site.org/feed.xml')
  80 + end
  81 +
76 end 82 end
test/unit/task_test.rb
@@ -207,6 +207,13 @@ class TaskTest &lt; Test::Unit::TestCase @@ -207,6 +207,13 @@ class TaskTest &lt; Test::Unit::TestCase
207 end 207 end
208 end 208 end
209 209
  210 + should 'not notify target if message is nil' do
  211 + task = Task.new
  212 + task.stubs(:target_notification_message).returns(nil)
  213 + TaskMailer.expects(:deliver_target_notification).never
  214 + task.save!
  215 + end
  216 +
210 protected 217 protected
211 218
212 def sample_user 219 def sample_user
test/unit/text_article_test.rb
@@ -19,5 +19,11 @@ class TextArticleTest &lt; Test::Unit::TestCase @@ -19,5 +19,11 @@ class TextArticleTest &lt; Test::Unit::TestCase
19 article = TextileArticle.create!(:name => 'found article test', :profile => person) 19 article = TextileArticle.create!(:name => 'found article test', :profile => person)
20 assert_equal TextileArticle.find_by_contents('found'), TextArticle.find_by_contents('found') 20 assert_equal TextileArticle.find_by_contents('found'), TextArticle.find_by_contents('found')
21 end 21 end
22 - 22 +
  23 + should 'remove comments from TextArticle body' do
  24 + person = create_user('testuser').person
  25 + article = TextArticle.create!(:profile => person, :name => 'article', :body => "the <!-- comment --> article ...")
  26 + assert_equal "the article ...", article.body
  27 + end
  28 +
23 end 29 end
test/unit/tiny_mce_article_test.rb
@@ -35,8 +35,12 @@ class TinyMceArticleTest &lt; Test::Unit::TestCase @@ -35,8 +35,12 @@ class TinyMceArticleTest &lt; Test::Unit::TestCase
35 should 'not translate & to amp; over times' do 35 should 'not translate & to amp; over times' do
36 article = TinyMceArticle.create!(:name => 'link', :body => "<a href='www.invalid.com?param1=value&param2=value'>link</a>", :profile => profile) 36 article = TinyMceArticle.create!(:name => 'link', :body => "<a href='www.invalid.com?param1=value&param2=value'>link</a>", :profile => profile)
37 assert article.save 37 assert article.save
38 - assert_no_match /&amp;amp;/, article.body  
39 - assert_match /&amp;/, article.body 38 + assert_no_match(/&amp;amp;/, article.body)
  39 + assert_match(/&amp;/, article.body)
40 end 40 end
41 41
  42 + should 'not escape comments from tiny mce article body' do
  43 + article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!-- comment --> article ...")
  44 + assert_equal "the <!-- comment --> article ...", article.body
  45 + end
42 end 46 end
vendor/plugins/white_list_sanitizer_unescape_before_reescape/init.rb
@@ -4,6 +4,13 @@ @@ -4,6 +4,13 @@
4 # this was solved in rails 2.2.1, then remove this patch when upgrade to it 4 # this was solved in rails 2.2.1, then remove this patch when upgrade to it
5 5
6 HTML::WhiteListSanitizer.module_eval do 6 HTML::WhiteListSanitizer.module_eval do
  7 +
  8 + def sanitize_with_filter_comments(*args, &block)
  9 + text = sanitize_without_filter_comments(*args, &block)
  10 + text.gsub(/&lt;!--/, '<!--') if text
  11 + end
  12 + alias_method_chain :sanitize, :filter_comments
  13 +
7 # unescape before reescape to avoid: 14 # unescape before reescape to avoid:
8 # & -> &amp; -> &amp;amp; -> &amp;amp;amp; -> &amp;amp;amp;amp; -> etc 15 # & -> &amp; -> &amp;amp; -> &amp;amp;amp; -> &amp;amp;amp;amp; -> etc
9 protected 16 protected