Commit 6c619a2d9c9570ff4d9456a12d83c31cc9ec3b4b

Authored by Victor Costa
2 parents 14a2302f aa847970

Merge branch 'master' into AI3191-private_environment

Conflicts:
	app/models/environment.rb
	app/views/features/index.rhtml
Showing 3001 changed files with 192815 additions and 47494 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 3001 files displayed.

AUTHORS
... ... @@ -6,6 +6,7 @@ noosfero, that's not a problem).
6 6 Developers
7 7 ==========
8 8  
  9 +Ábner Silva de Oliveira <abner.oliveira@serpro.gov.br>
9 10 Alan Freihof Tygel <alantygel@gmail.com>
10 11 alcampelo <alcampelo@alcampelo.(none)>
11 12 Alessandro Palmeira <alessandro.palmeira@gmail.com>
... ... @@ -43,6 +44,7 @@ Ana Losnak &lt;analosnak@gmail.com&gt;
43 44 Antonio Terceiro + Carlos Morais <terceiro@colivre.coop.br>
44 45 Antonio Terceiro + Paulo Meirelles <terceiro@colivre.coop.br>
45 46 Antonio Terceiro <terceiro@colivre.coop.br>
  47 +Arthur Del Esposte <arthurmde@gmail.com>
46 48 Arthur Del Esposte <arthurmde@yahoo.com.br>
47 49 Aurelio A. Heckert <aurelio@colivre.coop.br>
48 50 Braulio Bhavamitra <brauliobo@gmail.com>
... ... @@ -71,12 +73,14 @@ Caio Salgado + Renan Teruo &lt;caio.salgado@gmail.com&gt;
71 73 Caio Salgado + Renan Teruo + Jefferson Fernandes <jeffs.fernandes@gmail.com>
72 74 Caio Salgado + Renan Teruo <renanteruoc@gmail.com>
73 75 Caio SBA <caio@colivre.coop.br>
  76 +Caio Tiago Oliveira <caiotiago@colivre.coop.br>
74 77 Carlos Andre de Souza <carlos.andre.souza@msn.com>
75 78 Carlos Morais <carlos88morais@gmail.com>
76 79 Carlos Morais + Diego Araújo <diegoamc90@gmail.com>
77 80 Carlos Morais + Eduardo Morais <carlos88morais@gmail.com>
78 81 Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com>
79 82 Carlos Morais + Pedro Leal <carlos88morais@gmail.com>
  83 +Daniela Feitosa <dani@dohko.(none)>
80 84 Daniel Alves + Diego Araújo <danpaulalves@gmail.com>
81 85 Daniel Alves + Diego Araújo <diegoamc90@gmail.com>
82 86 Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com>
... ... @@ -117,6 +121,8 @@ Diego Martinez &lt;diegoamc90@gmail.com&gt;
117 121 Diego Martinez <diego@diego-K55A.(none)>
118 122 Diego + Renan <renanteruoc@gmail.com>
119 123 Eduardo Tourinho Edington <eduardo.edington@serpro.gov.br>
  124 +Evandro Jr <evandrojr@gmail.com>
  125 +Evandro Junior <evandrojr@gmail.com>
120 126 Fabio Teixeira <fabio1079@gmail.com>
121 127 Fernanda Lopes <nanda.listas+psl@gmail.com>
122 128 Francisco Marcelo A. Lima Júnior <francisco.lima-junior@serpro.gov.br>
... ... @@ -132,6 +138,7 @@ Italo Valcy &lt;italo@dcc.ufba.br&gt;
132 138 Jefferson Fernandes + Diego Araujo + Rafael Manzo <jeffs.fernandes@gmail.com>
133 139 Jefferson Fernandes + Joao M. M. da Silva <jeffs.fernandes@gmail.com>
134 140 Jefferson Fernandes + Joao M. M. Silva <jeffs.fernandes@gmail.com>
  141 +João da Silva + Eduardo Morais + Rafael Manzo <rr.manzo@gmail.com>
135 142 João da Silva <jaodsilv@linux.ime.usp.br>
136 143 João Marco Maciel da Silva + Rafael Manzo + Renan Teruo <jaodsilv@linux.ime.usp.br>
137 144 João M. M. da Silva + Alessandro Palmeira + Diego Araújo + Caio Salgado <jaodsilv@linux.ime.usp.br>
... ... @@ -162,9 +169,11 @@ João M. M. Silva + Rafael Manzo &lt;jaodsilv@linux.ime.usp.br&gt;
162 169 João M. M. Silva + Renan Teruo <jaodsilv@linux.ime.usp.br>
163 170 Joenio Costa <joenio@colivre.coop.br>
164 171 Josef Spillner <josef.spillner@tu-dresden.de>
  172 +Junior Silva <junior@bajor.localhost.localdomain>
165 173 Junior Silva <juniorsilva1001@gmail.com>
166 174 Junior Silva <juniorsilva7@juniorsilva-Aspire-5750Z.(none)>
167 175 Junior Silva <juniorsilva@colivre.coop.br>
  176 +juniorsilva <juniorsilva@QonoS.localhost.localdomain>
168 177 Keilla Menezes <keilla@colivre.coop.br>
169 178 Larissa Reis <larissa@colivre.coop.br>
170 179 Larissa Reis <reiss.larissa@gmail.com>
... ... @@ -175,7 +184,9 @@ Leandro Nunes dos Santos &lt;leandro.santos@serpro.gov.br&gt;
175 184 LinguÁgil 2010 <linguagil.bahia@gmail.com>
176 185 Lucas Melo <lucas@colivre.coop.br>
177 186 Lucas Melo <lucaspradomelo@gmail.com>
  187 +Luciano <lucianopcbr@gmail.com>
178 188 Luis David Aguilar Carlos <ludwig9003@gmail.com>
  189 +Luiz Fernando de Freitas Matos <luiz@luizff.matos@gmail.com>
179 190 Marcos Ramos <ms.ramos@outlook.com>
180 191 Martín Olivera <molivera@solar.org.ar>
181 192 Moises Machado <moises@colivre.coop.br>
... ...
Gemfile
1 1 source "https://rubygems.org"
  2 +gem 'rails'
  3 +gem 'fast_gettext'
  4 +gem 'acts-as-taggable-on'
  5 +gem 'prototype-rails'
  6 +gem 'prototype_legacy_helper', '0.0.0', :path => 'vendor/prototype_legacy_helper'
  7 +gem 'rails_autolink'
  8 +gem 'pg'
  9 +gem 'rmagick'
  10 +gem 'RedCloth'
  11 +gem 'will_paginate'
  12 +gem 'ruby-feedparser'
  13 +gem 'daemons'
  14 +gem 'thin'
  15 +gem 'hpricot'
  16 +gem 'nokogiri'
  17 +gem 'rake', :require => false
2 18  
3   -gem 'exception_notification', '1.0.20090728'
4   -gem 'system_timer'
  19 +# FIXME list here all actual dependencies (i.e. the ones in debian/control),
  20 +# with their GEM names (not the Debian package names)
  21 +
  22 +group :production do
  23 + gem 'dalli'
  24 +end
5 25  
6 26 group :test do
7   - gem 'rspec', '1.2.9'
8   - gem 'rspec-rails', '1.2.9'
  27 + gem 'rspec'
  28 + gem 'rspec-rails'
  29 + gem 'mocha', :require => false
9 30 end
10 31  
11 32 group :cucumber do
12   - gem 'rake', '0.8.7'
13   - gem 'cucumber-rails', '0.3.2'
14   - gem 'capybara', '1.1.1'
15   - gem 'cucumber', '1.1.0'
  33 + gem 'rake'
  34 + gem 'cucumber-rails', :require => false
  35 + gem 'capybara'
  36 + gem 'cucumber'
16 37 gem 'database_cleaner'
  38 + gem 'selenium-webdriver'
17 39 end
18 40  
19   -def program(name)
20   - unless system("which #{name} > /dev/null")
21   - puts "W: Program #{name} is needed, but was not found in your PATH"
22   - end
  41 +# include plugin gemfiles
  42 +Dir.glob(File.join('config', 'plugins', '*')).each do |plugin|
  43 + plugin_gemfile = File.join(plugin, 'Gemfile')
  44 + eval File.read(plugin_gemfile) if File.exists?(plugin_gemfile)
23 45 end
24   -
25   -program 'java'
26   -program 'firefox'
... ...
Gemfile.lock
  1 +PATH
  2 + remote: vendor/prototype_legacy_helper
  3 + specs:
  4 + prototype_legacy_helper (0.0.0)
  5 +
1 6 GEM
2 7 remote: https://rubygems.org/
3 8 specs:
4   - builder (3.1.4)
5   - capybara (1.1.1)
  9 + RedCloth (4.2.9)
  10 + actionmailer (3.2.6)
  11 + actionpack (= 3.2.6)
  12 + mail (~> 2.4.4)
  13 + actionpack (3.2.6)
  14 + activemodel (= 3.2.6)
  15 + activesupport (= 3.2.6)
  16 + builder (~> 3.0.0)
  17 + erubis (~> 2.7.0)
  18 + journey (~> 1.0.1)
  19 + rack (~> 1.4.0)
  20 + rack-cache (~> 1.2)
  21 + rack-test (~> 0.6.1)
  22 + sprockets (~> 2.1.3)
  23 + activemodel (3.2.6)
  24 + activesupport (= 3.2.6)
  25 + builder (~> 3.0.0)
  26 + activerecord (3.2.6)
  27 + activemodel (= 3.2.6)
  28 + activesupport (= 3.2.6)
  29 + arel (~> 3.0.2)
  30 + tzinfo (~> 0.3.29)
  31 + activeresource (3.2.6)
  32 + activemodel (= 3.2.6)
  33 + activesupport (= 3.2.6)
  34 + activesupport (3.2.6)
  35 + i18n (~> 0.6)
  36 + multi_json (~> 1.0)
  37 + acts-as-taggable-on (3.0.2)
  38 + rails (>= 3, < 5)
  39 + arel (3.0.2)
  40 + builder (3.0.0)
  41 + capybara (2.1.0)
6 42 mime-types (>= 1.16)
7 43 nokogiri (>= 1.3.3)
8 44 rack (>= 1.0.0)
9 45 rack-test (>= 0.5.4)
10   - selenium-webdriver (~> 2.0)
11   - xpath (~> 0.1.4)
12   - childprocess (0.3.6)
13   - ffi (~> 1.0, >= 1.0.6)
14   - cucumber (1.1.0)
  46 + xpath (~> 2.0)
  47 + childprocess (0.3.3)
  48 + ffi (~> 1.0.6)
  49 + cucumber (1.0.6)
15 50 builder (>= 2.1.2)
16 51 diff-lcs (>= 1.1.2)
17   - gherkin (~> 2.5.0)
  52 + gherkin (~> 2.4.18)
18 53 json (>= 1.4.6)
19 54 term-ansicolor (>= 1.0.6)
20   - cucumber-rails (0.3.2)
21   - cucumber (>= 0.8.0)
22   - database_cleaner (0.9.1)
  55 + cucumber-rails (1.0.6)
  56 + capybara (>= 1.1.1)
  57 + cucumber (>= 1.0.6)
  58 + nokogiri (>= 1.5.0)
  59 + daemons (1.1.5)
  60 + dalli (2.7.0)
  61 + database_cleaner (1.2.0)
23 62 diff-lcs (1.1.3)
24   - exception_notification (1.0.20090728)
25   - ffi (1.2.0)
26   - gherkin (2.5.4)
  63 + erubis (2.7.0)
  64 + eventmachine (0.12.11)
  65 + fast_gettext (0.6.8)
  66 + ffi (1.0.11)
  67 + gherkin (2.4.21)
27 68 json (>= 1.4.6)
28   - json (1.7.5)
29   - libwebsocket (0.1.6.1)
30   - websocket
  69 + hike (1.2.1)
  70 + hpricot (0.8.6)
  71 + i18n (0.6.0)
  72 + journey (1.0.3)
  73 + json (1.7.3)
  74 + mail (2.4.4)
  75 + i18n (>= 0.4.0)
  76 + mime-types (~> 1.16)
  77 + treetop (~> 1.4.8)
  78 + metaclass (0.0.1)
31 79 mime-types (1.19)
32   - multi_json (1.3.7)
  80 + mocha (0.11.3)
  81 + metaclass (~> 0.0.1)
  82 + multi_json (1.3.6)
33 83 nokogiri (1.5.5)
34   - rack (1.1.0)
35   - rack-test (0.6.2)
  84 + pg (0.13.2)
  85 + polyglot (0.3.3)
  86 + prototype-rails (3.2.1)
  87 + rails (~> 3.2)
  88 + rack (1.4.1)
  89 + rack-cache (1.2)
  90 + rack (>= 0.4)
  91 + rack-ssl (1.3.2)
  92 + rack
  93 + rack-test (0.6.1)
36 94 rack (>= 1.0)
37   - rake (0.8.7)
38   - rspec (1.2.9)
39   - rspec-rails (1.2.9)
40   - rack (>= 1.0.0)
41   - rspec (>= 1.2.9)
42   - rubyzip (0.9.9)
43   - selenium-webdriver (2.26.0)
  95 + rails (3.2.6)
  96 + actionmailer (= 3.2.6)
  97 + actionpack (= 3.2.6)
  98 + activerecord (= 3.2.6)
  99 + activeresource (= 3.2.6)
  100 + activesupport (= 3.2.6)
  101 + bundler (~> 1.0)
  102 + railties (= 3.2.6)
  103 + rails_autolink (1.1.5)
  104 + rails (> 3.1)
  105 + railties (3.2.6)
  106 + actionpack (= 3.2.6)
  107 + activesupport (= 3.2.6)
  108 + rack-ssl (~> 1.3.2)
  109 + rake (>= 0.8.7)
  110 + rdoc (~> 3.4)
  111 + thor (>= 0.14.6, < 2.0)
  112 + rake (0.9.2.2)
  113 + rdoc (3.9.4)
  114 + rmagick (2.13.1)
  115 + rspec (2.10.0)
  116 + rspec-core (~> 2.10.0)
  117 + rspec-expectations (~> 2.10.0)
  118 + rspec-mocks (~> 2.10.0)
  119 + rspec-core (2.10.1)
  120 + rspec-expectations (2.10.0)
  121 + diff-lcs (~> 1.1.3)
  122 + rspec-mocks (2.10.1)
  123 + rspec-rails (2.10.1)
  124 + actionpack (>= 3.0)
  125 + activesupport (>= 3.0)
  126 + railties (>= 3.0)
  127 + rspec (~> 2.10.0)
  128 + ruby-feedparser (0.7)
  129 + rubyzip (1.1.2)
  130 + selenium-webdriver (2.39.0)
44 131 childprocess (>= 0.2.5)
45   - libwebsocket (~> 0.1.3)
46 132 multi_json (~> 1.0)
47   - rubyzip
48   - system_timer (1.2.4)
  133 + rubyzip (~> 1.0)
  134 + websocket (~> 1.0.4)
  135 + sprockets (2.1.3)
  136 + hike (~> 1.2)
  137 + multi_json (~> 1.0)
  138 + rack (~> 1.0)
  139 + tilt (~> 1.1, != 1.3.0)
49 140 term-ansicolor (1.0.7)
50   - websocket (1.0.4)
51   - xpath (0.1.4)
  141 + thin (1.3.1)
  142 + daemons (>= 1.0.9)
  143 + eventmachine (>= 0.12.6)
  144 + rack (>= 1.0.0)
  145 + thor (0.15.3)
  146 + tilt (1.3.3)
  147 + treetop (1.4.10)
  148 + polyglot
  149 + polyglot (>= 0.3.1)
  150 + tzinfo (0.3.33)
  151 + websocket (1.0.7)
  152 + will_paginate (3.0.3)
  153 + xpath (2.0.0)
52 154 nokogiri (~> 1.3)
53 155  
54 156 PLATFORMS
55 157 ruby
56 158  
57 159 DEPENDENCIES
58   - capybara (= 1.1.1)
59   - cucumber (= 1.1.0)
60   - cucumber-rails (= 0.3.2)
  160 + RedCloth
  161 + acts-as-taggable-on
  162 + capybara
  163 + cucumber
  164 + cucumber-rails
  165 + daemons
  166 + dalli
61 167 database_cleaner
62   - exception_notification (= 1.0.20090728)
63   - rake (= 0.8.7)
64   - rspec (= 1.2.9)
65   - rspec-rails (= 1.2.9)
66   - system_timer
  168 + fast_gettext
  169 + hpricot
  170 + mocha
  171 + nokogiri
  172 + pg
  173 + prototype-rails
  174 + prototype_legacy_helper (= 0.0.0)!
  175 + rails
  176 + rails_autolink
  177 + rake
  178 + rmagick
  179 + rspec
  180 + rspec-rails
  181 + ruby-feedparser
  182 + selenium-webdriver
  183 + thin
  184 + will_paginate
... ...
INSTALL.md
... ... @@ -110,7 +110,7 @@ Setup Noosfero log and tmp directories:
110 110 # cd /var/lib/noosfero/current
111 111 # ./etc/init.d/noosfero setup
112 112  
113   -Now it's time to setup the database. In this example we are using PostgreSQL, so if you are planning to use a different database this steps won't apply.
  113 +Now it's time to setup the database. In this example we are using PostgreSQL, so if you are planning to use a different database this steps won't apply. Pay special attention to the default collation defined on your setup by the environment variable LC_COLLATE because it might interfere in some sorting operations on your database. For more information checkout `man locale`.
114 114  
115 115 # apt-get install postgresql libpgsql-ruby
116 116 # su postgres -c 'createuser noosfero -S -d -R'
... ...
MIGRATION_ISSUES 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +* ruby-get-text incmopatible with rails3. Maybe we can use it's gem
  2 +
  3 +* all js code is inside miscellaneous.js. Would be nice to refactor this
  4 +
  5 +* rails 2 uses prototype instead of jquery
  6 +
  7 +* config/environment.rb maybe still have some code that should be on the initializers
  8 +
  9 +* initializers session_store.rb inflections.rb... don't exist
  10 +
  11 +* rails gems version have to be forced on Gemfile or it will use incompatible pre3vious versions (3.1.3)
  12 +
  13 +* Sweepers are now natively supported on Rails 3. Would be nice to refactor it
  14 +
  15 +* On Rails 3 it is no more possible to add allowed tags to avoid scape. The html_safe initializer is an option.
  16 +
  17 +* error when call sqlite_extensiosn
  18 +
  19 +* error related to action_tracker
  20 +
  21 +* check FIXME's in script/quick-start
  22 +
  23 +* check FIXME's in Gemfile
  24 +
  25 +* Check the FIXME in config/routes.rb
  26 +
  27 +* rewrite conditional routing. See FIXME in lib/route_if.rb and re-implement using the Rails 3 mechanism - http://guides.rubyonrails.org/routing.html#advanced-constraints
  28 +
  29 +* check FIXME's in config/environment.rb
  30 +
  31 +* xss_terminate sucks. We should replace it with the builtin mechanism in Rails 3
  32 +
  33 +* instance_eval on Ruby 1.9 yields self, so lambdas that are passed to instance_eval and do not accept exactly 1 argument will blow up. See http://www.ruby-forum.com/topic/213313 ... search for instance_eval and fix where necessary. In special, most of the blocks still need fixing.
  34 +
  35 +* all instances of <% *_form_for ... %> must be changed to <%= instead of <%
  36 +
  37 +* all ActiveRecord models have to declare explicitly which attributes must be allowed for mass assignment with attr_accessible.
  38 +
  39 +* check if we need to update config/locales/*
  40 +
  41 +* check observe_field and labelled_form_for in app/helpers/application_helper.rb
... ...
README.md
  1 +[![Code Climate](https://codeclimate.com/github/Noosfero/noosfero.png)](https://codeclimate.com/github/Noosfero/noosfero)
  2 +
1 3 Noosfero - a web-based social platform
2 4 ======================================
3 5  
... ... @@ -30,4 +32,4 @@ Authorship and copyright information is available in the files listed below.
30 32 -------------------- -----------------------------------------
31 33 AUTHORS.md list of authors (updated at each release)
32 34 COPYRIGHT Copyright statement for the project
33 35 - COPYING Full text of the project license
  36 + COPYING Full text of the project license
34 37 \ No newline at end of file
... ...
Rakefile
  1 +#!/usr/bin/env rake
1 2 # Add your own tasks in files placed in lib/tasks ending in .rake,
2 3 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 4  
4   -require(File.join(File.dirname(__FILE__), 'config', 'boot'))
  5 +require File.expand_path('../config/application', __FILE__)
5 6  
6   -require 'rake'
7   -require 'rake/testtask'
8   -require 'rake/rdoctask'
9   -
10   -# rails tasks
11   -require 'tasks/rails'
12   -
13   -# plugins' tasks
14   -plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort +
15   - Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort
16   -plugins_tasks.each{ |ext| load ext }
  7 +Noosfero::Application.load_tasks
... ...
Vagrantfile 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +# -*- mode: ruby -*-
  2 +# vi: set ft=ruby :
  3 +
  4 +VAGRANTFILE_API_VERSION = "2"
  5 +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  6 + config.vm.box = "debian-wheezy"
  7 + config.vm.network :forwarded_port, host: 3000, guest: 3000
  8 + config.vm.provision :shell do |shell|
  9 + shell.inline = 'su vagrant -c /vagrant/script/vagrant'
  10 + end
  11 +end
... ...
app/controllers/admin/admin_panel_controller.rb
... ... @@ -7,6 +7,7 @@ class AdminPanelController &lt; AdminController
7 7 end
8 8  
9 9 def site_info
  10 + @no_design_blocks = true
10 11 if request.post?
11 12 if params[:environment][:languages]
12 13 params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact
... ... @@ -42,7 +43,7 @@ class AdminPanelController &lt; AdminController
42 43 end
43 44 redirect_to :action => 'set_portal_folders'
44 45 else
45   - session[:notice] = __('Community not found. You must insert the identifier of a community from this environment')
  46 + session[:notice] = _('Community not found. You must insert the identifier of a community from this environment')
46 47 end
47 48 end
48 49 end
... ...
app/controllers/admin/environment_design_controller.rb
... ... @@ -5,7 +5,7 @@ class EnvironmentDesignController &lt; BoxOrganizerController
5 5 def available_blocks
6 6 # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from
7 7 # the Noosfero core soon, see ActionItem3045
8   - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
  8 + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
9 9 @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment)
10 10 end
11 11  
... ...
app/controllers/admin/environment_role_manager_controller.rb
1 1 class EnvironmentRoleManagerController < AdminController
2 2 protect 'manage_environment_roles', :environment
3   -
  3 +
4 4 def index
5 5 @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments )
6 6 end
... ... @@ -8,7 +8,7 @@ class EnvironmentRoleManagerController &lt; AdminController
8 8 def change_roles
9 9 @admin = Person.find(params[:id])
10 10 @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) }
11   - end
  11 + end
12 12  
13 13 def update_roles
14 14 @roles = params[:roles] ? Role.find(params[:roles]) : []
... ... @@ -20,7 +20,7 @@ class EnvironmentRoleManagerController &lt; AdminController
20 20 end
21 21 redirect_to :action => :index
22 22 end
23   -
  23 +
24 24 def change_role
25 25 @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) }
26 26 @admin = Person.find(params[:id])
... ...
app/controllers/admin/features_controller.rb
... ... @@ -34,9 +34,9 @@ class FeaturesController &lt; AdminController
34 34 def manage_enterprise_fields
35 35 environment.custom_enterprise_fields = params[:enterprise_fields]
36 36 if environment.save!
37   - session[:notice] = __('Enterprise fields updated successfully.')
  37 + session[:notice] = _('Enterprise fields updated successfully.')
38 38 else
39   - flash[:error] = __('Enterprise fields not updated successfully.')
  39 + flash[:error] = _('Enterprise fields not updated successfully.')
40 40 end
41 41 redirect_to :action => 'manage_fields'
42 42 end
... ...
app/controllers/admin/users_controller.rb
... ... @@ -79,7 +79,7 @@ class UsersController &lt; AdminController
79 79 users = User.connection.execute(command)
80 80 csv_content = "name;email\n"
81 81 users.each { |u|
82   - CSV.generate_row([u['name'], u['email']], 2, csv_content, fs=';')
  82 + csv_content << CSV.generate_line([u['name'], u['email']], {:col_sep => ';'})
83 83 }
84 84 render :text => csv_content, :content_type => 'text/csv', :layout => false
85 85 end
... ...
app/controllers/application_controller.rb
  1 +require 'noosfero/multi_tenancy'
  2 +
1 3 class ApplicationController < ActionController::Base
  4 + protect_from_forgery
2 5  
3 6 before_filter :setup_multitenancy
4 7 before_filter :detect_stuff_by_domain
5   - before_filter :init_noosfero_plugins_controller_filters
  8 + before_filter :init_noosfero_plugins
6 9 before_filter :allow_cross_domain_access
7 10 before_filter :login_required, :if => :private_environment?
8 11 before_filter :verify_members_whitelist, :if => :user
... ... @@ -11,6 +14,12 @@ class ApplicationController &lt; ActionController::Base
11 14 render_access_denied unless user.is_admin? || environment.in_whitelist?(user)
12 15 end
13 16  
  17 + after_filter :set_csrf_cookie
  18 +
  19 + def set_csrf_cookie
  20 + cookies['_noosfero_.XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? && logged_in?
  21 + end
  22 +
14 23 def allow_cross_domain_access
15 24 origin = request.headers['Origin']
16 25 return if origin.blank?
... ... @@ -27,7 +36,8 @@ class ApplicationController &lt; ActionController::Base
27 36 include ApplicationHelper
28 37 layout :get_layout
29 38 def get_layout
30   - return nil if request.format == :js
  39 + return nil if request.format == :js or request.xhr?
  40 +
31 41 theme_layout = theme_option(:layout)
32 42 if theme_layout
33 43 theme_view_file('layouts/'+theme_layout) || theme_layout
... ... @@ -36,11 +46,9 @@ class ApplicationController &lt; ActionController::Base
36 46 end
37 47 end
38 48  
39   - filter_parameter_logging :password
40   -
41 49 def log_processing
42 50 super
43   - return unless ENV['RAILS_ENV'] == 'production'
  51 + return unless Rails.env == 'production'
44 52 if logger && logger.info?
45 53 logger.info(" HTTP Referer: #{request.referer}")
46 54 logger.info(" User Agent: #{request.user_agent}")
... ... @@ -71,6 +79,7 @@ class ApplicationController &lt; ActionController::Base
71 79 FastGettext.default_locale = environment.default_locale
72 80 FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en')
73 81 I18n.locale = FastGettext.locale
  82 + I18n.default_locale = FastGettext.default_locale
74 83 if params[:lang]
75 84 session[:lang] = params[:lang]
76 85 end
... ... @@ -80,18 +89,24 @@ class ApplicationController &lt; ActionController::Base
80 89  
81 90 attr_reader :environment
82 91  
83   - before_filter :load_terminology
84   -
85 92 # declares that the given <tt>actions</tt> cannot be accessed by other HTTP
86 93 # method besides POST.
87 94 def self.post_only(actions, redirect = { :action => 'index'})
88   - verify :method => :post, :only => actions, :redirect_to => redirect
  95 + before_filter(:only => actions) do |controller|
  96 + if !controller.request.post?
  97 + controller.redirect_to redirect
  98 + end
  99 + end
89 100 end
90 101  
91 102 helper_method :current_person, :current_person
92 103  
93 104 protected
94 105  
  106 + def verified_request?
  107 + super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
  108 + end
  109 +
95 110 def setup_multitenancy
96 111 Noosfero::MultiTenancy.setup!(request.host)
97 112 end
... ... @@ -117,7 +132,10 @@ class ApplicationController &lt; ActionController::Base
117 132 @environment = Environment.default
118 133 if @environment.nil? && Rails.env.development?
119 134 # This should only happen in development ...
120   - @environment = Environment.create!(:name => "Noosfero", :is_default => true)
  135 + @environment = Environment.new
  136 + @environment.name = "Noosfero"
  137 + @environment.is_default = true
  138 + @environment.save!
121 139 end
122 140 else
123 141 @environment = @domain.environment
... ... @@ -133,36 +151,15 @@ class ApplicationController &lt; ActionController::Base
133 151  
134 152 include Noosfero::Plugin::HotSpot
135 153  
136   - # This is a generic method that initialize any possible filter defined by a
137   - # plugin to the current controller being initialized.
138   - def init_noosfero_plugins_controller_filters
139   - plugins.each do |plugin|
140   - filters = plugin.send(self.class.name.underscore + '_filters')
141   - filters = [filters] if !filters.kind_of?(Array)
142   - controller_filters = self.class.filter_chain.map {|c| c.method }
143   - filters.each do |plugin_filter|
144   - filter_method = plugin.class.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name]
145   - unless controller_filters.include?(filter_method)
146   - self.class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {}))
147   - self.class.send(:define_method, filter_method) do
148   - instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin.class)
149   - end
150   - end
151   - end
152   - end
153   - end
154   -
155   - def load_terminology
156   - # cache terminology for performance
157   - @@terminology_cache ||= {}
158   - @@terminology_cache[environment.id] ||= environment.terminology
159   - Noosfero.terminology = @@terminology_cache[environment.id]
  154 + # FIXME this filter just loads @plugins to children controllers and helpers
  155 + def init_noosfero_plugins
  156 + plugins
160 157 end
161 158  
162 159 def render_not_found(path = nil)
163 160 @no_design_blocks = true
164 161 @path ||= request.path
165   - render :template => 'shared/not_found.rhtml', :status => 404, :layout => get_layout
  162 + render :template => 'shared/not_found.html.erb', :status => 404, :layout => get_layout
166 163 end
167 164 alias :render_404 :render_not_found
168 165  
... ... @@ -170,12 +167,12 @@ class ApplicationController &lt; ActionController::Base
170 167 @no_design_blocks = true
171 168 @message = message
172 169 @title = title
173   - render :template => 'shared/access_denied.rhtml', :status => 403
  170 + render :template => 'shared/access_denied.html.erb', :status => 403
174 171 end
175 172  
176 173 def load_category
177 174 unless params[:category_path].blank?
178   - path = params[:category_path].join('/')
  175 + path = params[:category_path]
179 176 @category = environment.categories.find_by_path(path)
180 177 if @category.nil?
181 178 render_not_found(path)
... ...
app/controllers/embed_controller.rb
... ... @@ -4,10 +4,10 @@ class EmbedController &lt; ApplicationController
4 4 def block
5 5 @block = Block.find(params[:id])
6 6 if !@block.embedable? || !@block.visible?
7   - render 'unavailable.rhtml', :status => 403
  7 + render 'unavailable', :status => 403
8 8 end
9 9 rescue ActiveRecord::RecordNotFound
10   - render 'not_found.rhtml', :status => 404
  10 + render 'not_found', :status => 404
11 11 end
12 12  
13 13 end
... ...
app/controllers/my_profile/cms_controller.rb
... ... @@ -53,8 +53,7 @@ class CmsController &lt; MyProfileController
53 53 conditions = ['type != ?', 'RssFeed']
54 54 end
55 55  
56   - @articles = @article.children.paginate(
57   - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC",
  56 + @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name").paginate(
58 57 :conditions => conditions,
59 58 :per_page => per_page,
60 59 :page => params[:npage]
... ... @@ -145,6 +144,7 @@ class CmsController &lt; MyProfileController
145 144  
146 145 @article.profile = profile
147 146 @article.last_changed_by = user
  147 + @article.created_by = user
148 148  
149 149 translations if @article.translatable?
150 150  
... ... @@ -188,7 +188,7 @@ class CmsController &lt; MyProfileController
188 188 end
189 189 if request.post? && params[:uploaded_files]
190 190 params[:uploaded_files].each do |file|
191   - @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user) unless file == ''
  191 + @uploaded_files << UploadedFile.create({:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user}, :without_protection => true) unless file == ''
192 192 end
193 193 @errors = @uploaded_files.select { |f| f.errors.any? }
194 194 if @errors.any?
... ... @@ -210,7 +210,7 @@ class CmsController &lt; MyProfileController
210 210 if request.post?
211 211 @article.destroy
212 212 session[:notice] = _("\"#{@article.name}\" was removed.")
213   - referer = ActionController::Routing::Routes.recognize_path URI.parse(request.referer).path rescue nil
  213 + referer = Rails.application.routes.recognize_path URI.parse(request.referer).path rescue nil
214 214 if referer and referer[:controller] == 'cms' and referer[:action] != 'edit'
215 215 redirect_to referer
216 216 elsif @article.parent
... ... @@ -232,7 +232,7 @@ class CmsController &lt; MyProfileController
232 232 @current_category = Category.find(params[:category_id])
233 233 @categories = @current_category.children
234 234 end
235   - render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false
  235 + render :template => 'shared/update_categories', :locals => { :category => @current_category }
236 236 end
237 237  
238 238 def publish
... ... @@ -253,7 +253,7 @@ class CmsController &lt; MyProfileController
253 253 begin
254 254 task.finish unless item[:group].moderated_articles?
255 255 rescue Exception => ex
256   - @failed[ex.clean_message] ? @failed[ex.clean_message] << item[:group].name : @failed[ex.clean_message] = [item[:group].name]
  256 + @failed[ex.message] ? @failed[ex.message] << item[:group].name : @failed[ex.message] = [item[:group].name]
257 257 end
258 258 end
259 259 if @failed.blank?
... ...
app/controllers/my_profile/manage_products_controller.rb
... ... @@ -48,6 +48,7 @@ class ManageProductsController &lt; ApplicationController
48 48 end
49 49  
50 50 def new
  51 + @no_design_blocks = true
51 52 @category = params[:selected_category_id] ? Category.find(params[:selected_category_id]) : nil
52 53 @product = @profile.products.build(:product_category => @category)
53 54 @categories = ProductCategory.top_level_for(environment)
... ... @@ -85,7 +86,7 @@ class ManageProductsController &lt; ApplicationController
85 86 @edit = true
86 87 @level = @category.level
87 88 if request.post?
88   - if @product.update_attributes(:product_category_id => params[:selected_category_id])
  89 + if @product.update_attributes({:product_category_id => params[:selected_category_id]}, :without_protection => true)
89 90 render :partial => 'shared/redirect_via_javascript',
90 91 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) }
91 92 else
... ... @@ -207,7 +208,7 @@ class ManageProductsController &lt; ApplicationController
207 208 }.to_json
208 209 else
209 210 render :text => {:ok => false,
210   - :error_msg => _(cost.errors['name']) % {:fn => _('Name')}
  211 + :error_msg => _(cost.errors['name'].join('\n')) % {:fn => _('Name')}
211 212 }.to_json
212 213 end
213 214 end
... ...
app/controllers/my_profile/memberships_controller.rb
... ... @@ -20,7 +20,7 @@ class MembershipsController &lt; MyProfileController
20 20 @community.environment = environment
21 21 @back_to = params[:back_to] || url_for(:action => 'index')
22 22 if request.post? && @community.valid?
23   - @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]))
  23 + @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment}))
24 24 redirect_to @back_to
25 25 return
26 26 end
... ...
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -9,14 +9,8 @@ class ProfileDesignController &lt; BoxOrganizerController
9 9  
10 10 blocks += plugins.dispatch(:extra_blocks)
11 11  
12   - # blocks exclusive for organizations
13   - if profile.has_members?
14   - blocks << MembersBlock
15   - end
16   -
17 12 # blocks exclusive to people
18 13 if profile.person?
19   - blocks << FriendsBlock
20 14 blocks << FavoriteEnterprisesBlock
21 15 blocks << CommunitiesBlock
22 16 blocks << EnterprisesBlock
... ...
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -15,20 +15,14 @@ class ProfileEditorController &lt; MyProfileController
15 15 @possible_domains = profile.possible_domains
16 16 if request.post?
17 17 params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash)
18   - begin
19   - Profile.transaction do
20   - Image.transaction do
21   - if profile.update_attributes!(params[:profile_data])
22   - redirect_to :action => 'index', :profile => profile.identifier
23   - end
  18 + Profile.transaction do
  19 + Image.transaction do
  20 + if @profile_data.update_attributes(params[:profile_data])
  21 + redirect_to :action => 'index', :profile => profile.identifier
  22 + else
  23 + profile.identifier = params[:profile] if profile.identifier.blank?
24 24 end
25   - end
26   - rescue Exception => ex
27   - if profile.identifier.blank?
28   - profile.identifier = params[:profile]
29   - end
30   - session[:notice] = _('Cannot update profile')
31   - logger.error ex.to_s
  25 + end
32 26 end
33 27 end
34 28 end
... ... @@ -60,7 +54,7 @@ class ProfileEditorController &lt; MyProfileController
60 54 @current_category = Category.find(params[:category_id])
61 55 @categories = @current_category.children
62 56 end
63   - render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false
  57 + render :template => 'shared/update_categories', :locals => { :category => @current_category }
64 58 end
65 59  
66 60 def header_footer
... ...
app/controllers/my_profile/tasks_controller.rb
... ... @@ -27,7 +27,7 @@ class TasksController &lt; MyProfileController
27 27 task.send(decision)
28 28 rescue Exception => ex
29 29 message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})"
30   - failed[ex.clean_message] ? failed[ex.clean_message] << message : failed[ex.clean_message] = [message]
  30 + failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message]
31 31 end
32 32 end
33 33 end
... ...
app/controllers/public/account_controller.rb
... ... @@ -140,12 +140,8 @@ class AccountController &lt; ApplicationController
140 140 params[:new_password_confirmation])
141 141 session[:notice] = _('Your password has been changed successfully!')
142 142 redirect_to :action => 'index'
143   - rescue User::IncorrectPassword => e
144   - session[:notice] = _('The supplied current password is incorrect.')
145   - render :action => 'change_password'
  143 + rescue Exception
146 144 end
147   - else
148   - render :action => 'change_password'
149 145 end
150 146 end
151 147  
... ... @@ -171,12 +167,12 @@ class AccountController &lt; ApplicationController
171 167 render :action => 'password_recovery_sent'
172 168 rescue ActiveRecord::RecordNotFound
173 169 if params[:value].blank?
174   - @change_password.errors.add_to_base(_('Can not recover user password with blank value.'))
  170 + @change_password.errors[:base] << _('Can not recover user password with blank value.')
175 171 else
176   - @change_password.errors.add_to_base(_('Could not find any user with %s equal to "%s".') % [fields_label, params[:value]])
  172 + @change_password.errors[:base] << _('Could not find any user with %s equal to "%s".') % [fields_label, params[:value]]
177 173 end
178 174 rescue ActiveRecord::RecordInvald
179   - @change_password.errors.add_to_base(_('Could not perform password recovery for the user.'))
  175 + @change_password.errors[:base] << _('Could not perform password recovery for the user.')
180 176 end
181 177 end
182 178 end
... ...
app/controllers/public/chat_controller.rb
... ... @@ -19,7 +19,7 @@ class ChatController &lt; PublicController
19 19 def avatar
20 20 profile = environment.profiles.find_by_identifier(params[:id])
21 21 filename, mimetype = profile_icon(profile, :minor, true)
22   - data = File.read(File.join(RAILS_ROOT, 'public', filename))
  22 + data = File.read(File.join(Rails.root, 'public', filename))
23 23 render :text => data, :layout => false, :content_type => mimetype
24 24 expires_in 24.hours
25 25 end
... ...
app/controllers/public/content_viewer_controller.rb
  1 +require 'diffy'
  2 +
1 3 class ContentViewerController < ApplicationController
2 4  
3 5 needs_profile
... ... @@ -6,47 +8,32 @@ class ContentViewerController &lt; ApplicationController
6 8 helper TagsHelper
7 9  
8 10 def view_page
9   - path = params[:page].join('/')
  11 + path = get_path(params[:page], params[:format])
  12 +
10 13 @version = params[:version].to_i
11 14  
12 15 if path.blank?
13   - @page = profile.home_page
14   - if @page.nil?
15   - redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier
16   - return
17   - end
  16 + @page = profile.home_page
  17 + return if redirected_to_profile_index
18 18 else
19 19 @page = profile.articles.find_by_path(path)
20   - unless @page
21   - page_from_old_path = profile.articles.find_by_old_path(path)
22   - if page_from_old_path
23   - redirect_to profile.url.merge(:page => page_from_old_path.explode_path)
24   - return
25   - end
26   - end
  20 + return if redirected_page_from_old_path(path)
27 21 end
28 22  
29 23 return unless allow_access_to_page(path)
30 24  
31 25 if @version > 0
32 26 return render_access_denied unless @page.display_versions?
33   - @versioned_article = @page.versions.find_by_version(@version)
34   - if @versioned_article && @page.versions.latest.version != @versioned_article.version
35   - render :template => 'content_viewer/versioned_article.rhtml'
36   - return
37   - end
  27 + return if rendered_versioned_article
38 28 end
39 29  
40   - redirect_to_translation if @page.profile.redirect_l10n
  30 + redirect_to_translation and return if @page.profile.redirect_l10n
41 31  
42   - if request.post?
43   - if @page.forum? && @page.has_terms_of_use && params[:terms_accepted] == "true"
44   - @page.add_agreed_user(user)
45   - end
46   - elsif !@page.parent.nil? && @page.parent.forum?
47   - unless @page.parent.agrees_with_terms?(user)
48   - redirect_to @page.parent.url
49   - end
  32 + if request.post? && @page.forum?
  33 + process_forum_terms_of_use(user, params[:terms_accepted])
  34 + elsif is_a_forum_topic?(@page)
  35 + redirect_to @page.parent.url unless @page.parent.agrees_with_terms?(user)
  36 + return
50 37 end
51 38  
52 39 # At this point the page will be showed
... ... @@ -54,64 +41,22 @@ class ContentViewerController &lt; ApplicationController
54 41  
55 42 @page = FilePresenter.for @page
56 43  
57   - if @page.download? params[:view]
58   - headers['Content-Type'] = @page.mime_type
59   - headers.merge! @page.download_headers
60   - data = @page.data
61   -
62   - # TODO test the condition
63   - if data.nil?
64   - raise "No data for file"
65   - end
66   -
67   - render :text => data, :layout => false
68   - return
69   - end
  44 + return if rendered_file_download(params[:view])
70 45  
71 46 @form_div = params[:form]
72 47  
73 48 #FIXME see a better way to do this. It's not need to pass this variable anymore
74 49 @comment = Comment.new
75 50  
76   - if @page.has_posts?
77   - posts = if params[:year] and params[:month]
78   - filter_date = DateTime.parse("#{params[:year]}-#{params[:month]}-01")
79   - @page.posts.by_range(filter_date..filter_date.at_end_of_month)
80   - else
81   - @page.posts
82   - end
83   -
84   - #FIXME Need to run this before the pagination because this version of
85   - # will_paginate returns a will_paginate collection instead of a
86   - # relation.
87   - blog_with_translation = @page.blog? && @page.display_posts_in_current_language?
88   - posts = posts.native_translations if blog_with_translation
89   -
90   - @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile)))
91   -
92   - if blog_with_translation
93   - @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact
94   - end
95   - end
  51 + process_page_posts(params)
96 52  
97 53 if @page.folder? && @page.gallery?
98   - @images = @page.images.select{ |a| a.display_to? user }
99   - @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow]
  54 + @images = get_images(@page, params[:npage], params[:slideshow])
100 55 end
101 56  
102   - @unfollow_form = params[:unfollow] && params[:unfollow] == 'true'
103   - if params[:unfollow] && params[:unfollow] == 'commit' && request.post?
104   - @page.followers -= [params[:email]]
105   - if @page.save
106   - session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email]
107   - end
108   - end
  57 + process_page_followers(params)
109 58  
110   - @comments = @page.comments.without_spam
111   - @comments = @plugins.filter(:unavailable_comments, @comments)
112   - @comments_count = @comments.count
113   - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] )
114   - @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order]
  59 + process_comments(params)
115 60  
116 61 if request.xhr? and params[:comment_order]
117 62 if @comment_order == 'newest'
... ... @@ -123,12 +68,20 @@ class ContentViewerController &lt; ApplicationController
123 68  
124 69 if params[:slideshow]
125 70 render :action => 'slideshow', :layout => 'slideshow'
  71 + return
126 72 end
  73 + render :view_page, :formats => [:html]
127 74 end
128 75  
129   - def article_versions
  76 + def versions_diff
130 77 path = params[:page].join('/')
131 78 @page = profile.articles.find_by_path(path)
  79 + @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2])
  80 + end
  81 +
  82 + def article_versions
  83 + path = params[:page]
  84 + @page = profile.articles.find_by_path(path)
132 85 return unless allow_access_to_page(path)
133 86  
134 87 render_access_denied unless @page.display_versions?
... ... @@ -173,7 +126,7 @@ class ContentViewerController &lt; ApplicationController
173 126 elsif !@page.display_to?(user)
174 127 if !profile.public?
175 128 private_profile_partial_parameters
176   - render :template => 'profile/_private_profile.rhtml', :status => 403
  129 + render :template => 'profile/_private_profile', :status => 403
177 130 allowed = false
178 131 else #if !profile.visible?
179 132 render_access_denied
... ... @@ -192,4 +145,126 @@ class ContentViewerController &lt; ApplicationController
192 145 user_agent.match(/\(.*https?:\/\/.*\)/)
193 146 end
194 147  
  148 + def get_path(page, format = nil)
  149 + path = page
  150 + path = path.join('/') if path.kind_of?(Array)
  151 + path = "#{path}.#{format}" if format
  152 +
  153 + return path
  154 + end
  155 +
  156 + def redirected_to_profile_index
  157 + if @page.nil?
  158 + redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier
  159 + return true
  160 + end
  161 +
  162 + return false
  163 + end
  164 +
  165 + def redirected_page_from_old_path(path)
  166 + unless @page
  167 + page_from_old_path = profile.articles.find_by_old_path(path)
  168 + if page_from_old_path
  169 + redirect_to profile.url.merge(:page => page_from_old_path.explode_path)
  170 + return true
  171 + end
  172 + end
  173 +
  174 + return false
  175 + end
  176 +
  177 + def process_forum_terms_of_use(user, terms_accepted = nil)
  178 + if @page.forum? && @page.has_terms_of_use && terms_accepted == "true"
  179 + @page.add_agreed_user(user)
  180 + end
  181 + end
  182 +
  183 + def is_a_forum_topic? (page)
  184 + return (!@page.parent.nil? && @page.parent.forum?)
  185 + end
  186 +
  187 + def rendered_versioned_article
  188 + @versioned_article = @page.versions.find_by_version(@version)
  189 + if @versioned_article && @page.versions.latest.version != @versioned_article.version
  190 + render :template => 'content_viewer/versioned_article.html.erb'
  191 + return true
  192 + end
  193 +
  194 + return false
  195 + end
  196 +
  197 + def rendered_file_download(view = nil)
  198 + if @page.download? view
  199 + headers['Content-Type'] = @page.mime_type
  200 + headers.merge! @page.download_headers
  201 + data = @page.data
  202 +
  203 + # TODO test the condition
  204 + if data.nil?
  205 + raise "No data for file"
  206 + end
  207 +
  208 + render :text => data, :layout => false
  209 + return true
  210 + end
  211 +
  212 + return false
  213 + end
  214 +
  215 + def process_page_posts(params)
  216 + if @page.has_posts?
  217 + posts = get_posts(params[:year], params[:month])
  218 +
  219 + #FIXME Need to run this before the pagination because this version of
  220 + # will_paginate returns a will_paginate collection instead of a
  221 + # relation.
  222 + posts = posts.native_translations if blog_with_translation?(@page)
  223 +
  224 + @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a
  225 +
  226 + if blog_with_translation?(@page)
  227 + @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact
  228 + end
  229 + end
  230 + end
  231 +
  232 + def get_posts(year = nil, month = nil)
  233 + if year && month
  234 + filter_date = DateTime.parse("#{year}-#{month}-01")
  235 + return @page.posts.by_range(filter_date..filter_date.at_end_of_month)
  236 + else
  237 + return @page.posts
  238 + end
  239 + end
  240 +
  241 + def blog_with_translation?(page)
  242 + return (page.blog? && page.display_posts_in_current_language?)
  243 + end
  244 +
  245 + def get_images(page, npage, slideshow)
  246 + images = page.images.select{ |a| a.display_to? user }
  247 + images = images.paginate(:per_page => per_page, :page => npage) unless slideshow
  248 +
  249 + return images
  250 + end
  251 +
  252 + def process_page_followers(params)
  253 + @unfollow_form = params[:unfollow] == 'true'
  254 + if params[:unfollow] == 'commit' && request.post?
  255 + @page.followers -= [params[:email]]
  256 + if @page.save
  257 + session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email]
  258 + end
  259 + end
  260 + end
  261 +
  262 + def process_comments(params)
  263 + @comments = @page.comments.without_spam
  264 + @comments = @plugins.filter(:unavailable_comments, @comments)
  265 + @comments_count = @comments.count
  266 + @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] )
  267 + @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order]
  268 + end
  269 +
195 270 end
... ...
app/controllers/public/profile_controller.rb
... ... @@ -32,7 +32,7 @@ class ProfileController &lt; PublicController
32 32 @tag = params[:id]
33 33 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_#{profile.id.to_s}_page_#{params[:npage]}"
34 34 if is_cache_expired?(@tag_cache_key)
35   - @tagged = profile.find_tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage])
  35 + @tagged = profile.tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage])
36 36 end
37 37 end
38 38  
... ... @@ -158,7 +158,7 @@ class ProfileController &lt; PublicController
158 158 session[:notice] = _("You have unblocked %s successfully. ") % profile.name
159 159 redirect_to :controller => 'profile', :action => 'index'
160 160 else
161   - message = __('You are not allowed to unblock enterprises in this environment.')
  161 + message = _('You are not allowed to unblock enterprises in this environment.')
162 162 render_access_denied(message)
163 163 end
164 164 end
... ... @@ -210,7 +210,7 @@ class ProfileController &lt; PublicController
210 210  
211 211 render :update do |page|
212 212 page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity],
213   - :partial => 'comment', :collection => activity.comments.paginate(:per_page => comments_per_page, :page => comment_page)
  213 + :partial => 'comment', :collection => activity.comments.flatten.paginate(:per_page => comments_per_page, :page => comment_page)
214 214  
215 215 if no_more_pages
216 216 page.remove 'profile-wall-activities-comments-more-'+params[:activity]
... ...
app/controllers/public/search_controller.rb
... ... @@ -29,7 +29,7 @@ class SearchController &lt; PublicController
29 29 @asset = key
30 30 send(key)
31 31 @order << key
32   - @names[key] = getterm(description)
  32 + @names[key] = _(description)
33 33 end
34 34 @asset = nil
35 35  
... ... @@ -80,7 +80,7 @@ class SearchController &lt; PublicController
80 80 end
81 81  
82 82 def enterprises
83   - @scope = visible_profiles(Enterprise, [{:products => :product_category}])
  83 + @scope = visible_profiles(Enterprise)
84 84 full_text_search
85 85 end
86 86  
... ... @@ -133,7 +133,7 @@ class SearchController &lt; PublicController
133 133 @tag = params[:tag]
134 134 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}"
135 135 if is_cache_expired?(@tag_cache_key)
136   - @searches[@asset] = {:results => environment.articles.find_tagged_with(@tag).paginate(paginate_options)}
  136 + @searches[@asset] = {:results => environment.articles.tagged_with(@tag).paginate(paginate_options)}
137 137 end
138 138 end
139 139  
... ... @@ -159,7 +159,7 @@ class SearchController &lt; PublicController
159 159 if params[:category_path].blank?
160 160 render_not_found if params[:action] == 'category_index'
161 161 else
162   - path = params[:category_path].join('/')
  162 + path = params[:category_path]
163 163 @category = environment.categories.find_by_path(path)
164 164 if @category.nil?
165 165 render_not_found(path)
... ...
app/helpers/account_helper.rb
... ... @@ -15,12 +15,17 @@ module AccountHelper
15 15  
16 16 def suggestion_based_on_username(requested_username='')
17 17 return "" if requested_username.empty?
  18 +
  19 + requested_username = requested_username.downcase.tr("^#{Profile::IDENTIFIER_FORMAT}", '')
18 20 usernames = []
  21 + tries = 0
19 22 3.times do
20 23 begin
21 24 valid_name = requested_username + rand(1000).to_s
22   - end while (usernames.include?(valid_name) || !Person.is_available?(valid_name, environment))
23   - usernames << valid_name
  25 + tries += 1
  26 + invalid = usernames.include?(valid_name) || !Person.is_available?(valid_name, environment)
  27 + end while tries <= 10 && invalid
  28 + usernames << valid_name unless invalid
24 29 end
25 30 usernames
26 31 end
... ...
app/helpers/application_helper.rb
  1 +# encoding: UTF-8
  2 +
1 3 require 'redcloth'
2 4  
3 5 # Methods added to this helper will be available to all templates in the
... ... @@ -175,7 +177,7 @@ module ApplicationHelper
175 177 # should be a current profile (i.e. while viewing some profile's pages, or the
176 178 # profile info, etc), because if there is no profile an exception is thrown.
177 179 def profile
178   - @controller.send(:profile)
  180 + controller.send(:profile)
179 181 end
180 182  
181 183 def category_color
... ... @@ -277,10 +279,9 @@ module ApplicationHelper
277 279 options[:class].nil? ?
278 280 options[:class]='button-bar' :
279 281 options[:class]+=' button-bar'
280   - concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options))
  282 + concat(content_tag('div', capture(&block).to_s + tag('br', :style => 'clear: left;'), options))
281 283 end
282 284  
283   - VIEW_EXTENSIONS = %w[.rhtml .html.erb]
284 285  
285 286 def partial_for_class_in_view_path(klass, view_path, prefix = nil, suffix = nil)
286 287 return nil if klass.nil?
... ... @@ -294,10 +295,8 @@ module ApplicationHelper
294 295 search_name = "_" + search_name
295 296 end
296 297  
297   - VIEW_EXTENSIONS.each do |ext|
298   - path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name+ext) : File.join(view_path, search_name+ext)
299   - return name if File.exists?(File.join(path))
300   - end
  298 + path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb')
  299 + return name if File.exists?(File.join(path))
301 300  
302 301 partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix)
303 302 end
... ... @@ -305,7 +304,7 @@ module ApplicationHelper
305 304 def partial_for_class(klass, prefix=nil, suffix=nil)
306 305 raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil?
307 306 name = klass.name.underscore
308   - @controller.view_paths.each do |view_path|
  307 + controller.view_paths.reverse_each do |view_path|
309 308 partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix)
310 309 return partial if partial
311 310 end
... ... @@ -317,15 +316,13 @@ module ApplicationHelper
317 316 raise ArgumentError, 'No profile actions view for this class.' if klass.nil?
318 317  
319 318 name = klass.name.underscore
320   - VIEW_EXTENSIONS.each do |ext|
321   - return "blocks/profile_info_actions/"+name+ext if File.exists?(File.join(RAILS_ROOT, 'app', 'views', 'blocks', 'profile_info_actions', name+ext))
322   - end
  319 + return "blocks/profile_info_actions/" + name + '.html.erb' if File.exists?(Rails.root.join('app', 'views', 'blocks', 'profile_info_actions', name + '.html.erb'))
323 320  
324 321 view_for_profile_actions(klass.superclass)
325 322 end
326 323  
327 324 def user
328   - @controller.send(:user)
  325 + controller.send(:user)
329 326 end
330 327  
331 328 # DEPRECATED. Do not use this.
... ... @@ -337,7 +334,7 @@ module ApplicationHelper
337 334 "\n" +
338 335 sources.flatten.map do |source|
339 336 filename = filename_for_stylesheet(source.to_s, themed_source)
340   - if File.exists?(File.join(RAILS_ROOT, 'public', filename))
  337 + if File.exists?(Rails.root.join('public', filename[1..-1]))
341 338 "@import url(#{filename});\n"
342 339 else
343 340 "/* Not included: url(#{filename}) */\n"
... ... @@ -378,10 +375,10 @@ module ApplicationHelper
378 375 # utility for developers: set the theme to 'random' in development mode and
379 376 # you will get a different theme every request. This is interesting for
380 377 # testing
381   - if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random'
  378 + if Rails.env.development? && environment.theme == 'random'
