forked from External/greenlight
redo rooms page
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
class Room < ApplicationRecord
|
||||
|
||||
before_create :generate_uids
|
||||
before_create :setup
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
belongs_to :user
|
||||
has_one :meeting
|
||||
|
||||
ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
|
||||
RETURNCODE_SUCCESS = "SUCCESS"
|
||||
|
||||
def to_param
|
||||
@ -116,9 +119,11 @@ class Room < ApplicationRecord
|
||||
end
|
||||
|
||||
# Generates a uid for the room and BigBlueButton.
|
||||
def generate_uids
|
||||
self.uid = [user.firstname, (0...8).map { (65 + rand(26)).chr }.join].join('-')
|
||||
def setup
|
||||
self.uid = [user.firstname, (0...8).map { (65 + rand(26)).chr }.join].join('-').downcase
|
||||
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
|
||||
|
||||
self.icon = ROOM_ICONS.sample
|
||||
end
|
||||
|
||||
# Rereives the loadbalanced BigBlueButton credentials for a user.
|
||||
|
@ -1,12 +1,12 @@
|
||||
class User < ApplicationRecord
|
||||
|
||||
after_create :initialize_room
|
||||
after_create :initialize_main_room
|
||||
before_save { email.downcase! unless email.nil? }
|
||||
|
||||
has_many :rooms
|
||||
belongs_to :main_room, class_name: 'Room', foreign_key: :room_id, required: false
|
||||
|
||||
validates :name, length: { maximum: 24 }, presence: true
|
||||
validates :username, presence: true
|
||||
validates :provider, presence: true
|
||||
validates :email, length: { maximum: 60 }, allow_nil: true,
|
||||
uniqueness: { case_sensitive: false },
|
||||
@ -27,6 +27,7 @@ class User < ApplicationRecord
|
||||
user.username = send("#{auth['provider']}_username", auth)
|
||||
user.email = send("#{auth['provider']}_email", auth)
|
||||
user.image = send("#{auth['provider']}_image", auth)
|
||||
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
@ -88,7 +89,8 @@ class User < ApplicationRecord
|
||||
private
|
||||
|
||||
# Initializes a room for the user.
|
||||
def initialize_room
|
||||
Room.create(user_id: self.id, name: firstname + "'s Room")
|
||||
def initialize_main_room
|
||||
self.main_room = Room.create!(user: self, name: firstname + "'s Room")
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user