Reindented
This commit is contained in:
parent
b3bc6c0b76
commit
591845a25d
1 changed files with 73 additions and 73 deletions
|
|
@ -212,86 +212,86 @@ class PackagesController < ApplicationController
|
||||||
# the description of their screenshot.
|
# the description of their screenshot.
|
||||||
def update_screenshot_description
|
def update_screenshot_description
|
||||||
# TODO: Check permissions to do that
|
# TODO: Check permissions to do that
|
||||||
@screenshot = Screenshot.find(params[:id])
|
@screenshot = Screenshot.find(params[:id])
|
||||||
# @screenshot.description = params[:description]
|
# @screenshot.description = params[:description]
|
||||||
@screenshot.update params_screenshot_description
|
@screenshot.update params_screenshot_description
|
||||||
|
@screenshot.save!
|
||||||
|
flash['notice'] = "Description updated."
|
||||||
|
redirect_back(fallback_location: package_path(name: @screenshot.package.name))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Receive an anonymous report from a user to have a screenshot removed.
|
||||||
|
def report_screenshot
|
||||||
|
@screenshot = Screenshot.find(params[:id])
|
||||||
|
# if verify_recaptcha
|
||||||
|
@screenshot.delete_reason = params[:delete_reason]
|
||||||
|
@screenshot.markedfordelete = true
|
||||||
|
if @screenshot.valid?
|
||||||
@screenshot.save!
|
@screenshot.save!
|
||||||
flash['notice'] = "Description updated."
|
flash['notice'] = "Screenshot reported. The moderators will deal with it."
|
||||||
redirect_back(fallback_location: package_path(name: @screenshot.package.name))
|
else
|
||||||
|
errors = @screenshot.errors.to_a.join(' and ')
|
||||||
|
flash['alert'] = "Sorry. #{errors}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Receive an anonymous report from a user to have a screenshot removed.
|
|
||||||
def report_screenshot
|
|
||||||
@screenshot = Screenshot.find(params[:id])
|
|
||||||
# if verify_recaptcha
|
|
||||||
@screenshot.delete_reason = params[:delete_reason]
|
|
||||||
@screenshot.markedfordelete = true
|
|
||||||
if @screenshot.valid?
|
|
||||||
@screenshot.save!
|
|
||||||
flash['notice'] = "Screenshot reported. The moderators will deal with it."
|
|
||||||
else
|
|
||||||
errors = @screenshot.errors.to_a.join(' and ')
|
|
||||||
flash['alert'] = "Sorry. #{errors}"
|
|
||||||
end
|
|
||||||
# end
|
|
||||||
redirect_back(fallback_location: package_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Show an HTML partial with reviews of this package from the Ubuntu API
|
|
||||||
# def reviews
|
|
||||||
# expires_in 1.day, public: true
|
|
||||||
# # @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews
|
|
||||||
# @reviews = get_ubuntu_reviews params[:name]
|
|
||||||
# render '_reviews', layout: false
|
|
||||||
# end
|
# end
|
||||||
|
redirect_back(fallback_location: package_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Show an HTML partial with reviews of this package from the Ubuntu API
|
||||||
|
# def reviews
|
||||||
|
# expires_in 1.day, public: true
|
||||||
|
# # @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews
|
||||||
|
# @reviews = get_ubuntu_reviews params[:name]
|
||||||
|
# render '_reviews', layout: false
|
||||||
|
# end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Seamlessly create a user account for the current client.
|
||||||
|
# It helps track uploads.
|
||||||
|
def create_pseudo_user
|
||||||
|
generated_password = Devise.friendly_token.first(8)
|
||||||
|
new_user = User.create(
|
||||||
|
name: 'Anonymous',
|
||||||
|
password: generated_password)
|
||||||
|
Log.log "New pseudo user for anonymous upload created: #{new_user}"
|
||||||
|
sign_in(new_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Send a dummy thumbnail reading "No screenshot available. Sorry."
|
||||||
|
def thumbnail404
|
||||||
|
send_file Rails.root.join('public/images/dummy/thumbnail404.png'),
|
||||||
|
type: "image/png",
|
||||||
|
disposition: 'inline',
|
||||||
|
status: 404
|
||||||
|
end
|
||||||
|
|
||||||
|
def screenshot404
|
||||||
|
send_file Rails.root.join('public/images/dummy/screenshot404.png'),
|
||||||
|
type: "image/png",
|
||||||
|
disposition: 'inline',
|
||||||
|
status: 404
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return packages matching the criteria given by parameters
|
||||||
|
def query_packages
|
||||||
|
packages = Package.includes(:screenshots).order(visits: :desc)
|
||||||
|
|
||||||
private
|
# text search
|
||||||
|
if params[:search].present?
|
||||||
# Seamlessly create a user account for the current client.
|
logger.debug "Searching for #{params[:search]}"
|
||||||
# It helps track uploads.
|
packages = packages.general_search(params[:search])
|
||||||
def create_pseudo_user
|
|
||||||
generated_password = Devise.friendly_token.first(8)
|
|
||||||
new_user = User.create(
|
|
||||||
name: 'Anonymous',
|
|
||||||
password: generated_password)
|
|
||||||
Log.log "New pseudo user for anonymous upload created: #{new_user}"
|
|
||||||
sign_in(new_user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Send a dummy thumbnail reading "No screenshot available. Sorry."
|
case params[:show]
|
||||||
def thumbnail404
|
when 'with'
|
||||||
send_file Rails.root.join('public/images/dummy/thumbnail404.png'),
|
packages = packages.with_screenshots
|
||||||
type: "image/png",
|
logger.debug 'Limiting packages to those with screenshots'
|
||||||
disposition: 'inline',
|
when 'without'
|
||||||
status: 404
|
packages = packages.without_screenshots
|
||||||
|
logger.debug 'Limiting packages to those without screenshots'
|
||||||
end
|
end
|
||||||
|
|
||||||
def screenshot404
|
|
||||||
send_file Rails.root.join('public/images/dummy/screenshot404.png'),
|
|
||||||
type: "image/png",
|
|
||||||
disposition: 'inline',
|
|
||||||
status: 404
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return packages matching the criteria given by parameters
|
|
||||||
def query_packages
|
|
||||||
packages = Package.includes(:screenshots).order(visits: :desc)
|
|
||||||
|
|
||||||
# text search
|
|
||||||
if params[:search].present?
|
|
||||||
logger.debug "Searching for #{params[:search]}"
|
|
||||||
packages = packages.general_search(params[:search])
|
|
||||||
end
|
|
||||||
|
|
||||||
case params[:show]
|
|
||||||
when 'with'
|
|
||||||
packages = packages.with_screenshots
|
|
||||||
logger.debug 'Limiting packages to those with screenshots'
|
|
||||||
when 'without'
|
|
||||||
packages = packages.without_screenshots
|
|
||||||
logger.debug 'Limiting packages to those without screenshots'
|
|
||||||
end
|
|
||||||
|
|
||||||
return packages
|
return packages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue