Skip to content

Commit

Permalink
LTI-366: complementary fixes for issue with codes already used error (#…
Browse files Browse the repository at this point in the history
…311)

* LTI-366 remove uniqueness from codes in Room table

* LTI-366: updated schema with last migration

* LTI-366: hot-fix and followup

* LTI-366: remove uniqueness validation from model
  • Loading branch information
jfederico authored May 7, 2024
1 parent 77d2813 commit cc263ff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def set_launch
def launch_room(launch_params, tenant)
handler = room_handler(launch_params, tenant)
handler_legacy = launch_params['custom_params']['custom_handler_legacy'].presence
code = SecureRandom.alphanumeric(10)

## Any launch.
@room = Room.find_by(handler: handler, tenant: tenant)
Expand All @@ -331,7 +332,7 @@ def launch_room(launch_params, tenant)
if handler_legacy.nil?
## Regular launch
logger.debug('This is a Regular launch...')
@room = Room.create(launch_room_params)
@room = Room.create(launch_room_params.merge({ code: code, shared_code: code }))
logger.debug(@room.errors.full_messages) if @room.errors.any?
return
end
Expand All @@ -351,7 +352,7 @@ def launch_room(launch_params, tenant)
logger.debug("Room #{@room.id} updated with fetched parameters...") && return if @room
else
# Create
@room = Room.create(fetched_room_params.merge({ code: '', shared_code: '' }))
@room = Room.create(fetched_room_params.merge({ code: code, shared_code: code }))
if @room.persisted?
logger.debug("Room #{@room.id} created with fetched parameters...") && return if @room
else
Expand All @@ -366,7 +367,7 @@ def launch_room(launch_params, tenant)
return unless Rails.configuration.handler_legacy_new_room_enabled

logger.debug('It will attempt to create a Room with passed parameters even though a handler_legacy was passed...')
@room = Room.create(launch_room_params)
@room = Room.create(launch_room_params.merge({ code: code, shared_code: code }))
end

def launch_user(launch_params)
Expand Down
1 change: 0 additions & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class Room < ApplicationRecord
before_save :default_values
validates :code, uniqueness: true

store_accessor :settings, [:lockSettingsDisableCam, :lockSettingsDisableMic, :lockSettingsDisablePrivateChat, :lockSettingsDisablePublicChat, :lockSettingsDisableNote]
store_accessor :settings, %i[waitForModerator allModerators guestPolicy record autoStartRecording allowStartStopRecording]
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20240507174455_remove_unique_index_from_rooms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class RemoveUniqueIndexFromRooms < ActiveRecord::Migration[6.1]
def up
# Remove the existing unique index
remove_index(:rooms, :code, unique: true, if_exists: true)
# Add a non-unique index
add_index(:rooms, :code, name: 'index_rooms_on_code')
end

def down
# Remove the non-unique index
remove_index(:rooms, name: 'index_rooms_on_code', if_exists: true)
# Re-add the unique index
add_index(:rooms, :code, unique: true, name: 'index_rooms_on_code_unique')
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_11_02_145703) do
ActiveRecord::Schema.define(version: 2024_05_07_174455) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -35,7 +35,7 @@
t.string "code"
t.string "shared_code"
t.boolean "use_shared_code"
t.index ["code"], name: "index_rooms_on_code", unique: true
t.index ["code"], name: "index_rooms_on_code"
t.index ["tenant", "handler"], name: "index_rooms_on_tenant_and_handler", unique: true
t.index ["tenant", "handler_legacy"], name: "index_rooms_on_tenant_and_handler_legacy", unique: true
end
Expand Down

0 comments on commit cc263ff

Please sign in to comment.