From 23d32ba1d58f96ecb3b92da4b5f371e93cad9dca Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 23 Dec 2011 00:13:35 -0200 Subject: [PATCH] Some fixes --- app/controllers/public/profile_controller.rb | 8 ++------ app/models/action_tracker_notification.rb | 1 - app/models/article.rb | 9 ++++++--- app/models/comment.rb | 4 +--- app/views/profile/_comment.rhtml | 22 +++++++++++----------- app/views/profile/_profile.rhtml | 1 - app/views/profile/_profile_activities.rhtml | 28 ---------------------------- app/views/profile/_profile_activities_scraps.rhtml | 2 +- app/views/profile/_profile_activity.rhtml | 31 ++++++++++++++++++++++++++----- app/views/profile/_profile_wall.rhtml | 10 ---------- config/initializers/action_tracker.rb | 18 ------------------ test/functional/profile_controller_test.rb | 41 +++++++++++++++++++++++++++++++++++++++-- test/unit/comment_test.rb | 10 ++++++++++ vendor/plugins/active_record_counter_cache_on_polymorphic_association/init.rb | 60 ++++++++++++++++++++++++++++++++---------------------------- 14 files changed, 128 insertions(+), 117 deletions(-) delete mode 100644 app/views/profile/_profile_activities.rhtml diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index b7153d9..ade39ca 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -3,17 +3,14 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse] - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report] + before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity] helper TagsHelper def index - @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) - @wall_items = [] @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) : [] if logged_in? && current_person.follows?(@profile) @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) if @network_activities.empty? - @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) end @tags = profile.article_tags @@ -187,7 +184,7 @@ class ProfileController < PublicController def leave_comment_on_activity @comment = Comment.new(params[:comment]) - @comment.author = user #'if logged_in? + @comment.author = user @comment.source = ActionTracker::Record.find(params[:comment][:source_id]) @tab_action = params[:tab_action] @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") @@ -201,7 +198,6 @@ class ProfileController < PublicController end def view_more_activities -# @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} end diff --git a/app/models/action_tracker_notification.rb b/app/models/action_tracker_notification.rb index 717d0a0..dda665c 100644 --- a/app/models/action_tracker_notification.rb +++ b/app/models/action_tracker_notification.rb @@ -11,4 +11,3 @@ class ActionTrackerNotification < ActiveRecord::Base end ActionTracker::Record.has_many :action_tracker_notifications, :class_name => 'ActionTrackerNotification', :foreign_key => 'action_tracker_id', :dependent => :destroy -ActionTracker::Record.has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' diff --git a/app/models/article.rb b/app/models/article.rb index 6be91a6..41cc421 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,7 +2,7 @@ require 'hpricot' class Article < ActiveRecord::Base - track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target + track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :id], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target # xss_terminate plugin can't sanitize array fields before_save :sanitize_tag_list @@ -15,7 +15,7 @@ class Article < ActiveRecord::Base belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' - has_many :comments, :dependent => :destroy, :order => 'created_at asc', :as => :source + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] has_many :categories, :through => :article_categorizations @@ -133,7 +133,10 @@ class Article < ActiveRecord::Base article.advertise = true end - after_update do |article| + after_update :update_creation_activity + def update_creation_activity + a = ActionTracker::Record.all.select {|a| a.verb == 'create_article' && a.target == article.profile} + a.first.touch #update article's activity end diff --git a/app/models/comment.rb b/app/models/comment.rb index 91ea076..6686e26 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,10 +1,8 @@ class Comment < ActiveRecord::Base -# track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target - validates_presence_of :body - belongs_to :source, :foreign_key => :source_id, :counter_cache => true, :polymorphic => true + belongs_to :source, :counter_cache => true, :polymorphic => true alias :article :source alias :article= :source= diff --git a/app/views/profile/_comment.rhtml b/app/views/profile/_comment.rhtml index 3277900..8eb871b 100644 --- a/app/views/profile/_comment.rhtml +++ b/app/views/profile/_comment.rhtml @@ -3,14 +3,14 @@
- <%# if comment.author %> - <%= link_to image_tag(profile_icon(comment.author, :minor)) + - content_tag('span', comment.author_name, :class => 'comment-info'), - comment.author.url, + <% if Person.find(comment.author_id) %> + <%= link_to image_tag(profile_icon(Person.find(comment.author_id), :minor)) + + content_tag('span', Person.find(comment.author_id).name, :class => 'comment-info'), + Person.find(comment.author_id).url, :class => 'comment-picture', - :title => comment.author_name + :title => Person.find(comment.author_id).name %> - <%# end %> + <% end %>

<%= comment.title %>

@@ -23,11 +23,11 @@
- <%# if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %> + <% if logged_in? && (user == profile || user == Person.find(comment.author_id) || user.has_permission?(:moderate_comments, profile)) %> <% button_bar(:style => 'float: right; margin-top: 0px;') do %> - <%= icon_button(:delete, _('Remove this comment and all its replies'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> + <%= icon_button(:delete, _('Remove'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> <% end %> - <%# end %> + <% end %>
<% if @comment && @comment.errors.any? && @comment.reply_of_id.to_i == comment.id %> @@ -39,7 +39,7 @@ }); <% end %> - <%= report_abuse(comment.author, :comment_link, comment) if comment.author %> + <%= report_abuse(Person.find(comment.author_id), :comment_link, comment) if Person.find(comment.author_id) %> <%= link_to_function _('Reply'), "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id, :class => 'comment-footer comment-footer-link comment-footer-hide', @@ -49,7 +49,7 @@
- <% unless comment.replies.blank? %> + <% unless Comment.find(comment.id).replies.blank? %>