This commit is contained in:
Christoph Haas 2025-05-02 00:38:59 +02:00
parent fa8a7fc77a
commit 3f4266d19b

View file

@ -4,28 +4,28 @@ class User < ApplicationRecord
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, devise :database_authenticatable,
# :registerable, # :registerable,
# :recoverable, # :recoverable,
# :rememberable, # :rememberable,
:trackable, :trackable,
# :validatable, # :validatable,
:timeoutable, :timeoutable,
# :lockable, # :lockable,
:omniauthable, omniauth_providers: [ :omniauthable, omniauth_providers: [
:salsa, :salsa
# :launchpad, # :launchpad,
# :stackexchange, # :stackexchange,
# :google_oauth2, # :google_oauth2,
# :amazon, # :amazon,
# :github # :github
] ]
include Gravtastic include Gravtastic
gravtastic size: 120 gravtastic size: 120
# Return a human-friendly string describing the user's SSO provider # Return a human-friendly string describing the user's SSO provider
def pretty_provider def pretty_provider
case self.provider case provider
# when 'launchpad' # when 'launchpad'
# 'Ubuntu One/Launchpad' # 'Ubuntu One/Launchpad'
# when 'stackexchange' # when 'stackexchange'
@ -44,21 +44,21 @@ class User < ApplicationRecord
end end
def pretty_name def pretty_name
if self.pseudo if pseudo
'Anonymous' 'Anonymous'
elsif self.name? elsif name?
self.name name
else else
'Dr. Who' 'Dr. Who'
end end
end end
def pretty_role def pretty_role
if self.pseudo if pseudo
'Contributor' 'Contributor'
elsif self.moderator_role elsif moderator_role
'Moderator' 'Moderator'
elsif self.admin_role elsif admin_role
'Admin' 'Admin'
end end
end end
@ -70,12 +70,10 @@ class User < ApplicationRecord
user.email = auth.info.email user.email = auth.info.email
user.name = auth.info.name user.name = auth.info.name
# Set a random password # Set a random password
user.password = Devise.friendly_token[0,20] user.password = Devise.friendly_token[0, 20]
# Users coming through salsa.debian.net/OpenID-Connect will get moderator role # Users coming through salsa.debian.net/OpenID-Connect will get moderator role
if user.email.end_with?('@debian.org') && user.provider=='salsa' user.moderator_role = true if user.email.end_with?('@debian.org') && user.provider == 'salsa'
user.moderator_role = true
end
end end
end end
@ -85,19 +83,18 @@ class User < ApplicationRecord
# TODO: The user can later decide to use a real account and get their screenshots transferred to that. # TODO: The user can later decide to use a real account and get their screenshots transferred to that.
def self.create_pseudo_user def self.create_pseudo_user
generated_password = Devise.friendly_token.first(8) generated_password = Devise.friendly_token.first(8)
new_user = User.create( User.create(
name: 'Anonymous', name: 'Anonymous',
password: generated_password, password: generated_password,
pseudo: true pseudo: true
) )
return new_user
end end
def to_s def to_s
if self.pseudo if pseudo
"Pseudo user #{self.id}" "Pseudo user #{id}"
else else
"#{self.email} (#{self.provider})" "#{email} (#{provider})"
end end
end end
end end