forked from External/greenlight
GRN2-xx: Fixed issue with recording row and added small fix to roles migration (Fixed #717, #718) (#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
This commit is contained in:
parent
4fc1714db8
commit
60f5cd5c81
|
@ -15,74 +15,64 @@
|
||||||
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
$(document).on('turbolinks:load', function(){
|
$(document).on('turbolinks:load', function(){
|
||||||
var controller = $("body").data('controller');
|
var controller = $("body").data('controller');
|
||||||
var action = $("body").data('action');
|
var action = $("body").data('action');
|
||||||
if ((controller == "admins" && action == "edit_user") || (controller == "users" && action == "edit")) {
|
if ((controller == "admins" && action == "edit_user") || (controller == "users" && action == "edit")) {
|
||||||
$(".setting-btn").click(function(data){
|
// Clear the role when the user clicks the x
|
||||||
var url = $("body").data("relative-root")
|
$(".clear-role").click(clearRole)
|
||||||
if (!url.endsWith("/")) {
|
|
||||||
url += "/"
|
|
||||||
}
|
|
||||||
url += "admins?setting=" + data.target.id
|
|
||||||
|
|
||||||
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
|
if(select_role_id){
|
||||||
$(".clear-role").click(clearRole)
|
// 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
|
// Add the role tag
|
||||||
$("#role-select-dropdown").change(function(data){
|
var tag_container = $("#role-tag-container");
|
||||||
var dropdown = $("#role-select-dropdown");
|
tag_container.append("<span id=\"user-role-tag_" + select_role_id + "\" style=\"background-color:" + selected_role.data("colour") + ";\" class=\"tag\">" +
|
||||||
var select_role_id = dropdown.val();
|
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){
|
// Update the role ids input that gets submited on user update
|
||||||
// Disable the role in the dropdown
|
var role_ids = $("#user_role_ids").val()
|
||||||
var selected_role = dropdown.find('[value=\"' + select_role_id + '\"]');
|
role_ids += " " + select_role_id
|
||||||
selected_role.prop("disabled", true)
|
$("#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
|
// Reset the dropdown
|
||||||
var tag_container = $("#role-tag-container");
|
dropdown.val(null)
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// This function removes the specfied role from a user
|
// This function removes the specfied role from a user
|
||||||
function clearRole(data){
|
function clearRole(data){
|
||||||
// Get the role id
|
// Get the role id
|
||||||
var role_id = $(data.target).data("role-id");
|
var role_id = $(data.target).data("role-id");
|
||||||
var role_tag = $("#user-role-tag_" + role_id);
|
var role_tag = $("#user-role-tag_" + role_id);
|
||||||
|
|
||||||
// Remove the role tag
|
// Remove the role tag
|
||||||
$(role_tag).remove()
|
$(role_tag).remove()
|
||||||
|
|
||||||
// Update the role ids input
|
// Update the role ids input
|
||||||
var role_ids = $("#user_role_ids").val()
|
var role_ids = $("#user_role_ids").val()
|
||||||
var parsed_ids = role_ids.split(' ')
|
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) {
|
if (index > -1) {
|
||||||
parsed_ids.splice(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
|
// Enable the role in the role select dropdown
|
||||||
var selected_role = $("#role-select-dropdown").find('[value=\"' + role_id + '\"]');
|
var selected_role = $("#role-select-dropdown").find('[value=\"' + role_id + '\"]');
|
||||||
selected_role.prop("disabled", false)
|
selected_role.prop("disabled", false)
|
||||||
}
|
}
|
|
@ -137,8 +137,8 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# Checks to make sure that the admin has changed his password from the default
|
# Checks to make sure that the admin has changed his password from the default
|
||||||
def check_admin_password
|
def check_admin_password
|
||||||
if current_user&.has_role?(:admin) && current_user&.greenlight_account? &&
|
if current_user&.has_role?(:admin) && current_user.email == "admin@example.com" &&
|
||||||
current_user&.authenticate(Rails.configuration.admin_password_default)
|
current_user&.greenlight_account? && current_user&.authenticate(Rails.configuration.admin_password_default)
|
||||||
|
|
||||||
flash.now[:alert] = I18n.t("default_admin",
|
flash.now[:alert] = I18n.t("default_admin",
|
||||||
edit_link: edit_user_path(user_uid: current_user.uid) + "?setting=password").html_safe
|
edit_link: edit_user_path(user_uid: current_user.uid) + "?setting=password").html_safe
|
||||||
|
@ -157,28 +157,7 @@ class ApplicationController < ActionController::Base
|
||||||
else
|
else
|
||||||
@user_domain = parse_user_domain(request.host)
|
@user_domain = parse_user_domain(request.host)
|
||||||
|
|
||||||
# Checks to see if the user exists
|
check_provider_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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
helper_method :set_user_domain
|
helper_method :set_user_domain
|
||||||
|
@ -199,4 +178,38 @@ class ApplicationController < ActionController::Base
|
||||||
def handle_bigbluebutton_error
|
def handle_bigbluebutton_error
|
||||||
render "errors/bigbluebutton_error"
|
render "errors/bigbluebutton_error"
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
required: true,
|
required: true,
|
||||||
class: "form-control join-form",
|
class: "form-control join-form",
|
||||||
placeholder: t("room.enter_the_access_code"),
|
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" %>
|
<%= f.submit t("room.login"), class: "btn btn-primary btn-sm col-sm-3 form-control join-form" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -39,7 +40,9 @@
|
||||||
class: "form-control join-form",
|
class: "form-control join-form",
|
||||||
placeholder: t("enter_your_name"),
|
placeholder: t("enter_your_name"),
|
||||||
value: "#{@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" %>
|
<%= 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>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<td class="overflow-hidden">
|
<td class="overflow-hidden">
|
||||||
<% p = recording[:playbacks].find do |p| p.key?(:preview) end %>
|
<% p = recording[:playbacks].find do |p| p.key?(:preview) end %>
|
||||||
<% if p %>
|
<% 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") %>
|
<%= image_tag(img[:content].strip, class: "thumbnail px-2") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<%= f.label t("email"), class: "form-label" %>
|
<%= f.label t("email"), class: "form-label" %>
|
||||||
<div class="input-icon">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,10 +63,10 @@
|
||||||
<%= f.label t("settings.account.image"), class: "form-label mt-5" %>
|
<%= f.label t("settings.account.image"), class: "form-label mt-5" %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<% if current_user.image.blank? %>
|
<% if @user.image.blank? %>
|
||||||
<span class="avatar avatar-xxl mr-5 mt-2"><%= current_user.name.first %></span>
|
<span class="avatar avatar-xxl mr-5 mt-2"><%= @user.name.first %></span>
|
||||||
<% else %>
|
<% 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-10 mt-5">
|
<div class="col-10 mt-5">
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% unless (defined?(admin_view)).nil? %>
|
<%= render "shared/settings/#{setting_id}" %>
|
||||||
<%= render "shared/admin_settings/#{setting_id}" %>
|
|
||||||
<% else %>
|
|
||||||
<%= render "shared/settings/#{setting_id}" %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -52,7 +52,12 @@ class AddCustomRoles < ActiveRecord::Migration[5.2]
|
||||||
new_assignments = []
|
new_assignments = []
|
||||||
|
|
||||||
old_assignments.each do |assignment|
|
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"] }
|
new_assignment = { "user_id" => assignment["user_id"] }
|
||||||
if assignment["role_id"] == super_admin_id
|
if assignment["role_id"] == super_admin_id
|
||||||
new_assignment["new_role_id"] = generate_scoped_role(user, "super_admin")
|
new_assignment["new_role_id"] = generate_scoped_role(user, "super_admin")
|
||||||
|
|
Loading…
Reference in New Issue