Skip to content

Commit

Permalink
Merge 843ab8a into 062525d
Browse files Browse the repository at this point in the history
  • Loading branch information
galupa committed Jan 28, 2021
2 parents 062525d + 843ab8a commit 6fe275a
Show file tree
Hide file tree
Showing 17 changed files with 339 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/controllers/concerns/bbb_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def join_path(room, name, options = {}, uid = nil)
join_opts = {}
join_opts[:userID] = uid if uid
join_opts[:join_via_html5] = true
options.select { |a, _| a.to_s.starts_with?("userdata-bbb") }.each do |k, v|
join_opts[k] = v
end
join_opts[:createTime] = room.last_session.to_datetime.strftime("%Q")

bbb_server.join_meeting_url(room.bbb_id, name, password, join_opts)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/concerns/joiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def join_room(opts)
opts[:mute_on_start] = room_setting_with_config("muteOnStart")

if current_user
join_settings = Rails.configuration.join_settings_features.split(",")
current_user.user_settings.each do |v|
opts[v.name] = v.value if join_settings.include? v.name
end
redirect_to join_path(@room, current_user.name, opts, current_user.uid)
else
join_name = params[:join_name] || params[@room.invite_path][:join_name]
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def start
opts[:mute_on_start] = room_setting_with_config("muteOnStart")
opts[:require_moderator_approval] = room_setting_with_config("requireModeratorApproval")
opts[:record] = record_meeting
opts[:voice_bridge] = @room_settings["voiceBridgePin"]
join_settings = Rails.configuration.join_settings_features.split(",")
current_user.user_settings.each do |v|
opts[v.name] = v.value if join_settings.include? v.name
end

begin
redirect_to join_path(@room, current_user.name, opts, current_user.uid)
Expand Down
28 changes: 27 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ class UsersController < ApplicationController
include Recorder
include Rolify

before_action :find_user, only: [:edit, :change_password, :delete_account, :update, :update_password]
before_action :find_user, only:
[:edit, :join_settings, :update_settings, :change_password, :delete_account, :update, :update_password]
before_action :ensure_unauthenticated_except_twitter, only: [:create]
before_action :check_user_signup_allowed, only: [:create]
before_action :check_admin_of, only: [:edit, :change_password, :delete_account]
before_action :read_join_settings, only: [:edit, :join_settings, :update_settings, :change_password, :delete_account]

# POST /u
def create
Expand Down Expand Up @@ -77,6 +79,30 @@ def change_password
redirect_to edit_user_path unless current_user.greenlight_account?
end

# GET /u/:user_uid/join_settings
def join_settings
redirect_to root_path unless current_user
end

# POST /u/:user_uid/join_settings
def update_settings
return redirect_to root_path unless current_user
settings_params = params.require(:user).permit(@join_settings)
@user.update_all_user_settings(settings_params)

# Notify the user that their account has been updated.
return redirect_back fallback_location: root_path, flash: { success: I18n.t("info_update_success") } if
@user.save

# redirect_to change_password_path
render :join_settings
end

def read_join_settings
@join_settings = Rails.configuration.join_settings_features.split(",")
@join_settings_defaults = Rails.configuration.join_settings_defaults.split(",")
end

# GET /u/:user_uid/delete_account
def delete_account
end
Expand Down
32 changes: 32 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class User < ApplicationRecord

belongs_to :role, required: false

has_many :user_settings

accepts_nested_attributes_for :user_settings

validates :name, length: { maximum: 256 }, presence: true,
format: { without: %r{https?://}i }
validates :provider, presence: true
Expand Down Expand Up @@ -215,6 +219,34 @@ def create_home_room
update_attributes(main_room: room)
end

def user_settings_as_hash
user_settings.map { |x| [x[:name], x[:value]] }.to_h
end

def update_all_user_settings(settings = {})
settings.each do |k, v|
if v == "0"
update_setting(k, "false")
else
update_setting(k, "true")
end
end
end

def update_setting(name, value)
# Dont update if it is not explicitly set to a value
return unless name.present? && value.present?

setting = user_settings.find_by(name: name)
# Setting already exists
if setting.present?
# Updates settings
setting.update_attributes(value: value)
else
user_settings.create(name: name, value: value)
end
end

private

# Destory a users rooms when they are removed.
Expand Down
5 changes: 5 additions & 0 deletions app/models/user_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class UserSetting < ApplicationRecord
belongs_to :user
end
38 changes: 38 additions & 0 deletions app/views/users/components/_join_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<%= form_for @user, url: user_update_settings_path, method: :post do |f| %>
<%= hidden_field_tag :setting, "join_settings" %>
<div class="form-group">
<div class="row">
<% @join_settings.each_with_index do |p, idx| %>
<div class="col-8">
<label class="custom-switch pl-0 mt-3 mb-3 w-100 text-left d-inline-block">
<span class="ml-0 custom-switch-description"><%= t("settings.user_settings." + p ) %></span>
<% if @user.user_settings_as_hash.key?(p) %>
<%= f.check_box p, :checked => (@user.user_settings_as_hash[p] == "true"), class: "custom-switch-input", disabled: false %>
<% else %>
<%= f.check_box p, :checked => (@join_settings_defaults[idx] == "true"), class: "custom-switch-input", disabled: false %>
<% end %>
<span class="custom-switch-indicator float-right"></span>
</label>
</div>
<% end %>
</div>
</div>
<div class="card-footer">
<%= f.submit t("update"), class: "btn btn-primary float-right" %>
</div>
<% end %>
5 changes: 5 additions & 0 deletions app/views/users/components/_menu_buttons.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<%= link_to edit_user_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "edit"}" do %>
<span class="icon mr-3"><i class="fas fa-user"></i></span><%= t("settings.account.title") %>
<% end %>
<% unless @join_settings.length <= 0 %>
<%= link_to join_settings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "join_settings"}" do %>
<span class="icon mr-3"><i class="fas fa-cog"></i></span><%= t("settings.account.join_settings") %>
<% end %>
<% end %>
<% if current_user.greenlight_account? %>
<%= link_to change_password_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "change_password"}" do %>
<span class="icon mr-3"><i class="fas fa-key"></i></span><%= t("settings.password.title") %>
Expand Down
35 changes: 35 additions & 0 deletions app/views/users/join_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<div class="container pt-6">
<%= render "shared/components/subtitle", subtitle: t("settings.title"), search: false %>

<div class="row">
<div class="col-lg-3 mb-4">
<%= render "users/components/menu_buttons" %>
<% if @user.errors.any? %>
<h5 class="mt-8"><%= t("errors.title") %>:</h5>
<ul>
<% @user.errors.full_messages.each do |err| %>
<li class="text-danger"><%= err %>.</li>
<% end %>
</ul>
<% end %>
</div>
<div class="col-lg-9">
<%= render "users/components/setting_view", setting_id: "join_settings", setting_title: "Settings" %>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class Application < Rails::Application
# Configure which settings are available to user on room creation/edit after creation
config.room_features = ENV['ROOM_FEATURES'] || ""

# Configure which settings are available to user on joining the room
config.join_settings_features = ENV['JOIN_SETTINGS_FEATURES'] || ""

# Configure default values user on joining the room
config.join_settings_defaults = ENV['JOIN_SETTINGS_DEFAULT_VALUES'] || ""

# The maximum number of rooms included in one bbbapi call
config.pagination_number = ENV['PAGINATION_NUMBER'].to_i.zero? ? 25 : ENV['PAGINATION_NUMBER'].to_i

Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ en:
subtitle: Update your Account Info
title: Account Info
reset_password: Reset user password
join_settings: Settings
delete:
button: Yes, I would like to delete my account.
disclaimer: If you choose to delete your account, it will <b>NOT</b> be recoverable. All information regarding your account, including settings, rooms, and recording will be removed.
Expand All @@ -617,6 +618,11 @@ en:
old: Old Password
subtitle: Change your Password
title: Password
user_settings:
userdata-bbb_skip_check_audio: Skip echo test
userdata-bbb_skip_video_preview: Skip video preview
userdata-bbb_auto_share_webcam: Auto share webcam
userdata-bbb_listen_only_mode: Enable listen only mode (disable this if you want to auto join microphone)
title: Profile
search: Search
signup:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@

# Account management.
get '/:user_uid/edit', to: 'users#edit', as: :edit_user
get '/:user_uid/join_settings', to: 'users#join_settings', as: :join_settings
get '/:user_uid/change_password', to: 'users#change_password', as: :change_password
get '/:user_uid/delete_account', to: 'users#delete_account', as: :delete_account
post '/:user_uid/edit', to: 'users#update', as: :update_user
post '/:user_uid/change_password', to: 'users#update_password', as: :update_password
post '/:user_uid/join_settings', to: 'users#update_settings', as: :user_update_settings
delete '/:user_uid', to: 'users#destroy', as: :delete_user

