diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index da0c3af..af7a453 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,8 +65,6 @@ class ApplicationController < ActionController::Base helper :language include DesignHelper - - # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem include PermissionCheck diff --git a/app/helpers/action_tracker_helper.rb b/app/helpers/action_tracker_helper.rb index e6f8a66..7d13a5b 100644 --- a/app/helpers/action_tracker_helper.rb +++ b/app/helpers/action_tracker_helper.rb @@ -67,19 +67,19 @@ module ActionTrackerHelper } end - def create_product_description + def create_product_description ta _('created the product %{title}') % { title: link_to(truncate(ta.get_name), ta.get_url), } end - def update_product_description + def update_product_description ta _('updated the product %{title}') % { title: link_to(truncate(ta.get_name), ta.get_url), } end - def remove_product_description + def remove_product_description ta _('removed the product %{title}') % { title: truncate(ta.get_name), } diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 11acb50..a1e60e8 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,11 @@ +require_relative '../helpers/application_helper' + class ApplicationMailer < ActionMailer::Base + include AuthenticatedSystem + + helper ApplicationHelper + attr_accessor :environment def default_url_options options = nil diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb index d286f6c..ba75c89 100644 --- a/app/models/person_notifier.rb +++ b/app/models/person_notifier.rb @@ -77,9 +77,8 @@ class PersonNotifier end - class Mailer < ActionMailer::Base + class Mailer < ApplicationMailer - helper ApplicationHelper helper ActionTrackerHelper def session @@ -88,8 +87,8 @@ class PersonNotifier def content_summary(person, notifications, tasks) if person.environment - ActionMailer::Base.asset_host = person.environment.top_url - ActionMailer::Base.default_url_options[:host] = person.environment.default_hostname + ApplicationMailer.asset_host = person.environment.top_url + ApplicationMailer.default_url_options[:host] = person.environment.default_hostname end @current_theme = 'default' diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index ab101d1..fc8ea89 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -16,7 +16,7 @@ class ProfileListBlock < Block def profile_list result = nil - public_profiles = profiles.public.includes([:image,:domains,:preferred_domain,:environment]) + public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment]) if !prioritize_profiles_with_image result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } elsif profiles.visible.with_image.count >= get_limit @@ -28,7 +28,7 @@ result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at end def profile_count - profiles.public.length + profiles.is_public.length end # the title of the block. Probably will be overriden in subclasses. diff --git a/app/views/person_notifier/mailer/_create_product.html.erb b/app/views/person_notifier/mailer/_create_product.html.erb new file mode 120000 index 0000000..e1169fd --- /dev/null +++ b/app/views/person_notifier/mailer/_create_product.html.erb @@ -0,0 +1 @@ +../../profile/_create_product.html.erb \ No newline at end of file diff --git a/app/views/person_notifier/mailer/_favorite_enterprise.html.erb b/app/views/person_notifier/mailer/_favorite_enterprise.html.erb new file mode 120000 index 0000000..601ec31 --- /dev/null +++ b/app/views/person_notifier/mailer/_favorite_enterprise.html.erb @@ -0,0 +1 @@ +../../profile/_favorite_enterprise.html.erb \ No newline at end of file diff --git a/app/views/person_notifier/mailer/_remove_product.html.erb b/app/views/person_notifier/mailer/_remove_product.html.erb new file mode 120000 index 0000000..49ea419 --- /dev/null +++ b/app/views/person_notifier/mailer/_remove_product.html.erb @@ -0,0 +1 @@ +../../profile/_remove_product.html.erb \ No newline at end of file diff --git a/app/views/person_notifier/mailer/_update_product.html.erb b/app/views/person_notifier/mailer/_update_product.html.erb new file mode 120000 index 0000000..81d9f5e --- /dev/null +++ b/app/views/person_notifier/mailer/_update_product.html.erb @@ -0,0 +1 @@ +../../profile/_update_product.html.erb \ No newline at end of file diff --git a/app/views/profile/_create_product.html.erb b/app/views/profile/_create_product.html.erb index d7021d3..094309f 100644 --- a/app/views/profile/_create_product.html.erb +++ b/app/views/profile/_create_product.html.erb @@ -3,7 +3,7 @@

<%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence activity.created_at %>

+

<%= time_ago_in_words activity.created_at %>

<%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> diff --git a/app/views/profile/_favorite_enterprise.html.erb b/app/views/profile/_favorite_enterprise.html.erb index 16ae381..185aa3a 100644 --- a/app/views/profile/_favorite_enterprise.html.erb +++ b/app/views/profile/_favorite_enterprise.html.erb @@ -5,7 +5,7 @@

<%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence activity.created_at %>

+

<%= time_ago_in_words activity.created_at %>

<%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> diff --git a/app/views/profile/_remove_product.html.erb b/app/views/profile/_remove_product.html.erb index 0ddb381..1fb0afa 100644 --- a/app/views/profile/_remove_product.html.erb +++ b/app/views/profile/_remove_product.html.erb @@ -2,7 +2,7 @@

<%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence activity.created_at %>

+

<%= time_ago_in_words activity.created_at %>

<%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> diff --git a/app/views/profile/_update_product.html.erb b/app/views/profile/_update_product.html.erb index d7021d3..094309f 100644 --- a/app/views/profile/_update_product.html.erb +++ b/app/views/profile/_update_product.html.erb @@ -3,7 +3,7 @@

<%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence activity.created_at %>

+

<%= time_ago_in_words activity.created_at %>

<%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> diff --git a/config/application.rb b/config/application.rb index 2ca973d..f1ed846 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,11 +22,10 @@ module Noosfero # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - config.autoload_paths += %W( #{Rails.root.join('app', 'sweepers')} ) + config.autoload_paths += %W( #{config.root.join('app', 'sweepers')} ) config.autoload_paths += Dir["#{config.root}/lib"] config.autoload_paths += Dir["#{config.root}/app/controllers/**/"] - config.autoload_paths += %W( #{Rails.root.join('test', 'mocks', Rails.env)} ) - + config.autoload_paths += %W( #{config.root.join('test', 'mocks', Rails.env)} ) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index 71d21e2..666f7a1 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb @@ -3,7 +3,7 @@ module AuthenticatedSystem protected # See impl. from http://stackoverflow.com/a/2513456/670229 - def self.included? base + def self.included base base.around_filter do begin User.current = current_user @@ -12,7 +12,11 @@ module AuthenticatedSystem # to address the thread variable leak issues in Puma/Thin webserver User.current = nil end - end + end if base.is_a? ActionController::Base + + # Inclusion hook to make #current_user and #logged_in? + # available as ActionView helper methods. + base.send :helper_method, :current_user, :logged_in? end # Returns true or false if the user is logged in. @@ -134,12 +138,6 @@ module AuthenticatedSystem end end - # Inclusion hook to make #current_user and #logged_in? - # available as ActionView helper methods. - def self.included(base) - base.send :helper_method, :current_user, :logged_in? - end - # When called with before_filter :login_from_cookie will check for an :auth_token # cookie and log the user back in if apropriate def login_from_cookie diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 7a880dd..056435d 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -713,5 +713,4 @@ end require 'noosfero/plugin/hot_spot' require 'noosfero/plugin/manager' -require 'noosfero/plugin/mailer_base' require 'noosfero/plugin/settings' diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 4830ec5..0c7d1f6 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1132,7 +1132,7 @@ class ProfileControllerTest < ActionController::TestCase ActionTracker::Record.destroy_all 40.times{ create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})} assert_equal 40, profile.tracked_actions.count - assert_equal 40, profile.activities.count + assert_equal 40, profile.activities.size get :view_more_activities, :profile => profile.identifier, :page => 2 assert_response :success assert_template '_profile_activities_list' diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb index 8fc5875..f96da54 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -163,6 +163,21 @@ class PersonNotifierTest < ActiveSupport::TestCase end end + Targets = { + create_article: -> { create Forum, profile: @profile }, + new_friendship: -> { create Friendship, person: @member, friend: @member }, + join_community: -> { @member }, + add_member_in_community: -> { create_user.person }, + upload_image: -> { create Forum, profile: @profile }, + leave_scrap: -> { create Scrap, sender: @member, receiver: @profile }, + leave_scrap_to_self: -> { create Scrap, sender: @member, receiver: @profile }, + reply_scrap_on_self: -> { create Scrap, sender: @member, receiver: @profile }, + create_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) }, + update_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) }, + remove_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) }, + favorite_enterprise: -> { create FavoriteEnterprisePerson, enterprise: create(Enterprise), person: @member }, + } + ActionTrackerConfig.verb_names.each do |verb| should "render notification for verb #{verb}" do @member.tracked_notifications = [] @@ -171,14 +186,15 @@ class PersonNotifierTest < ActiveSupport::TestCase a.verb = verb a.user = @member a.created_at = @member.notifier.notify_from + 1.day - profile = create(Community) - a.target = create(Forum, profile: profile) + @profile = create(Community) + a.target = instance_exec &Targets[verb.to_sym] a.comments_count = 0 a.params = { 'name' => 'home', 'url' => '/', 'lead' => '', 'receiver_url' => '/', 'content' => 'nothing', 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'], 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'], + 'enterprise_name' => 'coop', 'enterprise_url' => '/coop', 'view_url'=> ['/'], 'thumbnail_path' => ['1'], } a.get_url = '' -- libgit2 0.21.2