Creating query to get screenshots visible to a user

This commit is contained in:
Christoph Haas 2016-03-05 15:55:24 +01:00
parent 53b297da1e
commit 6192e1bc3b
3 changed files with 19 additions and 16 deletions

View file

@ -1,2 +1,13 @@
module PackagesHelper
# Return a query of all screenshots that the current user may see
# Consists of:
# - approved (public) screenshots
# - screenshots uploaded by the user (determined by cookie session)
def screenshots_visible_to_user
self.screenshots.where(
# "approved=true"
"approved=true OR uploaderhash=?", session[:token]
)
end
end

View file

@ -33,20 +33,8 @@ class Package < ActiveRecord::Base
end
# Return a query of all approved/public screenshots of this package
def self.query_approved
def self.screenshots_approved
self.screenshots.find_by(approved: true)
end
# Return a query of all screenshots that the current user may see
# Consists of:
# - approved (public) screenshots
# - screenshots uploaded by the user (determined by cookie session)
working on it
def self.query_visible_to_user
approved_screenshots = Screenshot.find_by()
subselect = Screenshot.select(:package_id)
where.not(id: subselect)
end
end

View file

@ -4,15 +4,16 @@
.small-7.medium-7.columns.packagepage
p.subtitle = @package.description
- if @package.screenshots.count > 0
- @package.screenshots.each do |screenshot|
- if @package.screenshots_visible_to_user.count > 0
- @package.screenshots_visible_to_user.each do |screenshot|
.row.listview
.small-12.columns
.text-center
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
.imgcaption =screenshot.caption
// TODO: Show information only if admin
// TODO: Show information only if admin
- if user_signed_in?
// Button that reveals a dropdown/modal for admins
.text-center
@ -28,6 +29,9 @@
p Uploaded #{screenshot.age_days} (#{screenshot.created_at})
p Status: #{screenshot.status}
// Anonymous users can see their own screenshots
- if not screenshot.approved
- else
.row.listview
img src='/images/dummy/no-screenshots-available.svg' width='100%' style='padding: 0 10%'