foreman_scc_manager 1.8.4 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/app/controllers/scc_accounts_controller.rb +20 -1
- data/app/models/scc_account.rb +3 -0
- data/app/models/scc_product.rb +2 -0
- data/app/views/scc_accounts/index.html.erb +4 -3
- data/app/views/scc_accounts/show.html.erb +3 -3
- data/db/migrate/20200520281300_fix_scc_permissions.rb +22 -0
- data/lib/foreman_scc_manager/engine.rb +36 -25
- data/lib/foreman_scc_manager/version.rb +1 -1
- data/lib/tasks/test.rake +1 -1
- data/test/fixtures/models/scc_products.yml +24 -0
- data/test/fixtures/models/scc_repositories.yml +15 -0
- data/test/models/scc_product_test.rb +56 -1
- data/test/support/fixtures_support.rb +3 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4d297d61cfdedf0fb329cba44d7925c052c1c8e80f8f0ec58b1435b90b229fe
|
4
|
+
data.tar.gz: 3b434307e158ce5b45ad3e719a7538895a8bcf8d01c98f449561c8d18d4ba87f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31980bb5ef8302a4015ddc5338a7cbb217e666c271ae03781ba530d3823a8608e8afd9d686f80113280ed9033a033b9988fcf8a7a376e791ed2e4a30d7bf159
|
7
|
+
data.tar.gz: 8ebaf1d499fbe65e28c61177ddfbbc6efdf6d1438dc854493686b3842d41ae8a0d9f3bb6ef66bede4ecb2c5c0c82a40da50221e376d96974e0bca18a684a6eb5
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ for how to install Foreman plugins
|
|
13
13
|
|
14
14
|
| Foreman Version | Katello Version | Plugin Version |
|
15
15
|
| --------------- | --------------- | -------------- |
|
16
|
+
| 2.1 | 3.16 | ~> 1.8.5 |
|
17
|
+
| 2.0 | 3.16 | ~> 1.8.4 |
|
16
18
|
| 1.24 | 3.14 | ~> 1.8.0 |
|
17
19
|
| 1.22 | 3.12 | ~> 1.7.0 |
|
18
20
|
| 1.21 | 3.10 | ~> 1.6.0 |
|
@@ -23,6 +25,9 @@ for how to install Foreman plugins
|
|
23
25
|
| 1.16 | 3.5 | <= 1.3.0 |
|
24
26
|
| 1.15 | 3.4 | ~> 1.1.0 |
|
25
27
|
|
28
|
+
## Documentation
|
29
|
+
The plugin documentation can be found at https://docs.orcharhino.com/sources/management_ui/the_content_menu/suse_subscriptions.html.
|
30
|
+
|
26
31
|
## Contributing
|
27
32
|
|
28
33
|
Fork and send a Pull Request. Thanks!
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class SccAccountsController < ApplicationController
|
2
|
+
helper_method :scc_filtered_products
|
2
3
|
before_action :find_organization
|
3
4
|
before_action :find_resource, only: %i[show edit update destroy sync bulk_subscribe]
|
4
5
|
include Foreman::Controller::AutoCompleteSearch
|
@@ -7,6 +8,11 @@ class SccAccountsController < ApplicationController
|
|
7
8
|
def index
|
8
9
|
@scc_accounts = resource_base.search_for(params[:search], order: params[:order])
|
9
10
|
.paginate(page: params[:page])
|
11
|
+
|
12
|
+
# overwrite the product list with filtered products that do not include products with empty repositories
|
13
|
+
@scc_accounts.each do |scc_account|
|
14
|
+
scc_account.scc_products_with_repos_count = scc_account.scc_products.only_products_with_repos.count
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
18
|
# GET /scc_accounts/new
|
@@ -121,9 +127,22 @@ class SccAccountsController < ApplicationController
|
|
121
127
|
when 'sync', 'test_connection'
|
122
128
|
:sync
|
123
129
|
when 'bulk_subscribe'
|
124
|
-
:
|
130
|
+
:use
|
125
131
|
else
|
126
132
|
super
|
127
133
|
end
|
128
134
|
end
|
135
|
+
|
136
|
+
# Function filters a product list and removes all products without valid repositories
|
137
|
+
# The .order call is necessary to apply the ordering to repository that have already been loaded from the database.
|
138
|
+
# Input parameters:
|
139
|
+
# product_list: list of SccProduct
|
140
|
+
# product_type: return only base products if type is set (default), else all
|
141
|
+
def scc_filtered_products(product_list, product_type = 'base')
|
142
|
+
if product_type == 'base'
|
143
|
+
product_list.only_products_with_repos.where(product_type: 'base').order(:friendly_name)
|
144
|
+
else
|
145
|
+
product_list.only_products_with_repos.order(:friendly_name)
|
146
|
+
end
|
147
|
+
end
|
129
148
|
end
|
data/app/models/scc_account.rb
CHANGED
data/app/models/scc_product.rb
CHANGED
@@ -17,15 +17,16 @@
|
|
17
17
|
<td class="display-two-pane ellipsis">
|
18
18
|
<%= link_to_if_authorized(scc_account.name, hash_for_edit_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer)) %>
|
19
19
|
</td>
|
20
|
-
<td><%= scc_account.
|
20
|
+
<td><%= scc_account.scc_products_with_repos_count.to_s %></td>
|
21
21
|
<td><%= link_to_if(scc_account.sync_task, scc_account.sync_status, scc_account.sync_task) %></td>
|
22
22
|
<td>
|
23
23
|
<%= action_buttons(
|
24
|
-
display_link_if_authorized(_("Select products"), hash_for_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer)),
|
24
|
+
display_link_if_authorized(_("Select products"), hash_for_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer, :permission => 'view_scc_accounts')),
|
25
25
|
display_link_if_authorized(_("Sync"), hash_for_sync_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer),
|
26
26
|
:method => :put),
|
27
|
-
display_delete_if_authorized(hash_for_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer),
|
27
|
+
display_delete_if_authorized(hash_for_scc_account_path(:id => scc_account).merge(:auth_object => scc_account, :authorizer => authorizer, :permission => 'delete_scc_accounts'),
|
28
28
|
:data => { :confirm => _("Delete %s?") % scc_account.to_s })
|
29
|
+
|
29
30
|
) %>
|
30
31
|
</td>
|
31
32
|
</tr>
|
@@ -11,8 +11,8 @@
|
|
11
11
|
</span>
|
12
12
|
<%= scc_product.friendly_name %>
|
13
13
|
<% if scc_product.scc_extensions.any? %>
|
14
|
-
<ul>
|
15
|
-
<% scc_product.scc_extensions
|
14
|
+
<ul style='padding-left: 20px;'>
|
15
|
+
<% scc_filtered_products(scc_product.scc_extensions, 'extension').each do |scc_extension| %>
|
16
16
|
<% render_list_node(f, scc_extension, parent_id + "_" + scc_product.id.to_s) %>
|
17
17
|
<% end %>
|
18
18
|
</ul>
|
@@ -29,7 +29,7 @@
|
|
29
29
|
<div class="tab-pane active" id="primary">
|
30
30
|
<ul>
|
31
31
|
<% if @scc_account.synced %>
|
32
|
-
<% @scc_account.scc_products
|
32
|
+
<% scc_filtered_products(@scc_account.scc_products).each do |scc_product| %>
|
33
33
|
<% render_list_node(f, scc_product) %>
|
34
34
|
<% end %>
|
35
35
|
<% else %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class FixSccPermissions < ActiveRecord::Migration[5.2]
|
2
|
+
PERMISSION_NAMES = {
|
3
|
+
:view_scc => :view_scc_accounts,
|
4
|
+
:use_scc => :use_scc_accounts,
|
5
|
+
:new_scc => :new_scc_accounts,
|
6
|
+
:edit_scc => :edit_scc_accounts,
|
7
|
+
:delete_scc => :delete_scc_accounts,
|
8
|
+
:sync_scc => :sync_scc_accounts
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def up
|
12
|
+
PERMISSION_NAMES.each do |old_n, new_n|
|
13
|
+
Permission.find_by(name: old_n)&.update(name: new_n, resource_type: 'SccAccount')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def down
|
18
|
+
PERMISSION_NAMES.each do |old_n, new_n|
|
19
|
+
Permission.find_by(name: new_n)&.update(name: old_n, resource_type: nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -29,37 +29,48 @@ module ForemanSccManager
|
|
29
29
|
|
30
30
|
# Add permissions
|
31
31
|
security_block :foreman_scc_manager do
|
32
|
-
permission :
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
permission :
|
53
|
-
|
54
|
-
|
55
|
-
|
32
|
+
permission :view_scc_accounts,
|
33
|
+
{ :scc_accounts => [:show, :index],
|
34
|
+
:'api/v2/scc_accounts' => [:show, :index] },
|
35
|
+
:resource_type => 'SccAccount'
|
36
|
+
|
37
|
+
permission :use_scc_accounts,
|
38
|
+
{ :scc_accounts => [:bulk_subscribe],
|
39
|
+
:'api/v2/scc_accounts' => [:bulk_subscribe] },
|
40
|
+
:resource_type => 'SccAccount'
|
41
|
+
|
42
|
+
permission :new_scc_accounts,
|
43
|
+
{ :scc_accounts => [:new, :create],
|
44
|
+
:'api/v2/scc_accounts' => [:create] },
|
45
|
+
:resource_type => 'SccAccount'
|
46
|
+
|
47
|
+
permission :edit_scc_accounts,
|
48
|
+
{ :scc_accounts => [:edit, :update],
|
49
|
+
:'api/v2/scc_accounts' => [:update] },
|
50
|
+
:resource_type => 'SccAccount'
|
51
|
+
|
52
|
+
permission :delete_scc_accounts,
|
53
|
+
{ :scc_accounts => [:destroy],
|
54
|
+
:'api/v2/scc_accounts' => [:destroy] },
|
55
|
+
:resource_type => 'SccAccount'
|
56
|
+
|
57
|
+
permission :sync_scc_accounts,
|
58
|
+
{ :scc_accounts => [:sync],
|
59
|
+
:'api/v2/scc_accounts' => [:sync] },
|
60
|
+
:resource_type => 'SccAccount'
|
56
61
|
end
|
57
62
|
|
58
63
|
# Add a new role called 'SccManager' if it doesn't exist
|
59
64
|
role 'SccManager',
|
60
|
-
%i[
|
65
|
+
%i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts delete_scc_accounts sync_scc_accounts],
|
61
66
|
'Role granting permissons to manage SUSE Subscriptions'
|
62
67
|
|
68
|
+
role 'SccViewer',
|
69
|
+
%i[view_scc_accounts use_scc_accounts sync_scc_accounts create_products view_products],
|
70
|
+
'Role granting permissons to view and use SUSE Subscriptions'
|
71
|
+
|
72
|
+
add_all_permissions_to_default_roles
|
73
|
+
|
63
74
|
# add menu entry
|
64
75
|
menu :top_menu, :scc_manager,
|
65
76
|
url_hash: { controller: :scc_accounts, action: :index },
|
data/lib/tasks/test.rake
CHANGED
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
namespace :jenkins do
|
16
16
|
desc 'Test ForemanSccManager with XML output for jenkins'
|
17
|
-
task 'foreman_scc_manager' do
|
17
|
+
task 'foreman_scc_manager' => :environment do
|
18
18
|
Rake::Task['jenkins:setup:minitest'].invoke
|
19
19
|
Rake::Task['rake:test:foreman_scc_manager'].invoke
|
20
20
|
end
|
@@ -19,3 +19,27 @@ two:
|
|
19
19
|
friendly_name: number two
|
20
20
|
description: lorem ipsum dolor sit amet
|
21
21
|
product_type: extras
|
22
|
+
|
23
|
+
three:
|
24
|
+
scc_account_id: test_account1
|
25
|
+
scc_id: 333
|
26
|
+
name: three
|
27
|
+
version: 3
|
28
|
+
arch: x86_128
|
29
|
+
friendly_name: number three
|
30
|
+
description: lorem ipsum dolor sit amet
|
31
|
+
product_type: base
|
32
|
+
|
33
|
+
# create a couple of products as scc_extensions
|
34
|
+
<% 1.upto(10) do |i| %>
|
35
|
+
p_extension_<%= i %>:
|
36
|
+
scc_account_id: test_account1
|
37
|
+
scc_id: <%= i %>
|
38
|
+
name: p_ext_<%= i%>
|
39
|
+
version: 3
|
40
|
+
arch: x86_128
|
41
|
+
friendly_name: number <%= i%>
|
42
|
+
description: lorem ipsum dolor sit amet
|
43
|
+
product_type: extension
|
44
|
+
<% end %>
|
45
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# repositories for testing the empty repository filtering
|
2
|
+
<% 1.upto(8) do |i| %>
|
3
|
+
repo_<%= i %>:
|
4
|
+
id: <%= i %>
|
5
|
+
scc_account_id: 1
|
6
|
+
scc_id: <%= 63 + i %>
|
7
|
+
name: SLE10-Debuginfo-Updates_<%= i %>
|
8
|
+
distro_target: sles_<%= i %>
|
9
|
+
description: SLE10-Debuginfo-Updates for sles-10-ppc_<%= i %>
|
10
|
+
url: https://updates.suse.com/repo/example_<%= i %>
|
11
|
+
token: token_<%= i %>
|
12
|
+
autorefresh: true
|
13
|
+
installer_updates: false
|
14
|
+
<% end %>
|
15
|
+
|
@@ -17,7 +17,11 @@ end
|
|
17
17
|
|
18
18
|
class SccProductSearchTest < ActiveSupport::TestCase
|
19
19
|
test 'default ordered by name' do
|
20
|
-
|
20
|
+
product_names = ['one', 'two', 'three',
|
21
|
+
'p_ext_1', 'p_ext_10', 'p_ext_2', 'p_ext_3',
|
22
|
+
'p_ext_4', 'p_ext_5', 'p_ext_6', 'p_ext_7',
|
23
|
+
'p_ext_8', 'p_ext_9']
|
24
|
+
assert_equal SccProduct.all.pluck(:name), product_names.sort
|
21
25
|
end
|
22
26
|
|
23
27
|
test 'search name' do
|
@@ -30,3 +34,54 @@ class SccProductSearchTest < ActiveSupport::TestCase
|
|
30
34
|
assert_empty empty
|
31
35
|
end
|
32
36
|
end
|
37
|
+
|
38
|
+
# These produt extension tests are pre-tests for the class ProductEmptyRepoAvailableTests.
|
39
|
+
# They do not test any direct functionality of the plugin.
|
40
|
+
class SccProductExtensionsTest < ActiveSupport::TestCase
|
41
|
+
def setup
|
42
|
+
@product_with_extensions = scc_products(:one)
|
43
|
+
@product_with_extensions.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
|
44
|
+
@product_with_wrong_extensions = scc_products(:two)
|
45
|
+
@product_with_wrong_extensions.scc_extensions = [scc_products(:three)]
|
46
|
+
@product_without_extensions = scc_products(:three)
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'check product extensions available' do
|
50
|
+
assert_equal @product_with_extensions.scc_extensions.count, 10
|
51
|
+
assert_not_empty @product_with_extensions.scc_extensions
|
52
|
+
assert_empty @product_without_extensions.scc_extensions
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'product extension of correct type' do
|
56
|
+
assert_empty(@product_with_extensions.scc_extensions.reject { |p| p.product_type == 'extension' })
|
57
|
+
assert_not_empty(@product_with_wrong_extensions.scc_extensions.reject { |p| p.product_type == 'extension' })
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class SccProductEmptyRepoAvailableTest < ActiveSupport::TestCase
|
62
|
+
def setup
|
63
|
+
@product_with_repos = scc_products(:one)
|
64
|
+
@product_with_repos.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
|
65
|
+
@product_with_repos.scc_repositories = scc_repositories[0..2]
|
66
|
+
@product_with_repos.scc_extensions[1].scc_repositories = scc_repositories[3..4]
|
67
|
+
@product_with_repos.scc_extensions[2].scc_repositories = scc_repositories[5..7]
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'products with empty repositories' do
|
71
|
+
products_with_repos = SccProduct.only_products_with_repos
|
72
|
+
assert_equal SccProduct.all.count { |prod| !prod.scc_repositories.empty? }, 3
|
73
|
+
assert_equal products_with_repos.count, 3
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class SccProductNoRepoTest < ActiveSupport::TestCase
|
78
|
+
def setup
|
79
|
+
@product_with_repos = scc_products(:one)
|
80
|
+
@product_with_repos.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'products without any repositories' do
|
84
|
+
products_with_repos = SccProduct.only_products_with_repos
|
85
|
+
assert_empty products_with_repos
|
86
|
+
end
|
87
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module ForemanSccManager
|
2
2
|
module FixturesSupport
|
3
3
|
FIXTURE_CLASSES = {
|
4
|
-
scc_accounts:
|
5
|
-
scc_products:
|
4
|
+
scc_accounts: ::SccAccount,
|
5
|
+
scc_products: ::SccProduct,
|
6
|
+
scc_repositories: ::SccRepository
|
6
7
|
}.freeze
|
7
8
|
|
8
9
|
def self.set_fixture_classes(test_class)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_scc_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ATIX AG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- db/migrate/20170505063726_add_sync_status_to_scc_account.rb
|
154
154
|
- db/migrate/20180321000000_change_sync_status_to_sync_task.rb
|
155
155
|
- db/migrate/20190417202427_add_recurring_sync.foreman_scc_manager.rb
|
156
|
+
- db/migrate/20200520281300_fix_scc_permissions.rb
|
156
157
|
- lib/foreman_scc_manager.rb
|
157
158
|
- lib/foreman_scc_manager/engine.rb
|
158
159
|
- lib/foreman_scc_manager/version.rb
|
@@ -176,6 +177,7 @@ files:
|
|
176
177
|
- test/fixtures/files/data_subscriptions.json
|
177
178
|
- test/fixtures/models/scc_accounts.yml
|
178
179
|
- test/fixtures/models/scc_products.yml
|
180
|
+
- test/fixtures/models/scc_repositories.yml
|
179
181
|
- test/models/scc_account_test.rb
|
180
182
|
- test/models/scc_product_test.rb
|
181
183
|
- test/support/fixtures_support.rb
|
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
202
|
- !ruby/object:Gem::Version
|
201
203
|
version: '0'
|
202
204
|
requirements: []
|
203
|
-
rubygems_version: 3.
|
205
|
+
rubygems_version: 3.1.2
|
204
206
|
signing_key:
|
205
207
|
specification_version: 4
|
206
208
|
summary: Suse Customer Center plugin for Foreman
|
@@ -210,6 +212,7 @@ test_files:
|
|
210
212
|
- test/test_plugin_helper.rb
|
211
213
|
- test/features/sync_test.rb
|
212
214
|
- test/support/fixtures_support.rb
|
215
|
+
- test/fixtures/models/scc_repositories.yml
|
213
216
|
- test/fixtures/models/scc_products.yml
|
214
217
|
- test/fixtures/models/scc_accounts.yml
|
215
218
|
- test/fixtures/files/data_subscriptions.json
|