Commit 4c3e514f0a9b6d28a567556bced17f5291ab56f3

Authored by Rodrigo Souto
2 parents 0111638e 3048e9e9

Merge branch 'stable'

app/models/contact.rb
@@ -23,23 +23,26 @@ class Contact < ActiveRecord::Base #WithoutTable @@ -23,23 +23,26 @@ class Contact < ActiveRecord::Base #WithoutTable
23 23
24 class Sender < ActionMailer::Base 24 class Sender < ActionMailer::Base
25 def mail(contact) 25 def mail(contact)
  26 + content_type 'text/html'
26 emails = contact.dest.notification_emails 27 emails = contact.dest.notification_emails
27 recipients emails 28 recipients emails
28 - from "#{contact.name} <#{contact.email}>" 29 + from "#{contact.name} <#{contact.dest.environment.contact_email}>"
  30 + reply_to contact.email
29 if contact.sender 31 if contact.sender
30 headers 'X-Noosfero-Sender' => contact.sender.identifier 32 headers 'X-Noosfero-Sender' => contact.sender.identifier
31 end 33 end
32 if contact.receive_a_copy 34 if contact.receive_a_copy
33 cc "#{contact.name} <#{contact.email}>" 35 cc "#{contact.name} <#{contact.email}>"
34 end 36 end
35 - subject contact.subject 37 + subject "[#{contact.dest.short_name(30)}] " + contact.subject
36 body :name => contact.name, 38 body :name => contact.name,
37 :email => contact.email, 39 :email => contact.email,
38 :city => contact.city, 40 :city => contact.city,
39 :state => contact.state, 41 :state => contact.state,
40 :message => contact.message, 42 :message => contact.message,
41 :environment => contact.dest.environment.name, 43 :environment => contact.dest.environment.name,
42 - :url => url_for(:host => contact.dest.environment.default_hostname, :controller => 'home') 44 + :url => url_for(:host => contact.dest.environment.default_hostname, :controller => 'home'),
  45 + :target => contact.dest.name
43 end 46 end
44 end 47 end
45 48
app/models/environment.rb
@@ -9,10 +9,10 @@ class Environment &lt; ActiveRecord::Base @@ -9,10 +9,10 @@ class Environment &lt; ActiveRecord::Base
9 9
10 has_many :tasks, :dependent => :destroy, :as => 'target' 10 has_many :tasks, :dependent => :destroy, :as => 'target'
11 11
12 - IDENTIFY_SCRIPTS = /(?:php[0-9s]?(\..*)?|[sp]htm[l]?(\..*)?|pl|py|cgi|rb)/ 12 + IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/
13 13
14 def self.verify_filename(filename) 14 def self.verify_filename(filename)
15 - filename += '.txt' if filename =~ IDENTIFY_SCRIPTS 15 + filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS
16 filename 16 filename
17 end 17 end
18 18
@@ -236,17 +236,17 @@ class Environment &lt; ActiveRecord::Base @@ -236,17 +236,17 @@ class Environment &lt; ActiveRecord::Base
236 236
237 # Enables a feature identified by its name 237 # Enables a feature identified by its name
238 def enable(feature) 238 def enable(feature)
239 - self.settings["#{feature}_enabled"] = true 239 + self.settings["#{feature}_enabled".to_sym] = true
240 end 240 end
241 241
242 # Disables a feature identified by its name 242 # Disables a feature identified by its name
243 def disable(feature) 243 def disable(feature)
244 - self.settings["#{feature}_enabled"] = false 244 + self.settings["#{feature}_enabled".to_sym] = false
245 end 245 end
246 246
247 # Tells if a feature, identified by its name, is enabled 247 # Tells if a feature, identified by its name, is enabled
248 def enabled?(feature) 248 def enabled?(feature)
249 - self.settings["#{feature}_enabled"] == true 249 + self.settings["#{feature}_enabled".to_sym] == true
250 end 250 end
251 251
252 # enables the features identified by <tt>features</tt>, which is expected to 252 # enables the features identified by <tt>features</tt>, which is expected to
app/views/cms/view.rhtml
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 </td> 50 </td>
51 <td class="article-controls"> 51 <td class="article-controls">
52 <%= button_without_text :edit, _('Edit'), :action => 'edit', :id => article.id %> 52 <%= button_without_text :edit, _('Edit'), :action => 'edit', :id => article.id %>
53 - <%= button_without_text :eyes, _('Public view'), article.url %> 53 + <%= button_without_text :eyes, _('Public view'), article.view_url %>
54 <%= display_spread_button(profile, article) unless article.folder? %> 54 <%= display_spread_button(profile, article) unless article.folder? %>
55 <% if !environment.enabled?('cant_change_homepage') %> 55 <% if !environment.enabled?('cant_change_homepage') %>
56 <%= button_without_text :home, _('Use as homepage'), { :action => 'set_home_page', :id => article.id }, :method => :post %> 56 <%= button_without_text :home, _('Use as homepage'), { :action => 'set_home_page', :id => article.id }, :method => :post %>
app/views/contact/sender/mail.rhtml
1 -<%= _('Name: %s') % @name %>  
2 -<%= _('e-Mail: %s') % @email %>  
3 -<% if @city || @state %>  
4 - <%= _('City and state: %s/%s') % [@city || '?', @state || '?'] %>  
5 -<% end %> 1 +<!DOCTYPE html>
  2 +<html>
  3 + <head>
  4 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5 + </head>
  6 + <body>
  7 + <p><%= _('This message was sent by %{sender} to %{target} on %{environment}.') %
  8 + {:sender => @name, :target => @target, :environment => @environment} %></p>
  9 + <%= _('Information about the user who sent this message:')%>
  10 + <ul>
  11 + <li><%= content_tag('b', _('Name')+': ') + @name.to_s %></li>
  12 + <li><%= content_tag('b', _('Email')+': ') + @email.to_s %></li>
  13 + <% if @city || @state %>
  14 + <li><%= content_tag('b', _('City and state')+': ') + (@city || '?')+'/'+(@state || '?') %></li>
  15 + <% end %>
  16 + </ul>
  17 + <hr/>
  18 + <%= content_tag('b', _('Message:')) %>
  19 + <p><%= word_wrap(@message) %></p>
