foreman_scc_manager 2.2.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/javascripts/foreman_scc_manager/locale/de/foreman_scc_manager.js +592 -0
  4. data/app/assets/javascripts/foreman_scc_manager/locale/el/foreman_scc_manager.js +592 -0
  5. data/app/assets/javascripts/foreman_scc_manager/locale/en/foreman_scc_manager.js +592 -0
  6. data/app/assets/javascripts/foreman_scc_manager/locale/fr/foreman_scc_manager.js +592 -0
  7. data/app/assets/javascripts/foreman_scc_manager/locale/ja/foreman_scc_manager.js +592 -0
  8. data/app/assets/javascripts/foreman_scc_manager/locale/ka/foreman_scc_manager.js +592 -0
  9. data/app/assets/javascripts/foreman_scc_manager/locale/zh_CN/foreman_scc_manager.js +592 -0
  10. data/app/controllers/api/v2/scc_accounts_controller.rb +21 -17
  11. data/app/controllers/api/v2/scc_products_controller.rb +2 -2
  12. data/app/controllers/scc_accounts_controller.rb +14 -8
  13. data/app/lib/actions/scc_manager/subscribe_product.rb +14 -14
  14. data/app/lib/actions/scc_manager/sync_products.rb +6 -6
  15. data/app/lib/actions/scc_manager/sync_repositories.rb +5 -5
  16. data/app/models/scc_account.rb +2 -2
  17. data/app/models/scc_product.rb +4 -4
  18. data/app/views/api/v2/scc_products/main.json.rabl +1 -1
  19. data/db/migrate/20200520281300_fix_scc_permissions.rb +1 -1
  20. data/db/migrate/20210713092440_add_permissions.rb +1 -1
  21. data/db/migrate/20220429102717_populate_scc_katello_repositories.rb +1 -0
  22. data/lib/foreman_scc_manager/engine.rb +41 -46
  23. data/lib/foreman_scc_manager/version.rb +1 -1
  24. data/lib/tasks/rubocop.rake +2 -2
  25. data/lib/tasks/setup_authentication_token.rake +1 -1
  26. data/locale/Makefile +8 -10
  27. data/locale/fr/LC_MESSAGES/foreman_scc_manager.mo +0 -0
  28. data/locale/fr/foreman_scc_manager.po +601 -0
  29. data/package.json +12 -15
  30. data/test/controllers/api/v2/scc_accounts_test.rb +21 -21
  31. data/test/controllers/scc_accounts_controller_test.rb +9 -9
  32. data/test/features/sync_test.rb +9 -9
  33. data/test/fixtures/models/scc_repositories.yml +1 -1
  34. data/test/models/scc_account_test.rb +3 -3
  35. data/test/models/scc_product_test.rb +1 -1
  36. data/test/support/fixtures_support.rb +1 -1
  37. data/test/test_plugin_helper.rb +4 -4
  38. data/webpack/components/SCCProductPage/components/SCCProductPicker/components/SCCTreePicker/components/SCCRepoPicker/index.js +8 -8
  39. data/webpack/components/SCCProductPage/components/SCCProductPicker/components/SCCTreePicker/index.js +4 -12
  40. data/webpack/components/SCCProductPage/components/SCCProductView/components/SCCRepoView/index.js +4 -4
  41. metadata +14 -20
  42. data/locale/action_names.rb +0 -88
@@ -33,7 +33,8 @@ class SccAccountsController < ApplicationController
33
33
  end
34
34
 
35
35
  # GET /scc_accounts/1/edit
36
- def edit; end
36
+ def edit
37
+ end
37
38
 
38
39
  # POST /scc_accounts/test_connection
39
40
  def test_connection
@@ -84,8 +85,8 @@ class SccAccountsController < ApplicationController
84
85
 
85
86
  if scc_products_to_subscribe.count > 0
