debshots/app/helpers/packages_helper.rb

29 lines
1.1 KiB
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 and can view all screenshots
package.screenshots
# TODO: User logins and assigned screenshots will come in a later version
# 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(uploaderhash: session.id.to_s) | \
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