Merge branch 'master' of salsa.debian.org:debian/debshots
This commit is contained in:
commit
33086f9430
12 changed files with 132 additions and 52 deletions
|
|
@ -69,6 +69,10 @@ server {
|
|||
alias /opt/debshots/public/favicon.ico;
|
||||
}
|
||||
|
||||
location /.well-known/ {
|
||||
alias /opt/debshots/public/.well-known/;
|
||||
}
|
||||
|
||||
location @backend {
|
||||
proxy_cache my_cache;
|
||||
proxy_set_header x_debian_sso_dn $ssl_client_s_dn;
|
||||
|
|
|
|||
|
|
@ -7,12 +7,14 @@ class Users::MySessionsController < Devise::SessionsController
|
|||
old_screenshots = session[:uploaded_screenshots]
|
||||
if old_screenshots.to_a.length > 0
|
||||
old_screenshots.each do |id|
|
||||
next unless id # sometimes we had 'nil' here
|
||||
ss = Screenshot.find(id)
|
||||
ss.user = @user
|
||||
ss.save!
|
||||
end
|
||||
flash[:info] = "#{old_screenshots.to_a.length} uploads have been added to your account"
|
||||
Log.log "Anonymously uploaded screenshots #{old_screenshots} added to account."
|
||||
# The message is probably confusing. Just add the screenshots.
|
||||
# flash[:info] = "#{old_screenshots.to_a.length} uploads have been added to your account"
|
||||
Log.log "Anonymously uploaded screenshots #{old_screenshots} added to #{current_user}."
|
||||
session[:uploaded_screenshots] = nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ class WelcomeController < ApplicationController
|
|||
# TODO: Only approved screenshots!
|
||||
@newest_upload = Screenshot.newest_upload
|
||||
|
||||
# TODO: Use the actually most popular package and not just a random one
|
||||
@most_popular_package = Package.order(:visits).last
|
||||
@most_popular_package = Package.with_screenshots.order(visits: :desc).first
|
||||
|
||||
@package_count = Package.count
|
||||
|
||||
@most_wanted_package = Package.without_screenshots_most_visits.first
|
||||
@most_wanted_package = Package.without_screenshots.order(visits: :desc).first
|
||||
end
|
||||
|
||||
def about
|
||||
|
|
|
|||
|
|
@ -52,12 +52,6 @@ class Package < ApplicationRecord
|
|||
where.not(id: subselect)
|
||||
end
|
||||
|
||||
# Packages that need screenshots and have most visits.
|
||||
# These packages are most likely to need a screenshot.
|
||||
def self.without_screenshots_most_visits
|
||||
self.without_screenshots.order(visits: :desc)
|
||||
end
|
||||
|
||||
# Return a query of all approved/public screenshots of this package
|
||||
def screenshots_approved
|
||||
self.screenshots.where(approved: true)
|
||||
|
|
|
|||
|
|
@ -39,8 +39,11 @@
|
|||
.large-3.medium-12.small-12.cell.text-center
|
||||
h2 Most popular
|
||||
.thumb-height
|
||||
a href=package_path(@most_popular_package.name)
|
||||
= image_tag(@most_popular_package.screenshots.first.image.variant(resize: "160x120"))
|
||||
- if @most_popular_package
|
||||
a href=package_path(@most_popular_package.name)
|
||||
= image_tag(@most_popular_package.screenshots.first.image.variant(resize: "160x120"))
|
||||
- else
|
||||
'No uploaded screenshots yet.
|
||||
p
|
||||
strong
|
||||
=@most_popular_package.name
|
||||
|
|
@ -49,8 +52,11 @@
|
|||
.large-3.medium-12.small-12.cell.text-center
|
||||
h2 Contribute
|
||||
.thumb-height
|
||||
a href=upload_path(@most_wanted_package.name)
|
||||
img src="/images/dummy/no-screenshots-upload-one.svg" width="160"
|
||||
- if @most_wanted_package.name
|
||||
a href=upload_path(@most_wanted_package.name)
|
||||
img src="/images/dummy/no-screenshots-upload-one.svg" width="160"
|
||||
- else
|
||||
'No uploaded screenshots yet.
|
||||
p
|
||||
/ TODO: Randomly choose one of ~30 packages
|
||||
' We lack a screenshot for the
|
||||
|
|
|
|||
|
|
@ -127,3 +127,14 @@ bundle exec rake debshots:remove_broken_screenshots
|
|||
|
||||
bundle exec rake debshots:remove_duplicate_images
|
||||
|
||||
# Frequent update of Debian SSO certificate
|
||||
|
||||
Run /etc/nginx/update-sso-ca regularly to update the CA certificate and the CRL.
|
||||
The CRL (certificate revocation list) is only valid for three days. So make sure
|
||||
you have a daily cron job for the updates. Do not forget to restart Nginx afterwards.
|
||||
|
||||
Otherwise you will end up with this error message:
|
||||
|
||||
400 Bad Request
|
||||
The SSL certificate error
|
||||
nginx
|
||||
|
|
|
|||
|
|
@ -150,16 +150,17 @@ module DebImporter
|
|||
end # def
|
||||
|
||||
class Version
|
||||
attr_reader :epoch, :version, :revision, :version_string
|
||||
attr_reader :epoch, :upstream, :revision, :version_string
|
||||
|
||||
def initialize(version_string)
|
||||
@version_string = version_string
|
||||
# Split into "[epoch:]version[-revision]"
|
||||
unless /^(?<epoch>(\d+)\:)?(?<version>.+)(?<revision>\-[\+\.~]+)?/ =~ version_string
|
||||
# Split into "[epoch:]upstream[-revision]"
|
||||
# See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
|
||||
unless /^((?<epoch>\d+)\:)?(?<upstream>.+?)(\-(?<revision>.+))?$/ =~ version_string
|
||||
raise ArgumentError, "Cannot parse version string: #{version_string}"
|
||||
end
|
||||
@epoch = epoch ? epoch : 0
|
||||
@version = version
|
||||
@epoch = epoch ? epoch : '0'
|
||||
@upstream = upstream
|
||||
@revision = revision if revision
|
||||
end # /def
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ namespace :debshots do
|
|||
new_version = DebImporter::Version.new(package[:Version])
|
||||
|
||||
Rails.logger.debug "Comparing package version: old=#{db_package.version} new=#{new_version}"
|
||||
if new_version > current_version
|
||||
if new_version.upstream > current_version.upstream
|
||||
# update the package information from new data
|
||||
update_data(package, db_package)
|
||||
Rails.logger.info "Updating package information"
|
||||
|
|
@ -241,7 +241,7 @@ def update_data(package, db_package)
|
|||
Rails.logger.debug "New information: #{package.inspect}"
|
||||
|
||||
# Rails.logger.info "New package version found. Updating details in database."
|
||||
db_package.version = package[:Version]
|
||||
db_package.version = Version.new(package[:Version]).upstream
|
||||
db_package.name = package[:Package] unless db_package.name # set the name for new packages
|
||||
db_package.description = package[:Description][0..79]
|
||||
db_package.homepage = package[:Homepage]
|
||||
|
|
|
|||
|
|
@ -21,43 +21,52 @@ class PackagesControllerTest < ActionController::TestCase
|
|||
# assert_response :success
|
||||
# end
|
||||
|
||||
test "upload screenshot anonymously then login and get screenshots assigned" do
|
||||
newest_screenshot1 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# test "upload screenshot anonymously then login and get screenshots assigned" do
|
||||
# newest_screenshot1 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
|
||||
# Load the upload page
|
||||
get :upload, params: { name: 'firefox' }
|
||||
assert_response :success
|
||||
# # Load the upload page
|
||||
# get :upload, params: { name: 'firefox' }
|
||||
# assert_response :success
|
||||
|
||||
# Upload a screenshot and except to be redirected afterwards
|
||||
post :upload_receive, params: { name: 'firefox', file: [ fixture_file_upload('test/fixtures/files/large1.png','image/png') ] }
|
||||
assert_redirected_to package_path(name: 'firefox')
|
||||
# # Upload a screenshot and expect to be redirected afterwards
|
||||
# post :upload_receive, params: { name: 'firefox', file: [ fixture_file_upload('test/fixtures/files/large1.png','image/png') ] }
|
||||
# assert_redirected_to package_path(name: 'firefox')
|
||||
|
||||
# Check that the newest screenshot is not yet approved
|
||||
newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
assert_not_equal newest_screenshot1, newest_screenshot2
|
||||
assert_equal newest_screenshot2.approved, false
|
||||
# # Check that the newest screenshot is not yet approved
|
||||
# newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# assert_not_equal newest_screenshot1, newest_screenshot2
|
||||
# assert_equal newest_screenshot2.approved, false
|
||||
|
||||
# # Login
|
||||
# sign_in users(:normal)
|
||||
|
||||
# # Get the information about the newest screenshot again
|
||||
# newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
|
||||
# # Expect the uploaded screenshot to be assigned to this user
|
||||
# byebug
|
||||
# assert_equal newest_screenshot2.user, users(:normal)
|
||||
|
||||
|
||||
# # (name: 'firefox')
|
||||
# # img_count_before = page.find_all('img').count
|
||||
# # attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
|
||||
# # click_on 'Start upload'
|
||||
|
||||
# (name: 'firefox')
|
||||
# img_count_before = page.find_all('img').count
|
||||
# attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
|
||||
# click_on 'Start upload'
|
||||
# # # The cookie session must remember this anonymous upload
|
||||
# # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# # assert_equal session[:uploaded_screenshots].length, [newest_screenshot]
|
||||
|
||||
# # The cookie session must remember this anonymous upload
|
||||
# newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# assert_equal session[:uploaded_screenshots].length, [newest_screenshot]
|
||||
# # #
|
||||
# # # sign_in users(:debian)
|
||||
|
||||
# #
|
||||
# # sign_in users(:debian)
|
||||
# # # # Screenshot is instantly public
|
||||
# # # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# # # assert_equal newest_screenshot.approved, true
|
||||
|
||||
# # # Screenshot is instantly public
|
||||
# # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
# # assert_equal newest_screenshot.approved, true
|
||||
|
||||
# # # Clean up
|
||||
# newest_screenshot.destroy
|
||||
# sign_out users(:normal)
|
||||
end
|
||||
# # # # Clean up
|
||||
# # newest_screenshot.destroy
|
||||
# # sign_out users(:normal)
|
||||
# end
|
||||
|
||||
end
|
||||
|
|
|
|||
2
test/fixtures/users.yml
vendored
2
test/fixtures/users.yml
vendored
|
|
@ -26,4 +26,4 @@ debian:
|
|||
sign_in_count: 0
|
||||
provider: debian-sso
|
||||
admin: 0
|
||||
encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %>
|
||||
encrypted_password: nil
|
||||
|
|
|
|||
|
|
@ -44,4 +44,31 @@ class BrowserBrowseTest < ActionDispatch::IntegrationTest
|
|||
sign_out users(:debian)
|
||||
end
|
||||
|
||||
test "upload screenshot anonymously, login in, get screenshots assigned" do
|
||||
visit upload_path(name: 'firefox')
|
||||
attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
|
||||
click_on 'Start upload'
|
||||
|
||||
# Screenshot has not yet a user assigned
|
||||
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
assert_nil newest_screenshot.user
|
||||
|
||||
# Login (sign_in is just a stub and would not call the callbacks!)
|
||||
visit root_path
|
||||
click_link 'Login'
|
||||
within 'form' do
|
||||
fill_in 'email address', with: users(:normal).email
|
||||
fill_in 'password', with: 'normalsecret'
|
||||
click_button 'Log in'
|
||||
end
|
||||
|
||||
# Check if screenshot was assigned to the user
|
||||
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||
assert_equal newest_screenshot.user, users(:normal)
|
||||
|
||||
# Clean up
|
||||
newest_screenshot.destroy
|
||||
sign_out users(:debian)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,6 +18,33 @@ class PackagesHelperTest < ActionView::TestCase
|
|||
assert(DebImporter::Version.new('1.0') > DebImporter::Version.new('1.0~pre'))
|
||||
end
|
||||
|
||||
test "should split version files into epoch, upstream and revision" do
|
||||
v = DebImporter::Version.new('1.0~git20170104-1')
|
||||
assert_equal v.epoch, '0'
|
||||
assert_equal v.upstream, '1.0~git20170104'
|
||||
assert_equal v.revision, '1'
|
||||
|
||||
v = DebImporter::Version.new('0~20161219-1')
|
||||
assert_equal v.epoch, '0'
|
||||
assert_equal v.upstream, '0~20161219'
|
||||
assert_equal v.revision, '1'
|
||||
|
||||
v = DebImporter::Version.new('17:2.0.0~git20161130.1.e60d0d5+dfsg1-1')
|
||||
assert_equal v.epoch, '17'
|
||||
assert_equal v.upstream, '2.0.0~git20161130.1.e60d0d5+dfsg1'
|
||||
assert_equal v.revision, '1'
|
||||
|
||||
v = DebImporter::Version.new('42')
|
||||
assert_equal v.epoch, '0'
|
||||
assert_equal v.upstream, '42'
|
||||
assert_nil v.revision
|
||||
|
||||
v = DebImporter::Version.new('100:9a_b~cdef')
|
||||
assert_equal v.epoch, '100'
|
||||
assert_equal v.upstream, '9a_b~cdef'
|
||||
assert_nil v.revision
|
||||
end
|
||||
|
||||
test "should be able to parse local Debian repository test files" do
|
||||
Rails.logger = Logger.new(STDOUT)
|
||||
# Rails.logger.level = Logger::ERROR
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue