Merge branch 'master' of bitbucket.org:signum/debshots

This commit is contained in:
Christoph Haas 2015-06-15 13:05:10 +02:00
commit a2178d8226
9 changed files with 28 additions and 23 deletions

View file

@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
# and show them even before moderation.
def create_user_token
session[:token] ||= SecureRandom.hex
session[:ip] ||= request.remote_ip
end
end

View file

@ -24,6 +24,8 @@ class PackagesController < ApplicationController
@package = Package.find_by(name: params[:name])
end
# POST target of the screenshots upload form.
# Checks upload images and creates a new Screenshot record for it.
def upload_image
@package = Package.find_by(name: params[:name])
@ -33,13 +35,15 @@ class PackagesController < ApplicationController
new_screenshot = @package.screenshots.new(image: img)
# Check if the image was valid
unless new_screenshot.valid?
errors = new_screenshot.errors[:image].join(' and ')
flash['alert'] = "Sorry - the image #{errors}"
else
if new_screenshot.valid?
new_screenshot.uploaderhash = session[:token]
new_screenshot.uploaderip = session[:ip]
new_screenshot.save
successful_upload_count += 1
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
else
errors = new_screenshot.errors[:image].join(' and ')
flash['alert'] = "Sorry - the image #{errors}"
end
if successful_upload_count > 0

View file

@ -42,7 +42,7 @@ class Screenshot < ActiveRecord::Base
# Return Debshots 1.x path to allow migration of images into Paperclip filesystem schema
def image_url(size)
"#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png"
"live/screenshots/approved/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png"
end

View file

@ -10,6 +10,9 @@
.small-12.columns
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
p Uploader IP=#{screenshot.uploaderip} / Token=#{screenshot.uploaderhash}
// TODO: Enable button only if admin or uploader
a.button.tiny.alert[
href=delete_screenshot_path(@package.name, screenshot.id)