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

Add vm security group operations #1997

Merged
merged 13 commits into from
Oct 26, 2017

Conversation

tzumainn
Copy link
Contributor

Adds VM security group operations

@tzumainn
Copy link
Contributor Author

screenshot from 2017-08-25 13 46 17

@tzumainn
Copy link
Contributor Author

@h-kataria Thanks for the guidance, let me know if I did this right!

@tzumainn
Copy link
Contributor Author

@miq-bot add_label UX/Review

@tzumainn tzumainn changed the title [WIP] Add vm security group operations Add vm security group operations Sep 7, 2017
@tzumainn
Copy link
Contributor Author

tzumainn commented Sep 7, 2017

@miq-bot remove_label wip

@tzumainn tzumainn closed this Sep 7, 2017
@tzumainn tzumainn reopened this Sep 7, 2017
@tzumainn
Copy link
Contributor Author

tzumainn commented Sep 7, 2017

@h-kataria I believe this is ready for review now!

@dclarizio
Copy link

@tzumainn we relaxed the codeclimate checks, can you see if you can address any of the 18 issues that are reported?

@tzumainn
Copy link
Contributor Author

@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!

@dclarizio
Copy link

@martinpovolny Can you review the CC issues? I know we relaxed CC checks, does CC need to be rerun?

@serenamarie125
Copy link

@tzumainn how are they accessing this operation?

@tzumainn
Copy link
Contributor Author

@serenamarie125 From a single VM view, under the Configuration menu - same place where associate/disassociate floating IP and similar operations,

@martinpovolny
Copy link
Member

@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?

@martinpovolny
Copy link
Member

To be more specific:

  • Why is the API not used?
  • There should be no new render :update code at all unless you are adding a small thing to a complex controller where everything is done that way.
  • app/controllers/mixins/actions/vm_actions/remove_security_group.rb and app/controllers/mixins/actions/vm_actions/add_security_group.rb look like c-n-ped.

@martinpovolny martinpovolny self-requested a review September 25, 2017 07:49
Copy link
Member

@martinpovolny martinpovolny left a 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");
Copy link
Member

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) {
Copy link
Member

@martinpovolny martinpovolny Sep 25, 2017

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.

Copy link
Contributor

@Hyperkid123 Hyperkid123 Sep 25, 2017

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).

Copy link
Contributor

@himdel himdel Sep 25, 2017

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 via templateUrl: '/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 the bindings entry - so no injecting vmCloudRemoveSecurityGroupFormId any more ;)
  • replace the original template with just something that uses the component .. so, %my-component{:record-id => @record.id}, and initializes angular (so that miq_bootstrap stays here, not in static - 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 the components dir for that - or if you're up to speed with the recent webpacker changes (talk), you can move it to app/javascript/ and use newer JS features.

EDIT: oh, and remove ng-controller from the template too

Copy link
Contributor

@himdel himdel Sep 25, 2017

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.)

@tzumainn
Copy link
Contributor Author

@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
Copy link
Member

@martinpovolny martinpovolny Sep 25, 2017

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.

Copy link
Contributor Author

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?

@tzumainn tzumainn force-pushed the vm-security-group-operations branch from d726a73 to 6751442 Compare October 21, 2017 05:11
@tzumainn
Copy link
Contributor Author

depends on ManageIQ/manageiq-api#137

@tzumainn
Copy link
Contributor Author

@martinpovolny I believe I've addressed your comments. Let me know if anything else should be changed.

@martinpovolny
Copy link
Member

@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:

app/controllers/mixins/actions/vm_actions/add_security_group.rb
app/controllers/mixins/actions/vm_actions/remove_security_group.rb
app/controllers/vm_common.rb

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}
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@martinpovolny
Copy link
Member

martinpovolny commented Oct 23, 2017

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:

Trailing spaces not allowed. NEW
Expected indentation of 8 spaces but found 7. NEW

Please, fix these 2.

@tzumainn
Copy link
Contributor Author

@miq-bot add_label pending/core

@miq-bot
Copy link
Member

miq-bot commented Oct 24, 2017

@tzumainn Cannot apply the following label because they are not recognized: pending/core

@miq-bot
Copy link
Member

miq-bot commented Oct 25, 2017

Checked commits tzumainn/manageiq-ui-classic@cb40a5c~...01932e2 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
7 files checked, 2 offenses detected

app/controllers/mixins/actions/vm_actions/add_security_group.rb

app/controllers/mixins/actions/vm_actions/remove_security_group.rb

@tzumainn
Copy link
Contributor Author

@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!

@tzumainn
Copy link
Contributor Author

@martinpovolny backend API PR is merged, so I think this should be ready! The test failures look unrelated... ?

@tzumainn tzumainn closed this Oct 26, 2017
@tzumainn tzumainn reopened this Oct 26, 2017
Copy link
Contributor

@h-kataria h-kataria left a 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

@h-kataria h-kataria added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 26, 2017
@h-kataria h-kataria merged commit 1cd88de into ManageIQ:master Oct 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants