Skip to content

Commit

Permalink
Fixes #37140 - Update web UI for SCA-only (Katello#10880)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz authored Feb 14, 2024
1 parent 4311086 commit 1bd84c2
Show file tree
Hide file tree
Showing 24 changed files with 13 additions and 355 deletions.
4 changes: 1 addition & 3 deletions app/controllers/katello/api/v2/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ def update
param :organization, Hash do
param :label, String, :required => false
end
param :simple_content_access, :bool, :desc => N_('Whether to turn on Simple Content Access for the organization.'), :required => false, :default => true, deprecated: true
def create
@organization = Organization.new(resource_params)
sca = params.key?(:simple_content_access) ? ::Foreman::Cast.to_bool(params[:simple_content_access]) : true
creator = ::Katello::OrganizationCreator.new(@organization, sca: sca)
creator = ::Katello::OrganizationCreator.new(@organization)
creator.create!
@organization.reload
# @taxonomy instance variable is necessary for foreman side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def create
if taxonomy_class == Organization
begin
@taxonomy = Organization.new(resource_params)
sca = ::Foreman::Cast.to_bool(params[:simple_content_access])
::Foreman::Deprecation.api_deprecation_warning(N_("Simple Content Access will be required for all organizations in Katello 4.12."))
::Katello::OrganizationCreator.new(@taxonomy, sca: sca).create!
::Katello::OrganizationCreator.new(@taxonomy).create!
@taxonomy.reload
switch_taxonomy
if @count_nil_hosts > 0
Expand All @@ -45,20 +43,6 @@ def create
end
end

def update
return if params[:simple_content_access].nil?
sca_param = ::Foreman::Cast.to_bool(params[:simple_content_access])
::Foreman::Deprecation.api_deprecation_warning("Simple Content Access will be required for all organizations in Katello 4.12.")
if sca_param && !@taxonomy.simple_content_access?(cached: false)
# user has requested SCA enable
sync_task(::Actions::Katello::Organization::SimpleContentAccess::Enable, params[:id])
elsif !sca_param && @taxonomy.simple_content_access?(cached: false)
# user has requested SCA disable
sync_task(::Actions::Katello::Organization::SimpleContentAccess::Disable, params[:id])
end
super
end

included do
prepend Overrides
end
Expand Down
18 changes: 0 additions & 18 deletions app/overrides/add_organization_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,8 @@
:text => '<% if taxonomy.is_a?(Location) %><%= render_original %><% end %>'
)

# Add organization attributes to org creation
Deface::Override.new(:virtual_path => "taxonomies/_step1",
:name => "add_organization_attributes_on_create",
:insert_after => 'erb[loud]:contains("text_f"):contains(":name")',
:partial => 'overrides/organizations/step_1_override')

# Add organization attributes to org edit
Deface::Override.new(:virtual_path => "taxonomies/_form",
:name => "add_organization_attributes_on_edit",
:insert_after => 'erb[loud]:contains("text_f"):contains(":name")',
:partial => 'overrides/organizations/edit_override')

# Add Simple Content Access column to org table
Deface::Override.new(:virtual_path => "taxonomies/index",
:name => "add_sca_column_on_index",
:insert_before => 'table th:last-child', # make it the second-to-last column
:partial => 'overrides/organizations/index_header_override')

# Add Simple Content Access cells to org table
Deface::Override.new(:virtual_path => "taxonomies/index",
:name => "add_sca_attributes_on_index",
:insert_before => 'tbody td:last-child',
:partial => 'overrides/organizations/index_row_override')
4 changes: 2 additions & 2 deletions app/services/katello/organization_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def self.create_all_organizations!
end
end

def initialize(organization, sca: true)
def initialize(organization)
@organization = organization
@content_access_mode = sca ? 'org_environment' : 'entitlement'
@content_access_mode = 'org_environment'
end

def seed!
Expand Down
11 changes: 0 additions & 11 deletions app/views/overrides/organizations/_edit_override.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,4 @@
:type => :button, :style => 'margin-top: 8px;', :class => 'btn btn-small',
'data-url' => "/katello/api/v2/organizations/#{@taxonomy.id}/download_debug_certificate"
end %>
<%= field(f, _('Simple Content Access')) do
tag1 = hidden_field_tag 'simple_content_access', '0'
tag2 = check_box_tag 'simple_content_access', '1', @taxonomy.simple_content_access?(cached: false)
tag1 + tag2
end %>

<div class="alert alert-warning" role="alert">
<%= _('Simple Content Access will be required for all organizations in Katello 4.12.') %>
</div>

<% end %>

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/overrides/organizations/_step_1_override.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ <h2>{{ activationKey.name }}</h2>
</div>

<nav data-block="navigation">
<div content-access-mode-banner></div>
<ul class="nav nav-tabs details-nav">
<li ng-class="{active: isState('activation-key.info')}">
<a ui-sref="activation-key.info">
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

34 changes: 0 additions & 34 deletions test/controllers/foreman/organizations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,10 @@ def test_use_newly_created_org
assert_equal session[:organization_id], org.id
end

def test_simple_content_access_disable
# use org with SCA enabled
org = get_organization(:organization2)
Organization.any_instance.stubs(:simple_content_access?).returns true
# assert correct task will be started
@controller.expects(:sync_task).with(::Actions::Katello::Organization::SimpleContentAccess::Disable, org.id.to_s)
# send request to disable SCA
put :update, params: { id: org.id, simple_content_access: false }
assert_response :found
end

