Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove central admin configuration #421

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angular.app.controller('pglogicalReplicationFormController', ['$http', '$scope', 'pglogicalReplicationFormId', 'miqService', '$modal', function($http, $scope, pglogicalReplicationFormId, miqService, $modal) {
ManageIQ.angular.app.controller('pglogicalReplicationFormController', ['$http', '$scope', 'pglogicalReplicationFormId', 'miqService', function($http, $scope, pglogicalReplicationFormId, miqService) {
var init = function() {
$scope.pglogicalReplicationModel = {
replication_type: 'none',
Expand Down Expand Up @@ -297,69 +297,6 @@ ManageIQ.angular.app.controller('pglogicalReplicationFormController', ['$http',
return false;
};

var $ctrl = this;

$ctrl.animationsEnabled = true;
$ctrl.ssh_params = {ssh_host: "", ssh_user: "", ssh_password: ""};

$scope.isCentralAdminEnabled = function(idx) {
return $scope.pglogicalReplicationModel.subscriptions[idx].auth_key_configured;
};

$scope.enableCentralAdmin = function(idx) {
var data = {};
data["provider_region"] = $scope.pglogicalReplicationModel.subscriptions[idx].provider_region;
data["ssh_host"] = $ctrl.ssh_params.ssh_host;
data["ssh_user"] = $ctrl.ssh_params.ssh_user;
data["ssh_password"] = $ctrl.ssh_params.ssh_password;

miqService.sparkleOn();
var url = "/ops/enable_central_admin";
miqService.miqAjaxButton(url, data);
};

$scope.disableCentralAdmin = function(idx) {
if (confirm("Are you sure you want to Disable Central Admin for this Region?")){
miqService.sparkleOn();
var url = "/ops/disable_central_admin/";
var data = {};
data["provider_region"] = $scope.pglogicalReplicationModel.subscriptions[idx].provider_region;
miqService.miqAjaxButton(url, data);
}
};

$scope.launchAuthKeyModal = function (idx) {
$ctrl.ssh_params.ssh_host = $scope.pglogicalReplicationModel.subscriptions[idx].remote_ws_address;
$ctrl.ssh_params.ssh_user = "";
$ctrl.ssh_params.ssh_password = "";

var modalInstance = $modal.open({
animation: $ctrl.animationsEnabled,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'authkeyModalForm.html',
controller: 'authkeyModalFormController',
controllerAs: '$ctrl',
resolve: {
ssh_params: function () {
return $ctrl.ssh_params;
}
}
});

modalInstance.result.then(function (ssh_params) {
$ctrl.ssh_params.ssh_host = ssh_params.ssh_host;
$ctrl.ssh_params.ssh_user = ssh_params.ssh_user;
$ctrl.ssh_params.ssh_password = ssh_params.ssh_password;
$scope.enableCentralAdmin(idx);
}, function () {
var dismissed_at = new Date();
});
};

$ctrl.toggleAnimation = function () {
$ctrl.animationsEnabled = !$ctrl.animationsEnabled;
};

function getPgLogicalFormData(response) {
var data = response.data;
Expand Down
47 changes: 0 additions & 47 deletions app/controllers/ops_controller/settings/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,6 @@ def pglogical_subscriptions_form_fields
replication_type = MiqRegion.replication_type
subscriptions = replication_type == :global ? PglogicalSubscription.all : []
subscriptions = get_subscriptions_array(subscriptions) unless subscriptions.empty?
if replication_type == :global
subscriptions.each do |h|
region = MiqRegion.find_by(:region => h[:provider_region])
h.merge!(
:auth_key_configured => !!region.try(:auth_key_configured?),
:remote_ws_address => region.try(:remote_ws_address).to_s
)
end
end

exclusion_list = replication_type == :remote ? MiqPglogical.new.active_excludes : MiqPglogical.default_excludes

render :json => {
Expand Down Expand Up @@ -255,43 +245,6 @@ def pglogical_validate_subscription
javascript_flash
end


def enable_central_admin
replication_type = MiqRegion.replication_type

if replication_type != :global || !@_params[:provider_region] || !@_params[:ssh_user] || !@_params[:ssh_password]
add_flash(_("Invalid data for enabling Central Admin"), :error)
else
provider_region = @_params[:provider_region]
region = MiqRegion.find_by(:region => provider_region)
if region
region.generate_auth_key_queue(@_params[:ssh_user], @_params[:ssh_password], @_params[:ssh_host])
add_flash(_("Enable Central Admin has been successfully initiated"))
else
add_flash(_("Region Not found"), :error)
end
end
javascript_flash
end

def disable_central_admin
replication_type = MiqRegion.replication_type

if replication_type != :global || !@_params[:provider_region]
add_flash(_("Invalid data for disabling Central Admin"), :error)
else
provider_region = @_params[:provider_region]
region = MiqRegion.find_by( :region => provider_region)
if region
region.remove_auth_key
add_flash(_("Central Admin has been disabled"))
else
add_flash(_("Region Not found"), :error)
end
end
javascript_flash
end

private

PASSWORD_MASK = '●●●●●●●●'.freeze
Expand Down
23 changes: 0 additions & 23 deletions app/views/ops/_authkey_modal_form.html.haml

This file was deleted.

57 changes: 1 addition & 56 deletions app/views/ops/_settings_replication_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,9 @@
- @angular_form = true

%form.form-horizontal#form_div{"name" => "angularForm",
"ng-controller" => "pglogicalReplicationFormController as $ctrl",
"ng-controller" => "pglogicalReplicationFormController",
"ng-show" => "afterGet"}
= render :partial => "layouts/flash_msg"
%script{:id => "authkeyModalForm.html", :type => "text/ng-template"}
:cdata
<div class="modal fade" id="authkeyModalForm" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-header">
<h4 class="modal-header">SSH Information For An Appliance In the Region</h4>
</div>
<form class="form-horizontal" name="authkeyModalForm" ng-submit="$ctrl.submitForm()" novalidate>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label">Host</label>
<div class="col-sm-10">
<input type="text" name="ssh_host" class="form-control" ng-model="$ctrl.ssh_params.ssh_host">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">User</label>
<div class="col-sm-10">
<input type="text" name="ssh_user" class="form-control" ng-model="$ctrl.ssh_params.ssh_user" required>
<p ng-show="authkeyModalForm.ssh_user.$invalid && !authkeyModalForm.ssh_user.$pristine" class="help-block">SSH user is required.</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" name="ssh_password" class="form-control" ng-model="$ctrl.ssh_params.ssh_password" required>
<p ng-show="authkeyModalForm.ssh_password.$invalid && !authkeyModalForm.ssh_password.$pristine" class="help-block">SSH password is required.</p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-disabled="authkeyModalForm.$invalid">Submit</button>
<button class="btn btn-default" ng-click="$ctrl.cancelForm()">Cancel</button>
</div>
</form>
</div>
.form-group{"ng-class" => "{'has-error': angularForm.subscriptions.$invalid}"}
%label.col-md-2.control-label
= _('Type')
Expand Down Expand Up @@ -71,7 +36,6 @@
%th= _('Username')
%th= _('Password')
%th= _('Port')
%th= _('Central Admin Enabled')
%th{:colspan => 2}=_('Actions')
%tbody
%tr{"ng-if" => "pglogicalReplicationModel.addEnabled"}
Expand Down Expand Up @@ -109,7 +73,6 @@
"id" => "port",
"name" => "port",
"ng-model" => "pglogicalReplicationModel.port"}
%td
%td{:class => "action-cell"}
%button.btn.btn-default.btn-block.btn-sm{:type => "button", "ng-disabled" => "!subscriptionValid()", "ng-click" => "addSubscription()"}= _('Accept')

Expand Down Expand Up @@ -179,15 +142,6 @@
"name" => "port",
"ng-model" => "pglogicalReplicationModel.port"}

%td.narrow
%input{"bs-switch" => "",
:data => {:on_text => 'Yes', :off_text => 'No', :size => 'mini'},
"id" => "auth_key_configured",
"type" => "checkbox",
"name" => "auth_key_configured",
"ng-model" => "subscription.auth_key_configured",
"switch-readonly" => true}

%td{:class => "action-cell", "ng-show" => "showCancelDelete($index)"}
%button.btn.btn-default.btn-sm{:type => "button", "ng-click" => "cancelDelete($index)"}= _('Cancel Delete')

Expand All @@ -206,15 +160,6 @@
%li
%a{"ng-click" => "validateSubscription($index)"}
= _('Validate')
%li
%a{"ng-click" => "launchAuthKeyModal($index)", "ng-show" => "isCentralAdminEnabled($index)"}
= _('Re-Enable Central Admin')
%li
%a{"ng-click" => "launchAuthKeyModal($index)", "ng-show" => "!isCentralAdminEnabled($index)"}
= _('Enable Central Admin')
%li
%a{"ng-click" => "disableCentralAdmin($index)", "ng-show" => "isCentralAdminEnabled($index)"}
= _('Disable Central Admin')

%td{:class => "action-cell", "ng-show" => "!showCancelDelete($index) && pglogicalReplicationModel.updateEnabled && $index === pglogicalReplicationModel.s_index"}
%button.btn.btn-default.btn-block.btn-sm{:type => "button", "ng-disabled" => "!subscriptionValid()", "ng-click" => "addSubscription($index)"}= _('Accept')
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2406,9 +2406,7 @@
diagnostics_server_list
diagnostics_tree_select
diagnostics_worker_selected
disable_central_admin
edit_rhn
enable_central_admin
explorer
fetch_build
fetch_target_ids
Expand Down
62 changes: 0 additions & 62 deletions spec/controllers/ops_controller/settings/common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,68 +201,6 @@
end
end

context "#enable_disable_central_admin" do
let(:expected_attrs) do
[
{
"id" => "region_11_subscription",
"status" => "replicating",
"dbname" => "vmdb's_test",
"host" => "example.com",
"user" => "root",
"provider_region" => 11,
"provider_region_name" => "The region"
},
{
"id" => "region_12_subscription",
"status" => "disabled",
"dbname" => "vmdb_test2",
"host" => "test.example.com",
"user" => "postgres",
"port" => 5432,
"provider_region" => 12
}
]
end
render_views

before do
EvmSpecHelper.local_miq_server(:zone => Zone.seed)
FactoryGirl.create(:miq_region, :region => 11, :description => "The 11th region")
FactoryGirl.create(:miq_region, :region => 12, :description => "The 12th region")
end

it "enables central admin when selected" do
allow(PglogicalSubscription).to receive(:all).and_return(expected_attrs)
allow(MiqRegion).to receive(:replication_type).and_return(:global)
params = {:ssh_user => 'User1', :ssh_host => 'Host1', :ssh_password => 'pwd1', :provider_region => '11'}
controller.instance_variable_set(:@_params, params)
allow(controller).to receive(:javascript_flash)
controller.send(:enable_central_admin)
expect(assigns(:flash_array).first[:message]).to include("Enable Central Admin has been successfully initiated")
end

it "fails to enable central admin if the user is mising" do
allow(PglogicalSubscription).to receive(:all).and_return(expected_attrs)
allow(MiqRegion).to receive(:replication_type).and_return(:global)
params = {:ssh_host => 'Host1', :ssh_password => 'pwd1', :provider_region => '11'}
controller.instance_variable_set(:@_params, params)
allow(controller).to receive(:javascript_flash)
controller.send(:enable_central_admin)
expect(assigns(:flash_array).first[:message]).to include("Invalid data for enabling Central Admin")
end

it "disables central admin when selected for a region that has it configured" do
allow(PglogicalSubscription).to receive(:all).and_return(expected_attrs)
allow(MiqRegion).to receive(:replication_type).and_return(:global)
allow(controller).to receive(:javascript_flash)
params = {:provider_region => '12'}
controller.instance_variable_set(:@_params, params)
controller.send(:disable_central_admin)
expect(assigns(:flash_array).first[:message]).to include("Central Admin has been disabled")
end
end

context "#update_exclude_tables_for_remote_region" do
render_views

Expand Down

This file was deleted.