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

Should not be able to add the same secret or config map to an application twice #2249

Merged
merged 1 commit into from Oct 17, 2017

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Oct 11, 2017

The Add to Application modal will only show applications which DC's won't contain the secret/configMap that user wants to add. In case one of the containers won't contain the secret/configMap the application will be shown in the dropbox, but the ref will be added only to the containers that don't contain the it.

Unfortunately if, in case of multiple container DC, user chooses to specify a specific container, the checkbox of the container that already contains the ref wont be pre-selected, cause that could mislead the user that by unchecking the checkbox he could remove the ref from that specific container. Other option would be to pre-select the checkbox and also disable it, but that would require add the disable logic to the select-container directive. Wasn't sure if we need that ATM...

@jeff-phillips-18 @spadgett PTAL

Closes #2226

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 11, 2017
@@ -26,12 +26,35 @@
var ctrl = this;
var humanizeKind = $filter('humanizeKind');

var checkContainerForRef = function(container) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, I think we might need an additional message option:

screen shot 2017-10-11 at 11 31 37 am

It says "There are no applications in this project", but that isn't true in this case. I've just already added this secret to both of the apps in my project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjaminapetersen what about "There is not any application with containers to add secret to"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to show all apps in the list, but show an error with a disabled save button when the user tries to pick one that already has the secret. Otherwise it might seem like a bug that their app isn't showing up, and it's not obvious why.

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 12, 2017
@jhadvig
Copy link
Member Author

jhadvig commented Oct 12, 2017

@benjaminapetersen as suggested by @spadgett I've reworked the logic so the selectbox will list all the applications but we will throw an warning and disable the Save button if the ref is already present in the application containers.

Screen:
twice

PTAL

@benjaminapetersen
Copy link
Contributor

Nice, I'm good with that!

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jhadvig, a few comments

var checkContainerForRef = function(container) {
var addRefName = ctrl.apiObject.metadata.name;
if (ctrl.apiObject.kind === "ConfigMap") {
return _.find(container.envFrom, {configMapRef: {name: addRefName}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use _.some instead of _.find if you are just checking if it exists.

if (ctrl.apiObject.kind === "ConfigMap") {
return _.find(container.envFrom, {configMapRef: {name: addRefName}});
} else {
return _.find(container.envFrom, {secretRef: {name: addRefName}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.some

@@ -25,6 +25,26 @@
function AddConfigToApplication($filter, $scope, APIService, ApplicationsService, DataService, Navigate, NotificationsService, StorageService) {
var ctrl = this;
var humanizeKind = $filter('humanizeKind');
ctrl.canAddRefToApplication = false;

var checkContainerForRef = function(container) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest conatinerHasRef

ctrl.canAddRefToApplication = true;
return false;
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be shortened to.

var containers = _.get(application, 'spec.template.spec.containers');
ctrl.canAddRefToApplication = !_.every(containers, checkContainerForRef);

@@ -5,10 +5,14 @@
<div class="dialog-body">
<form name="addToApplicationForm" novalidate>
<fieldset ng-disabled="disableInputs">
<div class="alert alert-warning" ng-if="ctrl.addType === 'env' && ctrl.application && !ctrl.canAddRefToApplication">
<span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span>
<strong>Containers of the selected application already contain this {{ctrl.apiObject.kind | humanizeKind}}.</strong>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just

<strong>The {{ctrl.apiObject.kind | humanizeKind}} has already been added to this application.</strong>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using the help-block / has-error style (instead of an alert) and moving it below the select.

@jhadvig
Copy link
Member Author

jhadvig commented Oct 16, 2017

@spadgett I've update the PR based on your comments :)
PTAL

@spadgett
Copy link
Member

Looks good. A couple small comments:

openshift web console 2017-10-16 08-41-56

  1. There should be more margin between the error message and the "Add secret as:" label below.
  2. The select should be highlighted red as well. If you have a has-error class on the form group, the entire select is highlighted. See https://github.com/openshift/origin-web-catalog/blob/master/src/components/select-project/selectProject.html#L2
  3. We should probably use a consistent style for the "Some keys for..." warning as well. It looks odd to have two error styles. I'd suggest switching the env warning to the help-block / has-warning style.

@jhadvig
Copy link
Member Author

jhadvig commented Oct 16, 2017

@spadgett comments addressed

screen:
twice4

PTAL

@@ -108,7 +111,7 @@
class="btn btn-primary"
ng-class="{'dialog-btn': isDialog}"
ng-click="ctrl.addToApplication()"
ng-disabled="ctrl.addType === 'volume' && addToApplicationForm.$invalid || !ctrl.application"
ng-disabled="(ctrl.addType === 'volume' && addToApplicationForm.$invalid) || (ctrl.addType === 'env' && !ctrl.canAddRefToApplication)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like you might be able to submit the form now while "applications" is still loading? canAddRefToApplication is initialized to true and the invalid check is skipped.

I'm guessing we're only checking addToApplicationForm.$invalid to keep the form submittable when mount path is invalid, but addType === 'env'. It would be better to disable the mount path input, however, and just check

ng-disabled="addToApplicationForm.$invalid || (ctrl.addType === 'env' && !ctrl.canAddRefToApplication)"

cc @jeff-phillips-18

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still need to ensure an application is selected either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeff-phillips-18 I've update the mount path input with the check if the application was selected as @spadgett suggested. This will force user to pick the application in order to make the form valid. Added separate commit so the changes are obvious.
PTAL

@spadgett
Copy link
Member

@jhadvig Looks like a dist mismatch

@jhadvig
Copy link
Member Author

jhadvig commented Oct 17, 2017

@spadgett will rebase and regenerate dist

@spadgett
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue.

@openshift-merge-robot openshift-merge-robot merged commit aeaf248 into openshift:master Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants