foreman_templates 9.1.0 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b520577905d85f390af67f22635c98defb339c3177cfc9b7ecfb8039b3999c2
4
- data.tar.gz: ae67963f134f9b53fe2f4520c028cd8426474e3aa10dc01733a292bbf1bb8284
3
+ metadata.gz: bda8e472a4ae76b0f1480738e9059423a249c4156842deebc385baa2f3c2a5ca
4
+ data.tar.gz: bb04b38ce6791e62f90fcea5a177d38ca62402e6c3037e7f3ed85c416f91696c
5
5
  SHA512:
6
- metadata.gz: 763f1cd44a8a5a91bad924c0c6eb50950b7cd552b762bc767c188eeae9f78d66ecb9f4f15d81012092683a2fff263c19bf2230e622167ec235557fac64244ea7
7
- data.tar.gz: e48d8b9ac3b46195afec1d2913a4ad4a6558dc2a7ea2d325e8f6566b7697ca8780e450ced74b7604d709940660dbdd54a438c6590b4c08fd66b7fa3bdd189f88
6
+ metadata.gz: 3c35d3ca52df290a50a3e1788ea654a0588067ab02278a5b77829bfaec46d8c855ae36f554a608eaf8e9c5797b650d5be1a95ed4e7f8486c905e601068180fc5
7
+ data.tar.gz: b58a200b8374f22481e1397949cc4126315234b6238ce08895acedb628c826515ce9ab514b85942b8388350f0e8939b0d088ccc6641fc4b3b84a1fc65ef16961
@@ -17,9 +17,9 @@ module Api
17
17
 
18
18
  api :POST, "/templates/import/", N_("Initiate Import")
19
19
  param :prefix, String, :required => false, :desc => N_("The string all imported templates should begin with.")
20
- param :associate, Setting::TemplateSync.associate_types.keys, :required => false, :desc => N_("Associate to OS's, Locations & Organizations. Options are: always, new or never.")
20
+ param :associate, ForemanTemplates.associate_types.keys, :required => false, :desc => N_("Associate to OS's, Locations & Organizations. Options are: always, new or never.")
21
21
  param :force, :bool, :required => false, :desc => N_("Update templates that are locked")
22
- param :lock, Setting::TemplateSync.lock_types.keys + ["true", "false", "0", "1"], :required => false, :desc => N_("Lock imported templates")
22
+ param :lock, ForemanTemplates.lock_types.keys + ["true", "false", "0", "1"], :required => false, :desc => N_("Lock imported templates")
23
23
  param :verbose, :bool, :required => false, :desc => N_("Show template diff in response")
24
24
  param_group :foreman_template_sync_params
25
25
  param_group :taxonomies, ::Api::V2::BaseController
@@ -32,7 +32,7 @@ module Api
32
32
  end
33
33
 
34
34
  api :POST, "/templates/export", N_("Initiate Export")
35
- param :metadata_export_mode, Setting::TemplateSync.metadata_export_mode_types.keys, :required => false, :desc => N_("Specify how to handle metadata")
35
+ param :metadata_export_mode, ForemanTemplates.metadata_export_mode_types.keys, :required => false, :desc => N_("Specify how to handle metadata")
36
36
  param :commit_msg, String, :desc => N_("Custom commit message for templates export")
37
37
  param_group :foreman_template_sync_params
38
38
  param_group :taxonomies, ::Api::V2::BaseController
@@ -8,8 +8,8 @@ class UiTemplateSyncsController < ApplicationController
8
8
  end
9
9
 
10
10
  def sync_settings
11
- import_settings = Setting.where :name => Setting::TemplateSync.import_setting_names(['verbose'])
12
- export_settings = Setting.where :name => Setting::TemplateSync.export_setting_names(['verbose'])
11
+ import_settings = setting_definitions(ForemanTemplates::IMPORT_SETTING_NAMES)
12
+ export_settings = setting_definitions(ForemanTemplates::EXPORT_SETTING_NAMES)
13
13
  @results = OpenStruct.new(:import => import_settings, :export => export_settings)
14
14
  end
15
15
 
@@ -45,4 +45,10 @@ class UiTemplateSyncsController < ApplicationController
45
45
  def render_errors(messages, severity = 'danger')
46
46
  render :json => { :error => { :errors => { :base => messages }, full_messages: messages, :severity => severity } }, :status => :unprocessable_entity
47
47
  end