6 20
7 -<%= _('Message:') %>  
8 --------------------------------------------------------------------------------  
9 -<%= word_wrap(@message) %>  
10 -------------------------------------------------------------------------------- 21 + --<br/>
  22 + <%= _('Greetings,') %><br/>
  23 + <%= _('%s team.') % @environment %><br/>
  24 + <%= @url %>
  25 + </body>
  26 +</html>
11 27
12 -<%= _('Greetings,') %>  
13 -  
14 ---  
15 -<%= _('%s team.') % @environment %>  
16 -<%= @url %>  
app/views/search/_article.rhtml
1 <li class="<%= icon_for_article(article) %>"> 1 <li class="<%= icon_for_article(article) %>">
2 - <strong><%= link_to(article.title, article.url) %></strong> 2 + <strong><%= link_to(article.title, article.view_url) %></strong>
3 <div class="item_meta"> 3 <div class="item_meta">
4 <% if article.last_changed_by %> 4 <% if article.last_changed_by %>
5 <span class="cat_item_by"> 5 <span class="cat_item_by">
config/environment.rb
@@ -106,7 +106,7 @@ end @@ -106,7 +106,7 @@ end
106 106
107 # Include your application configuration below 107 # Include your application configuration below
108 108
109 - 109 +ActiveRecord::Base.store_full_sti_class = true
110 110
111 Noosfero.locales = { 111 Noosfero.locales = {
112 'en' => 'English', 112 'en' => 'English',
db/migrate/20110706171330_fix_misunderstood_script_filename.rb 0 → 100644
@@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
  1 +#FIXME Don't know why, but this xss_terminate and sanitize_tag_list calls here
  2 +# from the migration fall on a loop and breaks the migration. Both them are
  3 +# related to alias_method_chain, probably there is a problem with this kind of
  4 +# alias on the migration level.
  5 +class Article < ActiveRecord::Base
  6 + def sanitize_tag_list
  7 + end
  8 +end
  9 +
  10 +module XssTerminate
  11 + module InstanceMethods
  12 + def sanitize_fields_with_white_list
  13 + end
  14 + end
  15 +end
  16 +
  17 +#FIXME This after save calls the environment methods 'blocks' and
  18 +# 'portal_community'. Both acts as not defined don't know why.
  19 +class ArticleSweeper < ActiveRecord::Observer
  20 + def after_save(article)
  21 + end
  22 +end
  23 +
  24 +class Environment < ActiveRecord::Base
  25 + def self.verify_filename(filename)
  26 + filename
  27 + end
  28 +end
  29 +
  30 +class FixMisunderstoodScriptFilename < ActiveRecord::Migration
  31 + def self.up
  32 + Image.all.select { |i| !i.thumbnail? && File.extname(i.filename) == '.txt'}.map do |image|
  33 + image.thumbnails.destroy_all
  34 + image.filename = fixed_name(image)
  35 + image.save!
  36 + image.create_thumbnails
  37 + end
  38 +
  39 + UploadedFile.all.select { |u| u.image? && File.extname(u.filename) == '.txt' }.map do |uploaded_file|
  40 + uploaded_file.thumbnails.destroy_all
  41 + uploaded_file.filename = fixed_name(uploaded_file)
  42 + uploaded_file.save!
  43 + uploaded_file.create_thumbnails
  44 + end
  45 +
  46 + Thumbnail.all.select { |u| u.image? && File.extname(u.filename) == '.txt' }.map do |thumbnail|
  47 + thumbnail.filename = fixed_name(thumbnail)
  48 + thumbnail.save!
  49 + end
  50 +
  51 + end
  52 +
  53 + def self.down
  54 + say "WARNING: cannot undo this migration"
  55 + end
  56 +
  57 + class << self
  58 + def fixed_name(file)
  59 + file.filename.gsub('.txt', '')
  60 + end
  61 + end
  62 +
  63 +end
db/migrate/20110714213405_symbolize_environment_settings_keys.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class SymbolizeEnvironmentSettingsKeys < ActiveRecord::Migration
  2 + def self.up
  3 + select_all("select id from environments").each do |environment|
  4 + env = Environment.find(environment['id'])
  5 + env.settings.symbolize_keys!
  6 + env.save
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + say "WARNING: cannot undo this migration"
  12 + end
  13 +end
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 20110527042608) do 12 +ActiveRecord::Schema.define(:version => 20110714213405) do
13 13
14 create_table "action_tracker", :force => true do |t| 14 create_table "action_tracker", :force => true do |t|
15 t.integer "user_id" 15 t.integer "user_id"
debian/changelog
  1 +noosfero (0.31.4) unstable; urgency=low
  2 +
  3 + * Bugfix Version release
  4 +
  5 + -- Rodrigo Souto <rodrigo@colivre.coop.br> Fri, 15 Jul 2011 16:40:05 -0300
  6 +
1 noosfero (0.31.3) unstable; urgency=low 7 noosfero (0.31.3) unstable; urgency=low
2 8
3 * Bugfix Version release. 9 * Bugfix Version release.
lib/acts_as_having_settings.rb
@@ -14,6 +14,11 @@ module ActsAsHavingSettings @@ -14,6 +14,11 @@ module ActsAsHavingSettings
14 def #{settings_field} 14 def #{settings_field}
15 self[:#{settings_field}] ||= Hash.new 15 self[:#{settings_field}] ||= Hash.new
16 end 16 end
  17 + before_save :symbolize_settings_keys
  18 + private
  19 + def symbolize_settings_keys
  20 + self[:#{settings_field}] && self[:#{settings_field}].symbolize_keys!
  21 + end
17 CODE 22 CODE
18 settings_items(*args) 23 settings_items(*args)
19 end 24 end
lib/noosfero.rb
1 module Noosfero 1 module Noosfero
2 PROJECT = 'noosfero' 2 PROJECT = 'noosfero'
3 - VERSION = '0.31.3' 3 + VERSION = '0.31.4'
4 4
5 def self.pattern_for_controllers_in_directory(dir) 5 def self.pattern_for_controllers_in_directory(dir)
6 disjunction = controllers_in_directory(dir).join('|') 6 disjunction = controllers_in_directory(dir).join('|')
test/unit/acts_as_having_settings_test.rb
@@ -74,4 +74,10 @@ class ActsAsHavingSettingsTest &lt; Test::Unit::TestCase @@ -74,4 +74,10 @@ class ActsAsHavingSettingsTest &lt; Test::Unit::TestCase
74 assert_equal true, obj.flag 74 assert_equal true, obj.flag
75 end 75 end
76 76
  77 + should 'symbolize keys when save' do
  78 + obj = TestClass.new
  79 + obj.settings.expects(:symbolize_keys!).once
  80 + assert obj.save
  81 + end
  82 +
77 end 83 end
test/unit/contact_sender_test.rb
@@ -16,8 +16,8 @@ class ContactSenderTest &lt; Test::Unit::TestCase @@ -16,8 +16,8 @@ class ContactSenderTest &lt; Test::Unit::TestCase
16 ent.contact_email = 'contact@invalid.com' 16 ent.contact_email = 'contact@invalid.com'
17 c = build(Contact, :dest => ent) 17 c = build(Contact, :dest => ent)
18 response = Contact::Sender.deliver_mail(c) 18 response = Contact::Sender.deliver_mail(c)
19 - assert_equal c.email, response.from  
20 - assert_equal c.subject, response.subject 19 + assert_equal Environment.default.contact_email, response.from.to_s
  20 + assert_equal "[#{ent.name}] #{c.subject}", response.subject
21 end 21 end
22 22
23 should 'deliver mail to contact_email' do 23 should 'deliver mail to contact_email' do
test/unit/contact_test.rb
@@ -22,7 +22,7 @@ class ContactTest &lt; ActiveSupport::TestCase @@ -22,7 +22,7 @@ class ContactTest &lt; ActiveSupport::TestCase
22 should 'validates format of email only if not empty' do 22 should 'validates format of email only if not empty' do
23 contact = Contact.new 23 contact = Contact.new
24 contact.valid? 24 contact.valid?
25 - assert_match /^.* can't be blank$/, contact.errors[:email] 25 + assert_match(/^.* can't be blank$/, contact.errors[:email])
26 end 26 end
27 27
28 should 'inicialize fields on instanciate' do 28 should 'inicialize fields on instanciate' do
@@ -44,4 +44,25 @@ class ContactTest &lt; ActiveSupport::TestCase @@ -44,4 +44,25 @@ class ContactTest &lt; ActiveSupport::TestCase
44 assert !c.deliver 44 assert !c.deliver
45 end 45 end
46 46
  47 + should 'use sender name and environment contact_email on from' do
  48 + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent')
  49 + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent)
  50 + email = c.deliver
  51 + assert_equal "#{c.name} <#{ent.environment.contact_email}>", email['from'].to_s
  52 + end
  53 +
  54 + should 'add dest name on subject' do
  55 + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent')
  56 + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent)
  57 + email = c.deliver
  58 + assert_equal "[#{ent.short_name(30)}] #{c.subject}", email['subject'].to_s
  59 + end
  60 +
  61 + should 'add sender email on reply_to' do
  62 + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent')
  63 + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent)
  64 + email = c.deliver
  65 + assert_equal c.email, email.reply_to.to_s
  66 + end
  67 +
