Skip to content

Commit

Permalink
GRN2-xx: Fixed issue with recording row and added small fix to roles …
Browse files Browse the repository at this point in the history
…migration (Fixed bigbluebutton#717, bigbluebutton#718) (bigbluebutton#719)

* Fixed issue with recording row and added small fix to roles migration

* Fixed issue with edit user avatar

* Small bug fixes for user settings

* Added autofocus on name field when joining

* Added extra check for admin password check

* Rubocop fixes
  • Loading branch information
farhatahmad authored and jfederico committed Aug 1, 2019
1 parent 4fc1714 commit 60f5cd5
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 92 deletions.
100 changes: 45 additions & 55 deletions app/assets/javascripts/user_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,64 @@
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

$(document).on('turbolinks:load', function(){
var controller = $("body").data('controller');
var action = $("body").data('action');
if ((controller == "admins" && action == "edit_user") || (controller == "users" && action == "edit")) {
$(".setting-btn").click(function(data){
var url = $("body").data("relative-root")
if (!url.endsWith("/")) {
url += "/"
}
url += "admins?setting=" + data.target.id
var controller = $("body").data('controller');
var action = $("body").data('action');
if ((controller == "admins" && action == "edit_user") || (controller == "users" && action == "edit")) {
// Clear the role when the user clicks the x
$(".clear-role").click(clearRole)

window.location.href = url
})
// When the user selects an item in the dropdown add the role to the user
$("#role-select-dropdown").change(function(data){
var dropdown = $("#role-select-dropdown");
var select_role_id = dropdown.val();

// Clear the role when the user clicks the x
$(".clear-role").click(clearRole)
if(select_role_id){
// Disable the role in the dropdown
var selected_role = dropdown.find('[value=\"' + select_role_id + '\"]');
selected_role.prop("disabled", true)

// When the user selects an item in the dropdown add the role to the user
$("#role-select-dropdown").change(function(data){
var dropdown = $("#role-select-dropdown");
var select_role_id = dropdown.val();
// Add the role tag
var tag_container = $("#role-tag-container");
tag_container.append("<span id=\"user-role-tag_" + select_role_id + "\" style=\"background-color:" + selected_role.data("colour") + ";\" class=\"tag\">" +
selected_role.text() + "<a data-role-id=\"" + select_role_id + "\" class=\"tag-addon clear-role\"><i data-role-id=\"" + select_role_id + "\" class=\"fas fa-times\"></i></a></span>");

if(select_role_id){
// Disable the role in the dropdown
var selected_role = dropdown.find('[value=\"' + select_role_id + '\"]');
selected_role.prop("disabled", true)
// Update the role ids input that gets submited on user update
var role_ids = $("#user_role_ids").val()
role_ids += " " + select_role_id
$("#user_role_ids").val(role_ids)

// Add the clear role function to the tag
$("#user-role-tag_" + select_role_id).click(clearRole);

// Add the role tag
var tag_container = $("#role-tag-container");
tag_container.append("<span id=\"user-role-tag_" + select_role_id + "\" style=\"background-color:" + selected_role.data("colour") + ";\" class=\"tag\">" +
selected_role.text() + "<a data-role-id=\"" + select_role_id + "\" class=\"tag-addon clear-role\"><i data-role-id=\"" + select_role_id + "\" class=\"fas fa-times\"></i></a></span>");

// Update the role ids input that gets submited on user update
var role_ids = $("#user_role_ids").val()
role_ids += " " + select_role_id
$("#user_role_ids").val(role_ids)

// Add the clear role function to the tag
$("#user-role-tag_" + select_role_id).click(clearRole);

// Reset the dropdown
dropdown.val(null)
}
})
}
// Reset the dropdown
dropdown.val(null)
}
})
}
})

// This function removes the specfied role from a user
function clearRole(data){
// Get the role id
var role_id = $(data.target).data("role-id");
var role_tag = $("#user-role-tag_" + role_id);
// Get the role id
var role_id = $(data.target).data("role-id");
var role_tag = $("#user-role-tag_" + role_id);

// Remove the role tag
$(role_tag).remove()
// Remove the role tag
$(role_tag).remove()

// Update the role ids input
var role_ids = $("#user_role_ids").val()
var parsed_ids = role_ids.split(' ')
// Update the role ids input
var role_ids = $("#user_role_ids").val()
var parsed_ids = role_ids.split(' ')

var index = parsed_ids.indexOf(role_id.toString());
var index = parsed_ids.indexOf(role_id.toString());

if (index > -1) {
parsed_ids.splice(index, 1);
}
if (index > -1) {
parsed_ids.splice(index, 1);
}

$("#user_role_ids").val(parsed_ids.join(' '))
$("#user_role_ids").val(parsed_ids.join(' '))

// Enable the role in the role select dropdown
var selected_role = $("#role-select-dropdown").find('[value=\"' + role_id + '\"]');
selected_role.prop("disabled", false)
// Enable the role in the role select dropdown
var selected_role = $("#role-select-dropdown").find('[value=\"' + role_id + '\"]');
selected_role.prop("disabled", false)
}
61 changes: 37 additions & 24 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def default_meeting_options

# Checks to make sure that the admin has changed his password from the default
def check_admin_password
if current_user&.has_role?(:admin) && current_user&.greenlight_account? &&
current_user&.authenticate(Rails.configuration.admin_password_default)
if current_user&.has_role?(:admin) && current_user.email == "[email protected]" &&
current_user&.greenlight_account? && current_user&.authenticate(Rails.configuration.admin_password_default)

flash.now[:alert] = I18n.t("default_admin",
edit_link: edit_user_path(user_uid: current_user.uid) + "?setting=password").html_safe
Expand All @@ -157,28 +157,7 @@ def set_user_domain
else
@user_domain = parse_user_domain(request.host)

# Checks to see if the user exists
begin
retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')
rescue => e
# Use the default site settings
@user_domain = "greenlight"

if e.message.eql? "No user with that id exists"
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_not_found.message"),
help: I18n.t("errors.not_found.user_not_found.help") }
elsif e.message.eql? "Provider not included."
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_missing.message"),
help: I18n.t("errors.not_found.user_missing.help") }
elsif e.message.eql? "That user has no configured provider."
render "errors/greenlight_error", locals: { status_code: 501,
message: I18n.t("errors.no_provider.message"),
help: I18n.t("errors.no_provider.help") }
else
render "errors/greenlight_error", locals: { status_code: 500, message: I18n.t("errors.internal.message"),
help: I18n.t("errors.internal.help"), display_back: true }
end
end
check_provider_exists
end
end
helper_method :set_user_domain
Expand All @@ -199,4 +178,38 @@ def check_user_role
def handle_bigbluebutton_error
render "errors/bigbluebutton_error"
end