48
+
49
+ private
50
+
51
+ def setting_definitions(short_names)
52
+ short_names.map { |name| Foreman.settings.find("template_sync_#{name}") }
53
+ end
48
54
  end
@@ -1,11 +1,11 @@
1
1
  object @setting
2
2
 
3
3
  node do |setting|
4
- { :name => setting.short_name }
4
+ { :name => setting.name.delete_prefix('template_sync_') }
5
5
  end
6
6
 
7
7
  attributes :id, :value, :description, :settings_type, :default, :full_name
8
8
 
9
9
  node do |setting|
10
- { :selection => setting.selection }
10
+ { :selection => (setting.select_values || {}).map { |key, label| { value: key, label: label } } }
11
11
  end
@@ -0,0 +1,5 @@
1
+ class TemplatesSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
2
+ def up
3
+ Setting.where(category: 'Setting::TemplateSync').update_all(category: 'Setting')
4
+ end
5
+ end
@@ -10,10 +10,6 @@ module ForemanTemplates
10
10
  class Engine < ::Rails::Engine
11
11
  engine_name 'foreman_templates'
12
12
 
13
- initializer 'foreman_templates.load_default_settings', :before => :load_config_initializers do
14
- require_dependency File.expand_path('../../app/models/setting/template_sync.rb', __dir__) if (Setting.table_exists? rescue(false))
15
- end
16
-
17
13
  initializer "foreman_templates.add_rabl_view_path" do
18
14
  Rabl.configure do |config|
19
15
  config.view_paths << ForemanTemplates::Engine.root.join('app', 'views')
@@ -28,10 +24,78 @@ module ForemanTemplates
28
24
 
29
25
  initializer 'foreman_templates.register_plugin', :before => :finisher_hook do
30
26
  Foreman::Plugin.register :foreman_templates do
31
- requires_foreman '>= 1.24'
27
+ requires_foreman '>= 3.2'
32
28
 
33
29
  apipie_documented_controllers ["#{ForemanTemplates::Engine.root}/app/controllers/api/v2/*.rb"]
34
30
 
31
+ settings do
32
+ category(:template_sync, N_('Template Sync')) do
33
+ setting('template_sync_verbose',
34
+ type: :boolean,
35
+ description: N_('Choose verbosity for Rake task importing templates'),
36
+ default: false,
37
+ full_name: N_('Verbosity'))
38
+ setting('template_sync_associate',
39
+ type: :string,
40
+ description: N_('Associate templates to OS, organization and location'),
41
+ default: 'new',
42
+ full_name: N_('Associate'),
43
+ collection: -> { ForemanTemplates.associate_types })
44
+ setting('template_sync_prefix',
45
+ type: :string,
46
+ description: N_('The string that will be added as prefix to imported templates'),
47
+ default: "",
48
+ full_name: N_('Prefix'))
49
+ setting('template_sync_dirname',
50
+ type: :string,
51
+ description: N_('The directory within the Git repo containing the templates'),
52
+ default: '/',
53
+ full_name: N_('Dirname'))
54
+ setting('template_sync_filter',
55
+ type: :string,
56
+ description: N_('Import/export names matching this regex (case-insensitive; snippets are not filtered)'),
57
+ default: '',
58
+ full_name: N_('Filter'))
59
+ setting('template_sync_repo',
60
+ type: :string,
61
+ description: N_('Target path to import/export. Different protocols can be used, for example /tmp/dir, git://example.com, https://example.com, ssh://example.com. When exporting to /tmp, note that production deployments may be configured to use private tmp.'),
62
+ default: 'https://github.com/theforeman/community-templates.git',
63
+ full_name: N_('Repo'))
64
+ setting('template_sync_negate',
65
+ type: :boolean,
66
+ description: N_('Negate the filter for import/export'),
67
+ default: false,
68
+ full_name: N_('Negate'))
69
+ setting('template_sync_branch',
70
+ type: :string,
71
+ description: N_('Default branch in Git repo'),
72
+ default: '',
73
+ full_name: N_('Branch'))
74
+ setting('template_sync_metadata_export_mode',
75
+ type: :string,
76
+ description: N_('Default metadata export mode, refresh re-renders metadata, keep will keep existing metadata, remove exports template without metadata'),
77
+ default: 'refresh',
78
+ full_name: N_('Metadata export mode'),
79
+ collection: -> { ForemanTemplates.metadata_export_mode_types })
80
+ setting('template_sync_force',
81
+ type: :boolean,
82
+ description: N_('Should importing overwrite locked templates?'),
83
+ default: false,
84
+ full_name: N_('Force import'))
85
+ setting('template_sync_lock',
86
+ type: :string,
87
+ description: N_('How to handle lock for imported templates?'),
88
+ default: 'keep',
89
+ full_name: N_('Lock templates'),
90
+ collection: -> { ForemanTemplates.lock_types })
91
+ setting('template_sync_commit_msg',
92
+ type: :string,
93
+ description: N_('Custom commit message for templates export'),
94
+ default: 'Templates export made by a Foreman user',
95
+ full_name: N_('Commit message'))
96
+ end
97
+ end
98
+
35
99
  security_block :templates do