86
87
  ForemanTasks.async_task(::Actions::BulkAction,
87
- ::Actions::SccManager::SubscribeProduct,
88
- scc_products_to_subscribe)
88
+ ::Actions::SccManager::SubscribeProduct,
89
+ scc_products_to_subscribe)
89
90
  success _('Task to subscribe products started.')
90
91
  else
91
92
  warning _('No products selected.')
@@ -114,17 +115,22 @@ class SccAccountsController < ApplicationController
114
115
 
115
116
  def scc_product_hash(scc_product)
116
117
  scc_product_json = scc_product.as_json(:only => [:scc_id, :id, :arch, :version, :product_id, :subscription_valid],
117
- include: { :scc_repositories => { :only => [:id, :name, :subscription_valid] } })
118
+ :include => { :scc_repositories => { :only => [:id, :name, :subscription_valid] } })
118
119
  .merge('name' => scc_product.pretty_name, 'product_category' => scc_product.product_category)
119
120
  # find if and which Katello root repository is associated with this SCC product
120
- repo_ids_katello = scc_product.product.blank? || scc_product.product.root_repository_ids.blank? ? nil : scc_product.product.root_repository_ids
121
+ repo_ids_katello = scc_product&.product&.root_repository_ids
121
122
  scc_product_json['scc_repositories'].each do |repo|
122
- # byebug
123
123
  if repo_ids_katello.blank?
124
- repo['katello_root_repository_id'] = nil
124
+ repo['katello_repository_id'] = nil
125
125
  else
126
126
  repo_ids_scc = scc_product.scc_repositories.find(repo['id']).katello_root_repository_ids
127
- repo['katello_root_repository_id'] = repo_ids_scc.blank? ? nil : (repo_ids_scc & repo_ids_katello).first
127
+ if repo_ids_scc.blank?
128
+ repo['katello_repository_id'] = nil
129
+ else
130
+ # we need to extract the library instance id for the correct repo link in the UI
131
+ root_repo_id = (repo_ids_scc & repo_ids_katello).first
132
+ repo['katello_repository_id'] = ::Katello::Repository.where({ root_id: root_repo_id, library_instance: nil }).pick(:id)
133
+ end
128
134
  end
129
135
  end
130
136
  scc_product_json
@@ -17,10 +17,10 @@ module Actions
17
17
  sequence do
18
18
  if scc_product.product_id.nil?
19
19
  product_create_action = plan_action(CreateProduct,
20
- :product_name => scc_product.pretty_name,
21
- :product_description => scc_product.pretty_description,
22
- :organization_id => scc_product.organization.id,
23
- :gpg_key => scc_product.scc_account.katello_gpg_key_id)
20
+ :product_name => scc_product.pretty_name,
21
+ :product_description => scc_product.pretty_description,
22
+ :organization_id => scc_product.organization.id,
23
+ :gpg_key => scc_product.scc_account.katello_gpg_key_id)
24
24
  end
25
25
  katello_repos = {}
26
26
  # we need to set the repositories to subscribe to
@@ -48,14 +48,14 @@ module Actions
48
48
  scc_repos.each do |repo|
49
49
  arch = scc_product.arch || 'noarch'
50
50
  repo_create_action = plan_action(CreateRepository,
51
- :product_id => scc_product.product_id || product_create_action.output[:product_id],
52
- :uniq_name => repo.uniq_name(scc_product),
53
- :pretty_repo_name => repo.pretty_name,
54
- :url => repo.url,
55
- :token => repo.token,
56
- :arch => arch,
57
- :download_policy => scc_product.scc_account.download_policy,
58
- :mirroring_policy => scc_product.scc_account.mirroring_policy)
51
+ :product_id => scc_product.product_id || product_create_action.output[:product_id],
52
+ :uniq_name => repo.uniq_name(scc_product),
53
+ :pretty_repo_name => repo.pretty_name,
54
+ :url => repo.url,
55
+ :token => repo.token,
56
+ :arch => arch,
57
+ :download_policy => scc_product.scc_account.download_policy,
58
+ :mirroring_policy => scc_product.scc_account.mirroring_policy)
59
59
  katello_repos[repo.id] = repo_create_action.output[:katello_root_repository_id]