47 end 68 end
test/unit/environment_test.rb
@@ -1124,15 +1124,25 @@ class EnvironmentTest &lt; Test::Unit::TestCase @@ -1124,15 +1124,25 @@ class EnvironmentTest &lt; Test::Unit::TestCase
1124 end 1124 end
1125 1125
1126 should 'identify scripts with regex' do 1126 should 'identify scripts with regex' do
1127 - scripts_extensions = %w[php php1 php4 phps php.bli cgi shtm phtm shtml phtml pl py rb]  
1128 - name = 'uploaded_file' 1127 + scripts_extensions = %w[php php1 php4 phps cgi shtm phtm shtml phtml pl py rb]
1129 scripts_extensions.each do |extension| 1128 scripts_extensions.each do |extension|
1130 - assert_not_nil name+'.'+extension =~ Environment::IDENTIFY_SCRIPTS 1129 + assert_not_nil extension =~ Environment::IDENTIFY_SCRIPTS
1131 end 1130 end
1132 end 1131 end
1133 1132
  1133 + should 'filter file as script only if it has the extension as a script extension' do
  1134 + name = 'file_php_testing'
  1135 + assert_equal name, Environment.verify_filename(name)
  1136 +
  1137 + name += '.php'
  1138 + assert_equal name+'.txt', Environment.verify_filename(name)
  1139 +
  1140 + name += '.bli'
  1141 + assert_equal name, Environment.verify_filename(name)
  1142 + end
  1143 +
