Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into radjabov
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed Nov 4, 2024
2 parents 54d72d0 + 0a3bfeb commit 873d25c
Show file tree
Hide file tree
Showing 61 changed files with 274 additions and 577 deletions.
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
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
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
45 changes: 14 additions & 31 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ def show_list
process_show_list(:dbname => :service, :gtl_dbname => :service)
end

def show
super
@options = {}
@view, @pages = get_view(Vm, :parent => @record, :parent_method => :all_vms, :all_pages => true)
end

def button
case params[:pressed]
when 'service_tag'
Expand All @@ -38,6 +32,8 @@ def button
javascript_redirect(:action => 'service_reconfigure', :id => params[:id])
when "custom_button"
@display == 'generic_objects' ? generic_object_custom_buttons : custom_buttons
when "generic_object_tag"
tag(GenericObject)
else
add_flash(_("Invalid button action"), :error)
render_flash
Expand All @@ -48,7 +44,7 @@ def generic_object_custom_buttons
display_options = {}
ids = @lastaction == 'generic_object' ? @sb[:rec_id] : 'LIST'
display_options[:display] = @display
display_options[:record_id] = parse_nodetype_and_id(x_node).last
display_options[:record_id] = @sb[:rec_id]
display_options[:display_id] = params[:id] if @lastaction == 'generic_object'
custom_buttons(ids, display_options)
end
Expand All @@ -57,20 +53,18 @@ def title
_("My Services")
end

def toolbar
return 'generic_object_center' if %w[generic_objects].include?(@display) # for nested generic objects list screen

%w[show_list].include?(@lastaction) ? 'services_center' : 'service_center'
end

def set_display
@display = params[:display]
@display ||= default_display unless pagination_or_gtl_request?
@display ||= 'generic_objects' if role_allows?(:feature => "generic_object_view") && @record.number_of(:generic_objects).positive?
end

def show_generic_object
if params[:generic_object_id]
show_single_generic_object
else
display_nested_list(@display)
end
end

def edit
assert_privileges("service_edit")
checked = find_checked_items
Expand Down Expand Up @@ -101,27 +95,17 @@ def service_form_fields
}
end

# display a single generic object
#
def show_single_generic_object
return unless init_show_variables

@lastaction = 'generic_object'
@item = @record.generic_objects.find { |e| e[:id] == params[:generic_object_id].to_i }
drop_breadcrumb(:name => _("%{name} (All Generic Objects)") % {:name => @record.name}, :url => show_link(@record, :display => 'generic_objects'))
drop_breadcrumb(:name => @item.name, :url => show_link(@record, :display => 'generic_objects', :generic_object_id => params[:generic_object_id]))
@view = get_db_view(GenericObject)
@sb[:rec_id] = params[:generic_object_id]
@record = @item
show_item
end

def self.display_methods
%w[generic_objects custom_button_events]
end

def display_generic_objects
nested_list(GenericObject)

if params[:generic_object_id]
generic_object_id = params[:generic_object_id]
redirect_to(:controller => 'generic_object', :action => "show", :id => generic_object_id)
end
end

def reconfigure_form_fields
Expand Down Expand Up @@ -287,5 +271,4 @@ def hide_record_info?
menu_section :svc
feature_for_actions "service_view", *ADV_SEARCH_ACTIONS
has_custom_buttons
toolbar :service, :services
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class ApplicationHelper::Toolbar::GenericObjectCenter < ApplicationHelper::Toolb
:generic_object_tag,
'pficon pficon-edit fa-lg',
N_('Edit Tags for this Generic Object Instance'),
N_('Edit Tags')),
N_('Edit Tags'),
:send_checked => true,
:enabled => false,
:onwhen => "1+"
),
]
),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def relationship_table_screen?
return false if @display.nil?
display_class = @display.camelize.singularize
return false unless custom_button_appliable_class?(display_class)
# Don't render custom buttons on nested generic object lists since it could contain generic objects with different definitions and custom buttons
return false if @display == 'generic_objects'

show_action = @lastaction == "show"
display_model = custom_button_class_model(display_class)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/service_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def textual_generic_object_instances
num = @record.number_of(:generic_objects)
h = {:label => _("Instances"), :value => num}
if role_allows?(:feature => "generic_object_view") && num.positive?
h.update(:link => url_for_only_path(:action => 'show', :id => @record, :display => 'generic_objects', :type => 'tile'),
h.update(:link => url_for_only_path(:action => 'show', :id => @record, :display => 'generic_objects'),
:title => _('Show Generic Object Instances for this Service'))
end
h
Expand Down
5 changes: 5 additions & 0 deletions app/javascript/components/gtl-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ const GtlView = ({
const [state, dispatch] = useReducer(gtlReducer, initState);

useEffect(() => {
// If id is explorer_wide, change back to explorer to ensure search bar fits on the same line of the page.
if (document.getElementById('explorer_wide')) {
document.getElementById('explorer_wide').setAttribute('id', 'explorer');
}

// eslint-disable-next-line no-unused-expressions
if (!noFlashDiv) {
flashMessages && flashMessages.forEach((message) => add_flash(message.message, message.level));
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/oldjs/components/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
require('./ae_resolve_options/ae-resolve-options.js');
require('./index.js');
require('./miq-button.js');
require('./miq_ae_class/namespace-form.js');
require('./provider-option-field-input.js');
require('./provier-option-section.js');
require('./sanitize.js');
require('./verify-button.js');
Loading

0 comments on commit 873d25c

Please sign in to comment.