60
60
  end
61
61
 
@@ -99,8 +99,8 @@ module Actions
99
99
  end
100
100
  product.description = input[:product_description]
101
101
  trigger(::Actions::Katello::Product::Create,
102
- product,
103
- Organization.find(input[:organization_id])).tap do
102
+ product,
103
+ Organization.find(input[:organization_id])).tap do
104
104
  output[:product_id] = product.id
105
105
  end
106
106
  end
@@ -7,16 +7,16 @@ module Actions
7
7
  action_subject(scc_account)
8
8
  password = encrypt_field(scc_account.password)
9
9
  plan_self(id: scc_account.id,
10
- base_url: scc_account.base_url,
11
- login: scc_account.login,
12
- password: password)
10
+ base_url: scc_account.base_url,
11
+ login: scc_account.login,
12
+ password: password)
13
13
  end
14
14
 
15
15
  def run
16
16
  products = ::SccManager.get_scc_data(input.fetch(:base_url),
17
- '/connect/organizations/products',
18
- input.fetch(:login),
19
- decrypt_field(input.fetch(:password)))
17
+ '/connect/organizations/products',
18
+ input.fetch(:login),
19
+ decrypt_field(input.fetch(:password)))
20
20
  output[:data] = ::SccManager.sanitize_products(products).values
21
21
  rescue StandardError => e
22
22
  ::Foreman::Logging.logger('foreman_scc_manager').error "Error while syncronizing SCC-Products: #{e}"
@@ -7,15 +7,15 @@ module Actions
7
7
  action_subject(scc_account)
8
8
  password = encrypt_field(scc_account.password)
9
9
  plan_self(base_url: scc_account.base_url,
10
- login: scc_account.login,
11
- password: password)
10
+ login: scc_account.login,
11
+ password: password)
12
12
  end
13
13
 
14
14
  def run
15
15
  output[:data] = ::SccManager.get_scc_data(input[:base_url],
16
- '/connect/organizations/repositories',
17
- input[:login],
18
- decrypt_field(input[:password]))
16
+ '/connect/organizations/repositories',
17
+ input[:login],
18
+ decrypt_field(input[:password]))
19
19
  rescue StandardError => e
20
20
  ::Foreman::Logging.logger('foreman_scc_manager').error "Error while syncronizing SCC-Repositories: #{e}"
21
21
  error! e.to_s
@@ -289,7 +289,7 @@ class SccAccount < ApplicationRecord
289
289
  def self.download_policy_selection_values
290
290
  names = {
291
291
  ::Katello::RootRepository::DOWNLOAD_ON_DEMAND => _('On Demand'),
292
- ::Katello::RootRepository::DOWNLOAD_IMMEDIATE => _('Immediate')
292
+ ::Katello::RootRepository::DOWNLOAD_IMMEDIATE => _('Immediate'),
293
293
  }
294
294
 
295
295
  ::Katello::RootRepository::DOWNLOAD_POLICIES.map do |p|
@@ -300,7 +300,7 @@ class SccAccount < ApplicationRecord
300
300
  def self.mirroring_policy_selection_values
301
301
  names = {
302
302
  ::Katello::RootRepository::MIRRORING_POLICY_ADDITIVE => _('Additive'),
303
- ::Katello::RootRepository::MIRRORING_POLICY_CONTENT => _('Content Only')
303
+ ::Katello::RootRepository::MIRRORING_POLICY_CONTENT => _('Content Only'),
304
304
  }
305
305
 
306
306
  ::Katello::RootRepository::MIRRORING_POLICIES.map do |p|
@@ -13,10 +13,10 @@ class SccProduct < ApplicationRecord
13
13
  has_many :scc_extendings, inverse_of: :scc_product, dependent: :destroy
14
14
  has_many :scc_extensions, through: :scc_extendings
