Commit 2a6128acf665a0489fe396f8b48c8581a938fd08
Exists in
staging
and in
42 other branches
Merge branch 'master' into AI3118-list_bug
Showing
2972 changed files
with
192112 additions
and
46914 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 2972 files displayed.
AUTHORS
| ... | ... | @@ -162,6 +162,7 @@ João M. M. Silva + Rafael Manzo <jaodsilv@linux.ime.usp.br> |
| 162 | 162 | João M. M. Silva + Renan Teruo <jaodsilv@linux.ime.usp.br> |
| 163 | 163 | Joenio Costa <joenio@colivre.coop.br> |
| 164 | 164 | Josef Spillner <josef.spillner@tu-dresden.de> |
| 165 | +Junior Silva <junior@bajor.localhost.localdomain> | |
| 165 | 166 | Junior Silva <juniorsilva1001@gmail.com> |
| 166 | 167 | Junior Silva <juniorsilva7@juniorsilva-Aspire-5750Z.(none)> |
| 167 | 168 | Junior Silva <juniorsilva@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' | |
| 9 | 29 | end |
| 10 | 30 | |
| 11 | 31 | 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' | |
| 32 | + gem 'rake' | |
| 33 | + gem 'cucumber-rails', :require => false | |
| 34 | + gem 'capybara' | |
| 35 | + gem 'cucumber' | |
| 16 | 36 | gem 'database_cleaner' |
| 37 | + gem 'selenium-webdriver' | |
| 17 | 38 | end |
| 18 | 39 | |
| 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 | |
| 40 | +# include plugin gemfiles | |
| 41 | +Dir.glob(File.join('config', 'plugins', '*')).each do |plugin| | |
| 42 | + plugin_gemfile = File.join(plugin, 'Gemfile') | |
| 43 | + eval File.read(plugin_gemfile) if File.exists?(plugin_gemfile) | |
| 23 | 44 | 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) | |
| 31 | 78 | mime-types (1.19) |
| 32 | - multi_json (1.3.7) | |
| 79 | + multi_json (1.3.6) | |
| 33 | 80 | nokogiri (1.5.5) |
| 34 | - rack (1.1.0) | |
| 35 | - rack-test (0.6.2) | |
| 81 | + pg (0.13.2) | |
| 82 | + polyglot (0.3.3) | |
| 83 | + prototype-rails (3.2.1) | |
| 84 | + rails (~> 3.2) | |
| 85 | + rack (1.4.1) | |
| 86 | + rack-cache (1.2) | |
| 87 | + rack (>= 0.4) | |
| 88 | + rack-ssl (1.3.2) | |
| 89 | + rack | |
| 90 | + rack-test (0.6.1) | |
| 36 | 91 | 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) | |
| 92 | + rails (3.2.6) | |
| 93 | + actionmailer (= 3.2.6) | |
| 94 | + actionpack (= 3.2.6) | |
| 95 | + activerecord (= 3.2.6) | |
| 96 | + activeresource (= 3.2.6) | |
| 97 | + activesupport (= 3.2.6) | |
| 98 | + bundler (~> 1.0) | |
| 99 | + railties (= 3.2.6) | |
| 100 | + rails_autolink (1.1.5) | |
| 101 | + rails (> 3.1) | |
| 102 | + railties (3.2.6) | |
| 103 | + actionpack (= 3.2.6) | |
| 104 | + activesupport (= 3.2.6) | |
| 105 | + rack-ssl (~> 1.3.2) | |
| 106 | + rake (>= 0.8.7) | |
| 107 | + rdoc (~> 3.4) | |
| 108 | + thor (>= 0.14.6, < 2.0) | |
| 109 | + rake (0.9.2.2) | |
| 110 | + rdoc (3.9.4) | |
| 111 | + rmagick (2.13.1) | |
| 112 | + rspec (2.10.0) | |
| 113 | + rspec-core (~> 2.10.0) | |
| 114 | + rspec-expectations (~> 2.10.0) | |
| 115 | + rspec-mocks (~> 2.10.0) | |
| 116 | + rspec-core (2.10.1) | |
| 117 | + rspec-expectations (2.10.0) | |
| 118 | + diff-lcs (~> 1.1.3) | |
| 119 | + rspec-mocks (2.10.1) | |
| 120 | + rspec-rails (2.10.1) | |
| 121 | + actionpack (>= 3.0) | |
| 122 | + activesupport (>= 3.0) | |
| 123 | + railties (>= 3.0) | |
| 124 | + rspec (~> 2.10.0) | |
| 125 | + ruby-feedparser (0.7) | |
| 126 | + rubyzip (1.1.2) | |
| 127 | + selenium-webdriver (2.39.0) | |
| 44 | 128 | childprocess (>= 0.2.5) |
| 45 | - libwebsocket (~> 0.1.3) | |
| 46 | 129 | multi_json (~> 1.0) |
| 47 | - rubyzip | |
| 48 | - system_timer (1.2.4) | |
| 130 | + rubyzip (~> 1.0) | |
| 131 | + websocket (~> 1.0.4) | |
| 132 | + sprockets (2.1.3) | |
| 133 | + hike (~> 1.2) | |
| 134 | + multi_json (~> 1.0) | |
| 135 | + rack (~> 1.0) | |
| 136 | + tilt (~> 1.1, != 1.3.0) | |
| 49 | 137 | term-ansicolor (1.0.7) |
| 50 | - websocket (1.0.4) | |
| 51 | - xpath (0.1.4) | |
| 138 | + thin (1.3.1) | |
| 139 | + daemons (>= 1.0.9) | |
| 140 | + eventmachine (>= 0.12.6) | |
| 141 | + rack (>= 1.0.0) | |
| 142 | + thor (0.15.3) | |
| 143 | + tilt (1.3.3) | |
| 144 | + treetop (1.4.10) | |
| 145 | + polyglot | |
| 146 | + polyglot (>= 0.3.1) | |
| 147 | + tzinfo (0.3.33) | |
| 148 | + websocket (1.0.7) | |
| 149 | + will_paginate (3.0.3) | |
| 150 | + xpath (2.0.0) | |
| 52 | 151 | nokogiri (~> 1.3) |
| 53 | 152 | |
| 54 | 153 | PLATFORMS |
| 55 | 154 | ruby |
| 56 | 155 | |
| 57 | 156 | DEPENDENCIES |
| 58 | - capybara (= 1.1.1) | |
| 59 | - cucumber (= 1.1.0) | |
| 60 | - cucumber-rails (= 0.3.2) | |
| 157 | + RedCloth | |
| 158 | + acts-as-taggable-on | |
| 159 | + capybara | |
| 160 | + cucumber | |
| 161 | + cucumber-rails | |
| 162 | + daemons | |
| 163 | + dalli | |
| 61 | 164 | 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 | |
| 165 | + fast_gettext | |
| 166 | + hpricot | |
| 167 | + nokogiri | |
| 168 | + pg | |
| 169 | + prototype-rails | |
| 170 | + prototype_legacy_helper (= 0.0.0)! | |
| 171 | + rails | |
| 172 | + rails_autolink | |
| 173 | + rake | |
| 174 | + rmagick | |
| 175 | + rspec | |
| 176 | + rspec-rails | |
| 177 | + ruby-feedparser | |
| 178 | + selenium-webdriver | |
| 179 | + thin | |
| 180 | + 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' | ... | ... |
| ... | ... | @@ -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 | +[](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 | ... | ... |
| ... | ... | @@ -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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 | |
| 11 | + after_filter :set_csrf_cookie | |
| 12 | + | |
| 13 | + def set_csrf_cookie | |
| 14 | + cookies['_noosfero_.XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? && logged_in? | |
| 15 | + end | |
| 16 | + | |
| 8 | 17 | def allow_cross_domain_access |
| 9 | 18 | origin = request.headers['Origin'] |
| 10 | 19 | return if origin.blank? |
| ... | ... | @@ -21,7 +30,8 @@ class ApplicationController < ActionController::Base |
| 21 | 30 | include ApplicationHelper |
| 22 | 31 | layout :get_layout |
| 23 | 32 | def get_layout |
| 24 | - return nil if request.format == :js | |
| 33 | + return nil if request.format == :js or request.xhr? | |
| 34 | + | |
| 25 | 35 | theme_layout = theme_option(:layout) |
| 26 | 36 | if theme_layout |
| 27 | 37 | theme_view_file('layouts/'+theme_layout) || theme_layout |
| ... | ... | @@ -30,11 +40,9 @@ class ApplicationController < ActionController::Base |
| 30 | 40 | end |
| 31 | 41 | end |
| 32 | 42 | |
| 33 | - filter_parameter_logging :password | |
| 34 | - | |
| 35 | 43 | def log_processing |
| 36 | 44 | super |
| 37 | - return unless ENV['RAILS_ENV'] == 'production' | |
| 45 | + return unless Rails.env == 'production' | |
| 38 | 46 | if logger && logger.info? |
| 39 | 47 | logger.info(" HTTP Referer: #{request.referer}") |
| 40 | 48 | logger.info(" User Agent: #{request.user_agent}") |
| ... | ... | @@ -65,6 +73,7 @@ class ApplicationController < ActionController::Base |
| 65 | 73 | FastGettext.default_locale = environment.default_locale |
| 66 | 74 | FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') |
| 67 | 75 | I18n.locale = FastGettext.locale |
| 76 | + I18n.default_locale = FastGettext.default_locale | |
| 68 | 77 | if params[:lang] |
| 69 | 78 | session[:lang] = params[:lang] |
| 70 | 79 | end |
| ... | ... | @@ -74,18 +83,24 @@ class ApplicationController < ActionController::Base |
| 74 | 83 | |
| 75 | 84 | attr_reader :environment |
| 76 | 85 | |
| 77 | - before_filter :load_terminology | |
| 78 | - | |
| 79 | 86 | # declares that the given <tt>actions</tt> cannot be accessed by other HTTP |
| 80 | 87 | # method besides POST. |
| 81 | 88 | def self.post_only(actions, redirect = { :action => 'index'}) |
| 82 | - verify :method => :post, :only => actions, :redirect_to => redirect | |
| 89 | + before_filter(:only => actions) do |controller| | |
| 90 | + if !controller.request.post? | |
| 91 | + controller.redirect_to redirect | |
| 92 | + end | |
| 93 | + end | |
| 83 | 94 | end |
| 84 | 95 | |
| 85 | 96 | helper_method :current_person, :current_person |
| 86 | 97 | |
| 87 | 98 | protected |
| 88 | 99 | |
| 100 | + def verified_request? | |
| 101 | + super || form_authenticity_token == request.headers['X-XSRF-TOKEN'] | |
| 102 | + end | |
| 103 | + | |
| 89 | 104 | def setup_multitenancy |
| 90 | 105 | Noosfero::MultiTenancy.setup!(request.host) |
| 91 | 106 | end |
| ... | ... | @@ -111,7 +126,10 @@ class ApplicationController < ActionController::Base |
| 111 | 126 | @environment = Environment.default |
| 112 | 127 | if @environment.nil? && Rails.env.development? |
| 113 | 128 | # This should only happen in development ... |
| 114 | - @environment = Environment.create!(:name => "Noosfero", :is_default => true) | |
| 129 | + @environment = Environment.new | |
| 130 | + @environment.name = "Noosfero" | |
| 131 | + @environment.is_default = true | |
| 132 | + @environment.save! | |
| 115 | 133 | end |
| 116 | 134 | else |
| 117 | 135 | @environment = @domain.environment |
| ... | ... | @@ -127,36 +145,15 @@ class ApplicationController < ActionController::Base |
| 127 | 145 | |
| 128 | 146 | include Noosfero::Plugin::HotSpot |
| 129 | 147 | |
| 130 | - # This is a generic method that initialize any possible filter defined by a | |
| 131 | - # plugin to the current controller being initialized. | |
| 132 | - def init_noosfero_plugins_controller_filters | |
| 133 | - plugins.each do |plugin| | |
| 134 | - filters = plugin.send(self.class.name.underscore + '_filters') | |
| 135 | - filters = [filters] if !filters.kind_of?(Array) | |
| 136 | - controller_filters = self.class.filter_chain.map {|c| c.method } | |
| 137 | - filters.each do |plugin_filter| | |
| 138 | - filter_method = plugin.class.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name] | |
| 139 | - unless controller_filters.include?(filter_method) | |
| 140 | - self.class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {})) | |
| 141 | - self.class.send(:define_method, filter_method) do | |
| 142 | - instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin.class) | |
| 143 | - end | |
| 144 | - end | |
| 145 | - end | |
| 146 | - end | |
| 147 | - end | |
| 148 | - | |
| 149 | - def load_terminology | |
| 150 | - # cache terminology for performance | |
| 151 | - @@terminology_cache ||= {} | |
| 152 | - @@terminology_cache[environment.id] ||= environment.terminology | |
| 153 | - Noosfero.terminology = @@terminology_cache[environment.id] | |
| 148 | + # FIXME this filter just loads @plugins to children controllers and helpers | |
| 149 | + def init_noosfero_plugins | |
| 150 | + plugins | |
| 154 | 151 | end |
| 155 | 152 | |
| 156 | 153 | def render_not_found(path = nil) |
| 157 | 154 | @no_design_blocks = true |
| 158 | 155 | @path ||= request.path |
| 159 | - render :template => 'shared/not_found.rhtml', :status => 404, :layout => get_layout | |
| 156 | + render :template => 'shared/not_found.html.erb', :status => 404, :layout => get_layout | |
| 160 | 157 | end |
| 161 | 158 | alias :render_404 :render_not_found |
| 162 | 159 | |
| ... | ... | @@ -164,12 +161,12 @@ class ApplicationController < ActionController::Base |
| 164 | 161 | @no_design_blocks = true |
| 165 | 162 | @message = message |
| 166 | 163 | @title = title |
| 167 | - render :template => 'shared/access_denied.rhtml', :status => 403 | |
| 164 | + render :template => 'shared/access_denied.html.erb', :status => 403 | |
| 168 | 165 | end |
| 169 | 166 | |
| 170 | 167 | def load_category |
| 171 | 168 | unless params[:category_path].blank? |
| 172 | - path = params[:category_path].join('/') | |
| 169 | + path = params[:category_path] | |
| 173 | 170 | @category = environment.categories.find_by_path(path) |
| 174 | 171 | if @category.nil? |
| 175 | 172 | render_not_found(path) | ... | ... |
app/controllers/embed_controller.rb
| ... | ... | @@ -4,10 +4,10 @@ class EmbedController < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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
| ... | ... | @@ -17,6 +17,8 @@ class AccountController < ApplicationController |
| 17 | 17 | @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] |
| 18 | 18 | if @user and @user.activate |
| 19 | 19 | @message = _("Your account has been activated, now you can log in!") |
| 20 | + check_redirection | |
| 21 | + session[:join] = params[:join] unless params[:join].blank? | |
| 20 | 22 | render :action => 'login', :userlogin => @user.login |
| 21 | 23 | else |
| 22 | 24 | session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") |
| ... | ... | @@ -35,6 +37,7 @@ class AccountController < ApplicationController |
| 35 | 37 | self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] |
| 36 | 38 | |
| 37 | 39 | if logged_in? |
| 40 | + check_join_in_community(self.current_user) | |
| 38 | 41 | if params[:remember_me] == "1" |
| 39 | 42 | self.current_user.remember_me |
| 40 | 43 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
| ... | ... | @@ -91,6 +94,7 @@ class AccountController < ApplicationController |
| 91 | 94 | if session[:may_be_a_bot] |
| 92 | 95 | return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') |
| 93 | 96 | end |
| 97 | + @user.community_to_join = session[:join] | |
| 94 | 98 | @user.signup! |
| 95 | 99 | owner_role = Role.find_by_name('owner') |
| 96 | 100 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
| ... | ... | @@ -101,6 +105,7 @@ class AccountController < ApplicationController |
| 101 | 105 | end |
| 102 | 106 | if @user.activated? |
| 103 | 107 | self.current_user = @user |
| 108 | + check_join_in_community(@user) | |
| 104 | 109 | go_to_signup_initial_page |
| 105 | 110 | else |
| 106 | 111 | @register_pending = true |
| ... | ... | @@ -135,12 +140,8 @@ class AccountController < ApplicationController |
| 135 | 140 | params[:new_password_confirmation]) |
| 136 | 141 | session[:notice] = _('Your password has been changed successfully!') |
| 137 | 142 | redirect_to :action => 'index' |
| 138 | - rescue User::IncorrectPassword => e | |
| 139 | - session[:notice] = _('The supplied current password is incorrect.') | |
| 140 | - render :action => 'change_password' | |
| 143 | + rescue Exception | |
| 141 | 144 | end |
| 142 | - else | |
| 143 | - render :action => 'change_password' | |
| 144 | 145 | end |
| 145 | 146 | end |
| 146 | 147 | |
| ... | ... | @@ -166,12 +167,12 @@ class AccountController < ApplicationController |
| 166 | 167 | render :action => 'password_recovery_sent' |
| 167 | 168 | rescue ActiveRecord::RecordNotFound |
| 168 | 169 | if params[:value].blank? |
| 169 | - @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.') | |
| 170 | 171 | else |
| 171 | - @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]] | |
| 172 | 173 | end |
| 173 | 174 | rescue ActiveRecord::RecordInvald |
| 174 | - @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.') | |
| 175 | 176 | end |
| 176 | 177 | end |
| 177 | 178 | end |
| ... | ... | @@ -392,12 +393,6 @@ class AccountController < ApplicationController |
| 392 | 393 | end |
| 393 | 394 | |
| 394 | 395 | def go_to_initial_page |
| 395 | - if params[:redirection] | |
| 396 | - session[:return_to] = @user.return_to | |
| 397 | - @user.return_to = nil | |
| 398 | - @user.save | |
| 399 | - end | |
| 400 | - | |
| 401 | 396 | if params[:return_to] |
| 402 | 397 | redirect_to params[:return_to] |
| 403 | 398 | elsif environment.enabled?('allow_change_of_redirection_after_login') |
| ... | ... | @@ -448,4 +443,19 @@ class AccountController < ApplicationController |
| 448 | 443 | redirect_back_or_default(default) |
| 449 | 444 | end |
| 450 | 445 | end |
| 446 | + | |
| 447 | + def check_redirection | |
| 448 | + unless params[:redirection].blank? | |
| 449 | + session[:return_to] = @user.return_to | |
| 450 | + @user.update_attributes(:return_to => nil) | |
| 451 | + end | |
| 452 | + end | |
| 453 | + | |
| 454 | + def check_join_in_community(user) | |
| 455 | + profile_to_join = session[:join] | |
| 456 | + unless profile_to_join.blank? | |
| 457 | + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) | |
| 458 | + session.delete(:join) | |
| 459 | + end | |
| 460 | + end | |
| 451 | 461 | end | ... | ... |
app/controllers/public/chat_controller.rb
| ... | ... | @@ -19,7 +19,7 @@ class ChatController < 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,7 +8,9 @@ class ContentViewerController < ApplicationController |
| 6 | 8 | helper TagsHelper |
| 7 | 9 | |
| 8 | 10 | def view_page |
| 9 | - path = params[:page].join('/') | |
| 11 | + path = params[:page] | |
| 12 | + path = path.join('/') if path.kind_of?(Array) | |
| 13 | + path = "#{path}.#{params[:format]}" if params[:format] | |
| 10 | 14 | @version = params[:version].to_i |
| 11 | 15 | |
| 12 | 16 | if path.blank? |
| ... | ... | @@ -32,12 +36,12 @@ class ContentViewerController < ApplicationController |
| 32 | 36 | return render_access_denied unless @page.display_versions? |
| 33 | 37 | @versioned_article = @page.versions.find_by_version(@version) |
| 34 | 38 | if @versioned_article && @page.versions.latest.version != @versioned_article.version |
| 35 | - render :template => 'content_viewer/versioned_article.rhtml' | |
| 39 | + render :template => 'content_viewer/versioned_article.html.erb' | |
| 36 | 40 | return |
| 37 | 41 | end |
| 38 | 42 | end |
| 39 | 43 | |
| 40 | - redirect_to_translation if @page.profile.redirect_l10n | |
| 44 | + redirect_to_translation and return if @page.profile.redirect_l10n | |
| 41 | 45 | |
| 42 | 46 | if request.post? |
| 43 | 47 | if @page.forum? && @page.has_terms_of_use && params[:terms_accepted] == "true" |
| ... | ... | @@ -87,7 +91,7 @@ class ContentViewerController < ApplicationController |
| 87 | 91 | blog_with_translation = @page.blog? && @page.display_posts_in_current_language? |
| 88 | 92 | posts = posts.native_translations if blog_with_translation |
| 89 | 93 | |
| 90 | - @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))) | |
| 94 | + @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a | |
| 91 | 95 | |
| 92 | 96 | if blog_with_translation |
| 93 | 97 | @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact |
| ... | ... | @@ -123,12 +127,20 @@ class ContentViewerController < ApplicationController |
| 123 | 127 | |
| 124 | 128 | if params[:slideshow] |
| 125 | 129 | render :action => 'slideshow', :layout => 'slideshow' |
| 130 | + return | |
| 126 | 131 | end |
| 132 | + render :view_page, :formats => [:html] | |
| 127 | 133 | end |
| 128 | 134 | |
| 129 | - def article_versions | |
| 135 | + def versions_diff | |
| 130 | 136 | path = params[:page].join('/') |
| 131 | 137 | @page = profile.articles.find_by_path(path) |
| 138 | + @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2]) | |
| 139 | + end | |
| 140 | + | |
| 141 | + def article_versions | |
| 142 | + path = params[:page] | |
| 143 | + @page = profile.articles.find_by_path(path) | |
| 132 | 144 | return unless allow_access_to_page(path) |
| 133 | 145 | |
| 134 | 146 | render_access_denied unless @page.display_versions? |
| ... | ... | @@ -173,7 +185,7 @@ class ContentViewerController < ApplicationController |
| 173 | 185 | elsif !@page.display_to?(user) |
| 174 | 186 | if !profile.public? |
| 175 | 187 | private_profile_partial_parameters |
| 176 | - render :template => 'profile/_private_profile.rhtml', :status => 403 | |
| 188 | + render :template => 'profile/_private_profile', :status => 403 | |
| 177 | 189 | allowed = false |
| 178 | 190 | else #if !profile.visible? |
| 179 | 191 | render_access_denied |
| ... | ... | @@ -191,5 +203,4 @@ class ContentViewerController < ApplicationController |
| 191 | 203 | user_agent.match(/crawler/) || |
| 192 | 204 | user_agent.match(/\(.*https?:\/\/.*\)/) |
| 193 | 205 | end |
| 194 | - | |
| 195 | 206 | end | ... | ... |
app/controllers/public/profile_controller.rb
| ... | ... | @@ -3,7 +3,7 @@ class ProfileController < PublicController |
| 3 | 3 | needs_profile |
| 4 | 4 | before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] |
| 5 | 5 | before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] |
| 6 | - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] | |
| 6 | + before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] | |
| 7 | 7 | |
| 8 | 8 | helper TagsHelper |
| 9 | 9 | |
| ... | ... | @@ -32,7 +32,7 @@ class ProfileController < 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 | |
| ... | ... | @@ -97,21 +97,12 @@ class ProfileController < PublicController |
| 97 | 97 | end |
| 98 | 98 | |
| 99 | 99 | def join_not_logged |
| 100 | - if request.post? | |
| 101 | - profile.add_member(user) | |
| 102 | - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? | |
| 103 | - redirect_to_previous_location | |
| 100 | + session[:join] = profile.identifier | |
| 101 | + | |
| 102 | + if user | |
| 103 | + redirect_to :controller => 'profile', :action => 'join' | |
| 104 | 104 | else |
| 105 | - if user.memberships.include?(profile) | |
| 106 | - session[:notice] = _('You are already a member of %s.') % profile.name | |
| 107 | - redirect_to profile.url | |
| 108 | - return | |
| 109 | - end | |
| 110 | - if request.xhr? | |
| 111 | - render :layout => false | |
| 112 | - else | |
| 113 | - redirect_to profile.url | |
| 114 | - end | |
| 105 | + redirect_to :controller => '/account', :action => 'login' | |
| 115 | 106 | end |
| 116 | 107 | end |
| 117 | 108 | |
| ... | ... | @@ -167,7 +158,7 @@ class ProfileController < PublicController |
| 167 | 158 | session[:notice] = _("You have unblocked %s successfully. ") % profile.name |
| 168 | 159 | redirect_to :controller => 'profile', :action => 'index' |
| 169 | 160 | else |
| 170 | - message = __('You are not allowed to unblock enterprises in this environment.') | |
| 161 | + message = _('You are not allowed to unblock enterprises in this environment.') | |
| 171 | 162 | render_access_denied(message) |
| 172 | 163 | end |
| 173 | 164 | end |
| ... | ... | @@ -219,7 +210,7 @@ class ProfileController < PublicController |
| 219 | 210 | |
| 220 | 211 | render :update do |page| |
| 221 | 212 | page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], |
| 222 | - :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) | |
| 223 | 214 | |
| 224 | 215 | if no_more_pages |
| 225 | 216 | page.remove 'profile-wall-activities-comments-more-'+params[:activity] | ... | ... |
app/controllers/public/search_controller.rb
| ... | ... | @@ -29,7 +29,7 @@ class SearchController < 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 < 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 < 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 < 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) |
| ... | ... | @@ -1027,8 +1033,8 @@ module ApplicationHelper |
| 1027 | 1033 | links.push(_('New content') => colorbox_options({:href => url_for({:controller => 'cms', :action => 'new', :profile => current_user.login, :cms => true})})) |
| 1028 | 1034 | end |
| 1029 | 1035 | |
| 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') | |
| 1036 | + link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') + | |
| 1037 | + link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger') | |
| 1032 | 1038 | end |
| 1033 | 1039 | alias :browse_contents_menu :search_contents_menu |
| 1034 | 1040 | |
| ... | ... | @@ -1044,7 +1050,7 @@ module ApplicationHelper |
| 1044 | 1050 | end |
| 1045 | 1051 | |
| 1046 | 1052 | 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') | |
| 1053 | + link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger') | |
| 1048 | 1054 | end |
| 1049 | 1055 | alias :browse_people_menu :search_people_menu |
| 1050 | 1056 | |
| ... | ... | @@ -1060,7 +1066,7 @@ module ApplicationHelper |
| 1060 | 1066 | end |
| 1061 | 1067 | |
| 1062 | 1068 | 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') | |
| 1069 | + link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger') | |
| 1064 | 1070 | end |
| 1065 | 1071 | alias :browse_communities_menu :search_communities_menu |
| 1066 | 1072 | |
| ... | ... | @@ -1072,7 +1078,7 @@ module ApplicationHelper |
| 1072 | 1078 | def render_environment_features(folder) |
| 1073 | 1079 | result = '' |
| 1074 | 1080 | environment.enabled_features.keys.each do |feature| |
| 1075 | - file = File.join(@controller.view_paths.last, 'shared', folder.to_s, "#{feature}.rhtml") | |
| 1081 | + file = Rails.root.join('app/views/shared', folder.to_s, "#{feature}.html.erb") | |
| 1076 | 1082 | if File.exists?(file) |
| 1077 | 1083 | result << render(:file => file, :use_full_path => false) |
| 1078 | 1084 | end |
| ... | ... | @@ -1085,10 +1091,10 @@ module ApplicationHelper |
| 1085 | 1091 | link_to_all = nil |
| 1086 | 1092 | if list.count > 5 |
| 1087 | 1093 | list = list.first(5) |
| 1088 | - link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => current_user.login) | |
| 1094 | + link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => user.identifier) | |
| 1089 | 1095 | end |
| 1090 | 1096 | 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]) | |
| 1097 | + 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 | 1098 | end |
| 1093 | 1099 | if link_to_all |
| 1094 | 1100 | link << link_to_all |
| ... | ... | @@ -1112,15 +1118,15 @@ module ApplicationHelper |
| 1112 | 1118 | pending_tasks_count = '' |
| 1113 | 1119 | count = user ? Task.to(user).pending.count : -1 |
| 1114 | 1120 | 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")) | |
| 1121 | + pending_tasks_count = link_to(count.to_s, user.tasks_url, :id => 'pending-tasks-count', :title => _("Manage your pending tasks")) | |
| 1116 | 1122 | end |
| 1117 | 1123 | |
| 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'))) + | |
| 1124 | + (_("<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 | 1125 | 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') + | |
| 1126 | + link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') + | |
| 1121 | 1127 | manage_enterprises.to_s + |
| 1122 | 1128 | 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")) + | |
| 1129 | + 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 | 1130 | pending_tasks_count + |
| 1125 | 1131 | link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) |
| 1126 | 1132 | end |
| ... | ... | @@ -1130,7 +1136,7 @@ module ApplicationHelper |
| 1130 | 1136 | text_area(object_name, method, { :id => text_area_id, :onkeyup => "limited_text_area('#{text_area_id}', #{limit})" }.merge(options)), |
| 1131 | 1137 | content_tag(:p, content_tag(:span, limit) + ' ' + _(' characters left'), :id => text_area_id + '_left'), |
| 1132 | 1138 | content_tag(:p, _('Limit of characters reached'), :id => text_area_id + '_limit', :style => 'display: none') |
| 1133 | - ], :class => 'limited-text-area') | |
| 1139 | + ].join, :class => 'limited-text-area') | |
| 1134 | 1140 | end |
| 1135 | 1141 | |
| 1136 | 1142 | def expandable_text_area(object_name, method, text_area_id, options = {}) |
| ... | ... | @@ -1148,6 +1154,7 @@ module ApplicationHelper |
| 1148 | 1154 | #FIXME Use time_ago_in_words instead of this method if you're using Rails 2.2+ |
| 1149 | 1155 | def time_ago_as_sentence(from_time, include_seconds = false) |
| 1150 | 1156 | to_time = Time.now |
| 1157 | + from_time = Time.parse(from_time.to_s) | |
| 1151 | 1158 | from_time = from_time.to_time if from_time.respond_to?(:to_time) |
| 1152 | 1159 | to_time = to_time.to_time if to_time.respond_to?(:to_time) |
| 1153 | 1160 | distance_in_minutes = (((to_time - from_time).abs)/60).round |
| ... | ... | @@ -1328,6 +1335,25 @@ module ApplicationHelper |
| 1328 | 1335 | expirable_content_reference content, action, text, url, options |
| 1329 | 1336 | end |
| 1330 | 1337 | |
| 1338 | + def error_messages_for(*args) | |
| 1339 | + options = args.pop if args.last.is_a?(Hash) | |
| 1340 | + errors = [] | |
| 1341 | + args.each do |name| | |
| 1342 | + object = instance_variable_get("@#{name}") | |
| 1343 | + object.errors.full_messages.each do |msg| | |
| 1344 | + errors << msg | |
| 1345 | + end if object | |
| 1346 | + end | |
| 1347 | + return '' if errors.empty? | |
| 1348 | + | |
| 1349 | + content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do | |
| 1350 | + content_tag(:h2, _('Errors while saving')) + | |
| 1351 | + content_tag(:ul) do | |
| 1352 | + errors.map { |err| content_tag(:li, err) }.join | |
| 1353 | + end | |
| 1354 | + end | |
| 1355 | + end | |
| 1356 | + | |
| 1331 | 1357 | def private_profile_partial_parameters |
| 1332 | 1358 | if profile.person? |
| 1333 | 1359 | @action = :add_friend |
| ... | ... | @@ -1357,7 +1383,7 @@ module ApplicationHelper |
| 1357 | 1383 | doc.search('.macro').each do |macro| |
| 1358 | 1384 | macro_name = macro['data-macro'] |
| 1359 | 1385 | result = @plugins.parse_macro(macro_name, macro, source) |
| 1360 | - macro.inner_html = result.kind_of?(Proc) ? self.instance_eval(&result) : result | |
| 1386 | + macro.inner_html = result.kind_of?(Proc) ? self.instance_exec(&result) : result | |
| 1361 | 1387 | end |
| 1362 | 1388 | doc.html |
| 1363 | 1389 | end | ... | ... |
app/helpers/article_helper.rb
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(' → '), 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(' → '), 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
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
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] || ' → ') |
| ... | ... | @@ -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? ? '': ' »')}</option>" | |
| 43 | + "<option value='#{category.id}' title='#{category.name}' #{selected_attribute}>#{category.name + (category.leaf? ? '': ' »')}</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 => '<' + _('Select domain') + '>')) | |
| 132 | + labelled_form_field(_('Preferred domain name:'), select(object, :preferred_domain_id, domains.map {|item| [item.name, item.id]}, :prompt => '<' + _('Select domain') + '>')) | |
| 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
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -0,0 +1,47 @@ |
| 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 | + | |
| 23 | + mail( | |
| 24 | + from: "#{user.environment.name} <#{user.environment.contact_email}>", | |
| 25 | + to: user.email, | |
| 26 | + subject: _("[%s] Activate your account") % [user.environment.name], | |
| 27 | + ) | |
| 28 | + end | |
| 29 | + | |
| 30 | + def signup_welcome_email(user) | |
| 31 | + @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) | |
| 32 | + email_subject = user.environment.signup_welcome_text_subject | |
| 33 | + mail( | |
| 34 | + content_type: 'text/html', | |
| 35 | + to: user.email, | |
| 36 | + from: "#{user.environment.name} <#{user.environment.contact_email}>", | |
| 37 | + subject: email_subject.blank? ? _("Welcome to environment %s") % [user.environment.name] : email_subject, | |
| 38 | + body: @body | |
| 39 | + ) | |
| 40 | + end | |
| 41 | + | |
| 42 | + class Job < Struct.new(:user, :method) | |
| 43 | + def perform | |
| 44 | + UserMailer.send(method, user).deliver | |
| 45 | + end | |
| 46 | + end | |
| 47 | +end | ... | ... |
app/models/abuse_report.rb
app/models/action_tracker_notification.rb
| ... | ... | @@ -8,6 +8,8 @@ class ActionTrackerNotification < 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 < 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 < 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 'hpricot' |
| 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 | |
| 6 | + | |
| 5 | 7 | acts_as_having_image |
| 6 | 8 | |
| 7 | 9 | SEARCHABLE_FIELDS = { |
| ... | ... | @@ -38,12 +40,6 @@ class Article < 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 < 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 < 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 < 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 < 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') |
| ... | ... | @@ -219,14 +221,19 @@ class Article < ActiveRecord::Base |
| 219 | 221 | |
| 220 | 222 | # retrieves all articles belonging to the given +profile+ that are not |
| 221 | 223 | # sub-articles of any other article. |
| 222 | - named_scope :top_level_for, lambda { |profile| | |
| 224 | + scope :top_level_for, lambda { |profile| | |
| 223 | 225 | {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} |
| 224 | 226 | } |
| 225 | 227 | |
| 226 | - named_scope :join_profile, :joins => [:profile] | |
| 228 | + scope :public, | |
| 229 | + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], :joins => [:profile] | |
| 227 | 230 | |
| 228 | - named_scope :public, | |
| 229 | - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] | |
| 231 | + scope :more_recent, | |
| 232 | + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND | |
| 233 | + ((articles.type != ?) OR articles.type is NULL)", | |
| 234 | + true, true, true, true, 'RssFeed' | |
| 235 | + ], | |
| 236 | + :order => 'articles.published_at desc, articles.id desc' | |
| 230 | 237 | |
| 231 | 238 | # retrives the most commented articles, sorted by the comment count (largest |
| 232 | 239 | # first) |
| ... | ... | @@ -234,7 +241,8 @@ class Article < ActiveRecord::Base |
| 234 | 241 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) |
| 235 | 242 | end |
| 236 | 243 | |
| 237 | - named_scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] | |
| 244 | + scope :more_popular, :order => 'hits DESC' | |
| 245 | + scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] | |
| 238 | 246 | |
| 239 | 247 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
| 240 | 248 | result = scoped({:conditions => extra_conditions}). |
| ... | ... | @@ -243,13 +251,6 @@ class Article < ActiveRecord::Base |
| 243 | 251 | limit(limit). |
| 244 | 252 | order(['articles.published_at desc', 'articles.id desc']) |
| 245 | 253 | |
| 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 | 254 | pagination ? result.paginate({:page => 1, :per_page => limit}) : result |
| 254 | 255 | end |
| 255 | 256 | |
| ... | ... | @@ -261,16 +262,18 @@ class Article < ActiveRecord::Base |
| 261 | 262 | # (To override short format representation, override the lead method) |
| 262 | 263 | def to_html(options = {}) |
| 263 | 264 | if options[:format] == 'short' |
| 264 | - display_short_format(self) | |
| 265 | + article = self | |
| 266 | + proc do | |
| 267 | + display_short_format(article) | |
| 268 | + end | |
| 265 | 269 | else |
| 266 | 270 | body || '' |
| 267 | 271 | end |
| 268 | 272 | end |
| 269 | 273 | |
| 270 | - include ApplicationHelper | |
| 271 | 274 | def reported_version(options = {}) |
| 272 | 275 | article = self |
| 273 | - search_path = File.join(Rails.root, 'app', 'views', 'shared', 'reported_versions') | |
| 276 | + search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions') | |
| 274 | 277 | partial_path = File.join('shared', 'reported_versions', partial_for_class_in_view_path(article.class, search_path)) |
| 275 | 278 | lambda { render_to_string(:partial => partial_path, :locals => {:article => article}) } |
| 276 | 279 | end |
| ... | ... | @@ -371,7 +374,7 @@ class Article < ActiveRecord::Base |
| 371 | 374 | {} |
| 372 | 375 | end |
| 373 | 376 | |
| 374 | - named_scope :native_translations, :conditions => { :translation_of_id => nil } | |
| 377 | + scope :native_translations, :conditions => { :translation_of_id => nil } | |
| 375 | 378 | |
| 376 | 379 | def translatable? |
| 377 | 380 | false |
| ... | ... | @@ -407,7 +410,7 @@ class Article < ActiveRecord::Base |
| 407 | 410 | |
| 408 | 411 | def native_translation_must_have_language |
| 409 | 412 | 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? | |
| 413 | + errors.add(:base, N_('A language must be choosen for the native article')) if self.translation_of.language.blank? | |
| 411 | 414 | end |
| 412 | 415 | end |
| 413 | 416 | |
| ... | ... | @@ -449,17 +452,17 @@ class Article < ActiveRecord::Base |
| 449 | 452 | ['TextArticle', 'TextileArticle', 'TinyMceArticle'] |
| 450 | 453 | end |
| 451 | 454 | |
| 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 ] } } | |
| 455 | + scope :published, :conditions => { :published => true } | |
| 456 | + scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }} | |
| 457 | + scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} | |
| 458 | + scope :galleries, :conditions => { :type => 'Gallery' } | |
| 459 | + scope :images, :conditions => { :is_image => true } | |
| 460 | + scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | |
| 461 | + scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } | |
| 459 | 462 | |
| 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" | |
| 463 | + scope :more_popular, :order => 'hits DESC' | |
| 464 | + scope :more_comments, :order => "comments_count DESC" | |
| 465 | + scope :more_recent, :order => "created_at DESC" | |
| 463 | 466 | |
| 464 | 467 | def self.display_filter(user, profile) |
| 465 | 468 | return {:conditions => ['published = ?', true]} if !user |
| ... | ... | @@ -531,13 +534,23 @@ class Article < ActiveRecord::Base |
| 531 | 534 | def copy(options = {}) |
| 532 | 535 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } |
| 533 | 536 | attrs.merge!(options) |
| 534 | - self.class.create(attrs) | |
| 537 | + object = self.class.new | |
| 538 | + attrs.each do |key, value| | |
| 539 | + object.send(key.to_s+'=', value) | |
| 540 | + end | |
| 541 | + object.save | |
| 542 | + object | |
| 535 | 543 | end |
| 536 | 544 | |
| 537 | 545 | def copy!(options = {}) |
| 538 | 546 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } |
| 539 | 547 | attrs.merge!(options) |
| 540 | - self.class.create!(attrs) | |
| 548 | + object = self.class.new | |
| 549 | + attrs.each do |key, value| | |
| 550 | + object.send(key.to_s+'=', value) | |
| 551 | + end | |
| 552 | + object.save! | |
| 553 | + object | |
| 541 | 554 | end |
| 542 | 555 | |
| 543 | 556 | ATTRIBUTES_NOT_COPIED = [ |
| ... | ... | @@ -617,30 +630,28 @@ class Article < ActiveRecord::Base |
| 617 | 630 | |
| 618 | 631 | def author(version_number = nil) |
| 619 | 632 | if version_number |
| 620 | - version = versions.find_by_version(version_number) | |
| 633 | + version = self.versions.find_by_version(version_number) | |
| 621 | 634 | author_id = version.last_changed_by_id if version |
| 622 | - Person.exists?(author_id) ? Person.find(author_id) : nil | |
| 623 | 635 | 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 | |
| 636 | + author_id = self.created_by_id | |
| 630 | 637 | end |
| 638 | + | |
| 639 | + environment.people.find_by_id(author_id) | |
| 631 | 640 | end |
| 632 | 641 | |
| 633 | 642 | def author_name(version_number = nil) |
| 634 | - person = version_number ? author(version_number) : author | |
| 643 | + person = author(version_number) | |
| 635 | 644 | person ? person.name : (setting[:author_name] || _('Unknown')) |
| 636 | 645 | end |
| 637 | 646 | |
| 638 | - def author_url | |
| 639 | - author ? author.url : nil | |
| 647 | + def author_url(version_number = nil) | |
| 648 | + person = author(version_number) | |
| 649 | + person ? person.url : nil | |
| 640 | 650 | end |
| 641 | 651 | |
| 642 | - def author_id | |
| 643 | - author ? author.id : nil | |
| 652 | + def author_id(version_number = nil) | |
| 653 | + person = author(version_number) | |
| 654 | + person ? person.id : nil | |
| 644 | 655 | end |
| 645 | 656 | |
| 646 | 657 | def version_license(version_number = nil) |
| ... | ... | @@ -734,7 +745,7 @@ class Article < ActiveRecord::Base |
| 734 | 745 | |
| 735 | 746 | def sanitize_tag_list |
| 736 | 747 | sanitizer = HTML::FullSanitizer.new |
| 737 | - self.tag_list.names.map!{|i| strip_tag_name sanitizer.sanitize(i) } | |
| 748 | + self.tag_list.map!{|i| strip_tag_name sanitizer.sanitize(i) } | |
| 738 | 749 | end |
| 739 | 750 | |
| 740 | 751 | 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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
app/models/change_password.rb
| ... | ... | @@ -2,7 +2,7 @@ class ChangePassword < 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 < 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
app/models/comment.rb
| ... | ... | @@ -6,6 +6,8 @@ class Comment < 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 < 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 < 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 < 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 | |
| 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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
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 < 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 < 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
| ... | ... | @@ -17,12 +17,12 @@ class Enterprise < Organization |
| 17 | 17 | has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' |
| 18 | 18 | |
| 19 | 19 | def product_categories |
| 20 | - products.includes(:product_category).map{|p| p.category_full_name}.compact | |
| 20 | + ProductCategory.by_enterprise(self) | |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') |
| 24 | 24 | |
| 25 | - settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country | |
| 25 | + settings_items :organization_website, :historic_and_current_context, :activities_short_description | |
| 26 | 26 | settings_items :products_per_catalog_page, :type => :integer, :default => 6 |
| 27 | 27 | |
| 28 | 28 | extend SetProfileRegionFromCityState::ClassMethods |
| ... | ... | @@ -54,8 +54,9 @@ class Enterprise < Organization |
| 54 | 54 | super + FIELDS |
| 55 | 55 | end |
| 56 | 56 | |
| 57 | - def validate | |
| 58 | - super | |
| 57 | + validate :presence_of_required_fieds | |
| 58 | + | |
| 59 | + def presence_of_required_fieds | |
| 59 | 60 | self.required_fields.each do |field| |
| 60 | 61 | if self.send(field).blank? |
| 61 | 62 | self.errors.add_on_blank(field) |
| ... | ... | @@ -97,14 +98,18 @@ class Enterprise < Organization |
| 97 | 98 | save |
| 98 | 99 | end |
| 99 | 100 | |
| 101 | + def activation_task | |
| 102 | + self.tasks.where(:type => 'EnterpriseActivation').first | |
| 103 | + end | |
| 104 | + | |
| 100 | 105 | def enable(owner) |
| 101 | 106 | 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! | |
| 107 | + # must be set first for the following to work | |
| 108 | + self.enabled = true | |
| 109 | + self.affiliate owner, Profile::Roles.all_roles(self.environment.id) if owner | |
| 110 | + self.apply_template template if self.environment.replace_enterprise_template_when_enable | |
| 111 | + self.activation_task.update_attribute :status, Task::Status::FINISHED rescue nil | |
| 112 | + self.save(:validate => false) | |
| 108 | 113 | end |
| 109 | 114 | |
| 110 | 115 | def question |
| ... | ... | @@ -168,7 +173,7 @@ class Enterprise < Organization |
| 168 | 173 | alias_method_chain :template, :inactive_enterprise |
| 169 | 174 | |
| 170 | 175 | def control_panel_settings_button |
| 171 | - {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | |
| 176 | + {:title => _('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | |
| 172 | 177 | end |
| 173 | 178 | |
| 174 | 179 | settings_items :enable_contact_us, :type => :boolean, :default => true |
| ... | ... | @@ -178,7 +183,7 @@ class Enterprise < Organization |
| 178 | 183 | end |
| 179 | 184 | |
| 180 | 185 | def control_panel_settings_button |
| 181 | - {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | |
| 186 | + {:title => _('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | |
| 182 | 187 | end |
| 183 | 188 | |
| 184 | 189 | 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 < 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 < 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 < 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 < 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 < 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 < 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'), |
| ... | ... | @@ -180,7 +182,6 @@ class Environment < ActiveRecord::Base |
| 180 | 182 | |
| 181 | 183 | # "right" area |
| 182 | 184 | env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6) |
| 183 | - env.boxes[2].blocks << PeopleBlock.new(:limit => 6) | |
| 184 | 185 | end |
| 185 | 186 | |
| 186 | 187 | # One Environment can be reached by many domains |
| ... | ... | @@ -199,6 +200,8 @@ class Environment < ActiveRecord::Base |
| 199 | 200 | |
| 200 | 201 | has_many :product_categories, :conditions => { :type => 'ProductCategory'} |
| 201 | 202 | has_many :regions |
| 203 | + has_many :states | |
| 204 | + has_many :cities | |
| 202 | 205 | |
| 203 | 206 | has_many :roles, :dependent => :destroy |
| 204 | 207 | |
| ... | ... | @@ -294,6 +297,12 @@ class Environment < ActiveRecord::Base |
| 294 | 297 | settings_items :access_control_allow_origin, :type => Array, :default => [] |
| 295 | 298 | settings_items :access_control_allow_methods, :type => String |
| 296 | 299 | |
| 300 | + settings_items :signup_welcome_screen_body, :type => String | |
| 301 | + | |
| 302 | + def has_custom_welcome_screen? | |
| 303 | + settings[:signup_welcome_screen_body].present? | |
| 304 | + end | |
| 305 | + | |
| 297 | 306 | def news_amount_by_folder=(amount) |
| 298 | 307 | settings[:news_amount_by_folder] = amount.to_i |
| 299 | 308 | end |
| ... | ... | @@ -352,19 +361,22 @@ class Environment < ActiveRecord::Base |
| 352 | 361 | features.delete_if{ |k, v| !self.enabled?(k) } |
| 353 | 362 | end |
| 354 | 363 | |
| 364 | + DEFAULT_FEATURES = %w( | |
| 365 | + disable_asset_products | |
| 366 | + disable_gender_icon | |
| 367 | + products_for_enterprises | |
| 368 | + disable_select_city_for_contact | |
| 369 | + enterprise_registration | |
| 370 | + media_panel | |
| 371 | + organizations_are_moderated_by_default | |
| 372 | + show_balloon_with_profile_links_when_clicked | |
| 373 | + show_zoom_button_on_article_images | |
| 374 | + use_portal_community | |
| 375 | + ) | |
| 376 | + | |
| 355 | 377 | before_create :enable_default_features |
| 356 | 378 | def enable_default_features |
| 357 | - %w( | |
| 358 | - disable_asset_products | |
| 359 | - disable_gender_icon | |
| 360 | - products_for_enterprises | |
| 361 | - disable_select_city_for_contact | |
| 362 | - enterprise_registration | |
| 363 | - media_panel | |
| 364 | - organizations_are_moderated_by_default | |
| 365 | - show_balloon_with_profile_links_when_clicked | |
| 366 | - use_portal_community | |
| 367 | - ).each do |feature| | |
| 379 | + DEFAULT_FEATURES.each do |feature| | |
| 368 | 380 | enable(feature, false) |
| 369 | 381 | end |
| 370 | 382 | end |
| ... | ... | @@ -408,22 +420,6 @@ class Environment < ActiveRecord::Base |
| 408 | 420 | self.settings[:organization_approval_method] = actual_value |
| 409 | 421 | end |
| 410 | 422 | |
| 411 | - def terminology | |
| 412 | - if self.settings[:terminology] | |
| 413 | - self.settings[:terminology].constantize.instance | |
| 414 | - else | |
| 415 | - Noosfero.terminology | |
| 416 | - end | |
| 417 | - end | |
| 418 | - | |
| 419 | - def terminology=(value) | |
| 420 | - if value | |
| 421 | - self.settings[:terminology] = value.class.name | |
| 422 | - else | |
| 423 | - self.settings[:terminology] = nil | |
| 424 | - end | |
| 425 | - end | |
| 426 | - | |
| 427 | 423 | def custom_person_fields |
| 428 | 424 | self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields] |
| 429 | 425 | end |
| ... | ... | @@ -614,7 +610,10 @@ class Environment < ActiveRecord::Base |
| 614 | 610 | validates_numericality_of :reports_lower_bound, :allow_nil => false, :only_integer => true, :greater_than_or_equal_to => 0 |
| 615 | 611 | |
| 616 | 612 | include WhiteListFilter |
| 617 | - filter_iframes :message_for_disabled_enterprise, :whitelist => lambda { trusted_sites_for_iframe } | |
| 613 | + filter_iframes :message_for_disabled_enterprise | |
| 614 | + def iframe_whitelist | |
| 615 | + trusted_sites_for_iframe | |
| 616 | + end | |
| 618 | 617 | |
| 619 | 618 | # ################################################# |
| 620 | 619 | # Business logic in general |
| ... | ... | @@ -643,6 +642,10 @@ class Environment < ActiveRecord::Base |
| 643 | 642 | domain |
| 644 | 643 | end |
| 645 | 644 | |
| 645 | + def admin_url | |
| 646 | + { :controller => 'admin_panel', :action => 'index' } | |
| 647 | + end | |
| 648 | + | |
| 646 | 649 | def top_url |
| 647 | 650 | url = 'http://' |
| 648 | 651 | url << (Noosfero.url_options.key?(:host) ? Noosfero.url_options[:host] : default_hostname) |
| ... | ... | @@ -664,9 +667,7 @@ class Environment < ActiveRecord::Base |
| 664 | 667 | has_many :tags, :through => :articles |
| 665 | 668 | |
| 666 | 669 | def tag_counts |
| 667 | - options = Article.find_options_for_tag_counts.merge(:conditions => ['profiles.environment_id = ?', self.id]) | |
| 668 | - options[:joins] = options[:joins] + ' LEFT OUTER JOIN profiles on profiles.id = articles.profile_id' | |
| 669 | - Tag.find(:all, options).inject({}) do |memo,tag| | |
| 670 | + articles.tag_counts.inject({}) do |memo,tag| | |
| 670 | 671 | memo[tag.name] = tag.count |
| 671 | 672 | memo |
| 672 | 673 | end |
| ... | ... | @@ -799,31 +800,68 @@ class Environment < ActiveRecord::Base |
| 799 | 800 | after_create :create_templates |
| 800 | 801 | |
| 801 | 802 | def create_templates |
| 802 | - pre = self.name.to_slug + '_' | |
| 803 | - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false, :is_template => true).id | |
| 804 | - inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false, :is_template => true) | |
| 805 | - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false, :is_template => true).id | |
| 803 | + prefix = self.name.to_slug + '_' | |
| 804 | + | |
| 805 | + enterprise_template = Enterprise.new( | |
| 806 | + :name => 'Enterprise template', | |
| 807 | + :identifier => prefix + 'enterprise_template' | |
| 808 | + ) | |
| 809 | + | |
| 810 | + inactive_enterprise_template = Enterprise.new( | |
| 811 | + :name => 'Inactive Enterprise template', | |
| 812 | + :identifier => prefix + 'inactive_enterprise_template' | |
| 813 | + ) | |
| 814 | + | |
| 815 | + community_template = Community.new( | |
| 816 | + :name => 'Community template', | |
| 817 | + :identifier => prefix + 'community_template' | |
| 818 | + ) | |
| 819 | + | |
| 820 | + [ | |
| 821 | + enterprise_template, | |
| 822 | + inactive_enterprise_template, | |
| 823 | + community_template | |
| 824 | + ].each do |profile| | |
| 825 | + profile.is_template = true | |
| 826 | + profile.visible = false | |
| 827 | + profile.environment = self | |
| 828 | + profile.save! | |
| 829 | + end | |
| 830 | + | |
| 806 | 831 | pass = Digest::MD5.hexdigest rand.to_s |
| 807 | - user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person | |
| 808 | - user.update_attributes(:visible => false, :name => "Person template", :is_template => true) | |
| 809 | - usr_id = user.id | |
| 810 | - self.settings[:enterprise_template_id] = ent_id | |
| 811 | - self.inactive_enterprise_template = inactive_enterprise_tmpl | |
| 812 | - self.settings[:community_template_id] = com_id | |
| 813 | - self.settings[:person_template_id] = usr_id | |
| 832 | + user = User.new(:login => (prefix + 'person_template'), :email => (prefix + 'template@template.noo'), :password => pass, :password_confirmation => pass) | |
| 833 | + user.environment = self | |
| 834 | + user.save! | |
| 835 | + | |
| 836 | + person_template = user.person | |
| 837 | + person_template.name = "Person template" | |
| 838 | + person_template.is_template = true | |
| 839 | + person_template.visible = false | |
| 840 | + person_template.save! | |
| 841 | + | |
| 842 | + self.enterprise_template = enterprise_template | |
| 843 | + self.inactive_enterprise_template = inactive_enterprise_template | |
| 844 | + self.community_template = community_template | |
| 845 | + self.person_template = person_template | |
| 814 | 846 | self.save! |
| 815 | 847 | end |
| 816 | 848 | |
| 817 | 849 | after_create :create_default_licenses |
| 818 | 850 | def create_default_licenses |
| 819 | - License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self) | |
| 820 | - License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self) | |
| 821 | - License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self) | |
| 822 | - License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self) | |
| 823 | - License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self) | |
| 824 | - License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self) | |
| 825 | - License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self) | |
| 826 | - License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self) | |
| 851 | + [ | |
| 852 | + { :name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode'}, | |
| 853 | + { :name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode'}, | |
| 854 | + { :name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode'}, | |
| 855 | + { :name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode'}, | |
| 856 | + { :name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode'}, | |
| 857 | + { :name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode'}, | |
| 858 | + { :name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en'}, | |
| 859 | + { :name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt'}, | |
| 860 | + ].each do |data| | |
| 861 | + license = License.new(data) | |
| 862 | + license.environment = self | |
| 863 | + license.save! | |
| 864 | + end | |
| 827 | 865 | end |
| 828 | 866 | |
| 829 | 867 | 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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
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 < 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 < 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 < 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 < 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 | |
| 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 < 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 |