private

def check_provider_exists
# Checks to see if the user exists
begin
# Check if the session has already checked that the user exists
# and return true if they did for this domain
return if session[:provider_exists] == @user_domain

retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')

# Add a session variable if the provider exists
session[:provider_exists] = @user_domain
rescue => e
# Use the default site settings
@user_domain = "greenlight"

if e.message.eql? "No user with that id exists"
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_not_found.message"),
help: I18n.t("errors.not_found.user_not_found.help") }
elsif e.message.eql? "Provider not included."
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_missing.message"),
help: I18n.t("errors.not_found.user_missing.help") }
elsif e.message.eql? "That user has no configured provider."
render "errors/greenlight_error", locals: { status_code: 501,
message: I18n.t("errors.no_provider.message"),
help: I18n.t("errors.no_provider.help") }
else
render "errors/greenlight_error", locals: { status_code: 500, message: I18n.t("errors.internal.message"),
help: I18n.t("errors.internal.help"), display_back: true }
end
end
end
end
7 changes: 5 additions & 2 deletions app/views/rooms/join.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
required: true,
class: "form-control join-form",
placeholder: t("room.enter_the_access_code"),
value: "" %>
value: "" ,
autofocus: true %>
<%= f.submit t("room.login"), class: "btn btn-primary btn-sm col-sm-3 form-control join-form" %>
</div>
<% end %>
Expand All @@ -39,7 +40,9 @@
class: "form-control join-form",
placeholder: t("enter_your_name"),
value: "#{@name}",
readonly: !current_user.nil? %>
readonly: !current_user.nil?,
autofocus: true
%>
<%= f.submit (!@is_running && @anyone_can_start)? t("room.start") : t("room.join"), class: "btn btn-primary btn-sm col-sm-3 form-control join-form" %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/components/_public_recording_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<td class="overflow-hidden">
<% p = recording[:playbacks].find do |p| p.key?(:preview) end %>
<% if p %>
<% p[:preview][:images][:image].each do |img| %>
<% safe_recording_images(p[:preview][:images][:image]).each do |img| %>
<%= image_tag(img[:content].strip, class: "thumbnail px-2") %>
<% end %>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/shared/settings/_account.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="col-6">
<%= f.label t("email"), class: "form-label" %>
<div class="input-icon">
<%= f.text_field :email, class: "form-control #{form_is_invalid?(@user, :email)}", placeholder: t("email"), readonly: !current_user.greenlight_account? %>
<%= f.text_field :email, class: "form-control #{form_is_invalid?(@user, :email)}", placeholder: t("email"), readonly: !@user.greenlight_account? %>
</div>
</div>
</div>
Expand Down Expand Up @@ -63,10 +63,10 @@
<%= f.label t("settings.account.image"), class: "form-label mt-5" %>
<div class="row">
<div class="col-2">
<% if current_user.image.blank? %>
<span class="avatar avatar-xxl mr-5 mt-2"><%= current_user.name.first %></span>
<% if @user.image.blank? %>
<span class="avatar avatar-xxl mr-5 mt-2"><%= @user.name.first %></span>
<% else %>
<span class="avatar avatar-xxl mr-5 mt-2" style="background-image: url(<%= current_user.image %>)"></span>
<span class="avatar avatar-xxl mr-5 mt-2" style="background-image: url(<%= @user.image %>)"></span>
<% end %>
</div>
<div class="col-10 mt-5">
Expand Down
6 changes: 1 addition & 5 deletions app/views/shared/settings/_setting_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
</div>
</div>

<% unless (defined?(admin_view)).nil? %>
<%= render "shared/admin_settings/#{setting_id}" %>
<% else %>
<%= render "shared/settings/#{setting_id}" %>
<% end %>
<%= render "shared/settings/#{setting_id}" %>
</div>
<% end %>
7 changes: 6 additions & 1 deletion db/migrate/20190726153012_add_custom_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def up
new_assignments = []

old_assignments.each do |assignment|
user = User.find(assignment["user_id"])
begin
user = User.find(assignment["user_id"])
rescue
next
end

new_assignment = { "user_id" => assignment["user_id"] }
if assignment["role_id"] == super_admin_id
new_assignment["new_role_id"] = generate_scoped_role(user, "super_admin")
Expand Down

0 comments on commit 60f5cd5

Please sign in to comment.