15
15
  has_many :inverse_scc_extendings,
16
- inverse_of: :scc_extension,
17
- dependent: :destroy,
18
- class_name: :SccExtending,
19
- foreign_key: :scc_extension_id
16
+ inverse_of: :scc_extension,
17
+ dependent: :destroy,
18
+ class_name: :SccExtending,
19
+ foreign_key: :scc_extension_id
20
20
  has_many :inverse_scc_extensions, through: :inverse_scc_extendings, source: :scc_product
21
21
 
22
22
  default_scope -> { order(:name) }
@@ -2,4 +2,4 @@
2
2
 
3
3
  object @scc_product
4
4
  extends 'api/v2/scc_products/base'
5
- attributes :organization_id, :organization_name, :scc_account_id, :name, :arch, :friendly_name, :description, :product_id
5
+ attributes :scc_account_id, :name, :arch, :friendly_name, :description, :product_id
@@ -5,7 +5,7 @@ class FixSccPermissions < ActiveRecord::Migration[5.2]
5
5
  :new_scc => :new_scc_accounts,
6
6
  :edit_scc => :edit_scc_accounts,
7
7
  :delete_scc => :delete_scc_accounts,
8
- :sync_scc => :sync_scc_accounts
8
+ :sync_scc => :sync_scc_accounts,
9
9
  }.freeze
10
10
 
11
11
  def up
@@ -1,7 +1,7 @@
1
1
  class AddPermissions < ActiveRecord::Migration[6.0]
2
2
  PRODUCT_PERMISSION_NAMES = [
3
3
  'view_scc_products',
4
- 'subscribe_scc_products'
4
+ 'subscribe_scc_products',
5
5
  ].freeze
6
6
 
7
7
  def up
@@ -3,6 +3,7 @@ class PopulateSccKatelloRepositories < ActiveRecord::Migration[6.0]
3
3
  belongs_to :product, class_name: 'Katello::Product'
4
4
  has_and_belongs_to_many :scc_repositories
5
5
  end
6
+
6
7
  class SccRepository < ApplicationRecord
7
8
  has_many :scc_katello_repositories
8
9
  has_many :katello_root_repositories, through: :scc_katello_repositories
@@ -22,8 +22,9 @@ module ForemanSccManager
22
22
 
23
23
  initializer 'foreman_scc_manager.register_plugin', :before => :finisher_hook do |_app|
24
24
  Foreman::Plugin.register :foreman_scc_manager do
25
- requires_foreman '>= 2.1'
25
+ requires_foreman '>= 3.7'
26
26
  requires_foreman_plugin 'katello', '>= 3.16.0'
27
+ register_gettext
27
28
 
28
29
  precompile_assets 'foreman_scc_manager/scc_accounts.js'
29
30
 
@@ -32,77 +33,77 @@ module ForemanSccManager
32
33
  # Add permissions
33
34
  security_block :foreman_scc_manager do
34
35
  permission :view_scc_accounts,
35
- { :scc_accounts => [:show, :index, :auto_complete_search],
36
- :'api/v2/scc_accounts' => [:show, :index, :auto_complete_search] },
37
- :resource_type => 'SccAccount'
36
+ { :scc_accounts => [:show, :index, :auto_complete_search],
37
+ :'api/v2/scc_accounts' => [:show, :index, :auto_complete_search] },
38
+ :resource_type => 'SccAccount'
38
39
 
39
40
  permission :use_scc_accounts,
40
- { :scc_accounts => [:bulk_subscribe],
41
- :'api/v2/scc_accounts' => [:bulk_subscribe, :bulk_subscribe_with_repos] },
42
- :resource_type => 'SccAccount'
41
+ { :scc_accounts => [:bulk_subscribe],
42
+ :'api/v2/scc_accounts' => [:bulk_subscribe, :bulk_subscribe_with_repos] },
43
+ :resource_type => 'SccAccount'
43
44
 
44
45
  permission :new_scc_accounts,