# All user recordings
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20210126001733_create_user_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class CreateUserSettings < ActiveRecord::Migration[5.2]
def change
create_table :user_settings do |t|
t.string :name
t.string :value, default: ""
t.references :user, foreign_key: true

t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion 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: 2020_12_14_232153) do
ActiveRecord::Schema.define(version: 2021_01_26_001733) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -121,6 +121,15 @@
t.index ["user_id"], name: "index_shared_accesses_on_user_id"
end

create_table "user_settings", force: :cascade do |t|
t.string "name"
t.string "value", default: ""
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_user_settings_on_user_id"
end

create_table "users", force: :cascade do |t|
t.integer "room_id"
t.string "provider"
Expand Down
15 changes: 15 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ RELATIVE_URL_ROOT=/b
# recording: Sessions are recorded
ROOM_FEATURES=mute-on-join,require-moderator-approval,anyone-can-start,all-join-moderator,recording

# Specify which room join settings you would like the users to configure on join / enter room session
# If no setting features configured, the join settings menu item will be removed.
# !! Do not forgot to set up the default value as well !!
#
# Current join settings available (see https://docs.bigbluebutton.org/2.2/customize.html for more details):
# userdata-bbb_skip_check_audio: If set to true, the user will not see the “echo test” prompt on login
# userdata-bbb_skip_video_preview: If set to true, the client will not see a preview of their webcam before sharing it
# userdata-bbb_auto_share_webcam: If set to true, the client will start the process of sharing webcam (if any) automatically upon loading the client
# userdata-bbb_listen_only_mode: If set to false, the user will not be able to join the audio part of the meeting without a microphone (disables listen-only mode)
JOIN_SETTINGS_FEATURES=userdata-bbb_skip_check_audio,userdata-bbb_skip_video_preview,userdata-bbb_auto_share_webcam,userdata-bbb_listen_only_mode

# Join settings default values, make sure to configure this if you configure the join settings features
# JOIN_SETTINGS_FEATURES[index] value is JOIN_SETTINGS_DEFAULT_VALUES[index]
JOIN_SETTINGS_DEFAULT_VALUES=false,false,false,true

# Specify the maximum number of records to be sent to the BigBlueButton API in one call
# Default is set to 25 records
PAGINATION_NUMBER=25
Expand Down
52 changes: 52 additions & 0 deletions spec/controllers/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,34 @@ def random_valid_room_params

expect(response).to redirect_to(root_path)
end

it "should have correct user setting params" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true)

@request.session[:user_id] = @user.id
allow(Rails.configuration).to receive(:join_settings_features).and_return("userdata-bbb_listen_only_mode")

@user.update_setting("userdata-bbb_listen_only_mode", "true")

post :join, params: { room_uid: @room, join_name: @user.name }

expect(response).to redirect_to(join_path(@owner.main_room, @user.name,
{ "userdata-bbb_listen_only_mode": true }, @user.uid))
end

it "should ignore user setting params when env is config" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true)

@request.session[:user_id] = @user.id
allow(Rails.configuration).to receive(:join_settings_features).and_return("")

@user.update_setting("userdata-bbb_listen_only_mode", "true")

post :join, params: { room_uid: @room, join_name: @user.name }

expect(response).to redirect_to(join_path(@owner.main_room, @user.name,
{}, @user.uid))
end
end

describe "DELETE #destroy" do
Expand Down Expand Up @@ -571,6 +599,30 @@ def random_valid_room_params

expect(response).to redirect_to(root_path)
end

it "should have correct user setting params" do
@request.session[:user_id] = @user.id
allow(Rails.configuration).to receive(:join_settings_features).and_return("userdata-bbb_listen_only_mode")

@user.update_setting("userdata-bbb_listen_only_mode", "true")

post :start, params: { room_uid: @user.main_room }

expect(response).to redirect_to(join_path(@user.main_room, @user.name,
{ user_is_moderator: true, "userdata-bbb_listen_only_mode": true }, @user.uid))
end

it "should ignore user setting params when not in config" do
@request.session[:user_id] = @user.id
allow(Rails.configuration).to receive(:join_settings_features).and_return("")

@user.update_setting("userdata-bbb_listen_only_mode", "true")

post :start, params: { room_uid: @user.main_room }

expect(response).to redirect_to(join_path(@user.main_room, @user.name,
{ user_is_moderator: true }, @user.uid))
end
end

describe "POST #update_settings" do
Expand Down

0 comments on commit 6fe275a

Please sign in to comment.