def test_simple_content_access_enable
# use org with SCA disabled
org = get_organization(:organization2)
Organization.any_instance.stubs(:simple_content_access?).returns false
# assert correct task will be started
@controller.expects(:sync_task).with(::Actions::Katello::Organization::SimpleContentAccess::Enable, org.id.to_s)
# send request to enable SCA
put :update, params: { id: org.id, simple_content_access: true }
assert_response :found
end

def test_simple_content_access_unchanged
# use org with SCA enabled
org = get_organization(:organization2)
Organization.any_instance.stubs(:simple_content_access?).returns true
# assert SCA task was not initiated
@controller.expects(:async_task).never
# update org and don't change SCA
put :update, params: { id: org.id, simple_content_access: true }
assert_response :found
end

def test_edit_override_can_toggle
org = get_organization(:organization2)
Organization.any_instance.stubs(:service_level)
Organization.any_instance.stubs(:service_levels).returns []
Organization.any_instance.expects(:simple_content_access?).returns true
get :edit, params: { id: org.id }
assert_response :success
end
Expand Down
16 changes: 0 additions & 16 deletions test/services/katello/organization_creator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ def test_create
validate_creator(creator)
end

def test_create_with_sca_off
org = FactoryBot.build(:organization)
creator = Katello::OrganizationCreator.new(org, sca: false)

Katello::Ping.expects(:ping!).returns(true)
org.expects(:candlepin_owner_exists?).returns(false)
Katello::Resources::Candlepin::Owner.expects(:create).with(org.name, org.name, content_access_mode: 'entitlement').returns(true)
Katello::Resources::Candlepin::Owner.expects(:get_ueber_cert).returns(true)
Katello::ContentViewEnvironment.any_instance.expects(:exists_in_candlepin?).returns(false)
Katello::Resources::Candlepin::Environment.expects(:create).returns(true)

creator.create!
validate_org(org)
validate_creator(creator)
end

def test_create_rollback
org = FactoryBot.build(:organization, name: 'rollback_org')
creator = Katello::OrganizationCreator.new(org)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
setContentOverrides,
} from './RepositorySetsActions';

import { selectOrganization, selectOrganizationStatus } from '../../Cards/SystemPurposeCard/SystemPurposeSelectors';
import { selectOrganizationStatus } from '../../Cards/SystemPurposeCard/SystemPurposeSelectors';
import { getOrganization } from '../../Cards/SystemPurposeCard/SystemPurposeActions';

import { REPOSITORY_SETS_KEY, STATUSES, STATUS_TO_PARAM, PARAM_TO_FRIENDLY_NAME, PROVIDER_TYPES, PROVIDER_TYPE_PARAM_TO_FRIENDLY_NAME, PROVIDER_TYPE_TO_PARAM } from './RepositorySetsConstants.js';
Expand Down Expand Up @@ -172,9 +172,6 @@ const RepositorySetsTab = () => {
organization_id: orgId,
} = hostDetails;

const {
simple_content_access: simpleContentAccess,
} = useSelector(state => selectOrganization(state, orgId));
const orgStatus = useSelector(state => selectOrganizationStatus(state, orgId));
const orgNotLoaded = orgStatus !== STATUS.RESOLVED;

Expand Down Expand Up @@ -265,14 +262,14 @@ const RepositorySetsTab = () => {
}
return getHostRepositorySets({
content_access_mode_env: toggleGroupState === LIMIT_TO_ENVIRONMENT,
content_access_mode_all: simpleContentAccess,
content_access_mode_all: true,
host_id: hostId,
...apiSortParams,
...modifiedParams,
});
},
[hostId, statusSelected, STATUS_LABEL, repoTypeSelected,
REPO_TYPE_LABEL, toggleGroupState, LIMIT_TO_ENVIRONMENT, simpleContentAccess, apiSortParams],
REPO_TYPE_LABEL, toggleGroupState, LIMIT_TO_ENVIRONMENT, apiSortParams],
);

useEffect(() => {
Expand Down Expand Up @@ -501,21 +498,10 @@ const RepositorySetsTab = () => {

const hostEnvText = 'the "{contentViewName}" content view and "{lifecycleEnvironmentName}" environment';

const scaAlert = (toggleGroupState === LIMIT_TO_ENVIRONMENT ?
const alertText = (toggleGroupState === LIMIT_TO_ENVIRONMENT ?
`Showing only repositories in ${hostEnvText}.` :
'Showing all available repositories.');

const nonScaAlert = (toggleGroupState === LIMIT_TO_ENVIRONMENT ?
`Showing repositories in ${hostEnvText} that are available through subscriptions.` :
'Showing all repositories available through subscriptions.');

let alertText;
if (simpleContentAccess) {
alertText = scaAlert;
} else {
alertText = nonScaAlert;
}

return (
<div>
<div id="repo-sets-tab">
Expand Down
3 changes: 0 additions & 3 deletions webpack/scenes/Organizations/OrganizationSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const selectManifestHref = state =>
export const selectIsManifestImported = state =>
!!selectOrganizationState(state).owner_details?.upstreamConsumer?.webUrl;

export const selectSimpleContentAccessEnabled = state =>
selectOrganizationState(state).simple_content_access;

export const selectCdnConfigurationUpdateStatus = state =>
selectAPIStatus(state, UPDATE_CDN_CONFIGURATION_KEY);

Expand Down
Loading

0 comments on commit 1bd84c2

Please sign in to comment.