Commit 924f3a20f3ac143d19d6138e75b0819837256c20
Exists in
staging
and in
42 other branches
Merge branch 'stable'
Showing
12 changed files
with
86 additions
and
23 deletions
Show diff stats
app/models/approve_article.rb
... | ... | @@ -68,6 +68,7 @@ class ApproveArticle < Task |
68 | 68 | end |
69 | 69 | |
70 | 70 | def target_notification_message |
71 | + return nil if target.organization? && !target.moderated_articles? | |
71 | 72 | description + "\n\n" + |
72 | 73 | _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } |
73 | 74 | end | ... | ... |
app/models/task.rb
... | ... | @@ -59,7 +59,7 @@ class Task < ActiveRecord::Base |
59 | 59 | |
60 | 60 | begin |
61 | 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 | 63 | rescue NotImplementedError => ex |
64 | 64 | RAILS_DEFAULT_LOGGER.info ex.to_s |
65 | 65 | end | ... | ... |
app/views/cms/media_listing.rhtml
... | ... | @@ -46,6 +46,17 @@ |
46 | 46 | <% end %> |
47 | 47 | </div><!-- id='media-listing-upload' --> |
48 | 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 | 60 | <div id='media-listing'> |
50 | 61 | <h3><%= _('Folders') %></h3> |
51 | 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 | 15 | def fetch(address) |
16 | 16 | begin |
17 | 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 | 24 | return content |
20 | 25 | rescue Exception => ex |
21 | 26 | raise FeedHandler::FetchError, ex.to_s |
... | ... | @@ -39,4 +44,14 @@ class FeedHandler |
39 | 44 | class ParseError < Exception; end |
40 | 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 | 57 | end | ... | ... |
public/javascripts/application.js
... | ... | @@ -45,12 +45,3 @@ function convToValidIdentifier( str, sep ) { |
45 | 45 | .replace( /ç/g, "c" ) |
46 | 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
test/unit/approve_article_test.rb
... | ... | @@ -2,8 +2,15 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 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 | 13 | should 'have name, reference article and profile' do |
6 | - profile = create_user('test_user').person | |
7 | 14 | article = profile.articles.create!(:name => 'test article') |
8 | 15 | |
9 | 16 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
... | ... | @@ -14,7 +21,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
14 | 21 | end |
15 | 22 | |
16 | 23 | should 'create published article when finished' do |
17 | - profile = create_user('test_user').person | |
18 | 24 | article = profile.articles.create!(:name => 'test article') |
19 | 25 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
20 | 26 | |
... | ... | @@ -24,7 +30,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
24 | 30 | end |
25 | 31 | |
26 | 32 | should 'override target notification message method from Task' do |
27 | - p1 = create_user('testuser1').person | |
33 | + p1 = profile | |
28 | 34 | p2 = create_user('testuser2').person |
29 | 35 | task = AddFriend.new(:person => p1, :friend => p2) |
30 | 36 | assert_nothing_raised NotImplementedError do |
... | ... | @@ -33,7 +39,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
33 | 39 | end |
34 | 40 | |
35 | 41 | should 'have parent if defined' do |
36 | - profile = create_user('test_user').person | |
37 | 42 | article = profile.articles.create!(:name => 'test article') |
38 | 43 | folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') |
39 | 44 | |
... | ... | @@ -43,7 +48,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
43 | 48 | end |
44 | 49 | |
45 | 50 | should 'not have parent if not defined' do |
46 | - profile = create_user('test_user').person | |
47 | 51 | article = profile.articles.create!(:name => 'test article') |
48 | 52 | |
49 | 53 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
... | ... | @@ -52,7 +56,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
52 | 56 | end |
53 | 57 | |
54 | 58 | should 'alert when reference article is removed' do |
55 | - profile = create_user('test_user').person | |
56 | 59 | article = profile.articles.create!(:name => 'test article') |
57 | 60 | |
58 | 61 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) |
... | ... | @@ -64,7 +67,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
64 | 67 | end |
65 | 68 | |
66 | 69 | should 'preserve article_parent' do |
67 | - profile = create_user('test_user').person | |
68 | 70 | article = profile.articles.create!(:name => 'test article') |
69 | 71 | a = ApproveArticle.new(:article_parent => article) |
70 | 72 | |
... | ... | @@ -72,7 +74,6 @@ class ApproveArticleTest < ActiveSupport::TestCase |
72 | 74 | end |
73 | 75 | |
74 | 76 | should 'handle blank names' do |
75 | - profile = create_user('test_user').person | |
76 | 77 | article = profile.articles.create!(:name => 'test article') |
77 | 78 | community = Community.create!(:name => 'test comm') |
78 | 79 | a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) |
... | ... | @@ -81,4 +82,19 @@ class ApproveArticleTest < ActiveSupport::TestCase |
81 | 82 | a.finish |
82 | 83 | end |
83 | 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 | 100 | end | ... | ... |
test/unit/feed_handler_test.rb
... | ... | @@ -73,4 +73,10 @@ class FeedHandlerTest < Test::Unit::TestCase |
73 | 73 | handler.process(container) |
74 | 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 | 82 | end | ... | ... |
test/unit/task_test.rb
... | ... | @@ -207,6 +207,13 @@ class TaskTest < Test::Unit::TestCase |
207 | 207 | end |
208 | 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 | 217 | protected |
211 | 218 | |
212 | 219 | def sample_user | ... | ... |
test/unit/text_article_test.rb
... | ... | @@ -19,5 +19,11 @@ class TextArticleTest < Test::Unit::TestCase |
19 | 19 | article = TextileArticle.create!(:name => 'found article test', :profile => person) |
20 | 20 | assert_equal TextileArticle.find_by_contents('found'), TextArticle.find_by_contents('found') |
21 | 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 | 29 | end | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -35,8 +35,12 @@ class TinyMceArticleTest < Test::Unit::TestCase |
35 | 35 | should 'not translate & to amp; over times' do |
36 | 36 | article = TinyMceArticle.create!(:name => 'link', :body => "<a href='www.invalid.com?param1=value¶m2=value'>link</a>", :profile => profile) |
37 | 37 | assert article.save |
38 | - assert_no_match /&amp;/, article.body | |
39 | - assert_match /&/, article.body | |
38 | + assert_no_match(/&amp;/, article.body) | |
39 | + assert_match(/&/, article.body) | |
40 | 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 | 46 | end | ... | ... |
vendor/plugins/white_list_sanitizer_unescape_before_reescape/init.rb
... | ... | @@ -4,6 +4,13 @@ |
4 | 4 | # this was solved in rails 2.2.1, then remove this patch when upgrade to it |
5 | 5 | |
6 | 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(/<!--/, '<!--') if text | |
11 | + end | |
12 | + alias_method_chain :sanitize, :filter_comments | |
13 | + | |
7 | 14 | # unescape before reescape to avoid: |
8 | 15 | # & -> & -> &amp; -> &amp;amp; -> &amp;amp;amp; -> etc |
9 | 16 | protected | ... | ... |