Skip to content

Commit

Permalink
GRN2-253: Added the ability to share rooms across multiple users (big…
Browse files Browse the repository at this point in the history
…bluebutton#912)

* Added ability to share rooms with other users

* Fixed testcases
  • Loading branch information
farhatahmad committed Feb 12, 2020
1 parent 8cbfc3f commit 967130e
Show file tree
Hide file tree
Showing 36 changed files with 748 additions and 55 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
//= require jquery-ui/widget
//= require jquery-ui/widgets/sortable
//= require pickr.min.js
//= require bootstrap-select.min.js
//= require_tree .
104 changes: 104 additions & 0 deletions app/assets/javascripts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,69 @@ $(document).on('turbolinks:load', function(){
$(".delete-room").click(function() {
showDeleteRoom(this)
})

$('.selectpicker').selectpicker({
liveSearchPlaceholder: "Start searching..."
});
// Fixes turbolinks issue with bootstrap select
$(window).trigger('load.bs.select.data-api');

$(".share-room").click(function() {
// Update the path of save button
$("#save-access").attr("data-path", $(this).data("path"))

// Get list of users shared with and display them
displaySharedUsers($(this).data("users-path"))
})

$("#shareRoomModal").on("show.bs.modal", function() {
$(".selectpicker").selectpicker('val','')
})

$(".bootstrap-select").on("click", function() {
$(".bs-searchbox").siblings().hide()
})

$(".bs-searchbox input").on("input", function() {
if ($(".bs-searchbox input").val() == '' || $(".bs-searchbox input").val().length < 3) {
$(".bs-searchbox").siblings().hide()
} else {
$(".bs-searchbox").siblings().show()
}
})

$(".remove-share-room").click(function() {
$("#remove-shared-confirm").parent().attr("action", $(this).data("path"))
})

// User selects an option from the Room Access dropdown
$(".bootstrap-select").on("changed.bs.select", function(){
// Get the uid of the selected user
let uid = $(".selectpicker").selectpicker('val')

// If the value was changed to blank, ignore it
if (uid == "") return

let currentListItems = $("#user-list li").toArray().map(user => $(user).data("uid"))

// Check to make sure that the user is not already there
if (!currentListItems.includes(uid)) {
// Create the faded list item and display it
let option = $("option[value='" + uid + "']")

let listItem = document.createElement("li")
listItem.setAttribute('class', 'list-group-item text-left not-saved add-access');
listItem.setAttribute("data-uid", uid)

let spanItem = "<span class='avatar float-left mr-2'>" + option.text().charAt(0) + "</span> <span class='shared-user'>" +
option.text() + " <span class='text-muted'>" + option.data("subtext") + "</span></span>" +
"<span class='text-primary float-right shared-user cursor-pointer' onclick='removeSharedUser(this)'><i class='fas fa-times'></i></span>"

listItem.innerHTML = spanItem

$("#user-list").append(listItem)
}
})
}
});

Expand Down Expand Up @@ -150,3 +213,44 @@ function ResetAccessCode(){
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
$("#room_access_code").val(null)
}

function saveAccessChanges() {
let listItemsToAdd = $("#user-list li:not(.remove-shared)").toArray().map(user => $(user).data("uid"))

$.post($("#save-access").data("path"), {add: listItemsToAdd})
}

// Get list of users shared with and display them
function displaySharedUsers(path) {
$.get(path, function(users) {
// Create list element and add to user list
var user_list_html = ""

users.forEach(function(user) {
user_list_html += "<li class='list-group-item text-left' data-uid='" + user.uid + "'>"

if (user.image) {
user_list_html += "<img id='user-image' class='avatar float-left mr-2' src='" + user.image + "'></img>"
} else {
user_list_html += "<span class='avatar float-left mr-2'>" + user.name.charAt(0) + "</span>"
}
user_list_html += "<span class='shared-user'>" + user.name + "<span class='text-muted ml-1'>" + user.uid + "</span></span>"
user_list_html += "<span class='text-primary float-right shared-user cursor-pointer' onclick='removeSharedUser(this)'><i class='fas fa-times'></i></span>"
user_list_html += "</li>"
})

$("#user-list").html(user_list_html)
});
}

// Removes the user from the list of shared users
function removeSharedUser(target) {
let parentLI = target.closest("li")

if (parentLI.classList.contains("not-saved")) {
parentLI.parentNode.removeChild(parentLI)
} else {
parentLI.removeChild(target)
parentLI.classList.add("remove-shared")
}
}
4 changes: 3 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@
@import "tabler-custom";
@import "font-awesome-sprockets";
@import "font-awesome";
@import "monolith.min.scss";
@import "bootstrap-select.min.css";

