Commit fb293ae3ae41d3820f0fb8e2778111ba6b0b94e7

Authored by Victor Costa
2 parents 230eab09 cc9cebd9

Merge branch 'master' into stable

app/controllers/my_profile/profile_members_controller.rb
... ... @@ -20,7 +20,7 @@ class ProfileMembersController < MyProfileController
20 20 redirect_to :action => :last_admin
21 21 elsif @person.define_roles(@roles, profile)
22 22 session[:notice] = _('Roles successfuly updated')
23   - redirect_to :controller => 'profile_editor'
  23 + redirect_to :action => 'index'
24 24 else
25 25 session[:notice] = _('Couldn\'t change the roles')
26 26 redirect_to :action => 'index'
... ...
app/helpers/application_helper.rb
... ... @@ -862,8 +862,9 @@ module ApplicationHelper
862 862 end
863 863  
864 864 def base_url
865   - environment.top_url
  865 + environment.top_url(request.scheme)
866 866 end
  867 + alias :top_url :base_url
867 868  
868 869 def helper_for_article(article)
869 870 article_helper = ActionView::Base.new
... ...
app/helpers/tinymce_helper.rb
... ... @@ -11,7 +11,7 @@ module TinymceHelper
11 11 end
12 12  
13 13 def tinymce_init_js options = {}
14   - options.merge! :document_base_url => environment.top_url,
  14 + options.merge! :document_base_url => top_url,
15 15 :content_css => "/stylesheets/tinymce.css,#{macro_css_files}",
16 16 :plugins => %w[compat3x advlist autolink lists link image charmap print preview hr anchor pagebreak
17 17 searchreplace wordcount visualblocks visualchars code fullscreen
... ...
app/models/environment.rb
... ... @@ -663,8 +663,8 @@ class Environment < ActiveRecord::Base
663 663 { :controller => 'admin_panel', :action => 'index' }
664 664 end
665 665  
666   - def top_url
667   - url = 'http://'
  666 + def top_url(scheme = 'http')
  667 + url = scheme + '://'
668 668 url << (Noosfero.url_options.key?(:host) ? Noosfero.url_options[:host] : default_hostname)
669 669 url << ':' << Noosfero.url_options[:port].to_s if Noosfero.url_options.key?(:port)
670 670 url << Noosfero.root('')
... ... @@ -943,6 +943,10 @@ class Environment &lt; ActiveRecord::Base
943 943 locales_list
944 944 end
945 945  
  946 + def has_license?
  947 + self.licenses.any?
  948 + end
  949 +
946 950 private
947 951  
948 952 def default_language_available
... ...
app/models/profile.rb
... ... @@ -161,6 +161,7 @@ class Profile &lt; ActiveRecord::Base
161 161 scope :visible, :conditions => { :visible => true }
162 162 scope :disabled, :conditions => { :visible => false }
163 163 scope :public, :conditions => { :visible => true, :public_profile => true }
  164 + scope :enabled, :conditions => { :enabled => true }
164 165  
165 166 # Subclasses must override this method
166 167 scope :more_popular
... ... @@ -430,7 +431,7 @@ class Profile &lt; ActiveRecord::Base
430 431 end
431 432  
432 433 xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation'
433   - xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list', :on => 'validation'
  434 + xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list'
434 435  
435 436 include WhiteListFilter
436 437 filter_iframes :custom_header, :custom_footer
... ...
app/views/cms/_general_fields.html.erb
1 1 <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id) %>
2   -<%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %>
  2 +<% if profile.environment.has_license? %>
  3 + <%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %>
  4 +<% end %>
... ...
app/views/enterprise_registration/basic_information.html.erb
... ... @@ -20,7 +20,7 @@
20 20  
21 21 <%= labelled_form_for :create_enterprise do |f| %>
22 22 <%= required f.text_field 'name', :onchange => "updateUrlField(this, 'create_enterprise_identifier')", :size => 40 %>
23   - <%= required labelled_form_field(_('Address'), content_tag('code', environment.top_url + "/" + text_field(:create_enterprise, 'identifier', :size => 26))) %>
  23 + <%= required labelled_form_field(_('Address'), content_tag('code', top_url + "/" + text_field(:create_enterprise, 'identifier', :size => 26))) %>
24 24 <%= render :partial => 'shared/organization_custom_fields', :locals => { :f => f, :object_name => :create_enterprise, :profile => @create_enterprise } %>
25 25 <%= required labelled_form_field(_('Region'), f.select('region_id', @regions)) if @validation == :region %>
26 26  
... ...
app/views/layouts/application-ng.html.erb
... ... @@ -14,7 +14,7 @@
14 14  
15 15 <!-- Open Graph -->
16 16 <meta property="og:type" content="<%= @page ? 'article' : 'website' %>">
17   - <meta property="og:url" content="<%= @page ? url_for(@page.url) : @environment.top_url %>">
  17 + <meta property="og:url" content="<%= @page ? url_for(@page.url) : top_url %>">
18 18 <meta property="og:title" content="<%= h page_title %>">
19 19 <meta property="og:site_name" content="<%= profile ? profile.name : @environment.name %>">
20 20 <meta property="og:description" content="<%= meta_description_tag(@page) %>">
... ...
app/views/layouts/application.html.erb
... ... @@ -68,7 +68,7 @@
68 68  
69 69 <div id="navigation_bar">
70 70 <%= link_to "<span>"+ @environment.name() +"</span>",
71   - @environment.top_url,
  71 + top_url,
72 72 :id=>"menu_link_to_envhome",
73 73 :title=>@environment.name %>
74 74 <% unless environment.enabled?(:disable_categories) %>
... ...
config/application.rb
... ... @@ -113,9 +113,6 @@ module Noosfero
113 113 config.secret_token = noosfero_session_secret
114 114 config.session_store :cookie_store, :key => '_noosfero_session'
115 115  
116   - config.time_zone = File.read('/etc/timezone').split("\n").first
117   - config.active_record.default_timezone = :local
118   -
119 116 config.paths['db/migrate'] += Dir.glob "#{Rails.root}/{baseplugins,config/plugins}/*/db/migrate"
120 117 config.i18n.load_path += Dir.glob "#{Rails.root}/{baseplugins,config/plugins}/*/locales/*.{rb,yml}"
121 118  
... ...
config/initializers/noosfero_urls.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +if Rails.env == 'development'
  2 + ActionController::Base.send(:prepend_before_filter) do |controller|
  3 + # XXX note that this is not thread-safe! Accessing a Noosfero instance in
  4 + # development mode under different ports concurrently _will_ lead to weird
  5 + # things happening.
  6 + if [80,443].include?(controller.request.port)
  7 + url_options = {}
  8 + else
  9 + url_options = { :port => controller.request.port }
  10 + end
  11 + Noosfero.instance_variable_set('@development_url_options', url_options)
  12 + end
  13 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20150113131617) do
  14 +ActiveRecord::Schema.define(:version => 20150122165042) do
15 15  
16 16 create_table "abuse_reports", :force => true do |t|
17 17 t.integer "reporter_id"
... ...
etc/pound.cfg
... ... @@ -23,6 +23,7 @@ End
23 23  
24 24 ListenHTTPS
25 25 Address 0.0.0.0
  26 + AddHeader "X-Forwarded-Proto: https"
26 27 Port 443
27 28 Cert "/etc/noosfero/ssl/noosfero.pem"
28 29 Ciphers "ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM"
... ...
features/step_definitions/activate_enterprise_steps.rb
... ... @@ -19,7 +19,7 @@ Given /^&quot;([^\&quot;]*)&quot; is the active enterprise template$/ do |enterprise|
19 19 template.save!
20 20  
21 21 e = Environment.default
22   - e.enterprise_template = template
  22 + e.enterprise_default_template = template
23 23 e.save
24 24 end
25 25  
... ...
lib/tasks/ci.rake
... ... @@ -5,7 +5,13 @@ namespace :ci do
5 5  
6 6 current_branch = `git rev-parse --abbrev-ref HEAD`.strip
7 7 from = ENV['PREV_HEAD'] || "origin/#{current_branch}"
  8 + if !system("git show-ref --verify --quiet refs/remotes/#{from}")
  9 + from = 'origin/master'
  10 + end
8 11 to = ENV['HEAD'] || current_branch
  12 +
  13 + puts "Testing changes between #{from} and #{to} ..."
  14 +
9 15 changed_files = `git diff --name-only #{from}..#{to}`.split.select do |f|
10 16 File.exist?(f) && f.split(File::SEPARATOR).first != 'vendor'
11 17 end
... ... @@ -33,14 +39,23 @@ namespace :ci do
33 39 end
34 40 end
35 41  
  42 + if tests.empty? && features.empty? && changed_plugins.empty?
  43 + puts "Could not figure out specific changes to be tested in isolation!"
  44 + end
  45 + puts
  46 +
36 47 sh 'testrb', '-Itest', *tests unless tests.empty?
37 48 sh 'cucumber', *features unless features.empty?
38 49 sh 'xvfb-run', 'cucumber', '-p', 'selenium', *features unless features.empty?
39 50  
40 51 changed_plugins.each do |plugin|
41   - task = "test:noosfero_plugins:#{plugin}"
42   - puts "Running #{task}"
43   - Rake::Task[task].execute
  52 + if $broken_plugins.include?(plugin)
  53 + puts "Skipping plugins/#{plugin}: marked as broken"
  54 + else
  55 + task = "test:noosfero_plugins:#{plugin}"
  56 + puts "Running #{task}"
  57 + Rake::Task[task].execute
  58 + end
44 59 end
45 60  
46 61 end
... ...
lib/tasks/plugins_tests.rake
1   -@broken_plugins = %w[
  1 +$broken_plugins = %w[
2 2 anti_spam
3 3 bsc
4 4 comment_classification
5 5 ldap
6 6 solr
  7 + stoa
7 8 ]
8 9  
9 10 @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template']
... ... @@ -204,14 +205,14 @@ namespace :test do
204 205 @all_tasks.each do |taskname|
205 206 desc "Run #{taskname} tests for all plugins"
206 207 task taskname do
207   - test_sequence(@all_plugins - @broken_plugins, taskname)
  208 + test_sequence(@all_plugins - $broken_plugins, taskname)
208 209 end
209 210 end
210 211 end
211 212  
212 213 desc "Run all tests for all plugins"
213 214 task :noosfero_plugins do
214   - test_sequence(@all_plugins - @broken_plugins, @all_tasks) do |failed|
  215 + test_sequence(@all_plugins - $broken_plugins, @all_tasks) do |failed|
215 216 plugins_status_report(failed)
216 217 end
217 218 end
... ... @@ -228,7 +229,7 @@ def plugins_status_report(failed)
228 229 printf ('-' * w) + ' ' + ('-' * 20) + "\n"
229 230  
230 231 @all_plugins.each do |plugin|
231   - if @broken_plugins.include?(plugin)
  232 + if $broken_plugins.include?(plugin)
232 233 status = "SKIP"
233 234 elsif !failed[plugin] || failed[plugin].empty?
234 235 status = "PASS"
... ...
plugins/bsc/views/shared/_fields.html.erb
... ... @@ -31,7 +31,7 @@
31 31 <%= hidden_field_tag 'old_bsc_identifier', profile.identifier %>
32 32 <div id="bsc-formitem">
33 33 <%= content_tag('code',
34   - environment.top_url + '/ ' +
  34 + top_url + '/ ' +
35 35 text_field(:profile_data, :identifier, :onchange => "warn_value_change()", :size => 25)
36 36 ) +
37 37 content_tag('div',
... ...
plugins/statistics/lib/statistics_block.rb
... ... @@ -85,7 +85,7 @@ class StatisticsBlock &lt; Block
85 85  
86 86 def enterprises
87 87 if owner.kind_of?(Environment) || owner.kind_of?(Person)
88   - owner.enterprises.visible.count
  88 + owner.enterprises.visible.enabled.count
89 89 else
90 90 0
91 91 end
... ...
plugins/statistics/test/unit/statistics_block_test.rb
... ... @@ -126,6 +126,19 @@ class StatisticsBlockTest &lt; ActiveSupport::TestCase
126 126 assert_equal 2, b.enterprises
127 127 end
128 128  
  129 + should 'return the amount of enabled enterprises' do
  130 + b = StatisticsBlock.new
  131 + e = fast_create(Environment)
  132 +
  133 + fast_create(Enterprise, :environment_id => e.id)
  134 + fast_create(Enterprise, :environment_id => e.id)
  135 + fast_create(Enterprise, :enabled => false, :environment_id => e.id)
  136 +
  137 + b.expects(:owner).at_least_once.returns(e)
  138 +
  139 + assert_equal 2, b.enterprises
  140 + end
  141 +
129 142 should 'categories return the amount of categories of the Environment' do
130 143 b = StatisticsBlock.new
131 144 e = fast_create(Environment)
... ...
public/designs/themes/noosfero/site_title.html.erb
1   -<%= link_to(image_tag("/designs/themes/noosfero/images/logo-noosfero.png"), environment.top_url) %>
  1 +<%= link_to(image_tag("/designs/themes/noosfero/images/logo-noosfero.png"), top_url) %>
... ...
public/designs/themes/profile-base/site_title.html.erb
1 1 <% if File.exists?(File.join(Rails.root, 'public', "/designs/themes/#{environment.theme}/images/thin-logo.png")) %>
2   - <%= link_to(image_tag("/designs/themes/#{environment.theme}/images/thin-logo.png"), environment.top_url) %>
  2 + <%= link_to(image_tag("/designs/themes/#{environment.theme}/images/thin-logo.png"), top_url) %>
3 3 <% else %>
4   - <%= link_to(image_tag("/designs/themes/noosfero/images/thin-logo.png"), environment.top_url) %>
  4 + <%= link_to(image_tag("/designs/themes/noosfero/images/thin-logo.png"), top_url) %>
5 5 <% end %>
... ...
test/functional/cms_controller_test.rb
... ... @@ -1678,6 +1678,15 @@ class CmsControllerTest &lt; ActionController::TestCase
1678 1678 assert_equal license, article.license
1679 1679 end
1680 1680  
  1681 + should 'not display license field if there is no license availabe in environment' do
  1682 + article = fast_create(Article, :profile_id => profile.id)
  1683 + License.delete_all
  1684 + login_as(profile.identifier)
  1685 +
  1686 + get :new, :profile => profile.identifier, :type => 'TinyMceArticle'
  1687 + assert_no_tag :tag => 'select', :attributes => {:id => 'article_license_id'}
  1688 + end
  1689 +
1681 1690 should 'list folders options to move content' do
1682 1691 article = fast_create(Article, :profile_id => profile.id)
1683 1692 f1 = fast_create(Folder, :profile_id => profile.id)
... ...
test/unit/environment_test.rb
... ... @@ -1627,4 +1627,26 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
1627 1627  
1628 1628 assert_equal 'Welcome to the environment', environment.signup_welcome_screen_body
1629 1629 end
  1630 +
  1631 + should 'has_license be true if there is one license in enviroment' do
  1632 + e = fast_create(Environment)
  1633 + fast_create(License, :name => 'Some', :environment_id => e.id)
  1634 +
  1635 + assert e.has_license?
  1636 + end
  1637 +
  1638 + should 'has_license be true if there is many licenses in enviroment' do
  1639 + e = fast_create(Environment)
  1640 + fast_create(License, :name => 'Some', :environment_id => e.id)
  1641 + fast_create(License, :name => 'Another', :environment_id => e.id)
  1642 +
  1643 + assert e.has_license?
  1644 + end
  1645 +
  1646 + should 'has_license be false if there is no license in enviroment' do
  1647 + e = fast_create(Environment)
  1648 +
  1649 + assert !e.has_license?
  1650 + end
  1651 +
1630 1652 end
... ...
test/unit/profile_test.rb
... ... @@ -840,6 +840,14 @@ class ProfileTest &lt; ActiveSupport::TestCase
840 840 assert_equal 'environment footer', profile.custom_footer
841 841 end
842 842  
  843 + should 'sanitize custom header and footer' do
  844 + p = fast_create(Profile)
  845 + script_kiddie_code = '<script>alert("look mom, I am a hacker!")</script>'
  846 + p.update_header_and_footer(script_kiddie_code, script_kiddie_code)
  847 + assert_no_tag_in_string p.custom_header, tag: 'script'
  848 + assert_no_tag_in_string p.custom_footer, tag: 'script'
  849 + end
  850 +
843 851 should 'store theme' do
844 852 p = build(Profile, :theme => 'my-shiny-theme')
845 853 assert_equal 'my-shiny-theme', p.theme
... ... @@ -1555,8 +1563,6 @@ class ProfileTest &lt; ActiveSupport::TestCase
1555 1563 profile.address = "<h1><</h2< Malformed >> html >< tag"
1556 1564 profile.contact_phone = "<h1<< Malformed ><>>> html >< tag"
1557 1565 profile.description = "<h1<a> Malformed >> html ></a>< tag"
1558   - profile.custom_header = "<h1<a>><<> Malformed >> html ></a>< tag"
1559   - profile.custom_footer = "<h1> Malformed <><< html ></a>< tag"
1560 1566 profile.valid?
1561 1567  
1562 1568 assert_no_match /[<>]/, profile.name
... ... @@ -1568,6 +1574,16 @@ class ProfileTest &lt; ActiveSupport::TestCase
1568 1574 assert_no_match /[<>]/, profile.custom_footer
1569 1575 end
1570 1576  
  1577 + should 'escape malformed html tags in header and footer' do
  1578 + profile = fast_create(Profile)
  1579 + profile.custom_header = "<h1<a>><<> Malformed >> html ></a>< tag"
  1580 + profile.custom_footer = "<h1> Malformed <><< html ></a>< tag"
  1581 + profile.save
  1582 +
  1583 + assert_no_match /[<>]/, profile.custom_header
  1584 + assert_no_match /[<>]/, profile.custom_footer
  1585 + end
  1586 +
1571 1587 should 'not sanitize html comments' do
1572 1588 profile = Profile.new
1573 1589 profile.custom_header = '<p><!-- <asdf> << aasdfa >>> --> <h1> Wellformed html code </h1>'
... ... @@ -1973,4 +1989,14 @@ class ProfileTest &lt; ActiveSupport::TestCase
1973 1989 assert_equal true, profile.disable
1974 1990 assert_equal false, profile.visible?
1975 1991 end
  1992 +
  1993 + should 'fetch enabled profiles' do
  1994 + p1 = fast_create(Profile, :enabled => true)
  1995 + p2 = fast_create(Profile, :enabled => true)
  1996 + p3 = fast_create(Profile, :enabled => false)
  1997 +
  1998 + assert_includes Profile.enabled, p1
  1999 + assert_includes Profile.enabled, p2
  2000 + assert_not_includes Profile.enabled, p3
  2001 + end
1976 2002 end
... ...
vendor/plugins/noosfero_urls/init.rb
... ... @@ -1,5 +0,0 @@
1   -if Rails.env == 'development'
2   - ActionController::Base.send(:prepend_before_filter) do |controller|
3   - Noosfero.instance_variable_set('@development_url_options', { :port => controller.request.port })
4   - end
5   -end