GRN2-xx: Replaced bbb_id field with a better string generator (#1250)

* Replaced bbb_id field with a better string generator

* Update room.rb

How about this instead @farhatahmad ?

* Update room.rb

Co-authored-by: Jesus Federico <jesus@123it.ca>
This commit is contained in:
Ahmad Farhat 2020-04-16 15:06:56 -04:00 committed by GitHub
parent 10ef20363a
commit f4990b4523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -85,7 +85,7 @@ class Room < ApplicationRecord
# Generates a uid for the room and BigBlueButton. # Generates a uid for the room and BigBlueButton.
def setup def setup
self.uid = random_room_uid self.uid = random_room_uid
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s self.bbb_id = unique_bbb_id
self.moderator_pw = RandomPassword.generate(length: 12) self.moderator_pw = RandomPassword.generate(length: 12)
self.attendee_pw = RandomPassword.generate(length: 12) self.attendee_pw = RandomPassword.generate(length: 12)
end end
@ -100,4 +100,12 @@ class Room < ApplicationRecord
def random_room_uid def random_room_uid
[owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase [owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase
end end
# Generates a unique bbb_id based on uuid.
def unique_bbb_id
loop do
bbb_id = SecureRandom.hex(20)
break bbb_id unless Room.exists?(bbb_id: bbb_id)
end
end
end end