@import "utilities/variables";
@import "admins";
@import "main";
@import "rooms";
@import "sessions";
@import "monolith.min.scss";
@import "utilities/fonts";
@import "users";

* {
outline: none !important;
Expand Down
17 changes: 17 additions & 0 deletions app/assets/stylesheets/rooms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@
margin-top: -6rem;
font-size: 5rem;
}

.bootstrap-select .dropdown-menu li.active small.text-muted{
color: #9aa0ac !important
}

.not-saved {
color: grey;
background: rgba(0, 40, 100, 0.12);
}

.dropdown-menu.show {
min-height: 0px !important;
}

.remove-shared {
text-decoration: line-through;
}
8 changes: 8 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@

.user-role-tag{
color: white !important;
}

.shared-user {
line-height: 30px;
}

.bootstrap-select {
border: 1px solid rgba(0, 40, 100, 0.12);
}
17 changes: 5 additions & 12 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AdminsController < ApplicationController
include Emailer
include Recorder
include Rolify
include Populator

manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve, :reset]
manage_deleted_users = [:undelete]
Expand Down Expand Up @@ -49,11 +50,7 @@ def site_settings

# GET /admins/server_recordings
def server_recordings
server_rooms = if Rails.configuration.loadbalanced_configuration
Room.includes(:owner).where(users: { provider: @user_domain }).pluck(:bbb_id)
else
Room.pluck(:bbb_id)
end
server_rooms = rooms_list_for_recordings

@search, @order_column, @order_direction, recs =
all_recordings(server_rooms, params.permit(:search, :column, :direction), true, true)
Expand All @@ -67,13 +64,9 @@ def server_rooms
@order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
@order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"

server_rooms = if Rails.configuration.loadbalanced_configuration
Room.includes(:owner).where(users: { provider: @user_domain })
.admins_search(@search)
.admins_order(@order_column, @order_direction)
else
Room.all.admins_search(@search).admins_order(@order_column, @order_direction)
end
server_rooms = server_rooms_list

@user_list = shared_user_list if shared_access_allowed

@pagy, @rooms = pagy_array(server_rooms)
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def configured_providers
end
helper_method :configured_providers

# Indicates whether users are allowed to share rooms
def shared_access_allowed
@settings.get_value("Shared Access") == "true"
end
helper_method :shared_access_allowed

# Parses the url for the user domain
def parse_user_domain(hostname)
return hostname.split('.').first if Rails.configuration.url_host.empty?
Expand Down
54 changes: 54 additions & 0 deletions app/controllers/concerns/populator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# 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/>.

module Populator
extend ActiveSupport::Concern

# Returns a list of rooms that are in the same context of the current user
def server_rooms_list
if Rails.configuration.loadbalanced_configuration
Room.includes(:owner).where(users: { provider: @user_domain })
.admins_search(@search)
.admins_order(@order_column, @order_direction)
else
Room.all.admins_search(@search).admins_order(@order_column, @order_direction)
end
end

# Returns list of rooms needed to get the recordings on the server
def rooms_list_for_recordings
if Rails.configuration.loadbalanced_configuration
Room.includes(:owner).where(users: { provider: @user_domain }).pluck(:bbb_id)
else
Room.pluck(:bbb_id)
end
end

# Returns a list of users that are in the same context of the current user
def shared_user_list
roles_can_appear = []
Role.where(provider: @user_domain).each do |role|
roles_can_appear << role.name if role.get_permission("can_appear_in_share_list") && role.name != "super_admin"
end

initial_list = User.where.not(uid: current_user.uid).with_highest_priority_role(roles_can_appear)

return initial_list unless Rails.configuration.loadbalanced_configuration
initial_list.where(provider: @user_domain)
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/rolify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def update_permissions(role)
role_params = params.require(:role).permit(:name)
permission_params = params.require(:role).permit(:can_create_rooms, :send_promoted_email,
:send_demoted_email, :can_edit_site_settings, :can_edit_roles, :can_manage_users,
:can_manage_rooms_recordings, :colour)
:can_manage_rooms_recordings, :can_appear_in_share_list, :colour)

permission_params.transform_values! do |v|
if v == "0"
Expand Down
Loading

0 comments on commit 967130e

Please sign in to comment.