Authorisation management using CanCanCan added

This commit is contained in:
Christoph Haas 2021-02-28 21:36:46 +01:00
parent 51be4a4777
commit 7a3b65fe50
24 changed files with 211 additions and 295 deletions

View file

@ -1,45 +1,5 @@
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
def screenshots_visible_to_user(package, user_session)
# Show all screenshots to admins
if current_user && current_user.is_admin?
package.screenshots
# Show screenshots belonging to the user or public/approved
else
package.screenshots.where(
uploaderhash: user_session.id.to_s
).or(
package.screenshots.where(
approved: true
)
)
end
end
def screenshot_uploaded_by_current_user?(screenshot)
screenshot.uploaderhash == session.id.to_s
end
# Return the description and/or the version of the package
def screenshot_caption(screenshot)
str = []
@ -78,9 +38,7 @@ module PackagesHelper
def status_text(screenshot)
# TODO: markedfordelete/reporting will be removed
if screenshot.markedfordelete
"Removal requested > #{screenshot.delete_reason}"
elsif screenshot.approved
if screenshot.approved
fa_icon('check-square') + ' Public'
else
fa_icon('hourglass') + ' Waiting for approval'