45
- { :scc_accounts => [:new, :create],
46
- :'api/v2/scc_accounts' => [:create] },
47
- :resource_type => 'SccAccount'
46
+ { :scc_accounts => [:new, :create],
47
+ :'api/v2/scc_accounts' => [:create] },
48
+ :resource_type => 'SccAccount'
48
49
 
49
50
  permission :edit_scc_accounts,
50
- { :scc_accounts => [:edit, :update],
51
- :'api/v2/scc_accounts' => [:update] },
52
- :resource_type => 'SccAccount'
51
+ { :scc_accounts => [:edit, :update],
52
+ :'api/v2/scc_accounts' => [:update] },
53
+ :resource_type => 'SccAccount'
53
54
 
54
55
  permission :delete_scc_accounts,
55
- { :scc_accounts => [:destroy],
56
- :'api/v2/scc_accounts' => [:destroy] },
57
- :resource_type => 'SccAccount'
56
+ { :scc_accounts => [:destroy],
57
+ :'api/v2/scc_accounts' => [:destroy] },
58
+ :resource_type => 'SccAccount'
58
59
 
59
60
  permission :sync_scc_accounts,
60
- { :scc_accounts => [:sync],
61
- :'api/v2/scc_accounts' => [:sync] },
62
- :resource_type => 'SccAccount'
61
+ { :scc_accounts => [:sync],
62
+ :'api/v2/scc_accounts' => [:sync] },
63
+ :resource_type => 'SccAccount'
63
64
 
64
65
  permission :test_connection_scc_accounts,
65
- { :scc_accounts => [:test_connection],
66
- :'api/v2/scc_accounts' => [:test_connection] },
67
- :resource_type => 'SccAccount'
66
+ { :scc_accounts => [:test_connection],
67
+ :'api/v2/scc_accounts' => [:test_connection] },
68
+ :resource_type => 'SccAccount'
68
69
 
69
70
  permission :view_scc_products,
70
- { :scc_products => [:index, :show],
71
- :'api/v2/scc_products' => [:index, :show] },
72
- :resource_type => 'SccProduct'
71
+ { :scc_products => [:index, :show],
72
+ :'api/v2/scc_products' => [:index, :show] },
73
+ :resource_type => 'SccProduct'
73
74
 
74
75
  permission :subscribe_scc_products,
75
- { :scc_products => [:subscribe, :unsubscribe],
76
- :'api/v2/scc_products' => [:subscribe, :unsibscribe] },
77
- :resource_type => 'SccProduct'
76
+ { :scc_products => [:subscribe, :unsubscribe],
77
+ :'api/v2/scc_products' => [:subscribe, :unsibscribe] },
78
+ :resource_type => 'SccProduct'
78
79
  end
79
80
 
80
81
  # Add a new role called 'SccManager' if it doesn't exist
81
82
  role 'SccManager',
82
- %i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts
83
- delete_scc_accounts sync_scc_accounts test_connection_scc_accounts
84
- view_scc_products subscribe_scc_products],
85
- 'Role granting permissons to manage SUSE Subscriptions'
83
+ %i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts
84
+ delete_scc_accounts sync_scc_accounts test_connection_scc_accounts
85
+ view_scc_products subscribe_scc_products],
86
+ 'Role granting permissons to manage SUSE Subscriptions'
86
87
 
87
88
  role 'SccViewer',
88
- %i[view_scc_accounts use_scc_accounts sync_scc_accounts
89
- create_products view_products subscribe_scc_products view_scc_products],
90
- 'Role granting permissons to view and use SUSE Subscriptions'
89
+ %i[view_scc_accounts use_scc_accounts sync_scc_accounts
90
+ create_products view_products subscribe_scc_products view_scc_products],
91
+ 'Role granting permissons to view and use SUSE Subscriptions'
91
92
 
92
93
  add_all_permissions_to_default_roles
93
94
 
94
95
  # add menu entry
95
96
  menu :top_menu, :scc_manager,
