-
Notifications
You must be signed in to change notification settings - Fork 356
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
Add vm security group operations #1997
Add vm security group operations #1997
Conversation
@h-kataria Thanks for the guidance, let me know if I did this right! |
@miq-bot add_label UX/Review |
@miq-bot remove_label wip |
@h-kataria I believe this is ready for review now! |
273bed6
to
fd7294f
Compare
@tzumainn we relaxed the codeclimate checks, can you see if you can address any of the 18 issues that are reported? |
@dclarizio thanks for pointing that out! I took a closer look at the codeclimate issues, and I'm not sure any of them can be addressed. The duplicated code is extremely minor, and feels dangerous to pull out. It looks like I already follow the suggested angular chaining - I think the lint is wrong. And the 'unless' statements look correct to me. Let me know if there's something specific in there you think I missed! |
@martinpovolny Can you review the CC issues? I know we relaxed CC checks, does CC need to be rerun? |
@tzumainn how are they accessing this operation? |
@serenamarie125 From a single VM view, under the Configuration menu - same place where associate/disassociate floating IP and similar operations, |
@tzumainn, @dclarizio : More that about CC issues -- yes, there are 18 -- I am concerned about creating more and more new RJS code. This PR introduces a lot of new technical debt. Is there a reason to do this? Are we in a hurry? Is this a Sev 1 fix? |
To be more specific:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, see comments I have added.
vm.resetClicked = function(angularForm) { | ||
vm.CloudModel = angular.copy( vm.modelCopy ); | ||
angularForm.$setPristine(true); | ||
miqService.miqFlash("warn", "All changes have been reset"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no i18n?
@@ -0,0 +1,40 @@ | |||
ManageIQ.angular.app.controller('vmCloudRemoveSecurityGroupFormController', ['$http', 'vmCloudRemoveSecurityGroupFormId', 'miqService', function($http, vmCloudRemoveSecurityGroupFormId, miqService) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to convert to Angular 1.6 so that we can move forward with Angular 2 and React. This should be a component. The partials below shoud not be created, those should be part of the component or separate componets too.
Ping @himdel, @AparnaKarve, @Hyperkid123.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no controllers in Angular 2+, so i completely agree that we should try to write any new angular controllers as components, since we will have to refactor them anyway... And that applies especially for partials, because refactoring them later after they go through several modifications is pain in the ass.
You can use this article as reference. There are also some components already in ui-classic(and more comming).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on the guide, but for now, pretty much all you need to do is:
- rename
init
to$onInit
- that gets called automagically by angular, so you no longer need to call it manually. - move the templates under
app/views/static/
- that way, you can reference it viatemplateUrl: '/static/....'
from angular - remove any controller-dependent logic from the moved template - that just means you can't use
@record.id
in your case - make it into a component...
ManageIQ.angular.app.controller("foo", **controller**);
should become
ManageIQ.angular.app.component("foo", {
bindings: {
recordId: "@",
}
templateUrl: "/static/foo.html.haml",
controller: **controller**,
});
- then you no longer need to pass the id using
value
, you can provide it to the component as a parameter - hence thebindings
entry - so no injectingvmCloudRemoveSecurityGroupFormId
any more ;) - replace the original template with just something that uses the component .. so,
%my-component{:record-id => @record.id}
, and initializes angular (so thatmiq_bootstrap
stays here, not instatic
- we usually use the component name as the first arg in those cases (so you don't need an extra#div
)) - don't leave the code in
app/assets/javascripts/controllers
, use thecomponents
dir for that - or if you're up to speed with the recent webpacker changes (talk), you can move it toapp/javascript/
and use newer JS features.
EDIT: oh, and remove ng-controller
from the template too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, that miqAjaxButton
is an anti-pattern now, with angular components, you should no longer rely on the server generating javascript to redirect you/show a flash message/whatever... instead, you should be using render :json => ...
in ruby, and read that json in JS to do the right thing.
(But, it's not miqAjaxButton(url, true)
which is the worst, so.. if the server-side logic to do that is not trivial, feel free to ignore this bit for now.)
@martinpovolny Thanks for looking at this! I'm pretty new at JS so it's difficult for me unless I'm following existing patterns. Do you have an example of a controller being a component? |
@@ -1049,6 +1051,8 @@ def process_vm_buttons(pfx) | |||
when "#{pfx}_live_migrate" then livemigratevms | |||
when "#{pfx}_associate_floating_ip" then associate_floating_ip_vms | |||
when "#{pfx}_disassociate_floating_ip" then disassociate_floating_ip_vms | |||
when "#{pfx}_add_security_group" then add_security_group_vms | |||
when "#{pfx}_remove_security_group" then remove_security_group_vms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to be relevant for multiple different entities?
What I mean: you are adding some "#{pfx}_action" here. It seems to be relevant for VMs, right? Is it going to be relevant for other entities?
Or is it just that you saw many of the VM button action being handled here?
If it's going to be relevant just for VMs then I'd prefer not to do the pfx
magic.
But if you actually rewrite this to be pure client-side throught the API then you probably will not need to change this file (and the one below) at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinpovolny hi! to be honest, I don't know what this code is for; would you suggest just removing this bit?
d726a73
to
6751442
Compare
depends on ManageIQ/manageiq-api#137 |
@martinpovolny I believe I've addressed your comments. Let me know if anything else should be changed. |
@tzumainn : Thanks! It looks much better ;-) I really appreciate that you did these changes and worked with the API. Moving forward we should figure how to avoid all the changes you did in:
and some more. As this is really just routing from one Angular-enabled page to another one by doing a HTTP request. That should not be necessary and it should be simpler. But we can do that in a separate PR. @himdel, @h-kataria : what do you think? @himdel, @ZitaNemeckova: Maybe we can take this for our Monday's "workshop" with @gildub and @aufi and make it into an example on how to progress with moving on the client. A blogpost maybe? |
t = N_('Add a Security Group to this Instance'), | ||
t, | ||
:klass => ApplicationHelper::Button::GenericFeatureButtonWithDisable, | ||
:options => {:feature => :add_security_group} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not needed.. instance_add_security_group
is the needed rbac feature, because of the toolbar button's identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! I had thought that the preference in feature names was to use non-entity specific names when possible. It's certainly possible that we'll be adding security groups to other things in the future, so isn't add_security_group preferable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well until that happens I'd go with the simple case.
Other that that I think this is ready to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the concern, but I've been explicitly told to do the opposite by reviewers who reviewed changes to the feature list in the supports_feature_mixin. If you look at https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/supports_feature_mixin.rb, none of the features are entity specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well @himdel and I both mixed up RBAC feature and product feature.
I know I said "last" but before pressing the merge button I took a look at the CC and besides the similar code warning, that I don't push you to address, there are 2 trivial ones:
Please, fix these 2. |
@miq-bot add_label pending/core |
@tzumainn Cannot apply the following label because they are not recognized: pending/core |
Checked commits tzumainn/manageiq-ui-classic@cb40a5c~...01932e2 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 app/controllers/mixins/actions/vm_actions/add_security_group.rb
app/controllers/mixins/actions/vm_actions/remove_security_group.rb
|
@martinpovolny fixed the issues (and updated the API call in accordance to a request on the API PR). I'll let you know when that API PR is merged, thanks! |
@martinpovolny backend API PR is merged, so I think this should be ready! The test failures look unrelated... ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like most of the comments/concerns from @martinpovolny @himdel were addressed. Looks good
Adds VM security group operations