From 2cb243827d65d0abb7a12c45e97920bf7ecf8c79 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 29 Feb 2012 03:47:46 -0300 Subject: [PATCH] Adding button to remove network activities --- app/controllers/public/profile_controller.rb | 18 +++++++++++++++++- app/views/profile/_profile_activities.rhtml | 2 +- app/views/profile/_profile_network_activities.rhtml | 1 + test/functional/profile_controller_test.rb | 45 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index af3a302..f301223 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -211,7 +211,8 @@ class ProfileController < PublicController def remove_activity begin - activity = current_person.tracked_actions.find(params[:activity_id]) + raise if !can_edit_profile + activity = ActionTracker::Record.find(params[:activity_id]) activity.destroy render :text => _('Activity successfully removed.') rescue @@ -219,6 +220,17 @@ class ProfileController < PublicController end end + def remove_notification + begin + raise if !can_edit_profile + notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) + notification.destroy + render :text => _('Notification successfully removed.') + rescue + render :text => _('You could not remove this notification.') + end + end + def profile_info begin @block = profile.blocks.find(params[:block_id]) @@ -320,4 +332,8 @@ class ProfileController < PublicController 20 end + def can_edit_profile + @can_edit_profile ||= user && user.has_permission?('edit_profile', profile) + end + helper_method :can_edit_profile end diff --git a/app/views/profile/_profile_activities.rhtml b/app/views/profile/_profile_activities.rhtml index d541b8c..3f2e74f 100644 --- a/app/views/profile/_profile_activities.rhtml +++ b/app/views/profile/_profile_activities.rhtml @@ -6,7 +6,7 @@

<%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %>

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

- <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> + <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if can_edit_profile %>

diff --git a/app/views/profile/_profile_network_activities.rhtml b/app/views/profile/_profile_network_activities.rhtml index 497283d..70959e9 100644 --- a/app/views/profile/_profile_network_activities.rhtml +++ b/app/views/profile/_profile_network_activities.rhtml @@ -9,6 +9,7 @@

<%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %>

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

+ <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_notification', :activity_id => activity.id}, :update => "profile-network-item-#{activity.id}") if can_edit_profile %>

<%= _('In community %s') % link_to(activity.target.name, activity.target.url) if !profile.is_a?(Community) && activity.target.is_a?(Community) %>