96
- url_hash: { controller: :scc_accounts, action: :index },
97
- caption: _('SUSE Subscriptions'),
98
- parent: :content_menu,
99
- after: :red_hat_subscriptions
97
+ url_hash: { controller: :scc_accounts, action: :index },
98
+ caption: _('SUSE Subscriptions'),
99
+ parent: :content_menu,
100
+ after: :red_hat_subscriptions
100
101
  end
101
102
  end
102
103
 
103
104
  initializer 'foreman_scc_manager.register_actions', :before => :finisher_hook do |_app|
104
105
  ForemanTasks.dynflow.require!
105
- action_paths = %W[#{ForemanSccManager::Engine.root}/app/lib/actions]
106
+ action_paths = [ForemanSccManager::Engine.root.join('app/lib/actions')]
106
107
  ForemanTasks.dynflow.config.eager_load_paths.concat(action_paths)
107
108
  end
108
109
 
@@ -129,11 +130,5 @@ module ForemanSccManager
129
130
  ForemanSccManager::Engine.load_seed
130
131
  end
131
132
  end
132
-
133
- initializer 'foreman_scc_manager.register_gettext', after: :load_config_initializers do |_app|
134
- locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
135
- locale_domain = 'foreman_scc_manager'
136
- Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
137
- end
138
133
  end
139
134
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '2.2.3'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -9,7 +9,7 @@ begin
9
9
  "#{ForemanSccManager::Engine.root}/db/**/*.rb",
10
10
  "#{ForemanSccManager::Engine.root}/lib/**/*.rake",
11
11
  "#{ForemanSccManager::Engine.root}/lib/**/*.rb",
12
- "#{ForemanSccManager::Engine.root}/test/**/*.rb"
12
+ "#{ForemanSccManager::Engine.root}/test/**/*.rb",
13
13
  ]
14
14
 
15
15
  namespace :foreman_scc_manager do
@@ -27,5 +27,5 @@ begin
27
27
  end
28
28
  end
29
29
  rescue LoadError
30
- puts 'Rubocop not loaded.'
30
+ # 'Rubocop not loaded.'
31
31
  end
@@ -23,5 +23,5 @@ begin
23
23
  end
24
24
  end
25
25
  rescue LoadError
26
- puts 'Rubocop not loaded.'
26
+ # 'Rubocop not loaded.'
27
27
  end
data/locale/Makefile CHANGED
@@ -14,6 +14,7 @@ POFILES = $(shell find . -name '$(DOMAIN).po')
14
14
  MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
15
  POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
16
  EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+ JSFILES = $(shell find ../app/assets/javascripts/*/locale -name '$(DOMAIN).js')
17
18
 
18
19
  %.mo: %.po
19
20
  mkdir -p $(shell dirname $@)/LC_MESSAGES
@@ -41,24 +42,21 @@ uniq-po:
41
42
  msguniq $$f -o $$f ; \
42
43
  done
43
44
 
44
- tx-new:
45
- tx pull --minimum-perc 50 --all
46
-
47
- tx-pull: tx-new $(EDITFILES)
48
- tx pull -f
45
+ tx-pull: $(EDITFILES)
46
+ cd .. && tx pull -f --all
49
47
  for f in $(EDITFILES) ; do \
50
48
  sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
51
49
  done
52
50
 
53
51
  tx-update: tx-pull
54
52
  @echo
55
- @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation
54
+ @echo then run rake plugin:po_to_json[$(DOMAIN)] from the Foreman installation
55
+ @echo then run make -C locale mo-files to finish
56
56
  @echo
57
57
 
58
- build-mo-files: $(MOFILES)
59
-
60
- mo-files: build-mo-files
61
- git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
58
+ mo-files: $(MOFILES)
59
+ git add $(POFILES) $(POTFILE) $(JSFILES) ../locale/*/LC_MESSAGES
62
60
  git commit -m "i18n - pulling from tx"
63
61
  @echo
64
62
  @echo Changes commited!