Skip to content

Commit

Permalink
handle user error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariam05 committed Dec 28, 2023
1 parent ca85d29 commit a34dcec
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
7 changes: 6 additions & 1 deletion app/controllers/concerns/bbb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ def string_to_bool(value)

# If the room is using a shared code, then use the shared room's recordings and bbb link
def room
@room.use_shared_code ? @shared_room : @room
use_shared_room? ? @shared_room : @room
end

# Returns true only if @room.use_shared_code and the shared code is valid
def use_shared_room?
@room.use_shared_code && Room.where(code: @room.shared_code, tenant: @room.tenant).exists?
end
end
8 changes: 7 additions & 1 deletion app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ def create
# PATCH/PUT /rooms/1.json
def update
respond_to do |format|
if @room.update(room_params)
# block update if shared_code doesn't exist
shared_code = room_params[:shared_code]
code_found = shared_code.blank? ? true : Room.where(code: shared_code, tenant: @room.tenant).exists?

if code_found && @room.update(room_params)
format.html { redirect_to(room_path(@room, launch_nonce: params[:launch_nonce]), notice: t('default.room.updated')) }
format.json { render(:show, status: :ok, location: @room) }
else
# If the room wasn't updated because a code was not found then show an error message
flash.now[:alert] = code_found ? nil : t('error.room.codenotfound.message')
format.html { render(:edit) }
format.json { render(json: @error, status: :unprocessable_entity) }
end
Expand Down
16 changes: 13 additions & 3 deletions app/javascript/packs/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

$(document).on('turbolinks:load', function(){

console.log("loaded...");
$('#allModerators_checkbox').on('click', function() {
var all_mod_checked = $('#allModerators_checkbox').prop("checked");
if (all_mod_checked){
Expand Down Expand Up @@ -54,15 +53,26 @@ $(document).on('turbolinks:load', function(){

// If shared room is selected, allow the code field to be editable
$('#use_shared_code_checkbox').on('click', function() {
console.log("clicked...")
var use_shared_code_checked = $('#use_shared_code_checkbox').prop("checked");
if (use_shared_code_checked){
$('#shared_code_field').prop("disabled", false);
$('#shared_code_field').val('');
} else {
$('#code_field').prop("disabled", true);
$('#shared_code_field').prop("disabled", true);
console.log("code_val: = ",$('#room_code_value').val() )
$('#shared_code_field').val($('#room_code_value').val());
}
})

function checkSharedCodeCheckboxStatus() {
var sharedcode_checked = $('#use_shared_code_checkbox').prop("checked");
if (!sharedcode_checked){
$('#shared_code_field').prop("disabled", true);
} else {
$('#shared_code_field').prop("disabled", false);
}
}

checkSharedCodeCheckboxStatus();

});
2 changes: 1 addition & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Room < ApplicationRecord

# after_find is used for the following so that rooms that already exist will have these fields upon launch
after_find :initialize_setting_defaults, if: :settings_blank?
after_find :set_empty_code, if: proc { :code.blank? }
after_find :set_empty_code

attr_accessor :can_grade

Expand Down
6 changes: 6 additions & 0 deletions app/views/rooms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<%= form.label t('default.room.code') %>
<%= form.text_field :shared_code, class: "form-control input mt-1 block disabled:border-slate-200 disabled:text-slate-500 disabled:shadow-none disabled:bg-slate-100", id: 'shared_code_field', disabled: true %>
</div>

<% unless flash[:alert] == nil %>
<div class="ml-3 text-sm font-medium text-red-500">
<%= flash.alert %>
</div>
<% end %>
<div class="field form-group input-group">
<%= form.check_box :use_shared_code, id: 'use_shared_code_checkbox' %>&nbsp;
<%= t('default.room.usesharedcode') %>&nbsp;
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,7 @@ en:
code: "InvalidSecret"
message: "The token could not be validated"
suggestion: "This problem can be caused by using an invalid key when validating the request through the LTI Provider"
codenotfound:
code: "Not found"
message: "A room with this code could not be found"
suggestion: "Please verify that the code shared with you is correct"
8 changes: 5 additions & 3 deletions db/migrate/20231102145703_add_columns_to_rooms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class AddColumnsToRooms < ActiveRecord::Migration[6.1]
def change
add_column(:rooms, :code, :string)
add_column(:rooms, :shared_code, :string)
add_column(:rooms, :use_shared_code, :boolean)
change_table(:rooms, bulk: true) do |t|
t.string(:code)
t.string(:shared_code)
t.boolean(:use_shared_code)
end

add_index(:rooms, :code, unique: true)
end
Expand Down

0 comments on commit a34dcec

Please sign in to comment.