1134 should 'verify filename and append .txt if script' do 1144 should 'verify filename and append .txt if script' do
1135 - scripts_extensions = %w[php php1 php4 phps php.bli cgi shtm phtm shtml phtml pl py rb] 1145 + scripts_extensions = %w[php php1 php4 phps cgi shtm phtm shtml phtml pl py rb]
1136 name = 'uploaded_file' 1146 name = 'uploaded_file'
1137 scripts_extensions.each do |extension| 1147 scripts_extensions.each do |extension|
1138 filename = name+'.'+extension 1148 filename = name+'.'+extension
@@ -1140,4 +1150,29 @@ class EnvironmentTest &lt; Test::Unit::TestCase @@ -1140,4 +1150,29 @@ class EnvironmentTest &lt; Test::Unit::TestCase
1140 end 1150 end
1141 end 1151 end
1142 1152
  1153 + should 'not conflict to save classes with namespace on sti' do
  1154 + class School; end;
  1155 + class Work; end;
  1156 + class School::Project < Article; end
  1157 + class Work::Project < Article; end
  1158 +
  1159 + title1 = "Sample Article1"
  1160 + title2 = "Sample Article2"
  1161 + profile = fast_create(Profile)
  1162 +
  1163 + p1 = School::Project.new(:name => title1, :profile => profile)
  1164 + p2 = Work::Project.new(:name => title2, :profile => profile)
  1165 +
  1166 + p1.save!
  1167 + p2.save!
  1168 + end
  1169 +
  1170 + should 'always store setting keys as symbol' do
  1171 + env = Environment.default
  1172 + env.settings['string_key'] = 'new value'
  1173 + env.save!; env.reload
  1174 + assert_nil env.settings['string_key']
  1175 + assert_equal env.settings[:string_key], 'new value'
  1176 + end
  1177 +
1143 end 1178 end