debshots/app/helpers/packages_helper.rb

27 lines
905 B
Ruby

module PackagesHelper
# Return a query of all screenshots that the current user may see
# Consists of:
# - approved (public) screenshots
# - screenshots uploaded by the user
# - all screenshots if the user is an admin
def screenshots_visible_to_user(package)
if user_signed_in? and current_user.is_admin?
# User is an admin
package.screenshots
elsif user_signed_in?
package.screenshots.where(id: (current_user.screenshots.select(:id))) | \
package.screenshots.where(approved: true).order('created_at DESC')
else
package.screenshots.where(approved: true).order('created_at DESC')
end
end
# Show filled/empty star icons from FontAwesome
# depending on the rating (1-5)
def star_rating(rating)
filled_stars = fa_icon('star') * rating
empty_stars = fa_icon('star-o') * (5-rating)
(filled_stars+empty_stars).html_safe
end
end