Authorisation management using CanCanCan added
This commit is contained in:
parent
51be4a4777
commit
7a3b65fe50
24 changed files with 211 additions and 295 deletions
|
|
@ -40,10 +40,6 @@ class User < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def is_admin?
|
||||
self.admin == 1
|
||||
end
|
||||
|
||||
# Check if a user has been created on-the-fly and is just an
|
||||
# anonymous user who uploaded a screenshot. They can turn this
|
||||
# user record into a registered account though.
|
||||
|
|
@ -59,6 +55,11 @@ class User < ApplicationRecord
|
|||
user.name = auth.info.name
|
||||
# Set a random password
|
||||
user.password = Devise.friendly_token[0,20]
|
||||
|
||||
# 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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -66,20 +67,18 @@ class User < ApplicationRecord
|
|||
self.screenshots.where(approved: true)
|
||||
end
|
||||
|
||||
# Seamlessly create a user account for the current client.
|
||||
# Seamlessly create a user account for the current visitor.
|
||||
# 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.
|
||||
# to this user record.
|
||||
# TODO: 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,
|
||||
pseudo: true
|
||||
)
|
||||
Log.log "New pseudo user for anonymous upload created: #{new_user}"
|
||||
return new_user
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue