Files
danbooru/app/policies/post_policy.rb
evazion 3ae62d08eb favorites: show favlist when hovering over favcount.
Changes:

* Make it so you can click or hover over a post's favorite count to see
  the list of public favorites.
* Remove the "Show »" button next to the favorite count.
* Make the favorites list visible to all users. Before favorites were
  only visible to Gold users.
* Make the /favorites page show the list of all public favorites,
  instead of redirecting to the current user's favorites.
* Add /posts/:id/favorites endpoint.
* Add /users/:id/favorites endpoint.

This is for several reasons:

* To make viewing favorites work the same way as viewing upvotes.
* To make posts load faster for Gold users. Before, we loaded all the
  favorites when viewing a post, even when the user didn't look at them.
  This made pageloads slower for posts that had hundreds or thousands of
  favorites. Now we only load the favlist if the user hovers over the favcount.
* To make the favorite list visible to all users. Before, it wasn't
  visible to non-Gold users, because of the performance issue listed above.
* To make it more obvious that favorites are public by default. Before,
  since regular users could only see the favcount, they may have
  mistakenly believed other users couldn't see their favorites.
2021-11-20 02:40:18 -06:00

87 lines
1.4 KiB
Ruby

class PostPolicy < ApplicationPolicy
def show_seq?
true
end
def random?
true
end
def update?
unbanned? && record.visible?
end
def revert?
update?
end
def copy_notes?
update?
end
def mark_as_translated?
update?
end
def move_favorites?
user.is_approver? && record.fav_count > 0 && record.parent_id.present?
end
def regenerate?
user.is_moderator?
end
def delete?
user.is_approver? && !record.is_deleted?
end
def destroy?
delete?
end
def ban?
user.is_approver? && !record.is_banned?
end
def unban?
user.is_approver? && record.is_banned?
end
def expunge?
user.is_admin?
end
def visible?
record.visible?(user)
end
def can_use_mode_menu?
user.is_gold?
end
# whether to show the + - links in the tag list.
def show_extra_links?
user.is_gold?
end
def permitted_attributes
[
:tag_string, :old_tag_string, :parent_id, :old_parent_id,
:source, :old_source, :rating, :old_rating, :has_embedded_notes,
].compact
end
def api_attributes
attributes = super
attributes += [:has_large, :has_visible_children]
attributes += TagCategory.categories.map {|x| "tag_string_#{x}".to_sym}
attributes += [:file_url, :large_file_url, :preview_file_url] if visible?
attributes -= [:id, :md5] if !visible?
attributes
end
def html_data_attributes
super + [:has_large?, :current_image_size]
end
end