Skip to content

Commit

Permalink
Do not show delete to unauthorized. Fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Jul 11, 2011
1 parent 5f1e171 commit 05c0cf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions app/models/activity.rb
Expand Up @@ -225,14 +225,23 @@ def allow?(subject, action)
when 'update' when 'update'
return true if contact.sender_id == Actor.normalize_id(subject) return true if contact.sender_id == Actor.normalize_id(subject)
when 'destroy' when 'destroy'
return true if [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject)) # We only allow destroying to sender and receiver by now
return [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject))
end end


Relation. Relation.
allow(subject, action, 'activity'). allow(subject, action, 'activity').
where('relations.id' => relation_ids). where('relations.id' => relation_ids).
any? any?
end end

# Can subject delete the object of this activity?
def delete_object_by?(subject)
subject.present? &&
direct_object.present? &&
! direct_object.is_a?(Actor) &&
allow?(subject, 'destroy')
end


private private


Expand Down
2 changes: 1 addition & 1 deletion app/views/activities/_options.html.erb
Expand Up @@ -5,7 +5,7 @@
<li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li> <li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li>
<% end %> <% end %>
<li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= link_like(activity)%></div></li> <li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= link_like(activity)%></div></li>
<% if activity.direct_object.present? && !activity.direct_object.is_a?(Actor) %> <% if activity.delete_object_by?(current_subject) %>
<li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('confirm_delete', :scope => activity.direct_object.class.to_s.underscore), :method => :delete, :remote => true %> </div></li> <li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('confirm_delete', :scope => activity.direct_object.class.to_s.underscore), :method => :delete, :remote => true %> </div></li>
<% end %> <% end %>
</ul> </ul>
Expand Down

0 comments on commit 05c0cf8

Please sign in to comment.