Skip to content

Commit

Permalink
Merge branch 'master' into substring-check
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-samuel authored Nov 6, 2024
2 parents bfa3e89 + 3fada58 commit fee053b
Show file tree
Hide file tree
Showing 72 changed files with 363 additions and 624 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
matrix:
ruby-version:
- '3.0'
- '3.1'
- '3.3'
node-version:
- 18
test-suite:
Expand Down Expand Up @@ -63,6 +63,6 @@ jobs:
- name: Run tests
run: bundle exec rake
- name: Report code coverage
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' && matrix.test-suite == 'spec' }}
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.3' && matrix.test-suite == 'spec' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v5
56 changes: 56 additions & 0 deletions .github/workflows/locale_po_to_json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Locale PO to JSON"

on:
workflow_dispatch:
permissions:
contents: read
jobs:
locale_po_to_json:
if: github.repository_owner == 'ManageIQ'
runs-on: ubuntu-latest
services:
postgres:
image: manageiq/postgresql:13
env:
POSTGRESQL_USER: root
POSTGRESQL_PASSWORD: smartvm
POSTGRESQL_DATABASE: vmdb_i18n
options: --health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
env:
PGHOST: localhost
PGPASSWORD: smartvm
RAILS_ENV: i18n
SKIP_TEST_RESET: true
steps:
- uses: actions/checkout@v4
- name: Set up system
run: bin/before_install
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
bundler-cache: true
timeout-minutes: 30
- name: Prepare dependencies
run: bin/setup
- name: Install gettext for msgfmt --check support
run: sudo apt-get install -y gettext
- name: Run app:locale:po_to_json
run: bundle exec rake app:locale:po_to_json
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
add-paths: |
app/javascript/oldjs/locale
commit-message: Update UI json translation files
branch: update_ui_json_translation_files
author: ManageIQ Bot <[email protected]>
committer: ManageIQ Bot <[email protected]>
delete-branch: true
labels: internationalization
push-to-fork: miq-bot/manageiq-ui-classic
title: Update UI json translation files
body: Update UI json translation files
token: ${{ secrets.PR_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/yarn_lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
committer: ManageIQ Bot <[email protected]>
delete-branch: true
labels: dependencies
assignees: jeffibm
assignees: GilbertCherrie
team-reviewers: ManageIQ/committers-ui
push-to-fork: miq-bot/manageiq-ui-classic
title: Update yarn.lock with latest dependencies
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller/wait_for_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def initiate_wait_for_task(options = {})
session[:async][:params] ||= {}

# save the incoming parms + extra_params
session[:async][:params] = params.deep_dup.merge(options[:extra_params] || {})
session[:async][:params] = params.to_unsafe_h.merge(options[:extra_params] || {})
session[:async][:params][:task_id] = task_id

# override method to be called, when the task is done
Expand Down
36 changes: 17 additions & 19 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class CatalogController < ApplicationController
include Mixins::ServiceDialogCreationMixin
include Mixins::BreadcrumbsMixin
include Mixins::AutomationMixin
include Mixins::ImageValidationMixin

before_action :check_privileges
before_action :get_session_data
Expand Down Expand Up @@ -533,31 +534,28 @@ def st_upload_image

err = false
identify_catalog(params[:id])
image_file = params.dig(:upload, :image)
if params[:pressed]
@record.picture = nil
@record.save
msg = _("Custom Image successfully removed")
elsif params[:upload] && params[:upload][:image] &&
params[:upload][:image].respond_to?(:read)
ext = params[:upload][:image].original_filename.split(".").last.downcase
if !%w[png jpg].include?(ext)
msg = _("Custom Image must be a .png or .jpg file")
err = true
else
picture = {:content => params[:upload][:image].read,
:extension => ext}
if @record.picture.nil?
@record.picture = Picture.new(picture)
else
@record.picture.update(picture)
end
@record.save
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
{:name => params[:upload][:image].original_filename}
end
else
elsif !image_file&.respond_to?(:read)
msg = _("Use the Choose file button to locate a .png or .jpg image file")
err = true
elsif !valid_image_file?(image_file)
msg = _("Custom Image must be a .png or .jpg file")
err = true
else
ext = image_file.original_filename.split(".").last.downcase
picture = {:content => image_file.read, :extension => ext}
if @record.picture.nil?
@record.picture = Picture.new(picture)
else
@record.picture.update(picture)
end
@record.save
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
{:name => image_file.original_filename}
end
params[:id] = x_build_node_id(@record) # Get the tree node id
add_flash(msg, err == true ? :error : nil)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/generic_object_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ def textual_group_list
end

helper_method :textual_group_list
has_custom_buttons
end
25 changes: 17 additions & 8 deletions app/controllers/miq_ae_class_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,11 @@ def method_form_fields
# ManageIQ::Providers::AnsibleTower::Provider.where('zone_id != ?', Zone.maintenance_zone.id)
list_of_managers = ManageIQ::Providers::ExternalAutomationManager
.where(:enabled => true)
.pluck(:id, :name)
.map { |r| {:id => r[0], :name => r[1]} }
.map { |provider| {:id => provider.id, :name => provider.name} }

if method&.options[:ansible_template_id]
manager_id = ManageIQ::Providers::ExternalAutomationManager::ConfigurationScript
.find_by(:id => method.options[:ansible_template_id])&.manager_id
manager_class = get_template_class(method.location)
manager_id = manager_class.find_by(:id => method.options[:ansible_template_id])&.manager_id
end
end

Expand Down Expand Up @@ -1844,6 +1843,14 @@ def ae_method_operations

private

def get_template_class(location)
if location == "ansible_workflow_template"
ManageIQ::Providers::ExternalAutomationManager::ConfigurationWorkflow
else
ManageIQ::Providers::ExternalAutomationManager::ConfigurationScript
end
end

def feature_by_action
features_in_action = %w[
miq_ae_class_copy miq_ae_class_edit miq_ae_class_new
Expand Down Expand Up @@ -2819,13 +2826,15 @@ def get_method_node_info(node_id)
set_right_cell_text(x_node, @record)
end

def fetch_manager_name(ansible_template_id)
def fetch_manager_name(ansible_template_id, klass)
return nil if ansible_template_id.blank?

ManageIQ::Providers::ExternalAutomationManager::ConfigurationScript.find_by(:id => ansible_template_id)&.manager&.name
klass.find_by(:id => ansible_template_id)&.manager&.name
end

def fetch_playbook_details(record)
template_class = get_template_class(record.location)

options = record.options
details = {
:repository => fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource, options[:repository_id]),
Expand All @@ -2837,12 +2846,12 @@ def fetch_playbook_details(record)
:hosts => options[:hosts],
:log_output => options[:log_output],
:ansible_template_id => options[:ansible_template_id],
:manager_name => fetch_manager_name(options[:ansible_template_id]),
:manager_name => fetch_manager_name(options[:ansible_template_id], template_class),
}
details[:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, options[:network_credential_id]) if options[:network_credential_id]
details[:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, options[:cloud_credential_id]) if options[:cloud_credential_id]
details[:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, options[:vault_credential_id]) if options[:vault_credential_id]
details[:ansible_template] = fetch_name_from_object(ManageIQ::Providers::ExternalAutomationManager::ConfigurationScript, options[:ansible_template_id]) if options[:ansible_template_id]
details[:ansible_template] = fetch_name_from_object(template_class, options[:ansible_template_id]) if options[:ansible_template_id]
details
end

Expand Down
6 changes: 1 addition & 5 deletions app/controllers/miq_ae_tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,7 @@ def upload
if params[:upload] && params[:upload][:datastore].present?
begin
MiqAeDatastore.upload(params[:upload][:datastore])
flash_to_session(_("Datastore import was successful.
Namespaces updated/added: %{namespace_stats}
Classes updated/added: %{class_stats}
Instances updated/added: %{instance_stats}
Methods updated/added: %{method_stats}") % stat_options)
flash_to_session(_("Datastore import was successful. Added/Updated %{namespace_stats} Namespaces, %{class_stats} Classes, %{instance_stats} Instances, %{method_stats} Methods.") % stat_options)
redirect_to(:action => 'import_export')
rescue StandardError => bang
flash_to_session(_("Error during 'upload': %{message}") % {:message => bang.message}, :error)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/mixins/custom_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def custom_toolbar_explorer
def custom_toolbar_simple
if @record && %w[show show_dashboard].include?(@lastaction) && %w[dashboard main].include?(@display)
Mixins::CustomButtons::Result.new(:single)
elsif @lastaction == "show_list"
Mixins::CustomButtons::Result.new(:list)
elsif relationship_table_screen?
elsif @lastaction == "show_list" || relationship_table_screen?
Mixins::CustomButtons::Result.new(:list)
elsif @display == 'generic_objects'
@lastaction == 'generic_object' ? Mixins::CustomButtons::Result.new(:single) : Mixins::CustomButtons::Result.new(:list)
Expand Down
32 changes: 32 additions & 0 deletions app/controllers/mixins/image_validation_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Mixins
module ImageValidationMixin
private

# @param file request parameter for a file
# @param ext if present, the only extension supported (default: nil / accept all extensions)
def valid_image_file?(file, type = nil)
ext = file.original_filename.split(".").last.downcase
return false if type && !Array.wrap(type).include?(ext)

valid_magic_number =
case ext
when "ico"
"\x00\x00\x01\x00".force_encoding("ASCII-8BIT")
when "png"
"\x89PNG\r\n\x1A\n".force_encoding("ASCII-8BIT")
when "jpg"
"\xff\xd8\xff".force_encoding("ASCII-8BIT")
else
return false
end

magic_number = File.open(file.tempfile.path, 'rb') do |f|
f.readpartial(valid_magic_number.size)
end

magic_number == valid_magic_number
rescue EOFError
return false
end
end
end
27 changes: 2 additions & 25 deletions app/controllers/ops_controller/settings/upload.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module OpsController::Settings::Upload
extend ActiveSupport::Concern
include Mixins::ImageValidationMixin

def upload_logo
assert_privileges("ops_settings")
Expand Down Expand Up @@ -31,7 +32,7 @@ def upload_favicon

def upload_logos(file, field, text, type)
if field && field[:logo] && field[:logo].respond_to?(:read)
unless valid_file?(field[:logo], type)
unless valid_image_file?(field[:logo], type)
add_flash(_("%{image} must be a .%{type} file") % {:image => text, :type => type}, :error)
else
File.open(file, "wb") { |f| f.write(field[:logo].read) }
Expand Down Expand Up @@ -115,28 +116,4 @@ def logo_dir
Dir.mkdir(dir) unless dir.exist?
dir.to_s
end

def valid_file?(file, type)
ext = file.original_filename.split(".").last.downcase
return false unless ext == type

case type
when "ico"
valid_magic_number = "\x00\x00\x01\x00".force_encoding("ASCII-8BIT")
when "png"
valid_magic_number = "\x89PNG\r\n\x1A\n".force_encoding("ASCII-8BIT")
else
return false
end

magic_number = File.open(file.tempfile.path, 'rb') do |f|
begin
f.readpartial(valid_magic_number.size)
rescue EOFError
return false
end
end

magic_number == valid_magic_number
end
end
Loading

0 comments on commit fee053b

Please sign in to comment.