382 379 @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
383 380 @random_theme
384   - elsif ENV['RAILS_ENV'] == 'development' && respond_to?(:params) && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme]))
  381 + elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
385 382 params[:theme]
386 383 else
387 384 if profile && !profile.theme.nil?
... ... @@ -404,10 +401,10 @@ module ApplicationHelper
404 401 end
405 402  
406 403 def theme_view_file(template)
407   - ['.rhtml', '.html.erb'].each do |ext|
408   - file = (RAILS_ROOT + '/public' + theme_path + '/' + template + ext)
409   - return file if File.exists?(file)
410   - end
  404 + # Since we cannot control what people are doing in external themes, we
  405 + # will keep looking for the deprecated .rhtml extension here.
  406 + file = Rails.root.join('public', theme_path[1..-1], template + '.html.erb')
  407 + return file if File.exists?(file)
411 408 nil
412 409 end
413 410  
... ... @@ -423,7 +420,7 @@ module ApplicationHelper
423 420  
424 421 def theme_favicon
425 422 return '/designs/themes/' + current_theme + '/favicon.ico' if profile.nil? || profile.theme.nil?
426   - if File.exists?(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico'))
  423 + if File.exists?(Rails.root.join('public', theme_path, 'favicon.ico'))
427 424 '/designs/themes/' + profile.theme + '/favicon.ico'
428 425 else
429 426 favicon = profile.articles.find_by_path('favicon.ico')
... ... @@ -452,7 +449,7 @@ module ApplicationHelper
452 449 end
453 450  
454 451 def is_testing_theme
455   - !@controller.session[:theme].nil?
  452 + !controller.session[:theme].nil?
456 453 end
457 454  
458 455 def theme_owner
... ... @@ -493,7 +490,7 @@ module ApplicationHelper
493 490 end
494 491  
495 492 def default_or_themed_icon(icon)
496   - if File.exists?(File.join(Rails.root, 'public', theme_path, icon))
  493 + if File.exists?(Rails.root.join('public', theme_path, icon))
497 494 theme_path + icon
498 495 else
499 496 icon
... ... @@ -514,24 +511,25 @@ module ApplicationHelper
514 511  
515 512 def profile_cat_icons( profile )
516 513 if profile.class == Enterprise
517   - icons = profile.product_categories.map{ |c| c.size > 1 ? c[1] : nil }.
518   - compact.uniq.map do |c|
519   - cat_name = c.gsub( /[-_\s,.;'"]+/, '_' )
520   - cat_icon = "/images/icons-cat/#{cat_name}.png"
521   - if ! File.exists? RAILS_ROOT.to_s() + '/public/' + cat_icon
522   - cat_icon = '/images/icons-cat/undefined.png'
523   - end
524   - content_tag('span',
525   - content_tag( 'span', c ),
526   - :title => c,
527   - :class => 'product-cat-icon cat_icon_' + cat_name,
528   - :style => "background-image:url(#{cat_icon})"
529   - )
530   - end.join("\n").html_safe
531   - content_tag('div',
532   - content_tag( 'span', _('Principal Product Categories'), :class => 'header' ) +"\n"+ icons,
533   - :class => 'product-category-icons'
  514 + icons = profile.product_categories.unique_by_level(2).limit(3).map do |c|
  515 + filtered_category = c.filtered_category.blank? ? c.path.split('/').last : c.filtered_category
  516 + category_title = filtered_category.split(/[-_\s,.;'"]+/).map(&:capitalize).join(' ')
  517 + category_name = category_title.gsub(' ', '_' )
  518 + category_icon = "/images/icons-cat/#{category_name}.png"
  519 + if ! File.exists?(Rails.root.join('public', category_icon))
  520 + category_icon = '/images/icons-cat/undefined.png'
  521 + end
  522 + content_tag('span',
  523 + content_tag( 'span', category_title ),
  524 + :title => category_title,
  525 + :class => 'product-cat-icon cat_icon_' + category_name,
  526 + :style => "background-image:url(#{category_icon})"
534 527 )
  528 + end.join("\n").html_safe
  529 + content_tag('div',
  530 + content_tag( 'span', _('Principal Product Categories'), :class => 'header' ) +"\n"+ icons,
  531 + :class => 'product-category-icons'
  532 + )
535 533 else
536 534 ''
537 535 end
... ... @@ -573,7 +571,7 @@ module ApplicationHelper
573 571 # #profile_image) and its name below it.
574 572 def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
575 573 if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info)
576   - return instance_eval(&content)
  574 + return instance_exec(&content)
577 575 end
578 576 name = profile.short_name
579 577 if profile.person?
... ... @@ -591,7 +589,7 @@ module ApplicationHelper
591 589 extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
592 590 links = links_for_balloon(profile)
593 591 content_tag('div', content_tag(tag,
594   - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") +
  592 + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") +
595 593 link_to(
596 594 content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
597 595 content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
... ... @@ -623,7 +621,7 @@ module ApplicationHelper
623 621 end
624 622  
625 623 def theme_option(opt = nil)
626   - conf = RAILS_ROOT.to_s() +
  624 + conf = Rails.root.to_s() +
627 625 '/public' + theme_path +
628 626 '/theme.yml'
629 627 if File.exists?(conf)
... ... @@ -650,7 +648,7 @@ module ApplicationHelper
650 648 lightbox_link_to '<span class="icon-menu-search"></span>'+ _('Search'), {
651 649 :controller => 'search',
652 650 :action => 'popup',
653   - :category_path => (@category ? @category.explode_path : []) },
  651 + :category_path => (@category ? @category.explode_path : nil)},
654 652 :id => 'open_search'
655 653 end
656 654 end
... ... @@ -662,7 +660,7 @@ module ApplicationHelper
662 660 option.each do |file|
663 661 file = theme_path +
664 662 '/javascript/'+ file +'.js'
665   - if File.exists? RAILS_ROOT.to_s() +'/public'+ file
  663 + if File.exists? Rails.root.to_s() +'/public'+ file
666 664 html << javascript_src_tag( file, {} )
667 665 else
668 666 html << '<!-- Not included: '+ file +' -->'
... ... @@ -673,7 +671,7 @@ module ApplicationHelper
673 671  
674 672 def theme_javascript_ng
675 673 script = File.join(theme_path, 'theme.js')
676   - if File.exists?(File.join(Rails.root, 'public', script))
  674 + if File.exists?(Rails.root.join('public', script))
677 675 javascript_include_tag script
678 676 else
679 677 nil
... ... @@ -736,6 +734,10 @@ module ApplicationHelper
736 734 (field_helpers - %w(hidden_field)).each do |selector|
737 735 src = <<-END_SRC
738 736 def #{selector}(field, *args, &proc)
  737 + begin
  738 + object ||= @template.instance_variable_get("@"+object_name.to_s)
  739 + rescue
  740 + end
739 741 text = object.class.respond_to?(:human_attribute_name) && object.class.human_attribute_name(field.to_s) || field.to_s.humanize
740 742 NoosferoFormBuilder::output_field(text, super)
741 743 end
... ... @@ -767,7 +769,7 @@ module ApplicationHelper
767 769 end
768 770 }
769 771 html += "<br />\n".html_safe if line_size == 0 || ( values.size % line_size ) > 0
770   - column = object.class.columns_hash[method.to_s]
  772 + column = object.class.columns_hash[method.to_s] if object
771 773 text =
772 774 ( column ?
773 775 column.human_name :
... ... @@ -803,9 +805,8 @@ module ApplicationHelper
803 805 fields_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
804 806 end
805 807  
806   - def labelled_form_for(name, object = nil, options = {}, &proc)
807   - object ||= instance_variable_get("@#{name}")
808   - form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
  808 + def labelled_form_for(name, options = {}, &proc)
  809 + form_for(name, { :builder => NoosferoFormBuilder }.merge(options), &proc)
809 810 end
810 811  
811 812 def optional_field(profile, name, field_html = nil, only_required = false, &block)
... ... @@ -862,6 +863,7 @@ module ApplicationHelper
862 863 article_helper = ActionView::Base.new
863 864 article_helper.controller = controller
864 865 article_helper.extend ArticleHelper
  866 + article_helper.extend Rails.application.routes.url_helpers
865 867 begin
866 868 class_name = article.class.name + 'Helper'
867 869 klass = class_name.constantize
... ... @@ -887,19 +889,31 @@ module ApplicationHelper
887 889 end
888 890 end
889 891  
  892 + def icon_theme_stylesheet_path
  893 + icon_themes = []
  894 + theme_icon_themes = theme_option(:icon_theme) || []
  895 + for icon_theme in theme_icon_themes do
  896 + theme_path = "/designs/icons/#{icon_theme}/style.css"
  897 + if File.exists?(Rails.root.join('public', theme_path[1..-1]))
  898 + icon_themes << theme_path
  899 + end
  900 + end
  901 + icon_themes
  902 + end
  903 +
890 904 def page_title
891 905 (@page ? @page.title + ' - ' : '') +
892 906 (@topic ? @topic.title + ' - ' : '') +
893 907 (@section ? @section.title + ' - ' : '') +
894 908 (@toc ? _('Online Manual') + ' - ' : '') +
895   - (@controller.controller_name == 'chat' ? _('Chat') + ' - ' : '') +
  909 + (controller.controller_name == 'chat' ? _('Chat') + ' - ' : '') +
896 910 (profile ? profile.short_name : environment.name) +
897 911 (@category ? " - #{@category.full_name}" : '')
898 912 end
899 913  
900 914 # DEPRECATED. Do not use this.
901 915 def import_controller_stylesheets(options = {})
902   - stylesheet_import( "controller_"+ @controller.controller_name(), options )
  916 + stylesheet_import( "controller_"+ controller.controller_name(), options )
903 917 end
904 918  
905 919 def link_to_email(email)
... ... @@ -913,7 +927,7 @@ module ApplicationHelper
913 927 def article_to_html(article, options = {})
914 928 options.merge!(:page => params[:npage])
915 929 content = article.to_html(options)
916   - content = content.kind_of?(Proc) ? self.instance_eval(&content).html_safe : content.html_safe
  930 + content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe
917 931 filter_html(content, article)
918 932 end
919 933  
... ... @@ -947,14 +961,6 @@ module ApplicationHelper
947 961 html
948 962 end
949 963  
950   - def colorpicker_field(object_name, method, options = {})
951   - text_field(object_name, method, options.merge(:class => 'colorpicker_field'))
952   - end
953   -
954   - def colorpicker_field_tag(name, value = nil, options = {})
955   - text_field_tag(name, value, options.merge(:class => 'colorpicker_field'))
956   - end
957   -
958 964 def ui_icon(icon_class, extra_class = '')
959 965 "<span class='ui-icon #{icon_class} #{extra_class}' style='float:left; margin-right:7px;'></span>".html_safe
960 966 end
... ... @@ -968,7 +974,7 @@ module ApplicationHelper
968 974 end
969 975  
970 976 def jquery_theme
971   - theme_option(:jquery_theme) || 'smoothness_mod'
  977 + theme_option(:jquery_theme) || 'smoothness'
972 978 end
973 979  
974 980 def ui_error(message)
... ... @@ -996,17 +1002,26 @@ module ApplicationHelper
996 1002 def display_category_menu(block, categories, root = true)
997 1003 categories = categories.sort{|x,y| x.name <=> y.name}
998 1004 return "" if categories.blank?
999   - content_tag(:ul,
  1005 + content_tag(:ul) do
1000 1006 categories.map do |category|
1001 1007 category_path = category.kind_of?(ProductCategory) ? {:controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id} : { :controller => 'search', :action => 'category_index', :category_path => category.explode_path }
1002   - category.display_in_menu? ?
1003   - content_tag(:li,
1004   - ( !category.is_leaf_displayable_in_menu? ? content_tag(:a, collapsed_item_icon, :href => "#", :id => "block_#{block.id}_category_#{category.id}", :class => 'category-link-expand ' + (root ? 'category-root' : 'category-no-root'), :onclick => "expandCategory(#{block.id}, #{category.id}); return false", :style => 'display: none') : leaf_item_icon) +
1005   - link_to(content_tag(:span, category.name, :class => 'category-name'), category_path, :class => ("category-leaf" if category.is_leaf_displayable_in_menu?)) +
1006   - content_tag(:div, display_category_menu(block, category.children, false), :id => "block_#{block.id}_category_content_#{category.id}", :class => 'child-category')
1007   - ) : ''
1008   - end
1009   - ) +
  1008 + if category.display_in_menu?
  1009 + content_tag(:li) do
  1010 + if !category.is_leaf_displayable_in_menu?
  1011 + content_tag(:a, collapsed_item_icon, :href => "#", :id => "block_#{block.id}_category_#{category.id}", :class => "category-link-expand " + (root ? "category-root" : "category-no-root"), :onclick => "expandCategory(#{block.id}, #{category.id}); return false", :style => "display: none")
  1012 + else
  1013 + leaf_item_icon
  1014 + end +
  1015 + link_to(content_tag(:span, category.name, :class => "category-name"), category_path, :class => ("category-leaf" if category.is_leaf_displayable_in_menu?)) +
  1016 + content_tag(:div, :id => "block_#{block.id}_category_content_#{category.id}", :class => 'child-category') do
  1017 + display_category_menu(block, category.children, false)
  1018 + end
  1019 + end
  1020 + else
  1021 + ""
  1022 + end
  1023 + end.join.html_safe
  1024 + end +
1010 1025 content_tag(:p) +
1011 1026 (root ? javascript_tag("
1012 1027 jQuery('.child-category').hide();
... ... @@ -1027,8 +1042,8 @@ module ApplicationHelper
1027 1042 links.push(_('New content') => colorbox_options({:href => url_for({:controller => 'cms', :action => 'new', :profile => current_user.login, :cms => true})}))
1028 1043 end
1029 1044  
1030   - link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => ''}, :id => 'submenu-contents') +
1031   - link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
  1045 + link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') +
  1046 + link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
1032 1047 end
1033 1048 alias :browse_contents_menu :search_contents_menu
1034 1049  
... ... @@ -1044,7 +1059,7 @@ module ApplicationHelper
1044 1059 end
1045 1060  
1046 1061 link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') +
1047   - link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
  1062 + link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
1048 1063 end
1049 1064 alias :browse_people_menu :search_people_menu
1050 1065  
... ... @@ -1060,7 +1075,7 @@ module ApplicationHelper
1060 1075 end
1061 1076  
1062 1077 link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') +
1063   - link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
  1078 + link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
1064 1079 end
1065 1080 alias :browse_communities_menu :search_communities_menu
1066 1081  
... ... @@ -1072,7 +1087,7 @@ module ApplicationHelper
1072 1087 def render_environment_features(folder)
1073 1088 result = ''
1074 1089 environment.enabled_features.keys.each do |feature|
1075   - file = File.join(@controller.view_paths.last, 'shared', folder.to_s, "#{feature}.rhtml")
  1090 + file = Rails.root.join('app/views/shared', folder.to_s, "#{feature}.html.erb")
1076 1091 if File.exists?(file)
1077 1092 result << render(:file => file, :use_full_path => false)
1078 1093 end
... ... @@ -1085,10 +1100,10 @@ module ApplicationHelper
1085 1100 link_to_all = nil
1086 1101 if list.count > 5
1087 1102 list = list.first(5)
1088   - link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => current_user.login)
  1103 + link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => user.identifier)
1089 1104 end
1090 1105 link = list.map do |element|
1091   - link_to(content_tag('strong', [_('<span>Manage</span> %s') % element.short_name(25)]), @environment.top_url + "/myprofile/#{element.identifier}", :class => "icon-menu-"+element.class.identification.underscore, :title => [_('Manage %s') % element.short_name])
  1106 + link_to(content_tag('strong', _('<span>Manage</span> %s') % element.short_name(25)), element.admin_url, :class => "icon-menu-"+element.class.identification.underscore, :title => _('Manage %s') % element.short_name)
1092 1107 end
1093 1108 if link_to_all
1094 1109 link << link_to_all
... ... @@ -1098,29 +1113,33 @@ module ApplicationHelper
1098 1113 end
1099 1114  
1100 1115 def manage_enterprises
1101   - return unless user && user.environment.enabled?(:display_my_enterprises_on_user_menu)
1102   - manage_link(user.enterprises, :enterprises)
  1116 + return '' unless user && user.environment.enabled?(:display_my_enterprises_on_user_menu)
  1117 + manage_link(user.enterprises, :enterprises).to_s
1103 1118 end
1104 1119  
1105 1120 def manage_communities
1106   - return unless user && user.environment.enabled?(:display_my_communities_on_user_menu)
  1121 + return '' unless user && user.environment.enabled?(:display_my_communities_on_user_menu)
1107 1122 administered_communities = user.communities.more_popular.select {|c| c.admins.include? user}
1108   - manage_link(administered_communities, :communities)
  1123 + manage_link(administered_communities, :communities).to_s
  1124 + end
  1125 +
  1126 + def admin_link
  1127 + user.is_admin?(environment) ? link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') : ''
1109 1128 end
1110 1129  
1111 1130 def usermenu_logged_in
1112 1131 pending_tasks_count = ''
1113 1132 count = user ? Task.to(user).pending.count : -1
1114 1133 if count > 0
1115   - pending_tasks_count = link_to(count.to_s, @environment.top_url + '/myprofile/{login}/tasks', :id => 'pending-tasks-count', :title => _("Manage your pending tasks"))
  1134 + pending_tasks_count = link_to(count.to_s, user.tasks_url, :id => 'pending-tasks-count', :title => _("Manage your pending tasks"))
1116 1135 end
1117 1136  
1118   - (_("<span class='welcome'>Welcome,</span> %s") % link_to('<i style="background-image:url({avatar})"></i><strong>{login}</strong>', @environment.top_url + '/{login}', :id => "homepage-link", :title => _('Go to your homepage'))) +
  1137 + (_("<span class='welcome'>Welcome,</span> %s") % link_to("<i style='background-image:url(#{user.profile_custom_icon(gravatar_default)})'></i><strong>#{user.identifier}</strong>", user.public_profile_url, :id => "homepage-link", :title => _('Go to your homepage'))) +
1119 1138 render_environment_features(:usermenu) +
1120   - link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.top_url + '/admin', :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') +
1121   - manage_enterprises.to_s +
1122   - manage_communities.to_s +
1123   - link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', @environment.top_url + '/myprofile/{login}', :class => 'ctrl-panel', :title => _("Configure your personal account and content")) +
  1139 + admin_link +
  1140 + manage_enterprises +
  1141 + manage_communities +
  1142 + link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :class => 'ctrl-panel', :title => _("Configure your personal account and content")) +
1124 1143 pending_tasks_count +
1125 1144 link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system"))
1126 1145 end
... ... @@ -1130,7 +1149,7 @@ module ApplicationHelper
1130 1149 text_area(object_name, method, { :id => text_area_id, :onkeyup => "limited_text_area('#{text_area_id}', #{limit})" }.merge(options)),
1131 1150 content_tag(:p, content_tag(:span, limit) + ' ' + _(' characters left'), :id => text_area_id + '_left'),
1132 1151 content_tag(:p, _('Limit of characters reached'), :id => text_area_id + '_limit', :style => 'display: none')
1133   - ], :class => 'limited-text-area')
  1152 + ].join, :class => 'limited-text-area')
