GRN-11: Ability to configure room specific settings (#348)

* Added the ability to set room settings on create or update

* Added room settings alerts and made fixes to other alerts

* Small bug fixes related to rubocop and the create room modal

* Update test case and fixed issue with small edge case

* Update room.js
This commit is contained in:
farhatahmad
2019-02-06 11:08:19 -05:00
committed by Jesus Federico
parent 992c154c10
commit 2e8670a8ab
21 changed files with 284 additions and 74 deletions

View File

@ -32,11 +32,11 @@ class PasswordResetsController < ApplicationController
@user.send_password_reset_email(reset_link)
redirect_to root_url, notice: I18n.t("email_sent")
else
redirect_to new_password_reset_path, notice: I18n.t("no_user_email_exists")
redirect_to new_password_reset_path, alert: I18n.t("no_user_email_exists")
end
rescue => e
logger.error "Error in email delivery: #{e}"
redirect_to root_path, notice: I18n.t(params[:message], default: I18n.t("delivery_error"))
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("delivery_error"))
end
def edit
@ -44,13 +44,14 @@ class PasswordResetsController < ApplicationController
def update
if params[:user][:password].empty?
flash.now[:notice] = I18n.t("password_empty_notice")
flash.now[:alert] = I18n.t("password_empty_notice")
render 'edit'
elsif params[:user][:password] != params[:user][:password_confirmation]
flash.now[:notice] = I18n.t("password_different_notice")
flash.now[:alert] = I18n.t("password_different_notice")
render 'edit'
elsif current_user.update_attributes(user_params)
redirect_to root_path, notice: I18n.t("password_reset_success")
flash[:success] = I18n.t("password_reset_success")
redirect_to root_path
else
render 'edit'
end
@ -73,7 +74,7 @@ class PasswordResetsController < ApplicationController
# Checks expiration of reset token.
def check_expiration
if current_user.password_reset_expired?
redirect_to new_password_reset_url, notice: I18n.t("expired_reset_token")
redirect_to new_password_reset_url, alert: I18n.t("expired_reset_token")
end
end

View File

@ -27,17 +27,22 @@ class RoomsController < ApplicationController
# POST /
def create
redirect_to root_path unless current_user
redirect_to(root_path) && return unless current_user
@room = Room.new(name: room_params[:name])
@room.owner = current_user
@room.room_settings = create_room_settings_string(room_params[:mute_on_join], room_params[:client])
if @room.save
if room_params[:auto_join] == "1"
start
else
flash[:success] = I18n.t("room.create_room_success")
redirect_to @room
end
else
flash[:alert] = I18n.t("room.create_room_error")
redirect_to current_user.main_room
end
end
@ -60,9 +65,9 @@ class RoomsController < ApplicationController
def update
if params[:setting] == "rename_block"
@room = Room.find_by!(uid: params[:room_block_uid])
update_room_attributes
update_room_attributes("name")
elsif params[:setting] == "rename_header"
update_room_attributes
update_room_attributes("name")
elsif params[:setting] == "rename_recording"
@room.update_recording(params[:record_id], "meta_name" => params[:record_name])
end
@ -86,6 +91,10 @@ class RoomsController < ApplicationController
# Determine if the user needs to join as a moderator.
opts[:user_is_moderator] = @room.owned_by?(current_user)
# Check if the user has specified which client to use
room_settings = JSON.parse(@room[:room_settings])
opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
if current_user
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else
@ -112,10 +121,15 @@ class RoomsController < ApplicationController
opts = default_meeting_options
opts[:user_is_moderator] = true
# Include the user's choices for the room settings
room_settings = JSON.parse(@room[:room_settings])
opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
begin
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
rescue BigBlueButton::BigBlueButtonException => exc
redirect_to room_path, notice: I18n.t(exc.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
redirect_to room_path, alert: I18n.t(exc.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
end
# Notify users that the room has started.
@ -123,6 +137,24 @@ class RoomsController < ApplicationController
NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
end
# POST /:room_uid/update_settings
def update_settings
begin
raise "Room name can't be blank" if room_params[:name].empty?
@room = Room.find_by!(uid: params[:room_uid])
# Update the rooms settings
update_room_attributes("settings")
# Update the rooms name if it has been changed
update_room_attributes("name") if @room.name != room_params[:name]
rescue StandardError
flash[:alert] = I18n.t("room.update_settings_error")
else
flash[:success] = I18n.t("room.update_settings_success")
end
redirect_to room_path
end
# GET /:room_uid/logout
def logout
# Redirect the correct page.
@ -149,14 +181,32 @@ class RoomsController < ApplicationController
private
def update_room_attributes
def update_room_attributes(update_type)
if @room.owned_by?(current_user) && @room != current_user.main_room
@room.update_attributes(name: params[:room_name])
if update_type.eql? "name"
@room.update_attributes(name: params[:room_name] || room_params[:name])
elsif update_type.eql? "settings"
room_settings_string = create_room_settings_string(room_params[:mute_on_join], room_params[:client])
@room.update_attributes(room_settings: room_settings_string)
end
end
end
def create_room_settings_string(mute_res, client_res)
room_settings = {}
room_settings["muteOnStart"] = mute_res == "1" ? true : false
if client_res.eql? "html5"
room_settings["joinViaHtml5"] = true
elsif client_res.eql? "flash"
room_settings["joinViaHtml5"] = false
end
room_settings.to_json
end
def room_params
params.require(:room).permit(:name, :auto_join)
params.require(:room).permit(:name, :auto_join, :mute_on_join, :client)
end
# Find the room from the uid.

View File

@ -29,11 +29,11 @@ class SessionsController < ApplicationController
def create
user = User.find_by(email: session_params[:email])
if user && !user.greenlight_account?
redirect_to root_path, notice: I18n.t("invalid_login_method")
redirect_to root_path, alert: I18n.t("invalid_login_method")
elsif user.try(:authenticate, session_params[:password])
login(user)
else
redirect_to root_path, notice: I18n.t("invalid_credentials")
redirect_to root_path, alert: I18n.t("invalid_credentials")
end
end
@ -48,7 +48,7 @@ class SessionsController < ApplicationController
# POST /auth/failure
def omniauth_fail
redirect_to root_path, notice: I18n.t(params[:message], default: I18n.t("omniauth_error"))
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("omniauth_error"))
end
private

View File

@ -85,7 +85,8 @@ class UsersController < ApplicationController
if errors.empty? && @user.save
# Notify the user that their account has been updated.
redirect_to edit_user_path(@user), notice: I18n.t("info_update_success")
flash[:success] = I18n.t("info_update_success")
redirect_to edit_user_path(@user)
else
# Append custom errors.
errors.each { |k, v| @user.errors.add(k, v) }
@ -93,10 +94,12 @@ class UsersController < ApplicationController
end
elsif user_params[:email] != @user.email && @user.update_attributes(user_params)
@user.update_attributes(email_verified: false)
redirect_to edit_user_path(@user), notice: I18n.t("info_update_success")
flash[:success] = I18n.t("info_update_success")
redirect_to edit_user_path(@user)
elsif @user.update_attributes(user_params)
update_locale(@user)
redirect_to edit_user_path(@user), notice: I18n.t("info_update_success")
flash[:success] = I18n.t("info_update_success")
redirect_to edit_user_path(@user)
else
render :edit, params: { settings: params[:settings] }
end
@ -178,7 +181,7 @@ class UsersController < ApplicationController
private
def mailer_delivery_fail
redirect_to root_path, notice: I18n.t(params[:message], default: I18n.t("delivery_error"))
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("delivery_error"))
end
def verification_link(user)