Attempt to assign anonymous screenshots to logged-in user

This commit is contained in:
Christoph Haas 2018-08-20 19:32:34 +02:00
parent 228b7375e7
commit 0dd63f6bf6
7 changed files with 65 additions and 25 deletions

View file

@ -2,6 +2,7 @@ class Screenshot < ApplicationRecord
belongs_to :package, inverse_of: :screenshots
belongs_to :user, inverse_of: :screenshots
# Use paperclip gem to handle image files related to screenshots
has_attached_file :image,
styles: { :large => '800x600>', :thumb => '160x120>' },
default_url: '/images/dummy/no-screenshots-available.svg',

View file

@ -52,6 +52,9 @@ class User < ApplicationRecord
# Do uploads from this user get approved automatically?
def auto_approve?
# Anonymous users need to go through moderation
return false unless user_signed_in?
# Admins do not need moderation
return true if current_user.is_admin?
@ -75,4 +78,21 @@ class User < ApplicationRecord
user.password = Devise.friendly_token[0,20]
end
end
# Seamlessly create a user account for the current client.
# It helps track uploads because uploaded screenshots get assigned
# to this user record. The user can later decide to use a real
# account and get their screenshots transferred to that.
# def self.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
#
# Currently the approach is different: do not create an account
# for a user. Instead store the IDs of the uploaded screenshots
# and transfer them if the user decides to do a real login using SSO.
end