1134 1153 end
1135 1154  
1136 1155 def expandable_text_area(object_name, method, text_area_id, options = {})
... ... @@ -1148,6 +1167,7 @@ module ApplicationHelper
1148 1167 #FIXME Use time_ago_in_words instead of this method if you're using Rails 2.2+
1149 1168 def time_ago_as_sentence(from_time, include_seconds = false)
1150 1169 to_time = Time.now
  1170 + from_time = Time.parse(from_time.to_s)
1151 1171 from_time = from_time.to_time if from_time.respond_to?(:to_time)
1152 1172 to_time = to_time.to_time if to_time.respond_to?(:to_time)
1153 1173 distance_in_minutes = (((to_time - from_time).abs)/60).round
... ... @@ -1328,6 +1348,25 @@ module ApplicationHelper
1328 1348 expirable_content_reference content, action, text, url, options
1329 1349 end
1330 1350  
  1351 + def error_messages_for(*args)
  1352 + options = args.pop if args.last.is_a?(Hash)
  1353 + errors = []
  1354 + args.each do |name|
  1355 + object = instance_variable_get("@#{name}")
  1356 + object.errors.full_messages.each do |msg|
  1357 + errors << msg
  1358 + end if object
  1359 + end
  1360 + return '' if errors.empty?
  1361 +
  1362 + content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do
  1363 + content_tag(:h2, _('Errors while saving')) +
  1364 + content_tag(:ul) do
  1365 + errors.map { |err| content_tag(:li, err) }.join
  1366 + end
  1367 + end
  1368 + end
  1369 +
1331 1370 def private_profile_partial_parameters
1332 1371 if profile.person?
1333 1372 @action = :add_friend
... ... @@ -1357,7 +1396,7 @@ module ApplicationHelper
1357 1396 doc.search('.macro').each do |macro|
1358 1397 macro_name = macro['data-macro']
1359 1398 result = @plugins.parse_macro(macro_name, macro, source)
1360   - macro.inner_html = result.kind_of?(Proc) ? self.instance_eval(&result) : result
  1399 + macro.inner_html = result.kind_of?(Proc) ? self.instance_exec(&result) : result
1361 1400 end
1362 1401 doc.html
1363 1402 end
... ...
app/helpers/article_helper.rb
1 1 module ArticleHelper
2 2  
  3 + include PrototypeHelper
3 4 include TokenHelper
4 5  
5 6 def custom_options_for_article(article, tokenized_children)
... ...
app/helpers/assets_helper.rb
... ... @@ -7,9 +7,9 @@ module AssetsHelper
7 7 [ options.merge(:asset => 'articles'), "icon-menu-articles", _('Articles') ],
8 8 [ options.merge(:asset => 'people'), "icon-menu-people", _('People') ],
9 9 [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ],
10   - [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", __('Enterprises') ],
11   - [ options.merge(:asset => 'communities'), "icon-menu-community", __('Communities') ],
12   - [ options.merge(:asset => 'events'), "icon-event", __('Events') ],
  10 + [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ],
  11 + [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ],
  12 + [ options.merge(:asset => 'events'), "icon-event", _('Events') ],
13 13  
14 14 ].select do |target, css_class, name|
15 15 !environment.enabled?('disable_asset_' + target[:asset])
... ...
app/helpers/boxes_helper.rb
1 1 module BoxesHelper
2 2  
3 3 def insert_boxes(content)
4   - if @controller.send(:boxes_editor?) && @controller.send(:uses_design_blocks?)
5   - content + display_boxes_editor(@controller.boxes_holder)
  4 + if controller.send(:boxes_editor?) && controller.send(:uses_design_blocks?)
  5 + content + display_boxes_editor(controller.boxes_holder)
6 6 else
7   - maybe_display_custom_element(@controller.boxes_holder, :custom_header_expanded, :id => 'profile-header') +
8   - if @controller.send(:uses_design_blocks?)
9   - display_boxes(@controller.boxes_holder, content)
  7 + maybe_display_custom_element(controller.boxes_holder, :custom_header_expanded, :id => 'profile-header') +
  8 + if controller.send(:uses_design_blocks?)
  9 + display_boxes(controller.boxes_holder, content)
10 10 else
11 11 content_tag('div',
12 12 content_tag('div',
... ... @@ -16,7 +16,7 @@ module BoxesHelper
16 16 :class => 'no-boxes'
17 17 )
18 18 end +
19   - maybe_display_custom_element(@controller.boxes_holder, :custom_footer_expanded, :id => 'profile-footer')
  19 + maybe_display_custom_element(controller.boxes_holder, :custom_footer_expanded, :id => 'profile-footer')
20 20 end
21 21 end
22 22  
... ... @@ -221,7 +221,7 @@ module BoxesHelper
221 221  
222 222 if block.embedable?
223 223 embed_code = block.embed_code
224   - embed_code = instance_eval(&embed_code) if embed_code.respond_to?(:call)
  224 + embed_code = instance_exec(&embed_code) if embed_code.respond_to?(:call)
225 225 html = content_tag('div',
226 226 content_tag('h2', _('Embed block code')) +
227 227 content_tag('div', _('Below, you''ll see a field containing embed code for the block. Just copy the code and paste it into your website or blogging software.'), :style => 'margin-bottom: 1em;') +
... ... @@ -234,7 +234,7 @@ module BoxesHelper
234 234 end
235 235  
236 236 def current_blocks
237   - @controller.boxes_holder.boxes.map(&:blocks).inject([]){|ac, a| ac + a}
  237 + controller.boxes_holder.boxes.map(&:blocks).inject([]){|ac, a| ac + a}
238 238 end
239 239  
240 240 # DEPRECATED. Do not use this.
... ...
app/helpers/catalog_helper.rb
... ... @@ -9,11 +9,9 @@ module CatalogHelper
9 9 @categories = ProductCategory.on_level(params[:level]).order(:name)
10 10 end
11 11  
12   - @products = profile.products.from_category(@category).paginate(
13   - :order => 'available desc, highlighted desc, name asc',
14   - :per_page => @profile.products_per_catalog_page,
15   - :page => options[:page]
16   - )
  12 + @products = profile.products.from_category(@category).
  13 + reorder('available desc, highlighted desc, name asc').
  14 + paginate(:per_page => @profile.products_per_catalog_page, :page => options[:page])
17 15 end
18 16  
19 17 def breadcrumb(category)
... ... @@ -41,7 +39,7 @@ module CatalogHelper
41 39 cat_link = category_link sub_category
42 40 sub_categories << content_tag('li', cat_link) unless cat_link.nil?
43 41 end
44   - content_tag('ul', sub_categories) if sub_categories.size > 0
  42 + content_tag('ul', sub_categories.join) if sub_categories.size > 0
45 43 end
46 44  
47 45 end
... ...
app/helpers/categories_helper.rb
... ... @@ -50,10 +50,17 @@ module CategoriesHelper
50 50  
51 51 #FIXME make this test
52 52 def selected_category_link(cat)
53   - content_tag('div', button_to_function_without_text(:remove, _('Remove'), nil) {|page| page["selected-category-#{cat.id}"].remove} +
54   - link_to_function(cat.full_name(' &rarr; '), nil, :id => "remove-selected-category-#{cat.id}-button", :class => 'select-subcategory-link') {|page| page["selected-category-#{cat.id}"].remove},
  53 + js_remove = "jQuery('#selected-category-#{cat.id}').remove();"
  54 + content_tag('div', button_to_function_without_text(:remove, _('Remove'), js_remove) +
  55 + link_to_function(cat.full_name(' &rarr; '), js_remove, :id => "remove-selected-category-#{cat.id}-button", :class => 'select-subcategory-link'),
55 56 :class => 'selected-category'
56 57 )
57 58 end
58 59  
  60 + def update_categories_link(body, category_id=nil, html_options={})
  61 + link_to body,
  62 + { :action => "update_categories", :category_id => category_id, :id => @object },
  63 + {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options)
  64 + end
  65 +
59 66 end
... ...
app/helpers/cms_helper.rb
... ... @@ -11,7 +11,7 @@ module CmsHelper
11 11  
12 12 def add_upload_file_field(name, locals)
13 13 button_to_function :add, name, nil do |page|
14   - page.insert_html :bottom, :uploaded_files, :partial => 'upload_file', :locals => locals, :object => UploadedFile.new
  14 + page.insert_html :bottom, :uploaded_files, CGI::escapeHTML(render(:partial => 'upload_file', :locals => locals, :object => UploadedFile.new))
15 15 end
16 16 end
17 17  
... ...
app/helpers/comment_helper.rb
... ... @@ -23,7 +23,7 @@ module CommentHelper
23 23  
24 24 def comment_extra_contents(comment)
25 25 @plugins.dispatch(:comment_extra_contents, comment).collect do |extra_content|
26   - extra_content.kind_of?(Proc) ? self.instance_eval(&extra_content) : extra_content
  26 + extra_content.kind_of?(Proc) ? self.instance_exec(&extra_content) : extra_content
27 27 end.join('\n')
28 28 end
29 29  
... ... @@ -41,7 +41,7 @@ module CommentHelper
41 41 def links_for_comment_actions(comment)
42 42 actions = [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)]
43 43 @plugins.dispatch(:comment_actions, comment).collect do |action|
44   - actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action)
  44 + actions << (action.kind_of?(Proc) ? self.instance_exec(&action) : action)
45 45 end
46 46 actions.flatten.compact
47 47 end
... ... @@ -56,9 +56,9 @@ module CommentHelper
56 56 def link_for_spam(comment)
57 57 if comment.can_be_marked_as_spam_by?(user)
58 58 if comment.spam?
59   - {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')}
  59 + {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, \'%s\'); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id), :class => 'comment-footer comment-footer-link comment-footer-hide')}
60 60 else
61   - {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')}
  61 + {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, \'%s\', \'%s\'); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id), _('Are you sure you want to mark this comment as SPAM?')], :class => 'comment-footer comment-footer-link comment-footer-hide')}
62 62 end
63 63 end
64 64 end
... ... @@ -71,7 +71,7 @@ module CommentHelper
71 71  
72 72 def link_for_remove(comment)
73 73 if comment.can_be_destroyed_by?(user)
74   - {:link => link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children')}
  74 + {:link => link_to_function(_('Remove'), 'remove_comment(this, \'%s\', \'%s\'); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id), _('Are you sure you want to remove this comment and all its replies?')], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children')}
75 75 end
76 76 end
77 77  
... ...
app/helpers/content_viewer_helper.rb
... ... @@ -26,7 +26,7 @@ module ContentViewerHelper
26 26 end
27 27 title << content_tag('span',
28 28 content_tag('span', show_date(article.published_at), :class => 'date') +
29   - content_tag('span', [_(", by %s") % link_to(article.author_name, article.author_url)], :class => 'author') +
  29 + content_tag('span', _(", by %s") % link_to(article.author_name, article.author_url), :class => 'author') +
30 30 content_tag('span', comments, :class => 'comments'),
31 31 :class => 'created-at'
32 32 )
... ... @@ -52,7 +52,7 @@ module ContentViewerHelper
52 52 end
53 53  
54 54 def addthis_image_tag
55   - if File.exists?(File.join(Rails.root, 'public', theme_path, 'images', 'addthis.gif'))
  55 + if File.exists?(Rails.root.join('public', theme_path, 'images', 'addthis.gif'))
56 56 image_tag(File.join(theme_path, 'images', 'addthis.gif'), :border => 0, :alt => '')
57 57 else
58 58 image_tag("/images/bt-bookmark.gif", :width => 53, :height => 16, :border => 0, :alt => '')
... ...
app/helpers/countries_helper.rb
1   -class CountriesHelper
  1 +# encoding: UTF-8
2 2  
3   - include Singleton
  3 +module CountriesHelper
  4 +
  5 + class Object
  6 + include ::CountriesHelper
  7 + include Singleton
  8 + end
4 9  
5 10 # a dump of iso_3166.xml from Debian source package iso-codes
6 11 COUNTRIES = [
... ... @@ -262,7 +267,7 @@ class CountriesHelper
262 267 end
263 268  
264 269 def countries
265   - self.class.countries.map {|item| [gettext(item[0]), item[1] ]}.sort_by { |entry| entry.first.transliterate }
  270 + CountriesHelper.countries.map {|item| [gettext(item[0]), item[1] ]}.sort_by { |entry| entry.first.transliterate }
266 271 end
267 272  
268 273 def lookup(code)
... ...
app/helpers/folder_helper.rb
  1 +require 'short_filename'
  2 +
1 3 module FolderHelper
2 4  
3 5 include ShortFilename
... ...
app/helpers/forms_helper.rb
1 1 module FormsHelper
2   -
3   - def generate_form( name, obj, fields={} )
4   - labelled_form_for name, obj do |f|
5   - f.text_field(:name)
6   - end
7   - end
8   -
9 2 def labelled_radio_button( human_name, name, value, checked = false, options = {} )
10 3 options[:id] ||= 'radio-' + FormsHelper.next_id_number
11 4 radio_button_tag( name, value, checked, options ) +
... ... @@ -41,6 +34,7 @@ module FormsHelper
41 34 the_class << ' ' << html_options[:class]
42 35 end
43 36  
  37 + html_options.delete(:cancel)
44 38 bt_submit = submit_tag(label, html_options.merge(:class => the_class))
45 39  
46 40 bt_submit + bt_cancel
... ...
app/helpers/forum_helper.rb
... ... @@ -36,7 +36,7 @@ module ForumHelper
36 36 :id => "post-#{art.id}"
37 37 )
38 38 }
39   - content_tag('table', content) + (pagination or '')
  39 + content_tag('table', content.join) + (pagination or '')
40 40 end
41 41  
42 42 def last_topic_update(article)
... ...
app/helpers/language_helper.rb
... ... @@ -22,7 +22,7 @@ module LanguageHelper
22 22 if options[:element] == 'dropdown'
23 23 select_tag('lang',
24 24 options_for_select(locales.map{|code,name| [name, code]}, current),
25   - :onchange => "document.location.href= #{url_for(params.merge(:lang => 'LANGUAGE')).inspect}.replace(/LANGUAGE/, this.value) ;",
  25 + :onchange => "document.location.href= #{url_for(params.merge(:lang => 'LANGUAGE'))}.replace(/LANGUAGE/, this.value) ;",
26 26 :help => _('The language you choose here is the language used for options, buttons, etc. It does not affect the language of the content created by other users.')
27 27 )
28 28 else
... ...
app/helpers/layout_helper.rb
... ... @@ -2,14 +2,14 @@ module LayoutHelper
2 2  
3 3 def body_classes
4 4 # Identify the current controller and action for the CSS:
5   - " controller-#{@controller.controller_name}" +
6   - " action-#{@controller.controller_name}-#{@controller.action_name}" +
7   - " template-#{profile.nil? ? "default" : profile.layout_template}" +
  5 + " controller-#{controller.controller_name}" +
  6 + " action-#{controller.controller_name}-#{controller.action_name}" +
  7 + " template-#{@layout_template || if profile.blank? then 'default' else profile.layout_template end}" +
8 8 (!profile.nil? && profile.is_on_homepage?(request.path,@page) ? " profile-homepage" : "")
9 9 end
10 10  
11 11 def noosfero_javascript
12   - plugins_javascripts = @plugins.map { |plugin| plugin.js_files.map { |js| plugin.class.public_path(js) } }.flatten
  12 + plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js) } }.flatten
13 13  
14 14 output = ''
15 15 output += render :file => 'layouts/_javascript'
... ... @@ -26,14 +26,13 @@ module LayoutHelper
26 26 'search',
27 27 'thickbox',
28 28 'lightbox',
29   - 'colorpicker',
30 29 'colorbox',
31 30 pngfix_stylesheet_path,
32 31 ] + tokeninput_stylesheets
33 32 plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') }
34 33  
35 34 output = ''
36   - output += stylesheet_link_tag standard_stylesheets, :cache => 'cache'
  35 + output += stylesheet_link_tag standard_stylesheets, :cache => 'cache/application'
37 36 output += stylesheet_link_tag template_stylesheet_path
38 37 output += stylesheet_link_tag icon_theme_stylesheet_path
39 38 output += stylesheet_link_tag jquery_ui_theme_stylesheet_path
... ... @@ -69,7 +68,7 @@ module LayoutHelper
69 68 theme_icon_themes = theme_option(:icon_theme) || []
70 69 for icon_theme in theme_icon_themes do
71 70 theme_path = "/designs/icons/#{icon_theme}/style.css"
72   - if File.exists?(File.join(RAILS_ROOT, 'public', theme_path))
  71 + if File.exists?(Rails.root.join('public', theme_path))
73 72 icon_themes << theme_path
74 73 end
75 74 end
... ... @@ -77,7 +76,7 @@ module LayoutHelper
77 76 end
78 77  
79 78 def jquery_ui_theme_stylesheet_path
80   - 'jquery.ui/' + jquery_theme + '/jquery-ui-1.8.2.custom'
  79 + "https://code.jquery.com/ui/1.10.4/themes/#{jquery_theme}/jquery-ui.css"
81 80 end
82 81  
83 82 def theme_stylesheet_path
... ... @@ -86,7 +85,7 @@ module LayoutHelper
86 85  
87 86 def addthis_javascript
88 87 if NOOSFERO_CONF['addthis_enabled']
89   - '<script src="http://s7.addthis.com/js/152/addthis_widget.js"></script>'
  88 + '<script src="https://s7.addthis.com/js/152/addthis_widget.js"></script>'
90 89 end
91 90 end
92 91  
... ...
app/helpers/macros_helper.rb
... ... @@ -39,7 +39,7 @@ module MacrosHelper
39 39 plugins_javascripts = []
40 40 @plugins.dispatch(:macros).map do |macro|
41 41 if macro.configuration[:js_files]
42   - macro.configuration[:js_files].map { |js| plugins_javascripts << macro.plugin.public_path(js) }
  42 + [macro.configuration[:js_files]].flatten.map { |js| plugins_javascripts << macro.plugin.public_path(js) }
43 43 end
44 44 end
45 45 javascript_include_tag(plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty?
... ... @@ -49,7 +49,7 @@ module MacrosHelper
49 49 plugins_css = []
50 50 @plugins.dispatch(:macros).map do |macro|
51 51 if macro.configuration[:css_files]
52   - macro.configuration[:css_files].map { |css| plugins_css << macro.plugin.public_path(css) }
  52 + [macro.configuration[:css_files]].flatten.map { |css| plugins_css << macro.plugin.public_path(css) }
53 53 end
54 54 end
55 55 plugins_css.join(',')
... ...
app/helpers/manage_products_helper.rb
  1 +# encoding: UTF-8
  2 +
1 3 module ManageProductsHelper
2 4  
3 5 def remote_function_to_update_categories_selection(container_id, options = {})
... ... @@ -26,27 +28,10 @@ module ManageProductsHelper
26 28 def hierarchy_category_navigation(current_category, options = {})
27 29 hierarchy = []
28 30 if current_category
29   - count_chars = 0
30   - unless options[:hide_current_category]
31   - hierarchy << current_category.name
32   - count_chars += current_category.name.length
33   - end
  31 + hierarchy << current_category.name unless options[:hide_current_category]
34 32 ancestors = current_category.ancestors
35   - toplevel = ancestors.pop
36   - if toplevel
37   - count_chars += toplevel.name.length
38   - end
39 33 ancestors.each do |category|
40   - if count_chars > 55
41   - hierarchy << hierarchy_category_item(category, options[:make_links], '( … )')
42   - break
43   - else
44   - hierarchy << hierarchy_category_item(category, options[:make_links])
45   - end
46   - count_chars += category.name.length
47   - end
48   - if toplevel
49   - hierarchy << hierarchy_category_item(toplevel, options[:make_links])
  34 + hierarchy << hierarchy_category_item(category, options[:make_links])
50 35 end
51 36 end
52 37 hierarchy.reverse.join(options[:separator] || ' &rarr; ')
... ... @@ -55,7 +40,7 @@ module ManageProductsHelper
55 40 def options_for_select_categories(categories, selected = nil)
56 41 categories.sort_by{|cat| cat.name.transliterate}.map do |category|
57 42 selected_attribute = selected.nil? ? '' : (category == selected ? "selected='selected'" : '')
58   - "<option value='#{category.id}' title='#{category.name}' #{selected_attribute}>#{truncate(category.name, :length => 33) + (category.leaf? ? '': ' &raquo;')}</option>"
  43 + "<option value='#{category.id}' title='#{category.name}' #{selected_attribute}>#{category.name + (category.leaf? ? '': ' &raquo;')}</option>"
59 44 end.join("\n")
60 45 end
61 46  
... ... @@ -161,7 +146,7 @@ module ManageProductsHelper
161 146 def cancel_edit_product_link(product, field, html_options = {})
162 147 return '' unless (user && user.has_permission?('manage_products', profile))
163 148 button_to_function(:cancel, _('Cancel'), nil, html_options) do |page|
164   - page.replace_html "product-#{field}", :partial => "display_#{field}", :locals => {:product => product}
  149 + page.replace_html "product-#{field}", CGI::escapeHTML(render :partial => "display_#{field}", :locals => {:product => product})
165 150 end
166 151 end
167 152  
... ...
app/helpers/profile_editor_helper.rb
... ... @@ -101,7 +101,7 @@ module ProfileEditorHelper
101 101 end
102 102  
103 103 def country_helper
104   - @country_helper ||= CountriesHelper.instance
  104 + @country_helper ||= CountriesHelper::Object.instance
105 105 end
106 106  
107 107 def select_country(title, object, method, html_options = {}, options = {})
... ... @@ -129,7 +129,7 @@ module ProfileEditorHelper
129 129 else
130 130 domains = environment.domains
131 131 end
132   - labelled_form_field(__('Preferred domain name:'), select(object, :preferred_domain_id, domains.map {|item| [item.name, item.id]}, :prompt => '&lt;' + _('Select domain') + '&gt;'))
  132 + labelled_form_field(_('Preferred domain name:'), select(object, :preferred_domain_id, domains.map {|item| [item.name, item.id]}, :prompt => '&lt;' + _('Select domain') + '&gt;'))
133 133 end
134 134  
135 135 def control_panel(&block)
... ...
app/helpers/sweeper_helper.rb
... ... @@ -18,9 +18,7 @@ module SweeperHelper
18 18 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s))
19 19 end
20 20  
21   - # friends blocks
22   - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}
23   - BlockSweeper.expire_blocks(blocks)
  21 + expire_blocks_cache(profile, [:profile])
24 22 end
25 23  
26 24 def expire_communities(profile)
... ...
app/helpers/tags_helper.rb
  1 +# encoding: UTF-8
  2 +
1 3 module TagsHelper
2 4  
3 5 module Cloud
... ... @@ -7,7 +9,7 @@ module TagsHelper
7 9  
8 10 # <tt>tags</tt> must be a hash where the keys are tag names and the values
9 11 # the count of elements tagged with the tag, as returned by
10   - # Profile#find_tagged_with. If not tags were returned, just returns
  12 + # Profile#tagged_with. If not tags were returned, just returns
11 13 # _('No tags yet.')
12 14 #
13 15 # <tagname_option> must be a symbol representing the key to be inserted in
... ... @@ -39,15 +41,11 @@ module TagsHelper
39 41 max = tags.values.max.to_f
40 42 min = tags.values.min.to_f
41 43  
42   - # Uses iconv to translate utf8 strings to ascii.
43   - # If can't translate a character, ignore it.
44   - require 'iconv'
45   - utf8_to_ascii = Iconv.new("ASCII//TRANSLIT//IGNORE","UTF8")
46 44 # Sorts first based on translated strings and then, if they are equal, based on the original form.
47 45 # This way variant characters falls on the same level as their base characters and don't end up
48 46 # at the end of the tag list.
49 47 # Example: AA ÁA AB Z instead of AA AB Z ÁA
50   - tags.collect{ |k,v| [utf8_to_ascii.iconv(k).downcase, [k,v]] }.sort.collect { |ascii, t| t }.map do |tag,count|
  48 + tags.collect{ |k,v| [ActiveSupport::Inflector.transliterate(k).downcase, [k,v]] }.sort.collect { |ascii, t| t }.map do |tag,count|
51 49 if ( max == min )
52 50 v = 0.5
53 51 else
... ...
app/helpers/users_helper.rb
... ... @@ -18,7 +18,7 @@ module UsersHelper
18 18 )
19 19 end
20 20  
21   - def filter_title(filter)
  21 + def users_filter_title(filter)
22 22 FILTER_TRANSLATION[filter]
23 23 end
24 24  
... ...
app/mailers/.gitkeep 0 → 100644
app/mailers/comment_notifier.rb 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +class Comment::Notifier < ActionMailer::Base
  2 + def notification(comment)
  3 + profile = comment.article.profile
  4 + @recipient = profile.nickname || profile.name
  5 + @sender = comment.author_name
  6 + @sender_link = comment.author_link
  7 + @article_title = comment.article.name
  8 + @comment_url = comment.url
  9 + @comment_title = comment.title
  10 + @comment_body = comment.body
  11 + @environment = profile.environment.name
  12 + @url = profile.environment.top_url
  13 +
  14 + mail(
  15 + to: comment.notification_emails,
  16 + from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
  17 + subject: _("[%s] you got a new comment!") % [profile.environment.name]
  18 + )
  19 + end
  20 +
  21 + def mail_to_followers(comment, emails)
  22 + profile = comment.article.profile
  23 + @recipient = profile.nickname || profile.name
  24 + @sender = comment.author_name
  25 + @sender_link = comment.author_link
  26 + @article_title = comment.article.name
  27 + @comment_url = comment.url
  28 + @unsubscribe_url = comment.article.view_url.merge({:unfollow => true})
  29 + @comment_title = comment.title
  30 + @comment_body = comment.body
  31 + @environment = profile.environment.name
  32 + @url = profile.environment.top_url
  33 +
  34 + mail(
  35 + bcc: emails,
  36 + from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
  37 + subject: _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name]
  38 + )
  39 + end
  40 +end
... ...
app/mailers/contact.rb 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +class Contact
  2 +
  3 + include ActiveModel::Validations
  4 +
  5 + def initialize(attributes = nil)
  6 + if attributes
  7 + attributes.each do |attr,value|
  8 + self.send("#{attr}=", value)
  9 + end
  10 + end
  11 + end
  12 +
  13 + attr_accessor :name
  14 + attr_accessor :subject
  15 + attr_accessor :message
  16 + attr_accessor :email
  17 + attr_accessor :state
  18 + attr_accessor :city
  19 + attr_accessor :receive_a_copy
  20 + attr_accessor :dest
  21 + attr_accessor :sender
  22 +
  23 + N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name')
  24 +
  25 + validates_presence_of :subject, :email, :message, :name
  26 + validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?})
  27 +
  28 + def deliver
  29 + return false unless self.valid?
  30 + Contact::Sender.notification(self).deliver
  31 + end
  32 +
  33 + class Sender < ActionMailer::Base
  34 + def notification(contact)
  35 + @name = contact.name
  36 + @email = contact.email
  37 + @city = contact.city
  38 + @state = contact.state
  39 + @message = contact.message
  40 + @environment = contact.dest.environment.name
  41 + @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home')
  42 + @target = contact.dest.name
  43 +
  44 + options = {
  45 + content_type: 'text/html',
  46 + to: contact.dest.notification_emails,
  47 + reply_to: contact.email,
  48 + subject: "[#{contact.dest.short_name(30)}] " + contact.subject,
  49 + from: "#{contact.name} <#{contact.dest.environment.noreply_email}>"
  50 + }
  51 +
  52 + if contact.sender
  53 + options.merge!('X-Noosfero-Sender' => contact.sender.identifier)
  54 + end
  55 +
  56 + if contact.receive_a_copy
  57 + options.merge!(cc: "#{contact.name} <#{contact.email}>")
  58 + end
  59 +
  60 + mail(options)
  61 + end
  62 + end
  63 +
  64 +end
... ...
app/mailers/environment_mailing.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +class EnvironmentMailing < Mailing
  2 +
  3 + def recipients(offset=0, limit=100)
  4 + source.people.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil })
  5 + end
  6 +
  7 + def each_recipient
  8 + offset = 0
  9 + limit = 100
  10 + while !(people = recipients(offset, limit)).empty?
  11 + people.each do |person|
  12 + yield person
  13 + end
  14 + offset = offset + limit
  15 + end
  16 + end
  17 +
  18 + def signature_message
  19 + _('Sent by %s.') % source.name
  20 + end
  21 +
  22 + def url
  23 + source.top_url
  24 + end
  25 +end
... ...
app/mailers/mailing.rb 0 → 100644
... ... @@ -0,0 +1,65 @@
  1 +require 'mailing_job'
  2 +
  3 +class Mailing < ActiveRecord::Base
  4 +
  5 + attr_accessible :subject, :body
  6 + validates_presence_of :source_id, :subject, :body
  7 + belongs_to :source, :foreign_key => :source_id, :polymorphic => true
  8 + belongs_to :person
  9 +
  10 + has_many :mailing_sents
  11 +
  12 + xss_terminate :only => [ :subject, :body ], :with => 'white_list', :on => 'validation'
  13 +
  14 + after_create do |mailing|
  15 + mailing.schedule
  16 + end
  17 +
  18 + def schedule
  19 + Delayed::Job.enqueue MailingJob.new(self.id)
  20 + end
  21 +
  22 + def generate_from
  23 + "#{source.name} <#{if source.is_a? Environment then source.noreply_email else source.contact_email end}>"
  24 + end
  25 +
  26 + def generate_subject
  27 + '[%s] %s' % [source.name, subject]
  28 + end
  29 +
  30 + def signature_message
  31 + _('Sent by Noosfero.')
  32 + end
  33 +
  34 + def url
  35 + ''
  36 + end
  37 +
  38 + def deliver
  39 + each_recipient do |recipient|
  40 + begin
  41 + Mailing::Sender.notification(self, recipient.email).deliver
  42 + self.mailing_sents.create(:person => recipient)
  43 + rescue Exception
  44 + # FIXME should not discard errors silently. An idea is to collect all
  45 + # errors and generate a task (notification) for the +source+
  46 + # (environment/organization) listing these errors.
  47 + end
  48 + end
  49 + end
  50 +
  51 + class Sender < ActionMailer::Base
  52 + def notification(mailing, recipient)
  53 + @message = mailing.body
  54 + @signature_message = mailing.signature_message
  55 + @url = mailing.url
  56 + mail(
  57 + :content_type => 'text/html',
  58 + :to => recipient,
  59 + :from => mailing.generate_from,
  60 + :reply_to => mailing.person.email,
  61 + :subject => mailing.generate_subject
  62 + )
  63 + end
  64 + end
  65 +end
... ...
app/mailers/organization_mailing.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +class OrganizationMailing < Mailing
  2 +
  3 + def generate_from
  4 + "#{person.name} <#{source.environment.noreply_email}>"
  5 + end
  6 +
  7 + def recipients(offset=0, limit=100)
  8 + source.members.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil })
  9 + end
  10 +
  11 + def each_recipient
  12 + offset = 0
  13 + limit = 50
  14 + while !(people = recipients(offset, limit)).empty?
  15 + people.each do |person|
  16 + yield person
  17 + end
  18 + offset = offset + limit
  19 + end
  20 + end
  21 +
  22 + def signature_message
  23 + _('Sent by community %s.') % source.name
  24 + end
  25 +
  26 + include Rails.application.routes.url_helpers
  27 + def url
  28 + url_for(source.url)
  29 + end
  30 +end
... ...
app/mailers/pending_task_notifier.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class PendingTaskNotifier < ActionMailer::Base
  2 +
  3 + def notification(person)
  4 + @person = person
  5 + @tasks = person.tasks.pending
  6 + @organizations_with_pending_tasks = person.organizations_with_pending_tasks
  7 + @environment = person.environment.name
  8 + @url = url_for(:host => person.environment.default_hostname, :controller => 'home')
  9 + @default_hostname = person.environment.default_hostname
  10 + @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier)
  11 +
  12 + mail(
  13 + to: person.email,
  14 + from: "#{person.environment.name} <#{person.environment.noreply_email}>",
  15 + subject: _("[%s] Pending tasks") % person.environment.name
  16 + )
  17 + end
  18 +
  19 +end
... ...
app/mailers/scrap_notifier.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Scrap::Notifier < ActionMailer::Base
  2 + def notification(scrap)
  3 + sender, receiver = scrap.sender, scrap.receiver
  4 + @recipient = receiver.name
  5 + @sender = sender.name
  6 + @sender_link = sender.url
  7 + @scrap_content = scrap.content
  8 + @wall_url = scrap.scrap_wall_url
  9 + @environment = sender.environment.name
  10 + @url = sender.environment.top_url
  11 + mail(
  12 + to: receiver.email,
  13 + from: "#{sender.environment.name} <#{sender.environment.noreply_email}>",
  14 + subject: _("[%s] You received a scrap!") % [sender.environment.name]
  15 + )
  16 + end
  17 +end
... ...
app/mailers/task_mailer.rb 0 → 100644
... ... @@ -0,0 +1,62 @@
  1 +class TaskMailer < ActionMailer::Base
  2 +
  3 + def target_notification(task, message)
  4 + @message = extract_message(message)
  5 + @target = task.target.name
  6 + @environment = task.environment.name
  7 + @url = generate_environment_url(task, :controller => 'home')
  8 + url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url)
  9 + @tasks_url = url_for_tasks_list
  10 +
  11 + mail(
  12 + to: task.target.notification_emails.compact,
  13 + from: self.class.generate_from(task),
  14 + subject: "[%s] %s" % [task.environment.name, task.target_notification_description]
  15 + )
  16 + end
  17 +
  18 + def invitation_notification(task)
  19 + msg = task.expanded_message
  20 + @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)
  21 +
  22 + mail(
  23 + to: task.friend_email,
  24 + from: self.class.generate_from(task),
  25 + subject: '[%s] %s' % [ task.requestor.environment.name, task.target_notification_description ]
  26 + )
  27 + end
  28 +
  29 + def generic_message(name, task)
  30 + return if !task.respond_to?("#{name}_message")
  31 +
  32 + @message = extract_message(task.send("#{name}_message"))
  33 + @requestor = task.requestor.name
  34 + @environment = task.requestor.environment.name
  35 + @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home')
  36 +
  37 + mail(
  38 + to: task.requestor.notification_emails,
  39 + from: self.class.generate_from(task),
  40 + subject: '[%s] %s' % [task.requestor.environment.name, task.target_notification_description]
  41 + )
  42 + end
  43 +
  44 + protected
  45 +
  46 + def extract_message(message)
  47 + if message.kind_of?(Proc)
  48 + self.instance_exec(&message)
  49 + else
  50 + message.to_s
  51 + end
  52 + end
  53 +
  54 + def self.generate_from(task)
  55 + "#{task.environment.name} <#{task.environment.noreply_email}>"
  56 + end
  57 +
  58 + def generate_environment_url(task, url = {})
  59 + url_for(Noosfero.url_options.merge(:host => task.environment.default_hostname).merge(url))
  60 + end
  61 +
  62 +end
... ...
app/mailers/user_mailer.rb 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +class UserMailer < ActionMailer::Base
  2 + def activation_email_notify(user)
  3 + user_email = "#{user.login}@#{user.email_domain}"
  4 + @name = user.name
  5 + @email = user_email
  6 + @webmail = MailConf.webmail_url(user.login, user.email_domain)
  7 + @environment = user.environment.name
  8 + @url = url_for(:host => user.environment.default_hostname, :controller => 'home')
  9 +
  10 + mail(
  11 + to: user_email,
  12 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  13 + subject: _("[%{environment}] Welcome to %{environment} mail!") % { :environment => user.environment.name }
  14 + )
  15 + end
  16 +
  17 + def activation_code(user)
  18 + @recipient = user.name
  19 + @activation_code = user.activation_code
  20 + @environment = user.environment.name
  21 + @url = user.environment.top_url
  22 + @redirection = (true if user.return_to)
  23 + @join = (user.community_to_join if user.community_to_join)
  24 +
  25 + mail(
  26 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  27 + to: user.email,
  28 + subject: _("[%s] Activate your account") % [user.environment.name],
  29 + )
  30 + end
  31 +
  32 + def signup_welcome_email(user)
  33 + @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
  34 + email_subject = user.environment.signup_welcome_text_subject
  35 + mail(
  36 + content_type: 'text/html',
  37 + to: user.email,
  38 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  39 + subject: email_subject.blank? ? _("Welcome to environment %s") % [user.environment.name] : email_subject,
  40 + body: @body
  41 + )
  42 + end
  43 +
  44 + class Job < Struct.new(:user, :method)
  45 + def perform
  46 + UserMailer.send(method, user).deliver
  47 + end
  48 + end
  49 +end
... ...
app/models/abuse_report.rb
1 1 class AbuseReport < ActiveRecord::Base
2 2  
  3 + attr_accessible :content, :reason
  4 +
3 5 belongs_to :reporter, :class_name => 'Person'
4 6 belongs_to :abuse_complaint
5 7 has_many :reported_images, :dependent => :destroy
... ...
app/models/action_tracker_notification.rb
... ... @@ -8,6 +8,8 @@ class ActionTrackerNotification &lt; ActiveRecord::Base
8 8 validates_presence_of :profile_id, :action_tracker_id
9 9 validates_uniqueness_of :action_tracker_id, :scope => :profile_id
10 10  
  11 + attr_accessible :profile_id, :action_tracker_id
  12 +
11 13 end
12 14  
13 15 ActionTracker::Record.has_many :action_tracker_notifications, :class_name => 'ActionTrackerNotification', :foreign_key => 'action_tracker_id', :dependent => :destroy
... ...
app/models/approve_article.rb
... ... @@ -48,7 +48,7 @@ class ApproveArticle &lt; Task
48 48 end
49 49  
50 50 def perform
51   - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author_id)
  51 + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.last_changed_by_id, :created_by_id => article.created_by_id)
52 52 end
53 53  
54 54 def title
... ...
app/models/approve_comment.rb
... ... @@ -6,7 +6,11 @@ class ApproveComment &lt; Task
6 6 validates_presence_of :comment_attributes
7 7  
8 8 def comment
9   - @comment ||= Comment.new(ActiveSupport::JSON.decode(self.comment_attributes)) unless self.comment_attributes.nil?
  9 + unless @comment || self.comment_attributes.nil?
  10 + @comment = Comment.new
  11 + @comment.assign_attributes(ActiveSupport::JSON.decode(self.comment_attributes), :without_protection => true)
  12 + end
  13 + @comment
10 14 end
11 15  
12 16 def requestor_name
... ...
app/models/article.rb
... ... @@ -2,6 +2,8 @@ require &#39;hpricot&#39;
2 2  
3 3 class Article < ActiveRecord::Base
4 4  
  5 + attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link
  6 +
5 7 acts_as_having_image
6 8  
7 9 SEARCHABLE_FIELDS = {
... ... @@ -38,12 +40,6 @@ class Article &lt; ActiveRecord::Base
38 40 # xss_terminate plugin can't sanitize array fields
39 41 before_save :sanitize_tag_list
40 42  
41   - before_create do |article|
42   - if article.last_changed_by_id
43   - article.author_name = Person.find(article.last_changed_by_id).name
44   - end
45   - end
46   -
47 43 belongs_to :profile
48 44 validates_presence_of :profile_id, :name
49 45 validates_presence_of :slug, :path, :if => lambda { |article| !article.name.blank? }
... ... @@ -53,6 +49,7 @@ class Article &lt; ActiveRecord::Base
53 49 validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => N_('The title (article name) is already being used by another article, please use another title.'), :if => lambda { |article| !article.slug.blank? }
54 50  
55 51 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'
  52 + belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id'
56 53  
57 54 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'
58 55  
... ... @@ -87,6 +84,11 @@ class Article &lt; ActiveRecord::Base
87 84 article.parent = article.profile.blog
88 85 end
89 86 end
  87 +
  88 + if article.created_by
  89 + article.author_name = article.created_by.name
  90 + end
  91 +
90 92 end
91 93  
92 94 after_destroy :destroy_activity
... ... @@ -96,11 +98,11 @@ class Article &lt; ActiveRecord::Base
96 98  
97 99 xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
98 100  
99   - named_scope :in_category, lambda { |category|
  101 + scope :in_category, lambda { |category|
100 102 {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }}
101 103 }
102 104  
103   - named_scope :by_range, lambda { |range| {
  105 + scope :by_range, lambda { |range| {
104 106 :conditions => [
105 107 'published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last }
106 108 ]
... ... @@ -148,7 +150,7 @@ class Article &lt; ActiveRecord::Base
148 150 self.profile
149 151 end
150 152  
151   - def self.human_attribute_name(attrib)
  153 + def self.human_attribute_name(attrib, options = {})
152 154 case attrib.to_sym
153 155 when :name
154 156 _('Title')
... ... @@ -203,6 +205,10 @@ class Article &lt; ActiveRecord::Base
203 205 acts_as_versioned
204 206 self.non_versioned_columns << 'setting'
205 207  
  208 + def version_condition_met?
  209 + (['name', 'body', 'abstract', 'filename', 'start_date', 'end_date', 'image_id', 'license_id'] & changed).length > 0
  210 + end
  211 +
206 212 def comment_data
207 213 comments.map {|item| [item.title, item.body].join(' ') }.join(' ')
208 214 end
... ... @@ -219,14 +225,19 @@ class Article &lt; ActiveRecord::Base
219 225  
220 226 # retrieves all articles belonging to the given +profile+ that are not
221 227 # sub-articles of any other article.
222   - named_scope :top_level_for, lambda { |profile|
  228 + scope :top_level_for, lambda { |profile|
223 229 {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]}
224 230 }
225 231  
226   - named_scope :join_profile, :joins => [:profile]
  232 + scope :public,
  233 + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], :joins => [:profile]
227 234  
228   - named_scope :public,
229   - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ]
  235 + scope :more_recent,
  236 + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND
  237 + ((articles.type != ?) OR articles.type is NULL)",
  238 + true, true, true, true, 'RssFeed'
  239 + ],
  240 + :order => 'articles.published_at desc, articles.id desc'
230 241  
231 242 # retrives the most commented articles, sorted by the comment count (largest
232 243 # first)
... ... @@ -234,7 +245,8 @@ class Article &lt; ActiveRecord::Base
234 245 paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit)
235 246 end
236 247  
237   - named_scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"]
  248 + scope :more_popular, :order => 'hits DESC'
  249 + scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"]
238 250  
239 251 def self.recent(limit = nil, extra_conditions = {}, pagination = true)
240 252 result = scoped({:conditions => extra_conditions}).
... ... @@ -243,13 +255,6 @@ class Article &lt; ActiveRecord::Base
243 255 limit(limit).
244 256 order(['articles.published_at desc', 'articles.id desc'])
245 257  
246   - if !( scoped_methods && scoped_methods.last &&
247   - scoped_methods.last[:find] &&
248   - scoped_methods.last[:find][:joins] &&
249   - scoped_methods.last[:find][:joins].index('profiles') )
250   - result = result.includes(:profile)
251   - end
252   -
253 258 pagination ? result.paginate({:page => 1, :per_page => limit}) : result
254 259 end
255 260  
... ... @@ -261,16 +266,18 @@ class Article &lt; ActiveRecord::Base
261 266 # (To override short format representation, override the lead method)
262 267 def to_html(options = {})
263 268 if options[:format] == 'short'
264   - display_short_format(self)
  269 + article = self
  270 + proc do
  271 + display_short_format(article)
  272 + end
265 273 else
266 274 body || ''
267 275 end
268 276 end
269 277  
270   - include ApplicationHelper
271 278 def reported_version(options = {})
272 279 article = self
273   - search_path = File.join(Rails.root, 'app', 'views', 'shared', 'reported_versions')
  280 + search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions')
274 281 partial_path = File.join('shared', 'reported_versions', partial_for_class_in_view_path(article.class, search_path))
275 282 lambda { render_to_string(:partial => partial_path, :locals => {:article => article}) }
276 283 end
... ... @@ -371,7 +378,7 @@ class Article &lt; ActiveRecord::Base
371 378 {}
372 379 end
373 380  
374   - named_scope :native_translations, :conditions => { :translation_of_id => nil }
  381 + scope :native_translations, :conditions => { :translation_of_id => nil }
375 382  
376 383 def translatable?
377 384 false
... ... @@ -407,7 +414,7 @@ class Article &lt; ActiveRecord::Base
407 414  
408 415 def native_translation_must_have_language
409 416 unless self.translation_of.nil?
410   - errors.add_to_base(N_('A language must be choosen for the native article')) if self.translation_of.language.blank?
  417 + errors.add(:base, N_('A language must be choosen for the native article')) if self.translation_of.language.blank?
411 418 end
412 419 end
413 420  
... ... @@ -449,17 +456,17 @@ class Article &lt; ActiveRecord::Base
449 456 ['TextArticle', 'TextileArticle', 'TinyMceArticle']
450 457 end
451 458  
452   - named_scope :published, :conditions => { :published => true }
453   - named_scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }}
454   - named_scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}}
455   - named_scope :galleries, :conditions => { :type => 'Gallery' }
456   - named_scope :images, :conditions => { :is_image => true }
457   - named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
458   - named_scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } }
  459 + scope :published, :conditions => { :published => true }
  460 + scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }}
  461 + scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}}
  462 + scope :galleries, :conditions => { :type => 'Gallery' }
  463 + scope :images, :conditions => { :is_image => true }
  464 + scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
  465 + scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } }
459 466  
460   - named_scope :more_popular, :order => 'hits DESC'
461   - named_scope :more_comments, :order => "comments_count DESC"
462   - named_scope :more_recent, :order => "created_at DESC"
  467 + scope :more_popular, :order => 'hits DESC'
  468 + scope :more_comments, :order => "comments_count DESC"
  469 + scope :more_recent, :order => "created_at DESC"
463 470  
464 471 def self.display_filter(user, profile)
465 472 return {:conditions => ['published = ?', true]} if !user
... ... @@ -531,13 +538,23 @@ class Article &lt; ActiveRecord::Base
531 538 def copy(options = {})
532 539 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) }
533 540 attrs.merge!(options)
534   - self.class.create(attrs)
  541 + object = self.class.new
  542 + attrs.each do |key, value|
  543 + object.send(key.to_s+'=', value)
  544 + end
  545 + object.save
  546 + object
535 547 end
536 548  
537 549 def copy!(options = {})
538 550 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) }
539 551 attrs.merge!(options)
540   - self.class.create!(attrs)
  552 + object = self.class.new
  553 + attrs.each do |key, value|
  554 + object.send(key.to_s+'=', value)
  555 + end
  556 + object.save!
  557 + object
541 558 end
542 559  
543 560 ATTRIBUTES_NOT_COPIED = [
... ... @@ -617,30 +634,28 @@ class Article &lt; ActiveRecord::Base
617 634  
618 635 def author(version_number = nil)
619 636 if version_number
620   - version = versions.find_by_version(version_number)
  637 + version = self.versions.find_by_version(version_number)
621 638 author_id = version.last_changed_by_id if version
622   - Person.exists?(author_id) ? Person.find(author_id) : nil
623 639 else
624   - if versions.empty?
625   - last_changed_by
626   - else
627   - author_id = versions.first.last_changed_by_id
628   - Person.exists?(author_id) ? Person.find(author_id) : nil
629   - end
  640 + author_id = self.created_by_id
630 641 end
  642 +
  643 + environment.people.find_by_id(author_id)
631 644 end
632 645  
633 646 def author_name(version_number = nil)
634   - person = version_number ? author(version_number) : author
  647 + person = author(version_number)
635 648 person ? person.name : (setting[:author_name] || _('Unknown'))
636 649 end
637 650  
638   - def author_url
639   - author ? author.url : nil
  651 + def author_url(version_number = nil)
  652 + person = author(version_number)
  653 + person ? person.url : nil
640 654 end
641 655  
642   - def author_id
643   - author ? author.id : nil
  656 + def author_id(version_number = nil)
  657 + person = author(version_number)
  658 + person ? person.id : nil
644 659 end
645 660  
646 661 def version_license(version_number = nil)
... ... @@ -734,7 +749,7 @@ class Article &lt; ActiveRecord::Base
734 749  
735 750 def sanitize_tag_list
736 751 sanitizer = HTML::FullSanitizer.new
737   - self.tag_list.names.map!{|i| strip_tag_name sanitizer.sanitize(i) }
  752 + self.tag_list.map!{|i| strip_tag_name sanitizer.sanitize(i) }
738 753 end
739 754  
740 755 def strip_tag_name(tag_name)
... ...
app/models/article_block.rb
1 1 class ArticleBlock < Block
2 2  
  3 + attr_accessible :article_id
  4 +
3 5 def self.description
4 6 _('Display one of your contents')
5 7 end
... ... @@ -10,7 +12,7 @@ class ArticleBlock &lt; Block
10 12  
11 13 def content(args={})
12 14 block = self
13   - lambda do
  15 + proc do
14 16 block_title(block.title) +
15 17 (block.article ? article_to_html(FilePresenter.for(block.article),
16 18 :gallery_view => false,
... ...
app/models/block.rb
1 1 class Block < ActiveRecord::Base
2 2  
  3 + attr_accessible :title, :display, :limit, :box_id, :posts_per_page, :visualization_format, :language, :display_user, :box
  4 +
3 5 # to be able to generate HTML
4 6 include ActionView::Helpers::UrlHelper
5 7 include ActionView::Helpers::TagHelper
... ... @@ -14,7 +16,7 @@ class Block &lt; ActiveRecord::Base
14 16  
15 17 acts_as_having_settings
16 18  
17   - named_scope :enabled, :conditions => { :enabled => true }
  19 + scope :enabled, :conditions => { :enabled => true }
18 20  
19 21 def embedable?
20 22 false
... ... @@ -22,7 +24,7 @@ class Block &lt; ActiveRecord::Base
22 24  
23 25 def embed_code
24 26 me = self
25   - lambda do
  27 + proc do
26 28 content_tag('iframe', '',
27 29 :src => url_for(:controller => 'embed', :action => 'block', :id => me.id, :only_path => false),
28 30 :frameborder => 0,
... ... @@ -196,10 +198,10 @@ class Block &lt; ActiveRecord::Base
196 198 end
197 199  
198 200 DISPLAY_OPTIONS = {
199   - 'always' => __('In all pages'),
200   - 'home_page_only' => __('Only in the homepage'),
201   - 'except_home_page' => __('In all pages, except in the homepage'),
202   - 'never' => __('Don\'t display'),
  201 + 'always' => _('In all pages'),
  202 + 'home_page_only' => _('Only in the homepage'),
  203 + 'except_home_page' => _('In all pages, except in the homepage'),
  204 + 'never' => _('Don\'t display'),
203 205 }
204 206  
205 207 def display_options_available
... ... @@ -212,14 +214,14 @@ class Block &lt; ActiveRecord::Base
212 214  
213 215 def display_user_options
214 216 @display_user_options ||= {
215   - 'all' => __('All users'),
216   - 'logged' => __('Logged'),
217   - 'not_logged' => __('Not logged'),
  217 + 'all' => _('All users'),
  218 + 'logged' => _('Logged'),
  219 + 'not_logged' => _('Not logged'),
218 220 }
219 221 end
220 222  
221 223 def duplicate
222   - duplicated_block = self.clone
  224 + duplicated_block = self.dup
223 225 duplicated_block.display = 'never'
224 226 duplicated_block.created_at = nil
225 227 duplicated_block.updated_at = nil
... ...
app/models/blog.rb
1 1 class Blog < Folder
2 2  
  3 + attr_accessible :visualization_format
  4 +
3 5 acts_as_having_posts
4 6 include PostsLimit
5 7  
... ... @@ -26,7 +28,7 @@ class Blog &lt; Folder
26 28 include ActionView::Helpers::TagHelper
27 29 def to_html(options = {})
28 30 me = self
29   - lambda do
  31 + proc do
30 32 render :file => 'content_viewer/blog_page', :locals => { :blog=>me, :inside_block=>options[:inside_block] }
31 33 end
32 34 end
... ... @@ -46,12 +48,14 @@ class Blog &lt; Folder
46 48 self.external_feed_data = efeed
47 49 end
48 50  
49   - def validate
  51 + validate :prepare_external_feed
  52 +
  53 + def prepare_external_feed
50 54 unless self.external_feed_data.nil?
51 55 if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i
52 56 self.external_feed.attributes = self.external_feed_data
53 57 else
54   - self.build_external_feed(self.external_feed_data)
  58 + self.build_external_feed(self.external_feed_data, :without_protection => true)
55 59 end
56 60 self.external_feed.valid?
57 61 self.external_feed.errors.delete(:blog_id) # dont validate here relation: external_feed <-> blog
... ...
app/models/blog_archives_block.rb
... ... @@ -2,7 +2,8 @@ class BlogArchivesBlock &lt; Block
2 2  
3 3 include ActionView::Helpers::TagHelper
4 4 include ActionView::Helpers::UrlHelper
5   - include ActionController::UrlWriter
  5 + include ActionView::Helpers
  6 + include Rails.application.routes.url_helpers
6 7 include ActionView::Helpers::AssetTagHelper
7 8 include DatesHelper
8 9  
... ... @@ -31,10 +32,10 @@ class BlogArchivesBlock &lt; Block
31 32 return nil unless owner_blog
32 33 results = ''
33 34 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 + posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count|
35 36 results << content_tag('li', content_tag('strong', "#{year} (#{count})"))
36 37 results << "<ul class='#{year}-archive'>"
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 + posts.except(:order).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 39 month_name = gettext(MONTHS[month.to_i - 1])
39 40 results << content_tag('li', link_to("#{month_name} (#{count})", owner_blog.url.merge(:year => year, :month => month)))
40 41 end
... ...
app/models/box.rb
... ... @@ -3,9 +3,11 @@ class Box &lt; ActiveRecord::Base
3 3 acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\''
4 4 has_many :blocks, :dependent => :destroy, :order => 'position'
5 5  
  6 + attr_accessible :owner
  7 +
6 8 include Noosfero::Plugin::HotSpot
7 9  
8   - named_scope :with_position, :conditions => ['boxes.position > 0']
  10 + scope :with_position, :conditions => ['boxes.position > 0']
9 11  
10 12 def environment
11 13 owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil
... ... @@ -32,14 +34,11 @@ class Box &lt; ActiveRecord::Base
32 34 FansBlock,
33 35 FavoriteEnterprisesBlock,
34 36 FeedReaderBlock,
35   - FriendsBlock,
36 37 HighlightsBlock,
37 38 LinkListBlock,
38 39 LoginBlock,
39 40 MainBlock,
40   - MembersBlock,
41 41 MyNetworkBlock,
42   - PeopleBlock,
43 42 ProfileImageBlock,
44 43 RawHTMLBlock,
45 44 RecentDocumentsBlock,
... ... @@ -61,14 +60,11 @@ class Box &lt; ActiveRecord::Base
61 60 FavoriteEnterprisesBlock,
62 61 FeaturedProductsBlock,
63 62 FeedReaderBlock,
64   - FriendsBlock,
65 63 HighlightsBlock,
66 64 LinkListBlock,
67 65 LocationBlock,
68 66 LoginBlock,
69   - MembersBlock,
70 67 MyNetworkBlock,
71   - PeopleBlock,
72 68 ProductsBlock,
73 69 ProductCategoriesBlock,
74 70 ProfileImageBlock,
... ...
app/models/categories_block.rb
... ... @@ -8,6 +8,8 @@ class CategoriesBlock &lt; Block
8 8  
9 9 settings_items :category_types, :type => Array, :default => []
10 10  
  11 + attr_accessible :category_types
  12 +
11 13 def self.description
12 14 _("Categories Menu")
13 15 end
... ... @@ -30,7 +32,7 @@ class CategoriesBlock &lt; Block
30 32  
31 33 def content(args={})
32 34 block = self
33   - lambda do
  35 + proc do
34 36 render :file => 'blocks/categories', :locals => { :block => block }
35 37 end
36 38 end
... ...
app/models/category.rb
1 1 class Category < ActiveRecord::Base
2 2  
  3 + attr_accessible :name, :parent_id, :display_color, :display_in_menu, :image_builder, :environment, :parent
  4 +
3 5 SEARCHABLE_FIELDS = {
4 6 :name => 10,
5 7 :acronym => 5,
... ... @@ -16,11 +18,11 @@ class Category &lt; ActiveRecord::Base
16 18 validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('{fn} was already assigned to another category.').fix_i18n
17 19  
18 20 # Finds all top level categories for a given environment.
19   - named_scope :top_level_for, lambda { |environment|
  21 + scope :top_level_for, lambda { |environment|
20 22 {:conditions => ['parent_id is null and environment_id = ?', environment.id ]}
21 23 }
22 24  
23   - named_scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} }
  25 + scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} }
24 26  
25 27 acts_as_filesystem
26 28  
... ... @@ -40,7 +42,7 @@ class Category &lt; ActiveRecord::Base
40 42  
41 43 acts_as_having_image
42 44  
43   - named_scope :from_types, lambda { |types|
  45 + scope :from_types, lambda { |types|
44 46 types.select{ |t| t.blank? }.empty? ?
45 47 { :conditions => { :type => types } } :
46 48 { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] }
... ... @@ -67,7 +69,7 @@ class Category &lt; ActiveRecord::Base
67 69 end
68 70  
69 71 def recent_comments(limit = 10)
70   - comments.paginate(:all, :order => 'created_at DESC, comments.id DESC', :page => 1, :per_page => limit)
  72 + comments.paginate(:order => 'created_at DESC, comments.id DESC', :page => 1, :per_page => limit)
71 73 end
72 74  
73 75 def most_commented_articles(limit = 10)
... ...
app/models/certifier.rb
1 1 class Certifier < ActiveRecord::Base
2 2  
  3 + attr_accessible :name, :environment
  4 +
3 5 SEARCHABLE_FIELDS = {
4 6 :name => 10,
5 7 :description => 3,
... ...
app/models/change_password.rb
... ... @@ -2,7 +2,7 @@ class ChangePassword &lt; Task
2 2  
3 3 attr_accessor :password, :password_confirmation
4 4  
5   - def self.human_attribute_name(attrib)
  5 + def self.human_attribute_name(attrib, options = {})
6 6 case attrib.to_sym
7 7 when :password
8 8 _('Password')
... ... @@ -58,13 +58,13 @@ class ChangePassword &lt; Task
58 58 _('Your password was changed successfully.')
59 59 end
60 60  
61   - include ActionController::UrlWriter
  61 + include Rails.application.routes.url_helpers
62 62 def task_created_message
63 63 hostname = self.requestor.environment.default_hostname
64 64 code = self.code
65 65 url = url_for(:host => hostname, :controller => 'account', :action => 'new_password', :code => code)
66 66  
67   - lambda do
  67 + proc do
68 68 _("In order to change your password, please visit the following address:\n\n%s\n\nIf you did not required any change to your password just desconsider this email.") % url
69 69 end
70 70 end
... ...
app/models/city.rb
1 1 class City < Region
  2 + attr_accessible :name, :parent_id
2 3 end
... ...
app/models/comment.rb
... ... @@ -6,6 +6,8 @@ class Comment &lt; ActiveRecord::Base
6 6 :body => 2,
7 7 }
8 8  
  9 + attr_accessible :body, :author, :name, :email, :title, :reply_of_id, :source
  10 +
9 11 validates_presence_of :body
10 12  
11 13 belongs_to :source, :counter_cache => true, :polymorphic => true
... ... @@ -16,7 +18,7 @@ class Comment &lt; ActiveRecord::Base
16 18 has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy
17 19 belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id'
18 20  
19   - named_scope :without_reply, :conditions => ['reply_of_id IS NULL']
  21 + scope :without_reply, :conditions => ['reply_of_id IS NULL']
20 22  
21 23 # unauthenticated authors:
22 24 validates_presence_of :name, :if => (lambda { |record| !record.email.blank? })
... ... @@ -127,11 +129,11 @@ class Comment &lt; ActiveRecord::Base
127 129 def notify_by_mail
128 130 if source.kind_of?(Article) && article.notify_comments?
129 131 if !notification_emails.empty?
130   - Comment::Notifier.deliver_mail(self)
  132 + Comment::Notifier.notification(self).deliver
131 133 end
132 134 emails = article.followers - [author_email]
133 135 if !emails.empty?
134   - Comment::Notifier.deliver_mail_to_followers(self, emails)
  136 + Comment::Notifier.mail_to_followers(self, emails).deliver
135 137 end
136 138 end
137 139 end
... ... @@ -168,40 +170,6 @@ class Comment &lt; ActiveRecord::Base
168 170 body || ''
169 171 end
170 172  
171   - class Notifier < ActionMailer::Base
172   - def mail(comment)
173   - profile = comment.article.profile
174   - recipients comment.notification_emails
175   - from "#{profile.environment.name} <#{profile.environment.noreply_email}>"
176   - subject _("[%s] you got a new comment!") % [profile.environment.name]
177   - body :recipient => profile.nickname || profile.name,
178   - :sender => comment.author_name,
179   - :sender_link => comment.author_link,
180   - :article_title => comment.article.name,
181   - :comment_url => comment.url,
182   - :comment_title => comment.title,
183   - :comment_body => comment.body,
184   - :environment => profile.environment.name,
185   - :url => profile.environment.top_url
186   - end
187   - def mail_to_followers(comment, emails)
188   - profile = comment.article.profile
189   - bcc emails
190   - from "#{profile.environment.name} <#{profile.environment.noreply_email}>"
191   - subject _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name]
192   - body :recipient => profile.nickname || profile.name,
193   - :sender => comment.author_name,
194   - :sender_link => comment.author_link,
195   - :article_title => comment.article.name,
196   - :comment_url => comment.url,
197   - :unsubscribe_url => comment.article.view_url.merge({:unfollow => true}),
198   - :comment_title => comment.title,
199   - :comment_body => comment.body,
200   - :environment => profile.environment.name,
201   - :url => profile.environment.top_url
202   - end
203   - end
204   -
205 173 def rejected?
206 174 @rejected
207 175 end
... ...
app/models/communities_block.rb
1 1 class CommunitiesBlock < ProfileListBlock
2 2  
  3 + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
  4 +
3 5 def self.description
4   - __('Communities')
  6 + _('Communities')
5 7 end
6 8  
7 9 def default_title
8   - n__('{#} community', '{#} communities', profile_count)
  10 + n_('{#} community', '{#} communities', profile_count)
9 11 end
10 12  
11 13 def help
12   - __('This block displays the communities in which the user is a member.')
  14 + _('This block displays the communities in which the user is a member.')
13 15 end
14 16  
15 17 def footer
16 18 owner = self.owner
17 19 case owner
18 20 when Profile
19   - lambda do
  21 + lambda do |context|
20 22 link_to s_('communities|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
21 23 end
22 24 when Environment
23   - lambda do
  25 + lambda do |context|
24 26 link_to s_('communities|View all'), :controller => 'search', :action => 'communities'
25 27 end
26 28 else
... ...
app/models/community.rb
1 1 class Community < Organization
2 2  
  3 + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type, :address_reference, :district, :tag_list, :language
  4 + after_destroy :check_invite_member_for_destroy
  5 +
3 6 def self.type_name
4 7 _('Community')
5 8 end
... ... @@ -8,7 +11,6 @@ class Community &lt; Organization
8 11 N_('Language')
9 12  
10 13 settings_items :language
11   - settings_items :zip_code, :city, :state, :country
12 14  
13 15 extend SetProfileRegionFromCityState::ClassMethods
14 16 set_profile_region_from_city_state
... ... @@ -17,12 +19,22 @@ class Community &lt; Organization
17 19 community.moderated_articles = true if community.environment.enabled?('organizations_are_moderated_by_default')
18 20 end
19 21  
  22 + def check_invite_member_for_destroy
  23 + InviteMember.pending.select { |task| task.community_id == self.id }.map(&:destroy)
  24 + end
  25 +
  26 + # Since it's not a good idea to add the environment as accessible through
  27 + # mass-assignment, we set it manually here. Note that this requires that the
  28 + # places that call this method are safe from mass-assignment by setting the
  29 + # environment key themselves.
20 30 def self.create_after_moderation(requestor, attributes = {})
  31 + environment = attributes.delete(:environment)
21 32 community = Community.new(attributes)
  33 + community.environment = environment
22 34 if community.environment.enabled?('admin_must_approve_new_communities')
23   - CreateCommunity.create(attributes.merge(:requestor => requestor))
  35 + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment))
24 36 else
25   - community = Community.create(attributes)
  37 + community.save!
26 38 community.add_admin(requestor)
27 39 end
28 40 community
... ... @@ -38,8 +50,9 @@ class Community &lt; Organization
38 50 super + FIELDS
39 51 end
40 52  
41   - def validate
42   - super
  53 + validate :presence_of_required_fieds
  54 +
  55 + def presence_of_required_fieds
43 56 self.required_fields.each do |field|
44 57 if self.send(field).blank?
45 58 self.errors.add_on_blank(field)
... ... @@ -72,10 +85,6 @@ class Community &lt; Organization
72 85 recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight])
73 86 end
74 87  
75   - def blocks_to_expire_cache
76   - [MembersBlock]
77   - end
78   -
79 88 def each_member(offset=0)
80 89 while member = self.members.first(:order => :id, :offset => offset)
81 90 yield member
... ... @@ -84,7 +93,7 @@ class Community &lt; Organization
84 93 end
85 94  
86 95 def control_panel_settings_button
87   - {:title => __('Community Info and settings'), :icon => 'edit-profile-group'}
  96 + {:title => _('Community Info and settings'), :icon => 'edit-profile-group'}
88 97 end
89 98  
90 99 def activities
... ...
app/models/contact.rb
... ... @@ -1,49 +0,0 @@
1   -class Contact < ActiveRecord::Base #WithoutTable
2   - tableless :columns => [
3   - [:name, :string],
4   - [:subject, :string],
5   - [:message, :string],
6   - [:email, :string],
7   - [:state, :string],
8   - [:city, :string],
9   - [:receive_a_copy, :boolean]
10   - ]
11   - attr_accessor :dest
12   - attr_accessor :sender
13   -
14   - N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name')
15   -
16   - validates_presence_of :subject, :email, :message, :name
17   - validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?})
18   -
19   - def deliver
20   - return false unless self.valid?
21   - Contact::Sender.deliver_mail(self)
22   - end
23   -
24   - class Sender < ActionMailer::Base
25   - def mail(contact)
26   - content_type 'text/html'
27   - emails = contact.dest.notification_emails
28   - recipients emails
29   - from "#{contact.name} <#{contact.dest.environment.noreply_email}>"
30   - reply_to contact.email
31   - if contact.sender
32   - headers 'X-Noosfero-Sender' => contact.sender.identifier
33   - end
34   - if contact.receive_a_copy
35   - cc "#{contact.name} <#{contact.email}>"
36   - end
37   - subject "[#{contact.dest.short_name(30)}] " + contact.subject
38   - body :name => contact.name,
39   - :email => contact.email,
40   - :city => contact.city,
41   - :state => contact.state,
42   - :message => contact.message,
43   - :environment => contact.dest.environment.name,
44   - :url => url_for(:host => contact.dest.environment.default_hostname, :controller => 'home'),
45   - :target => contact.dest.name
46   - end
47   - end
48   -
49   -end
app/models/contact_list.rb
... ... @@ -16,12 +16,16 @@ class ContactList &lt; ActiveRecord::Base
16 16  
17 17 def register_auth_error
18 18 msg = _('There was an error while authenticating. Did you enter correct login and password?')
19   - self.update_attributes(:fetched => true, :error_fetching => msg)
  19 + self.fetched = true
  20 + self.error_fetching = msg
  21 + self.save!
20 22 end
21 23  
22 24 def register_error
23 25 msg = _('There was an error while looking for your contact list. Please, try again')
24   - self.update_attributes(:fetched => true, :error_fetching => msg)
  26 + self.fetched = true
  27 + self.error_fetching = msg
  28 + self.save!
25 29 end
26 30  
27 31 end
... ...
app/models/create_enterprise.rb
... ... @@ -36,14 +36,18 @@ class CreateEnterprise &lt; Task
36 36 validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } )
37 37 xss_terminate :only => [ :acronym, :address, :contact_person, :contact_phone, :economic_activity, :legal_form, :management_information, :name ], :on => 'validation'
38 38  
39   - def validate
  39 + validate :validator_correct_region
  40 + validate :not_used_identifier
40 41  
  42 + def validator_correct_region
41 43 if self.region && self.target
42 44 unless self.region.validators.include?(self.target) || self.target_type == "Environment"
43 45 self.errors.add(:target, _('{fn} is not a validator for the chosen region').fix_i18n)
44 46 end
45 47 end
  48 + end
46 49  
  50 + def not_used_identifier
47 51 if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier)
48 52 self.errors.add(:identifier, _('{fn} is already being as identifier by another enterprise, organization or person.').fix_i18n)
49 53 end
... ... @@ -165,18 +169,18 @@ class CreateEnterprise &lt; Task
165 169 end
166 170  
167 171 def task_finished_message
168   - __('Your request for registering the enterprise "%{enterprise}" was approved. You can access %{environment} now and provide start providing all relevant information your new enterprise.') % { :enterprise => self.name, :environment => self.environment }
  172 + _('Your request for registering the enterprise "%{enterprise}" was approved. You can access %{environment} now and provide start providing all relevant information your new enterprise.') % { :enterprise => self.name, :environment => self.environment }
169 173 end
170 174  
171 175 def task_cancelled_message
172   - __("Your request for registering the enterprise %{enterprise} at %{environment} was NOT approved by the validator organization. The following explanation was given: \n\n%{explanation}") % { :enterprise => self.name, :environment => self.environment, :explanation => self.reject_explanation }
  176 + _("Your request for registering the enterprise %{enterprise} at %{environment} was NOT approved by the validator organization. The following explanation was given: \n\n%{explanation}") % { :enterprise => self.name, :environment => self.environment, :explanation => self.reject_explanation }
