Returning 404 if packages are not found
This commit is contained in:
parent
5ced4d3898
commit
473346d9f3
1 changed files with 10 additions and 11 deletions
|
|
@ -11,12 +11,11 @@ class PackagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def details
|
def details
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by!(name: params[:name])
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload
|
def upload
|
||||||
raise "name not given" unless params[:name]
|
@package = Package.find_by!(name: params[:name])
|
||||||
@package = Package.find_by(name: params[:name])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST target of the screenshots upload form.
|
# POST target of the screenshots upload form.
|
||||||
|
|
@ -25,7 +24,7 @@ class PackagesController < ApplicationController
|
||||||
# Remember the user by the cookie session
|
# Remember the user by the cookie session
|
||||||
create_user_token
|
create_user_token
|
||||||
|
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by!(name: params[:name])
|
||||||
|
|
||||||
successful_upload_count = 0
|
successful_upload_count = 0
|
||||||
|
|
||||||
|
|
@ -63,7 +62,7 @@ class PackagesController < ApplicationController
|
||||||
# - description
|
# - description
|
||||||
# - file
|
# - file
|
||||||
def legacy_uploadfile
|
def legacy_uploadfile
|
||||||
@package = Package.find_by(name: params[:packagename])
|
@package = Package.find_by!(name: params[:packagename])
|
||||||
|
|
||||||
new_screenshot = @package.screenshots.new(image: params[:file])
|
new_screenshot = @package.screenshots.new(image: params[:file])
|
||||||
|
|
||||||
|
|
@ -82,7 +81,7 @@ class PackagesController < ApplicationController
|
||||||
|
|
||||||
def delete_screenshot
|
def delete_screenshot
|
||||||
# Is the user allowed to delete the screenshot?
|
# Is the user allowed to delete the screenshot?
|
||||||
@screenshot = Screenshot.find(params[:id])
|
@screenshot = Screenshot.find!(params[:id])
|
||||||
|
|
||||||
if user_can_alter_screenshot?
|
if user_can_alter_screenshot?
|
||||||
@screenshot.destroy
|
@screenshot.destroy
|
||||||
|
|
@ -94,7 +93,7 @@ class PackagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve_screenshot
|
def approve_screenshot
|
||||||
@screenshot = Screenshot.find(params[:id])
|
@screenshot = Screenshot.find!(params[:id])
|
||||||
@screenshot.approve_screenshot!
|
@screenshot.approve_screenshot!
|
||||||
flash['notice'] = "Screenshot approved."
|
flash['notice'] = "Screenshot approved."
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
@ -105,7 +104,7 @@ class PackagesController < ApplicationController
|
||||||
# If the package is found but has no screenshots then it also returns a
|
# If the package is found but has no screenshots then it also returns a
|
||||||
# dummy image along with status 404.
|
# dummy image along with status 404.
|
||||||
def thumbnail
|
def thumbnail
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by!(name: params[:name])
|
||||||
unless @package
|
unless @package
|
||||||
thumbnail404
|
thumbnail404
|
||||||
return
|
return
|
||||||
|
|
@ -134,7 +133,7 @@ class PackagesController < ApplicationController
|
||||||
# If the package is found but has no screenshots then it also returns a
|
# If the package is found but has no screenshots then it also returns a
|
||||||
# dummy image along with status 404.
|
# dummy image along with status 404.
|
||||||
def screenshot
|
def screenshot
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by!(name: params[:name])
|
||||||
unless @package
|
unless @package
|
||||||
screenshot404
|
screenshot404
|
||||||
return
|
return
|
||||||
|
|
@ -161,7 +160,7 @@ class PackagesController < ApplicationController
|
||||||
# Receives a form with a simple text field 'description' so that users can update
|
# Receives a form with a simple text field 'description' so that users can update
|
||||||
# the description of their screenshot.
|
# the description of their screenshot.
|
||||||
def update_screenshot_description
|
def update_screenshot_description
|
||||||
@screenshot = Screenshot.find(params[:id])
|
@screenshot = Screenshot.find!(params[:id])
|
||||||
@screenshot.description = params[:description]
|
@screenshot.description = params[:description]
|
||||||
@screenshot.save!
|
@screenshot.save!
|
||||||
flash['notice'] = "Description updated."
|
flash['notice'] = "Description updated."
|
||||||
|
|
@ -170,7 +169,7 @@ class PackagesController < ApplicationController
|
||||||
|
|
||||||
# Receive an anonymous report from a user to have a screenshot removed.
|
# Receive an anonymous report from a user to have a screenshot removed.
|
||||||
def report_screenshot
|
def report_screenshot
|
||||||
@screenshot = Screenshot.find(params[:id])
|
@screenshot = Screenshot.find!(params[:id])
|
||||||
@screenshot.delete_reason = params[:delete_reason]
|
@screenshot.delete_reason = params[:delete_reason]
|
||||||
@screenshot.markedfordelete = true
|
@screenshot.markedfordelete = true
|
||||||
@screenshot.save!
|
@screenshot.save!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue