Skip to content

Commit

Permalink
GRN2-269: Pulling room settings using GET instead of data-attributes (b…
Browse files Browse the repository at this point in the history
…igbluebutton#953)

* GRN2-269: Pulling room settings using GET instead of data-attributes

* GRN2-269: added test case and fixed documentation

* GRN2:269: rubocop fix

* GRN2-269: Fixed test case
  • Loading branch information
etiennevvv authored Feb 21, 2020
1 parent c75c624 commit 92da1f6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
18 changes: 11 additions & 7 deletions app/assets/javascripts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function showCreateRoom(target) {
function showUpdateRoom(target) {
var modal = $(target)
var update_path = modal.closest("#room-block").data("path")
var settings_path = modal.data("settings-path")
$("#create-room-name").val(modal.closest("#room-block").find("#room-name-text").text())
$("#createRoomModal form").attr("action", update_path)

Expand All @@ -176,7 +177,7 @@ function showUpdateRoom(target) {
if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
})

updateCurrentSettings(modal.closest("#room-block").data("room-settings"))
updateCurrentSettings(settings_path)

var accessCode = modal.closest("#room-block").data("room-access-code")

Expand All @@ -195,12 +196,15 @@ function showDeleteRoom(target) {
}

//Update the createRoomModal to show the correct current settings
function updateCurrentSettings(settings){
//set checkbox
$("#room_mute_on_join").prop("checked", settings.muteOnStart)
$("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval)
$("#room_anyone_can_start").prop("checked", settings.anyoneCanStart)
$("#room_all_join_moderator").prop("checked", settings.joinModerator)
function updateCurrentSettings(settings_path){
// Get current room settings and set checkbox
$.get(settings_path, function(room_settings) {
var settings = JSON.parse(room_settings)
$("#room_mute_on_join").prop("checked", settings.muteOnStart)
$("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval)
$("#room_anyone_can_start").prop("checked", settings.anyoneCanStart)
$("#room_all_join_moderator").prop("checked", settings.joinModerator)
})
}

function generateAccessCode(){
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ def shared_users
end
end

# GET /:room_uid/room_settings
def room_settings
# Respond with JSON object of the room_settings
respond_to do |format|
format.json { render body: @room.room_settings.to_json }
end
end

# GET /:room_uid/logout
def logout
logger.info "Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}"
Expand Down
4 changes: 2 additions & 2 deletions app/views/rooms/components/_room_block.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>

<div id="room-block" data-path="<%= update_settings_path(room) %>" data-room-settings=<%= room.room_settings %> data-room-access-code="<%= room.access_code %>" class="card">
<div id="room-block" data-path="<%= update_settings_path(room) %>" data-room-access-code="<%= room.access_code %>" class="card">
<div class="card-body p-1">
<table class="table table-hover table-vcenter text-wrap table-no-border">
<tbody class="no-border-top">
Expand Down Expand Up @@ -47,7 +47,7 @@
<i class="fas fa-ellipsis-v px-4"></i>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-md-left">
<a href="" data-toggle="modal" data-target="#createRoomModal" class="update-room dropdown-item">
<a href="" data-toggle="modal" data-target="#createRoomModal" class="update-room dropdown-item" data-settings-path="<%= room_settings_path(room) %>">
<i class="dropdown-icon fas fa-cog"></i> <%= t("room.settings") %>
</a>
<% if shared_access_allowed %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
scope '/:room_uid' do
post '/', to: 'rooms#join'
patch '/', to: 'rooms#update', as: :update_room
get '/room_settings', to: 'rooms#room_settings'
post '/update_settings', to: 'rooms#update_settings'
post '/update_shared_access', to: 'rooms#shared_access', as: :room_shared_access
delete '/remove_shared_access', to: 'rooms#remove_shared_access', as: :room_remove_shared_access
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ def random_valid_room_params
expect(response).to redirect_to(r)
end

it "should respond with JSON object of the room_settings" do
@request.session[:user_id] = @owner.id

@owner.main_room.update_attribute(:room_settings, { "muteOnStart": true, "requireModeratorApproval": true,
"anyoneCanStart": true, "joinModerator": true }.to_json)

json_room_settings = "{\"muteOnStart\":true,\"requireModeratorApproval\":true," \
"\"anyoneCanStart\":true,\"joinModerator\":true}"

get :room_settings, params: { room_uid: @owner.main_room }, format: :json

expect(JSON.parse(response.body)).to eql(json_room_settings)
end

it "should redirect to root if not logged in" do
expect do
name = Faker::Games::Pokemon.name
Expand Down

0 comments on commit 92da1f6

Please sign in to comment.