From 60f5cd5c817c8cca6b2a4aac024a9dd512ff0559 Mon Sep 17 00:00:00 2001 From: farhatahmad <35435341+farhatahmad@users.noreply.github.com> Date: Thu, 1 Aug 2019 16:53:26 -0400 Subject: [PATCH] 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 --- app/assets/javascripts/user_edit.js | 100 ++++++++---------- app/controllers/application_controller.rb | 61 ++++++----- app/views/rooms/join.html.erb | 7 +- .../components/_public_recording_row.html.erb | 2 +- app/views/shared/settings/_account.html.erb | 8 +- .../shared/settings/_setting_view.html.erb | 6 +- db/migrate/20190726153012_add_custom_roles.rb | 7 +- 7 files changed, 99 insertions(+), 92 deletions(-) diff --git a/app/assets/javascripts/user_edit.js b/app/assets/javascripts/user_edit.js index ecd0756f71..2c5fa6bb88 100644 --- a/app/assets/javascripts/user_edit.js +++ b/app/assets/javascripts/user_edit.js @@ -15,74 +15,64 @@ // with BigBlueButton; if not, see . $(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("" + + selected_role.text() + ""); - 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("" + - selected_role.text() + ""); - - // 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) } \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6d407183ae..833ac5b7c3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 == "admin@example.com" && + 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 @@ -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 @@ -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 diff --git a/app/views/rooms/join.html.erb b/app/views/rooms/join.html.erb index e457e6ad55..1e8496a406 100644 --- a/app/views/rooms/join.html.erb +++ b/app/views/rooms/join.html.erb @@ -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" %> <% end %> @@ -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" %> <% end %> diff --git a/app/views/shared/components/_public_recording_row.html.erb b/app/views/shared/components/_public_recording_row.html.erb index 4c1536f1d3..43be87e57e 100644 --- a/app/views/shared/components/_public_recording_row.html.erb +++ b/app/views/shared/components/_public_recording_row.html.erb @@ -32,7 +32,7 @@ <% 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 %> diff --git a/app/views/shared/settings/_account.html.erb b/app/views/shared/settings/_account.html.erb index f0b579e1a9..298858e4e8 100644 --- a/app/views/shared/settings/_account.html.erb +++ b/app/views/shared/settings/_account.html.erb @@ -27,7 +27,7 @@
<%= f.label t("email"), class: "form-label" %>
- <%= 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? %>
@@ -63,10 +63,10 @@ <%= f.label t("settings.account.image"), class: "form-label mt-5" %>
- <% if current_user.image.blank? %> - <%= current_user.name.first %> + <% if @user.image.blank? %> + <%= @user.name.first %> <% else %> - + <% end %>
diff --git a/app/views/shared/settings/_setting_view.html.erb b/app/views/shared/settings/_setting_view.html.erb index a2c65c6093..4c8b8bd266 100644 --- a/app/views/shared/settings/_setting_view.html.erb +++ b/app/views/shared/settings/_setting_view.html.erb @@ -21,10 +21,6 @@
- <% unless (defined?(admin_view)).nil? %> - <%= render "shared/admin_settings/#{setting_id}" %> - <% else %> - <%= render "shared/settings/#{setting_id}" %> - <% end %> + <%= render "shared/settings/#{setting_id}" %> <% end %> diff --git a/db/migrate/20190726153012_add_custom_roles.rb b/db/migrate/20190726153012_add_custom_roles.rb index dfe5d78335..1c0b1fd623 100644 --- a/db/migrate/20190726153012_add_custom_roles.rb +++ b/db/migrate/20190726153012_add_custom_roles.rb @@ -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")