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

Fixes #20999 - Reset env/cv for Activation Keys #7351

Merged
merged 1 commit into from May 10, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,10 +30,17 @@ angular.module('Bastion.activation-keys').controller('ActivationKeyDetailsInfoCo
});

$scope.$watch('activationKey.environment', function (environment) {
if (environment && $scope.originalEnvironment) {
if (environment.id !== $scope.originalEnvironment.id) {
$scope.editContentView = true;
if ($scope.originalEnvironment) {
if (environment) {
if (environment.id !== $scope.originalEnvironment.id) {
$scope.editContentView = true;
$scope.disableEnvironmentSelection = true;
}
} else {
$scope.disableEnvironmentSelection = true;
$scope.editContentView = false;
$scope.activationKey["environment_id"] = null;
$scope.resetContentView($scope.activationKey);
}
} else if (environment) {
$scope.editEnvironment = true;
Expand All @@ -57,10 +64,34 @@ angular.module('Bastion.activation-keys').controller('ActivationKeyDetailsInfoCo
$scope.editEnvironment = false;
$scope.save(activationKey).then(function (actKey) {
$scope.originalEnvironment = actKey.environment;
$scope.resetEnvironmentPathSelector(activationKey);
});
$scope.disableEnvironmentSelection = false;
};

$scope.resetEnvironmentPathSelector = function (activationKey) {
// reset "selected" in the environment widget.
_.each($scope.environments, function (environmentPath) {
_.each(environmentPath, function (individualEnv) {
if (activationKey["environment_id"] !== individualEnv.id) {
delete individualEnv.selected;
} else {
individualEnv.selected = true;
}
});
});
};

$scope.resetEnvironment = function (activationKey) {
delete activationKey.environment;
};

$scope.resetContentView = function (activationKey) {
activationKey["content_view_id"] = null;
activationKey["content_view"] = null;
$scope.saveContentView(activationKey);
};

$scope.releaseVersions = function () {
var deferred = $q.defer();

Expand Down
Expand Up @@ -100,11 +100,13 @@ <h4 translate>Activation Key Content</h4>
</dt>
<dd bst-feature-flag="lifecycle_environments">
<div bst-edit-select="activationKey.content_view.name"
readonly="denied('edit_activation_keys', activationKey)"
readonly="denied('edit_activation_keys', activationKey) || activationKey.environment === undefined || activationKey.environment === null"
selector="activationKey.content_view.id"
options="contentViews()"
on-cancel="cancelContentViewUpdate()"
on-save="saveContentView(activationKey)"
deletable="activationKey.content_view"
on-delete="resetEnvironment(activationKey)"
edit-trigger="editContentView">
</div>

Expand Down