36
100
  permission :import_templates, {
37
101
  :"api/v2/template" => [:import],
@@ -58,6 +122,8 @@ module ForemanTemplates
58
122
  end
59
123
 
60
124
  config.to_prepare do
125
+ Setting::NOT_STRIPPED << 'template_sync_prefix'
126
+
61
127
  Template.include ForemanTemplates::TemplateExtensions
62
128
  end
63
129
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanTemplates
2
- VERSION = '9.1.0'.freeze
2
+ VERSION = '9.2.0'.freeze
3
3
  end
@@ -1,4 +1,19 @@
1
1
  require 'foreman_templates/engine'
2
2
 
3
3
  module ForemanTemplates
4
+ BASE_SETTING_NAMES = %w(repo branch dirname filter negate).freeze
5
+ IMPORT_SETTING_NAMES = (BASE_SETTING_NAMES | %w(prefix associate force lock)).freeze
6
+ EXPORT_SETTING_NAMES = (BASE_SETTING_NAMES | %w(metadata_export_mode commit_msg)).freeze
7
+
8
+ def self.associate_types
9
+ { 'always' => _('Always'), 'new' => _('New'), 'never' => _('Never') }
10
+ end
11
+
12
+ def self.lock_types
13
+ { 'lock' => _('Lock'), 'keep_lock_new' => _('Keep, lock new'), 'keep' => _('Keep, do not lock new'), 'unlock' => _('Unlock') }
14
+ end
15
+
16
+ def self.metadata_export_mode_types
17
+ { 'refresh' => _('Refresh'), 'keep' => _('Keep'), 'remove' => _('Remove') }
18
+ end
4
19
  end
@@ -0,0 +1,2 @@
1
+ const Pagination = () => jest.fn();
2
+ export default Pagination;
@@ -1,6 +1,6 @@
1
1
  // move to some sort of pagination helper in core
2
2
  export const templatesPage = (templates, pagination) => {
3
- const offset = (pagination.page - 1) * pagination.perPage;
3
+ const offset = (pagination.page - 1) * pagination.per_page;
4
4
 
5
- return templates.slice(offset, offset + pagination.perPage);
5
+ return templates.slice(offset, offset + pagination.per_page);
6
6
  };
@@ -12,7 +12,7 @@ export const initialState = Immutable({
12
12
 
13
13
  pagination: {
14
14
  page: 1,
15
- perPage: 20,
15
+ per_page: 20,
16
16
  },
17
17
  });
18
18
 
@@ -4,7 +4,7 @@ exports[`TemplateSyncResultReducer should return initial state 1`] = `
4
4
  Object {
5
5
  "pagination": Object {
6
6
  "page": 1,
7
- "perPage": 20,
7
+ "per_page": 20,
8
8
  },
9
9
  "resultAction": "",
10
10
  "templates": Array [],
@@ -27,7 +27,7 @@ Object {
27
27
  "branch": "master",
28
28
  "pagination": Object {
29
29
  "page": 1,
30
- "perPage": 20,
30
+ "per_page": 20,
31
31
  },
32
32
  "repo": "https://github.com/theforeman/community-templates.git",
33
33
  "resultAction": "import",
@@ -2,13 +2,19 @@ import React from 'react';
2
2
  import { ListView } from 'patternfly-react';
3
3
  import PropTypes from 'prop-types';
4
4
 
5
- import Pagination from 'foremanReact/components/Pagination/PaginationWrapper';
5
+ import Pagination from 'foremanReact/components/Pagination';
6
6
 
7
7
  import SyncedTemplate from './SyncedTemplate';
8
8
  import { templatesPage } from '../TemplateSyncResultHelpers';
9
9
  import ListViewHeader from './ListViewHeader';
10
10
 
11
- const SyncResultList = ({ pagination, pageChange, templates, editPaths }) => (
11
+ const SyncResultList = ({
12
+ pagination,
13
+ pagination: { page, per_page: perPage },
14
+ pageChange,
15
+ templates,
16
+ editPaths,
17
+ }) => (
12
18
  <ListView>
13
19
  <ListViewHeader />
14
20
  {templatesPage(templates, pagination).map((template, idx) => (
@@ -19,11 +25,10 @@ const SyncResultList = ({ pagination, pageChange, templates, editPaths }) => (
19
25
  />
20
26
  ))}
21
27
  <Pagination
22
- viewType="list"
23
28
  itemCount={templates.length}
24
- pagination={pagination}
25
29
  onChange={pageChange}
26
- dropdownButtonId="template-sync-result-dropdown"
30
+ page={page}
31
+ perPage={perPage}
27
32
  />
28
33
  </ListView>
29
34
  );
@@ -31,7 +36,7 @@ const SyncResultList = ({ pagination, pageChange, templates, editPaths }) => (
31
36
  SyncResultList.propTypes = {
32
37
  pagination: PropTypes.shape({
33
38
  page: PropTypes.number,
34
- perPage: PropTypes.number,
39
+ per_page: PropTypes.number,
35
40
  }).isRequired,
36
41
  pageChange: PropTypes.func.isRequired,
37
42
  templates: PropTypes.array.isRequired,
@@ -18,7 +18,7 @@ const fixtures = {
18
18
  editPaths,
19
19
  pagination: {
20
20
  page: 1,
21
- perPage: 20,
21
+ per_page: 20,
22
22
  },
23
23
  },
24
24
  };
@@ -88,17 +88,11 @@ exports[`SyncResultList should render 1`] = `
88
88
  }
89
89
  }
90
90
  />
91
- <PaginationWrapper
92
- dropdownButtonId="template-sync-result-dropdown"
91
+ <Pagination
93
92
  itemCount={5}
94
93
  onChange={[Function]}
95
- pagination={
96
- Object {
97
- "page": 1,
98
- "perPage": 20,
99
- }
100
- }
101
- viewType="list"
94
+ page={1}
95
+ perPage={20}
102
96
  />
103
97
  </ListView>
104
98
  `;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-25 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -69,7 +69,6 @@ files:
69
69
  - app/controllers/ui_template_syncs_controller.rb
70
70
  - app/helpers/foreman_templates_helper.rb
71
71
  - app/models/concerns/foreman_templates/template_extensions.rb
72
- - app/models/setting/template_sync.rb
73
72
  - app/services/foreman_templates/action.rb
74
73
  - app/services/foreman_templates/cleaner.rb
75
74
  - app/services/foreman_templates/export_result.rb
@@ -89,6 +88,7 @@ files:
89
88
  - app/views/ui_template_syncs/template_import_results.json.rabl
90
89
  - config/routes.rb
91
90
  - db/migrate/20180627134929_change_lock_setting.rb
91
+ - db/migrate/20211122154929_templates_settings_category_to_dsl.rb
92
92
  - lib/foreman_templates.rb
93
93
  - lib/foreman_templates/engine.rb
94
94
  - lib/foreman_templates/version.rb
@@ -99,7 +99,7 @@ files:
99
99
  - webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js
100
100
  - webpack/__mocks__/foremanReact/common/helpers.js
101
101
  - webpack/__mocks__/foremanReact/components/Layout/LayoutSelectors.js
102
- - webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js
102
+ - webpack/__mocks__/foremanReact/components/Pagination/index.js
103
103
  - webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js
104
104
  - webpack/__mocks__/foremanReact/components/common/forms/ForemanForm.js
105
105
  - webpack/__mocks__/foremanReact/components/common/forms/TextField.js
@@ -1,115 +0,0 @@
1
- class Setting
2
- class TemplateSync < ::Setting
3
- self.include_root_in_json = false
4
-
5
- def self.common_stripped_names
6
- %w(verbose repo branch dirname filter negate)
7
- end
8
-
9
- def self.import_stripped_names
10
- %w(prefix associate force lock)
11
- end
12
-
13
- def self.export_stripped_names
14
- %w(metadata_export_mode commit_msg)
15
- end
16
-
17
- def self.import_setting_names(except = [])
18
- map_prefix omit_settings(common_stripped_names + import_stripped_names, except)
19
- end
20
-
21
- def self.export_setting_names(except = [])
22
- map_prefix omit_settings(common_stripped_names + export_stripped_names, except)
23
- end
24
-
25
- def self.map_prefix(stripped_names)
26
- stripped_names.map { |item| "template_sync_#{item}" }
27
- end
28
-
29
- def self.omit_settings(setting_names, except_array)
30
- setting_names.reject { |name| except_array.include? name }
31
- end
32
-
33
- def self.associate_types
34
- {
35
- 'always' => _('Always'),
36
- 'new' => _('New'),
37
- 'never' => _('Never')
38
- }
39
- end
40
-
41
- def self.lock_types
42
- {
43
- 'lock' => _('Lock'),
44
- 'keep_lock_new' => _('Keep, lock new'),
45
- 'keep' => _('Keep, do not lock new'),
46
- 'unlock' => _('Unlock')
47
- }
48
- end
49
-
50
- def self.metadata_export_mode_types
51
- {
52
- 'refresh' => _('Refresh'),
53
- 'keep' => _('Keep'),
54
- 'remove' => _('Remove')
55
- }
56
- end
57
-
58
- def short_name
59
- name.split('template_sync_').last
60
- end
61
-
62
- def selection
63
- selection_method = name.split('template_sync_').last.concat('_types')
64
- return transformed_selection(selection_method) if self.class.respond_to?(selection_method)
65
-
66
- []
67
- end
68
-
69
- def self.load_defaults
70
- return unless super
71
-
72
- %w(template_sync_filter template_sync_branch template_sync_prefix).each { |s| Setting::BLANK_ATTRS << s }
73
- Setting::NOT_STRIPPED << 'template_sync_prefix'
74
-
75
- self.transaction do
76
- [
77
- self.set('template_sync_verbose', N_('Choose verbosity for Rake task importing templates'), false, N_('Verbosity')),
78
- self.set('template_sync_associate', N_('Associate templates to OS, organization and location'), 'new', N_('Associate'), nil, { :collection => Proc.new { self.associate_types } }),
79
- self.set('template_sync_prefix', N_('The string that will be added as prefix to imported templates'), "", N_('Prefix')),
80
- self.set('template_sync_dirname', N_('The directory within the Git repo containing the templates'), '/', N_('Dirname')),
81
- self.set('template_sync_filter', N_('Import/export names matching this regex (case-insensitive; snippets are not filtered)'), '', N_('Filter')),
82
- self.set('template_sync_repo', N_('Target path to import/export. Different protocols can be used, for example /tmp/dir, git://example.com, https://example.com, ssh://example.com. When exporting to /tmp, note that production deployments may be configured to use private tmp.'), 'https://github.com/theforeman/community-templates.git', N_('Repo')),
83
- self.set('template_sync_negate', N_('Negate the filter for import/export'), false, N_('Negate')),
84
- self.set('template_sync_branch', N_('Default branch in Git repo'), '', N_('Branch')),
85
- self.set('template_sync_metadata_export_mode', N_('Default metadata export mode, refresh re-renders metadata, keep will keep existing metadata, remove exports template without metadata'), 'refresh', N_('Metadata export mode'), nil, { :collection => Proc.new { self.metadata_export_mode_types } }),
86
- self.set('template_sync_force', N_('Should importing overwrite locked templates?'), false, N_('Force import')),
87
- self.set('template_sync_lock', N_('How to handle lock for imported templates?'), 'keep', N_('Lock templates'), nil, { :collection => Proc.new { self.lock_types } }),
88
- self.set('template_sync_commit_msg', N_('Custom commit message for templates export'), 'Templates export made by a Foreman user', N_('Commit message'))
89
- ].compact.each { |s| self.create! s.update(:category => "Setting::TemplateSync") }
90
- end
91
-
92
- true
93
- end
94
-
95
- def validate_template_sync_associate(record)
96
- values = record.class.associate_types.keys
97
- if record.value && !values.include?(record.value)
98
- record.errors[:base] << (_("template_sync_associate must be one of %s") % values.join(', '))
99
- end
100
- end
101
-
102
- def validate_template_sync_metadata_export_mode(record)
103
- values = record.class.metadata_export_mode_types.keys
104
- if record.value && !values.include?(record.value)
105
- record.errors[:base] << (_("template_sync_metadata_export_mode must be one of %s") % values.join(', '))
106
- end
107
- end
108
-
109
- private
110
-
111
- def transformed_selection(selection_method)
112
- self.class.public_send(selection_method).map { |key, translated| { :value => key, :label => translated } }
113
- end
114
- end
115
- end
@@ -1,2 +0,0 @@
1
- const PaginationWrapper = () => jest.fn();
2
- export default PaginationWrapper;