From f4990b4523b6748ef75534851102143b608a02f6 Mon Sep 17 00:00:00 2001 From: Ahmad Farhat Date: Thu, 16 Apr 2020 15:06:56 -0400 Subject: [PATCH] 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 --- app/models/room.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/room.rb b/app/models/room.rb index 82650001..e657fd12 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -85,7 +85,7 @@ class Room < ApplicationRecord # Generates a uid for the room and BigBlueButton. def setup 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.attendee_pw = RandomPassword.generate(length: 12) end @@ -100,4 +100,12 @@ class Room < ApplicationRecord def random_room_uid [owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase 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