173 177 end
174 178  
175 179 def target_notification_message
176 180 msg = ""
177   - msg << __("Enterprise \"%{enterprise}\" just requested to enter %{environment}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :enterprise => self.name, :environment => self.environment }
  181 + msg << _("Enterprise \"%{enterprise}\" just requested to enter %{environment}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :enterprise => self.name, :environment => self.environment }
178 182 msg << "\n"
179   - msg << __("The data provided by the enterprise was the following:\n") << "\n"
  183 + msg << _("The data provided by the enterprise was the following:\n") << "\n"
180 184  
181 185  
182 186 msg << (_("Name: %s") % self.name) << "\n"
... ... @@ -186,12 +190,12 @@ class CreateEnterprise &lt; Task
186 190 msg << (_("Foundation Year: %d") % self.foundation_year) << "\n" unless self.foundation_year.blank?
187 191 msg << (_("Economic activity: %s") % self.economic_activity) << "\n"
188 192  
189   - msg << __("Information about enterprise's management:\n") << self.management_information.to_s << "\n"
  193 + msg << _("Information about enterprise's management:\n") << self.management_information.to_s << "\n"
190 194  
191 195 msg << (_("Contact phone: %s") % self.contact_phone) << "\n"
192 196 msg << (_("Contact person: %s") % self.contact_person) << "\n"
193 197  
194   - msg << __('CreateEnterprise|Identifier')
  198 + msg << _('CreateEnterprise|Identifier')
195 199  
196 200 msg
197 201 end
... ...
app/models/disabled_enterprise_message_block.rb
1 1 class DisabledEnterpriseMessageBlock < Block
2 2  
3 3 def self.description
4   - __('"Disabled enterprise" message')
  4 + _('"Disabled enterprise" message')
5 5 end
6 6  
7 7 def help
8   - __('Shows a message for disabled enterprises.')
  8 + _('Shows a message for disabled enterprises.')
9 9 end
10 10  
11 11 def default_title
... ... @@ -14,7 +14,7 @@ class DisabledEnterpriseMessageBlock &lt; Block
14 14  
15 15 def content(args={})
16 16 message = self.owner.environment.message_for_disabled_enterprise || ''
17   - lambda do
  17 + lambda do |_|
18 18 render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message}
19 19 end
20 20 end
... ...
app/models/doc_item.rb
... ... @@ -31,7 +31,7 @@ class DocItem
31 31 search_path.unshift("/designs/themes/#{theme}#{translation}") # higher priority
32 32 search_path.push("/designs/themes/#{theme}#{image}") # lower priority
33 33 end
34   - search_path.find {|file| File.exist?("#{RAILS_ROOT}/public#{file}") }
  34 + search_path.find {|file| File.exist?(Rails.root.join('public', file[1..-1])) }
35 35 end
36 36  
37 37 end
... ...
app/models/doc_section.rb
1 1 class DocSection < DocItem
2 2  
3 3 def self.root_dir
4   - @root_dir ||= File.join(RAILS_ROOT, 'doc', 'noosfero')
  4 + @root_dir ||= Rails.root.join('doc', 'noosfero')
5 5 end
6 6  
7 7 def items
... ...
app/models/domain.rb
  1 +require 'noosfero/multi_tenancy'
  2 +
1 3 class Domain < ActiveRecord::Base
2 4  
  5 + attr_accessible :name, :owner
  6 +
3 7 # relationships
4 8 ###############
5 9  
... ... @@ -15,7 +19,9 @@ class Domain &lt; ActiveRecord::Base
15 19 # checks validations that could not be expressed using Rails' predefined
16 20 # validations. In particular:
17 21 # * <tt>name</tt> must not start with 'www.'
18   - def validate
  22 + validate :no_www
  23 +
  24 + def no_www
19 25 if self.name =~ /^www\./
20 26 self.errors.add(:name, _('{fn} must not start with www.').fix_i18n)
21 27 end
... ...
app/models/email_activation.rb
1 1 class EmailActivation < Task
2 2  
3 3 validates_presence_of :requestor_id, :target_id
  4 + validate :already_requested, :on => :create
4 5  
5 6 alias :environment :target
6 7 alias :person :requestor
7 8  
8   - def validate_on_create
  9 + def already_requested
9 10 if !self.requestor.nil? && self.requestor.user.email_activation_pending?
10   - self.errors.add_to_base(_('You have already requested activation of your mailbox.'))
  11 + self.errors.add(:base, _('You have already requested activation of your mailbox.'))
11 12 end
12 13 end
13 14  
... ... @@ -33,7 +34,7 @@ class EmailActivation &lt; Task
33 34  
34 35 # :nodoc:
35 36 def after_finish
36   - User::Mailer.deliver_activation_email_notify(person.user)
  37 + UserMailer.activation_email_notify(person.user).deliver
37 38 end
38 39  
39 40 def sends_email?
... ...
app/models/enterprise.rb
... ... @@ -2,6 +2,8 @@
2 2 # only enterprises can offer products and services.
3 3 class Enterprise < Organization
4 4  
  5 + attr_accessible :business_name, :address_reference, :district, :tag_list, :organization_website, :historic_and_current_context, :activities_short_description, :products_per_catalog_page
  6 +
5 7 SEARCH_DISPLAYS += %w[map full]
6 8  
7 9 def self.type_name
... ... @@ -17,12 +19,12 @@ class Enterprise &lt; Organization
17 19 has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people'
18 20  
19 21 def product_categories
20   - products.includes(:product_category).map{|p| p.category_full_name}.compact
  22 + ProductCategory.by_enterprise(self)
21 23 end
22 24  
23 25 N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code')
24 26  
25   - settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country
  27 + settings_items :organization_website, :historic_and_current_context, :activities_short_description
26 28 settings_items :products_per_catalog_page, :type => :integer, :default => 6
27 29  
28 30 extend SetProfileRegionFromCityState::ClassMethods
... ... @@ -54,8 +56,9 @@ class Enterprise &lt; Organization
54 56 super + FIELDS
55 57 end
56 58  
57   - def validate
58   - super
  59 + validate :presence_of_required_fieds
  60 +
  61 + def presence_of_required_fieds
59 62 self.required_fields.each do |field|
60 63 if self.send(field).blank?
61 64 self.errors.add_on_blank(field)
... ... @@ -97,14 +100,18 @@ class Enterprise &lt; Organization
97 100 save
98 101 end
99 102  
  103 + def activation_task
  104 + self.tasks.where(:type => 'EnterpriseActivation').first
  105 + end
  106 +
100 107 def enable(owner)
101 108 return if enabled
102   - affiliate(owner, Profile::Roles.all_roles(environment.id))
103   - update_attribute(:enabled,true)
104   - if environment.replace_enterprise_template_when_enable
105   - apply_template(template)
106   - end
107   - save_without_validation!
  109 + # must be set first for the following to work
  110 + self.enabled = true
  111 + self.affiliate owner, Profile::Roles.all_roles(self.environment.id) if owner
  112 + self.apply_template template if self.environment.replace_enterprise_template_when_enable
  113 + self.activation_task.update_attribute :status, Task::Status::FINISHED rescue nil
  114 + self.save(:validate => false)
108 115 end
109 116  
110 117 def question
... ... @@ -168,7 +175,7 @@ class Enterprise &lt; Organization
168 175 alias_method_chain :template, :inactive_enterprise
169 176  
170 177 def control_panel_settings_button
171   - {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'}
  178 + {:title => _('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'}
172 179 end
173 180  
174 181 settings_items :enable_contact_us, :type => :boolean, :default => true
... ... @@ -178,7 +185,7 @@ class Enterprise &lt; Organization
178 185 end
179 186  
180 187 def control_panel_settings_button
181   - {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'}
  188 + {:title => _('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'}
182 189 end
183 190  
184 191 def create_product?
... ...
app/models/enterprise_activation.rb
1 1 class EnterpriseActivation < Task
2 2  
3   - class RequestorRequired < Exception; end
  3 + alias :person :requestor
  4 + alias :person= :requestor=
4 5  
5   - settings_items :enterprise_id, :integer
  6 + alias :enterprise :target
  7 + alias :enterprise= :target=
6 8  
7   - validates_presence_of :enterprise_id
8   -
9   - def enterprise
10   - Enterprise.find(enterprise_id)
11   - end
12   -
13   - def enterprise=(ent)
14   - self.enterprise_id = ent.id
15   - end
  9 + validates_presence_of :enterprise
16 10  
17 11 def perform
18   - raise EnterpriseActivation::RequestorRequired if requestor.nil?
19   - self.enterprise.enable(requestor)
  12 + self.enterprise.enable self.requestor
20 13 end
21 14  
22 15 def title
... ... @@ -28,15 +21,27 @@ class EnterpriseActivation &lt; Task
28 21 end
29 22  
30 23 def information
31   - {:message => _('%{requestor} wants to activate enterprise %{linked_subject}.')}
  24 + if self.requestor
  25 + {:message => _('%{requestor} wants to activate enterprise %{linked_subject}.')}
  26 + else
  27 + {:message => _('Pending activation of enterprise %{linked_subject}.')}
  28 + end
32 29 end
33 30  
34 31 def icon
35   - {:type => :profile_image, :profile => requestor, :url => requestor.url}
  32 + if self.requestor
  33 + {:type => :profile_image, :profile => self.requestor, :url => self.requestor.url}
  34 + else
  35 + {:type => :profile_image, :profile => self.enterprise, :url => self.enterprise.url}
  36 + end
36 37 end
37 38  
38 39 def target_notification_description
39   - _('%{requestor} wants to activate enterprise %{enterprise}.') % {:requestor => requestor.name, :enterprise => enterprise.name}
  40 + if self.requestor
  41 + _('%{requestor} wants to activate enterprise %{enterprise}.') % {:requestor => self.requestor.name, :enterprise => self.enterprise.name}
  42 + else
  43 + _('Pending activation of enterprise %{enterprise}.') % {:enterprise => self.enterprise.name}
  44 + end
40 45 end
41 46  
42 47 end
... ...
app/models/enterprise_homepage.rb
... ... @@ -5,7 +5,7 @@ class EnterpriseHomepage &lt; Article
5 5 end
6 6  
7 7 def self.short_description
8   - __('Enterprise homepage')
  8 + _('Enterprise homepage')
9 9 end
10 10  
11 11 def self.description
... ... @@ -18,7 +18,7 @@ class EnterpriseHomepage &lt; Article
18 18  
19 19 def to_html(options = {})
20 20 enterprise_homepage = self
21   - lambda do
  21 + proc do
22 22 extend EnterpriseHomepageHelper
23 23 extend CatalogHelper
24 24 catalog_load_index :page => 1, :show_categories => false
... ... @@ -26,6 +26,11 @@ class EnterpriseHomepage &lt; Article
26 26 end
27 27 end
28 28  
  29 + # disable cache because of products
  30 + def cache_key params = {}, the_profile = nil, language = 'en'
  31 + rand
  32 + end
  33 +
29 34 def can_display_hits?
30 35 false
31 36 end
... ...
app/models/enterprises_block.rb
1 1 class EnterprisesBlock < ProfileListBlock
2 2  
3 3 def default_title
4   - n__('{#} enterprise', '{#} enterprises', profile_count)
  4 + n_('{#} enterprise', '{#} enterprises', profile_count)
5 5 end
6 6  
7 7 def help
8   - __('This block displays the enterprises where this user works.')
  8 + _('This block displays the enterprises where this user works.')
9 9 end
10 10  
11 11 def self.description
12   - __('Enterprises')
  12 + _('Enterprises')
13 13 end
14 14  
15 15 def footer
16 16 owner = self.owner
17 17 case owner
18 18 when Profile
19   - lambda do
  19 + proc do
20 20 link_to s_('enterprises|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'
21 21 end
22 22 when Environment
23   - lambda do
  23 + proc do
24 24 link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'
25 25 end
26 26 else
... ...
app/models/environment.rb
... ... @@ -3,6 +3,8 @@
3 3 # domains.
4 4 class Environment < ActiveRecord::Base
5 5  
  6 + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body
  7 +
6 8 has_many :users
7 9  
8 10 self.partial_updates = false
... ... @@ -91,9 +93,9 @@ class Environment &lt; ActiveRecord::Base
91 93 def self.available_features
92 94 {
93 95 'disable_asset_articles' => _('Disable search for articles '),
94   - 'disable_asset_enterprises' => __('Disable search for enterprises'),
  96 + 'disable_asset_enterprises' => _('Disable search for enterprises'),
95 97 'disable_asset_people' => _('Disable search for people'),
96   - 'disable_asset_communities' => __('Disable search for communities'),
  98 + 'disable_asset_communities' => _('Disable search for communities'),
97 99 'disable_asset_products' => _('Disable search for products'),
98 100 'disable_asset_events' => _('Disable search for events'),
99 101 'disable_categories' => _('Disable categories'),
... ... @@ -104,11 +106,11 @@ class Environment &lt; ActiveRecord::Base
104 106 'disable_contact_person' => _('Disable contact for people'),
105 107 'disable_contact_community' => _('Disable contact for groups/communities'),
106 108  
107   - 'products_for_enterprises' => __('Enable products for enterprises'),
108   - 'enterprise_registration' => __('Enterprise registration'),
109   - 'enterprise_activation' => __('Enable activation of enterprises'),
110   - 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),
111   - 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),
  109 + 'products_for_enterprises' => _('Enable products for enterprises'),
  110 + 'enterprise_registration' => _('Enterprise registration'),
  111 + 'enterprise_activation' => _('Enable activation of enterprises'),
  112 + 'enterprises_are_disabled_when_created' => _('Enterprises are disabled when created'),
  113 + 'enterprises_are_validated_when_created' => _('Enterprises are validated when created'),
112 114  
113 115 'media_panel' => _('Media panel in WYSIWYG editor'),
114 116 'select_preferred_domain' => _('Select preferred domains per profile'),
... ... @@ -181,7 +183,6 @@ class Environment &lt; ActiveRecord::Base
181 183  
182 184 # "right" area
183 185 env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6)
184   - env.boxes[2].blocks << PeopleBlock.new(:limit => 6)
185 186 end
186 187  
187 188 # One Environment can be reached by many domains
... ... @@ -200,6 +201,8 @@ class Environment &lt; ActiveRecord::Base
200 201  
201 202 has_many :product_categories, :conditions => { :type => 'ProductCategory'}
202 203 has_many :regions
  204 + has_many :states
  205 + has_many :cities
203 206  
204 207 has_many :roles, :dependent => :destroy
205 208  
... ... @@ -295,6 +298,12 @@ class Environment &lt; ActiveRecord::Base
295 298 settings_items :access_control_allow_origin, :type => Array, :default => []
296 299 settings_items :access_control_allow_methods, :type => String
297 300  
  301 + settings_items :signup_welcome_screen_body, :type => String
  302 +
  303 + def has_custom_welcome_screen?
  304 + settings[:signup_welcome_screen_body].present?
  305 + end
  306 +
298 307 settings_items :members_whitelist_enabled, :type => :boolean, :default => false
299 308 settings_items :members_whitelist, :type => Array, :default => []
300 309  
... ... @@ -364,19 +373,22 @@ class Environment &lt; ActiveRecord::Base
364 373 features.delete_if{ |k, v| !self.enabled?(k) }
365 374 end
366 375  
  376 + DEFAULT_FEATURES = %w(
  377 + disable_asset_products
  378 + disable_gender_icon
  379 + products_for_enterprises
  380 + disable_select_city_for_contact
  381 + enterprise_registration
  382 + media_panel
  383 + organizations_are_moderated_by_default
  384 + show_balloon_with_profile_links_when_clicked
  385 + show_zoom_button_on_article_images
  386 + use_portal_community
  387 + )
  388 +
367 389 before_create :enable_default_features
368 390 def enable_default_features
369   - %w(
370   - disable_asset_products
371   - disable_gender_icon
372   - products_for_enterprises
373   - disable_select_city_for_contact
374   - enterprise_registration
375   - media_panel
376   - organizations_are_moderated_by_default
377   - show_balloon_with_profile_links_when_clicked
378   - use_portal_community
379   - ).each do |feature|
  391 + DEFAULT_FEATURES.each do |feature|
380 392 enable(feature, false)
381 393 end
382 394 end
... ... @@ -420,22 +432,6 @@ class Environment &lt; ActiveRecord::Base
420 432 self.settings[:organization_approval_method] = actual_value
421 433 end
422 434  
423   - def terminology
424   - if self.settings[:terminology]
425   - self.settings[:terminology].constantize.instance
426   - else
427   - Noosfero.terminology
428   - end
429   - end
430   -
431   - def terminology=(value)
432   - if value
433   - self.settings[:terminology] = value.class.name
434   - else
435   - self.settings[:terminology] = nil
436   - end
437   - end
438   -
439 435 def custom_person_fields
440 436 self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields]
441 437 end
... ... @@ -626,7 +622,10 @@ class Environment &lt; ActiveRecord::Base
626 622 validates_numericality_of :reports_lower_bound, :allow_nil => false, :only_integer => true, :greater_than_or_equal_to => 0
627 623  
628 624 include WhiteListFilter
629   - filter_iframes :message_for_disabled_enterprise, :whitelist => lambda { trusted_sites_for_iframe }
  625 + filter_iframes :message_for_disabled_enterprise
  626 + def iframe_whitelist
  627 + trusted_sites_for_iframe
  628 + end
630 629  
631 630 # #################################################
632 631 # Business logic in general
... ... @@ -655,6 +654,10 @@ class Environment &lt; ActiveRecord::Base
655 654 domain
656 655 end
657 656  
  657 + def admin_url
  658 + { :controller => 'admin_panel', :action => 'index' }
  659 + end
  660 +
658 661 def top_url
659 662 url = 'http://'
660 663 url << (Noosfero.url_options.key?(:host) ? Noosfero.url_options[:host] : default_hostname)
... ... @@ -676,9 +679,7 @@ class Environment &lt; ActiveRecord::Base
676 679 has_many :tags, :through => :articles
677 680  
678 681 def tag_counts
679   - options = Article.find_options_for_tag_counts.merge(:conditions => ['profiles.environment_id = ?', self.id])
680   - options[:joins] = options[:joins] + ' LEFT OUTER JOIN profiles on profiles.id = articles.profile_id'
681   - Tag.find(:all, options).inject({}) do |memo,tag|
  682 + articles.tag_counts.inject({}) do |memo,tag|
682 683 memo[tag.name] = tag.count
683 684 memo
684 685 end
... ... @@ -811,31 +812,68 @@ class Environment &lt; ActiveRecord::Base
811 812 after_create :create_templates
812 813  
813 814 def create_templates
814   - pre = self.name.to_slug + '_'
815   - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false, :is_template => true).id
816   - inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false, :is_template => true)
817   - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false, :is_template => true).id
  815 + prefix = self.name.to_slug + '_'
  816 +
  817 + enterprise_template = Enterprise.new(
  818 + :name => 'Enterprise template',
  819 + :identifier => prefix + 'enterprise_template'
  820 + )
  821 +
  822 + inactive_enterprise_template = Enterprise.new(
  823 + :name => 'Inactive Enterprise template',
  824 + :identifier => prefix + 'inactive_enterprise_template'
  825 + )
  826 +
  827 + community_template = Community.new(
  828 + :name => 'Community template',
  829 + :identifier => prefix + 'community_template'
  830 + )
  831 +
  832 + [
  833 + enterprise_template,
  834 + inactive_enterprise_template,
  835 + community_template
  836 + ].each do |profile|
  837 + profile.is_template = true
  838 + profile.visible = false
  839 + profile.environment = self
  840 + profile.save!
  841 + end
  842 +
818 843 pass = Digest::MD5.hexdigest rand.to_s
819   - user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person
820   - user.update_attributes(:visible => false, :name => "Person template", :is_template => true)
821   - usr_id = user.id
822   - self.settings[:enterprise_template_id] = ent_id
823   - self.inactive_enterprise_template = inactive_enterprise_tmpl
824   - self.settings[:community_template_id] = com_id
825   - self.settings[:person_template_id] = usr_id
  844 + user = User.new(:login => (prefix + 'person_template'), :email => (prefix + 'template@template.noo'), :password => pass, :password_confirmation => pass)
  845 + user.environment = self
  846 + user.save!
  847 +
  848 + person_template = user.person
  849 + person_template.name = "Person template"
  850 + person_template.is_template = true
  851 + person_template.visible = false
  852 + person_template.save!
  853 +
  854 + self.enterprise_template = enterprise_template
  855 + self.inactive_enterprise_template = inactive_enterprise_template
  856 + self.community_template = community_template
  857 + self.person_template = person_template
826 858 self.save!
827 859 end
828 860  
829 861 after_create :create_default_licenses
830 862 def create_default_licenses
831   - License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self)
832   - License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self)
833   - License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self)
834   - License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self)
835   - License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self)
836   - License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self)
837   - License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self)
838   - License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self)
  863 + [
  864 + { :name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode'},
  865 + { :name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode'},
  866 + { :name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode'},
  867 + { :name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode'},
  868 + { :name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode'},
  869 + { :name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode'},
  870 + { :name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en'},
  871 + { :name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt'},
  872 + ].each do |data|
  873 + license = License.new(data)
  874 + license.environment = self
  875 + license.save!
  876 + end
839 877 end
840 878  
841 879 def highlighted_products_with_image(options = {})
... ...
app/models/environment_mailing.rb
... ... @@ -1,25 +0,0 @@
1   -class EnvironmentMailing < Mailing
2   -
3   - def recipients(offset=0, limit=100)
4   - source.people.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil })
5   - end
6   -
7   - def each_recipient
8   - offset = 0
9   - limit = 100
10   - while !(people = recipients(offset, limit)).empty?
11   - people.each do |person|
12   - yield person
13   - end
14   - offset = offset + limit
15   - end
16   - end
17   -
18   - def signature_message
19   - _('Sent by %s.') % source.name
20   - end
21   -
22   - def url
23   - source.top_url
24   - end
25   -end
app/models/environment_statistics_block.rb
... ... @@ -23,9 +23,9 @@ class EnvironmentStatisticsBlock &lt; Block
23 23 info = []
24 24 info << (n_('One user', '%{num} users', users) % { :num => users })
25 25 unless owner.enabled?('disable_asset_enterprises')
26   - info << (n__('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises })
  26 + info << (n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises })
27 27 end
28   - info << (n__('One community', '%{num} communities', communities) % { :num => communities })
  28 + info << (n_('One community', '%{num} communities', communities) % { :num => communities })
29 29  
30 30 block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n"))
31 31 end
... ...
app/models/event.rb
  1 +require 'noosfero/translatable_content'
  2 +require 'builder'
  3 +
1 4 class Event < Article
2 5  
  6 + attr_accessible :start_date, :end_date, :link, :address
  7 +
3 8 def self.type_name
4 9 _('Event')
5 10 end
... ... @@ -29,27 +34,30 @@ class Event &lt; Article
29 34 end
30 35 end
31 36  
32   - named_scope :by_day, lambda { |date|
  37 + scope :by_day, lambda { |date|
33 38 { :conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}],
34 39 :order => 'start_date ASC'
35 40 }
36 41 }
37 42  
38   - named_scope :next_events_from_month, lambda { |date|
  43 + scope :next_events_from_month, lambda { |date|
39 44 date_temp = date.strftime("%Y-%m-%d")
40 45 { :conditions => ["start_date >= ?","#{date_temp}"],
41 46 :order => 'start_date ASC'
42 47 }
43 48 }
44 49  
45   - named_scope :by_month, lambda { |date|
  50 + scope :by_month, lambda { |date|
46 51 { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month],
47 52 :order => 'start_date ASC'
48 53 }
49 54 }
50 55  
51 56 include WhiteListFilter
52   - filter_iframes :body, :link, :address, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe }
  57 + filter_iframes :body, :link, :address
  58 + def iframe_whitelist
  59 + profile && profile.environment && profile.environment.trusted_sites_for_iframe
  60 + end
53 61  
54 62 def self.description
55 63 _('A calendar event.')
... ... @@ -63,7 +71,7 @@ class Event &lt; Article
63 71 'event'
64 72 end
65 73  
66   - named_scope :by_range, lambda { |range| {
  74 + scope :by_range, lambda { |range| {
67 75 :conditions => [
68 76 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day',
69 77 { :start_day => range.first, :end_day => range.last }
... ... @@ -93,29 +101,27 @@ class Event &lt; Article
93 101 # FIXME this shouldn't be needed
94 102 include ActionView::Helpers::TagHelper
95 103 include ActionView::Helpers::UrlHelper
96   - include ActionController::UrlWriter
97 104 include DatesHelper
98 105  
99 106 def to_html(options = {})
100 107  
101 108 result = ''
102   - html = Builder::XmlMarkup.new(:target => result)
  109 + html = ::Builder::XmlMarkup.new(:target => result)
103 110  
104 111 html.div(:class => 'event-info' ) {
105   -
106 112 html.ul(:class => 'event-data' ) {
107 113 html.li(:class => 'event-dates' ) {
108 114 html.span _('When:')
109 115 html.text! show_period(start_date, end_date)
110   - }
  116 + } if start_date.present? || end_date.present?
111 117 html.li {
112 118 html.span _('URL:')
113 119 html.a(self.link || "", 'href' => self.link || "")
114   - }
  120 + } if self.link.present?
115 121 html.li {
116 122 html.span _('Address:')
117 123 html.text! self.address || ""
118   - }
  124 + } if self.address.present?
119 125 }
120 126  
121 127 # TODO: some good soul, please clean this ugly hack:
... ...
app/models/external_feed.rb
... ... @@ -5,11 +5,13 @@ class ExternalFeed &lt; ActiveRecord::Base
5 5 validates_presence_of :address, :if => lambda {|efeed| efeed.enabled}
6 6 validates_uniqueness_of :blog_id
7 7  
8   - named_scope :enabled, :conditions => { :enabled => true }
9   - named_scope :expired, lambda {
  8 + scope :enabled, :conditions => { :enabled => true }
  9 + scope :expired, lambda {
10 10 { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] }
11 11 }
12 12  
  13 + attr_accessible :address, :enabled
  14 +
13 15 def add_item(title, link, date, content)
14 16 doc = Hpricot(content)
15 17 doc.search('*').each do |p|
... ... @@ -20,7 +22,14 @@ class ExternalFeed &lt; ActiveRecord::Base
20 22 end
21 23 content = doc.to_s
22 24  
23   - article = TinyMceArticle.new(:name => title, :profile => blog.profile, :body => content, :published_at => date, :source => link, :profile => blog.profile, :parent => blog)
  25 + article = TinyMceArticle.new
  26 + article.name = title
  27 + article.profile = blog.profile
  28 + article.body = content
  29 + article.published_at = date
  30 + article.source = link
  31 + article.profile = blog.profile
  32 + article.parent = blog
24 33 unless blog.children.exists?(:slug => article.slug)
25 34 article.save!
26 35 article.delay.create_activity
... ...
app/models/fans_block.rb
... ... @@ -5,7 +5,7 @@ class FansBlock &lt; ProfileListBlock
5 5 end
6 6  
7 7 def default_title
8   - n__('{#} fan', '{#} fans', profile_count)
  8 + n_('{#} fan', '{#} fans', profile_count)
9 9 end
10 10  
11 11 def help
... ... @@ -14,7 +14,7 @@ class FansBlock &lt; ProfileListBlock
14 14  
15 15 def footer
16 16 profile = self.owner
17   - lambda do
  17 + proc do
18 18 link_to _('View all'), :profile => profile.identifier, :controller =>
19 19 'profile', :action => 'fans'
20 20 end
... ...
app/models/favorite_enterprises_block.rb
1 1 class FavoriteEnterprisesBlock < ProfileListBlock
2 2  
3 3 def default_title
4   - __('Favorite Enterprises')
  4 + _('Favorite Enterprises')
5 5 end
6 6  
7 7 def help
8   - __('This block lists your favorite enterprises.')
  8 + _('This block lists your favorite enterprises.')
9 9 end
10 10  
11 11 def self.description
12   - __('Favorite Enterprises')
  12 + _('Favorite Enterprises')
13 13 end
14 14  
15 15 def footer
16 16 owner = self.owner
17 17 return '' unless owner.kind_of?(Person)
18   - lambda do
19   - link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'
  18 + proc do
  19 + link_to _('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'
20 20 end
21 21 end
22 22  
... ...
app/models/featured_products_block.rb
... ... @@ -28,7 +28,7 @@ class FeaturedProductsBlock &lt; Block
28 28  
29 29 def content(args={})
30 30 block = self
31   - lambda do
  31 + proc do
32 32 render :file => 'blocks/featured_products', :locals => { :block => block }
33 33 end
34 34 end
... ...
app/models/feed_reader_block.rb
1 1 class FeedReaderBlock < Block
2 2  
3   - def initialize(attributes = nil)
  3 + attr_accessible :address, :update_errors
  4 +
  5 + def initialize(attributes = nil, options = {})
4 6 data = attributes || {}
5   - super({ :enabled => !data[:address].blank? }.merge(data))
  7 + super(data)
  8 + self.enabled= !data[:address].blank?
6 9 end
7 10  
8 11 include DatesHelper
... ... @@ -24,7 +27,7 @@ class FeedReaderBlock &lt; Block
24 27 settings_items :update_errors, :type => :integer, :default => 0
25 28 settings_items :error_message, :type => :string
26 29  
27   - named_scope :expired, lambda {
  30 + scope :expired, lambda {
28 31 { :conditions => [ '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] }
29 32 }
30 33  
... ...
app/models/folder.rb
... ... @@ -15,7 +15,10 @@ class Folder &lt; Article
15 15 xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation'
16 16  
17 17 include WhiteListFilter
18   - filter_iframes :body, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe }
  18 + filter_iframes :body
  19 + def iframe_whitelist
  20 + profile && profile.environment && profile.environment.trusted_sites_for_iframe
  21 + end
19 22  
20 23 def self.short_description
21 24 _('Folder')
... ... @@ -32,7 +35,7 @@ class Folder &lt; Article
32 35 include ActionView::Helpers::TagHelper
33 36 def to_html(options = {})
34 37 folder = self
35   - lambda do
  38 + proc do
36 39 render :file => 'content_viewer/folder', :locals => {:folder => folder}
37 40 end
38 41 end
... ...
app/models/forum.rb
... ... @@ -3,6 +3,8 @@ class Forum &lt; Folder
3 3 acts_as_having_posts :order => 'updated_at DESC'
4 4 include PostsLimit
5 5  
  6 + attr_accessible :has_terms_of_use, :terms_of_use, :allows_members_to_create_topics
  7 +
6 8 settings_items :terms_of_use, :type => :string, :default => ""
7 9 settings_items :has_terms_of_use, :type => :boolean, :default => false
8 10 settings_items :allows_members_to_create_topics, :type => :boolean, :default => false
... ... @@ -33,7 +35,7 @@ class Forum &lt; Folder
33 35  
34 36 include ActionView::Helpers::TagHelper
35 37 def to_html(options = {})
36   - lambda do
  38 + proc do
37 39 render :file => 'content_viewer/forum_page'
38 40 end
39 41 end
... ...
app/models/friends_block.rb
... ... @@ -1,26 +0,0 @@
1   -class FriendsBlock < ProfileListBlock
2   -
3   - def self.description
4   - __('Friends')
5   - end
6   -
7   - def default_title
8   - n__('{#} friend', '{#} friends', profile_count)
9   - end
10   -
11   - def help
12   - _('This block displays your friends.')
13   - end
14   -
15   - def footer
16   - owner_id = owner.identifier
17   - lambda do
18   - link_to s_('friends|View all'), :profile => owner_id, :controller => 'profile', :action => 'friends'
19   - end
20   - end
21   -
22   - def profiles
23   - owner.friends
24   - end
25   -
26   -end