GRN2-269: Pulling room settings using GET instead of data-attributes (#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
This commit is contained in:
etiennevvv 2020-02-21 09:20:22 -05:00 committed by GitHub
parent c75c624a1a
commit 92da1f6f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 9 deletions

View File

@ -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)
@ -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")
@ -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(){

View File

@ -248,6 +248,14 @@ class RoomsController < ApplicationController
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}"

View File

@ -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">
@ -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 %>

View File

@ -112,6 +112,7 @@ Rails.application.routes.draw do
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

View File

@ -180,6 +180,20 @@ describe RoomsController, type: :controller do
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