-
Notifications
You must be signed in to change notification settings - Fork 357
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
Fix resize approval to work for editing requests #2598
Conversation
8122a04
to
e3b92fe
Compare
FYI, this isn't quite ready to merge. I'm working through some issues that @mansam and I discovered (redirect problems, etc.) I'm working on an update to this. |
65e5302
to
d16cf5d
Compare
The latest update should include the fixes that @mansam and I discovered. |
if (vmCloudResizeFormId == 'new') | ||
vm.newRecord = true; | ||
else | ||
vm.newRecord = false; |
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 can be replaced by vm.newRecord = vmCloudResizeFormId == 'new';
.
@miq-bot add_label gaprindashvili/yes |
@ZitaNemeckova To test: |
d16cf5d
to
d8b32ca
Compare
$http.get('/vm_cloud/resize_form_fields/' + vmCloudResizeFormId) | ||
vm.newRecord = vmCloudResizeFormId == 'new'; | ||
|
||
$http.get('/vm_cloud/resize_form_fields/' + vmCloudResizeFormId + ',' + vm.objectId) |
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.
Don't send two ids in one param. Later you have to split them and it's too "hacky". You can send the second id as '&req_id=' + vm.objectId
as you do in js redirect later. That way it's always clear what it is.
@@ -86,7 +98,9 @@ def resize_vm | |||
|
|||
def resize_form_fields | |||
assert_privileges("instance_resize") | |||
@record = find_record_with_rbac(VmOrTemplate, params[:id]) | |||
|
|||
@request_id, record_id = params[:id].split(/\s*,\s*/, 2) |
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 send those ids in separate params. Do something like this:
record_id = params[:id]
@request_id = params[:req_is]
(I hope I didn't switch them in my example :D )
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.
Sure. I can switch this around. The above was modeled after the existing reconfigure code, so if we're changing this here, at some point perhaps the other should be modified as well.
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.
And yes, you did switch them in your example, but that's OK -- I know what you meant.
Editing looks good but redirect after submit/cancel is weird. It redirects to instance summary page but it's missing the tree. Do you want it to be redirected there or to previous page (request summary page). If latter you can change this line https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/controllers/mixins/actions/vm_actions/resize.rb#L78 to |
d8b32ca
to
6529936
Compare
So I made the first suggested changes (around the URL param passing). The redirect on submit suggestion didn't work, though -- the issue is that with the suggestion applied, on the initial resize form, that prevents the form from going anywhere. You click submit and the form stays as-is. However irregular the redirect behavior is with the PR as-is, it's better than having a form that doesn't disappear on submit. Also, I remember when first going through this functionality, I was unable to come up with a way that worked as desired for both initial form submission and on edit in the approval process. |
@sseago I didn't test my suggestion on initial form (shame on me). I fixed and tested it on both forms. Could you try |
fca9083
to
4658b64
Compare
@ZitaNemeckova With the prior update, the suggested changes have been made. |
@sseago Thanks :) I'm not sure about one thing. When editing a request original flavor is not set and it's hard to say which one was set before. Is that an intension or not? Chosen flavor is unknown: Otherwise it looks good :) |
@ZitaNemeckova I've removed WIP from the title. I don't think I have permission to remove labels, but perhaps miq-bot removes WIP automatically in response to the title change like it does when adding [WIP] |
var vm = this; | ||
|
||
var init = function() { | ||
vm.vmCloudModel = { | ||
flavor_id: null, | ||
}; | ||
vm.flavors = []; | ||
vm.formId = vmCloudResizeFormId; | ||
vm.modelCopy = angular.copy(vm.vmCloudModel); | ||
vm.vmCloudResizeformId = vmCloudResizeFormId; |
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.
prefer formId
, but if you need this name, please make sure this is vmCloudResizeFormId
and not ...formId
also, note that formId should be the id of the thing being edited - which is not a request, it's the vm
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'll fix the capitalization of the 'F' there. With so many moving parts (and a review dragging out six months), I'd rather not mess with the name beyond that and risk breaking something that I'd forgotten about. In the context of this form (just like the reconfigure javascript form controller that I'm not touching), the ID is in fact the request, since that's the way the existing UI is already designed (again, I'm just fixing a bug here, not writing a new feature). It's a "resize instance request" that's being created or edited -- the actual VM doesn't get changed until the request is approved.
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, the thing is - there is a possibility you're introducing new bugs, just by removing the vm.formId
as it was before.
(Not sure, but we'd have to check.)
So... can you fix the bug without chaning the meaning of vm.formId
?
}; | ||
|
||
$scope.submitClicked = function() { | ||
miqService.sparkleOn(); | ||
var url = '/vm_cloud/resize_vm/' + vmCloudResizeFormId + '?button=submit'; | ||
miqService.miqAjaxButton(url, vm.vmCloudModel); | ||
miqService.miqAjaxButton(url, {objectId: vm.objectId, |
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.
bad indent
miqService.miqAjaxButton(url, {
objectId: vm.objectId,
flavor_id: vm.vmCloudModel.flavor_id,
});
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.
fixing...
var vm = this; | ||
|
||
var init = function() { | ||
vm.vmCloudModel = { | ||
flavor_id: null, | ||
}; | ||
vm.flavors = []; | ||
vm.formId = vmCloudResizeFormId; | ||
vm.modelCopy = angular.copy(vm.vmCloudModel); |
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.
missing modelCopy for new
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.
See comment above from @ZitaNemeckova -- modelCopy has been moved into getResizeFormData since it has to be called after setting everything in vmCloudMOdel
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.
Ah, sorry about that. Usually get*FormData
only gets called when editing, not new.
But you're right, in your case it handles both, withdrawing my objection :).
@@ -39,7 +39,11 @@ def request_edit | |||
session[:checked_items] = provision_request.options[:src_ids] | |||
@refresh_partial = "reconfigure" | |||
@_params[:controller] = "vm" | |||
reconfigurevms | |||
if provision_request.kind_of?(VmCloudReconfigureRequest) | |||
resizevms |
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.
Why this? Is this really the place?
It doesn't sound right that reconfigure also does resize sometimes.
Is this a new feature? (The PR title does not seem to indicate so)
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.
The back end is "resize" (with request class VmCloudReconfigureRequest) for OpenStack and "reconfigure" (with request class VmReconfigureRequest) for other providers. The issue is that it was decided at some point in the past to expose these two completely different back-end actions as the same thing in the UI. On the model/back end side the actions are completely different, but from a user perspective, they have similar effects (in different providers). The result is that conditionals like this are necessary here.
This is not a new feature -- this PR fixes a bug -- the "edit request" action for administrators does not currently work for resize. A user can request a resize, and an admin can approve it as-is, but without this PR, the request cannot be edited.
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.
Aah, makes sense, thanks for the explanation! :)
@@ -3,16 +3,26 @@ module Actions | |||
module VmActions | |||
module Resize | |||
def resizevms | |||
assert_privileges("instance_resize") | |||
recs = find_checked_items | |||
assert_privileges(params[:pressed]) |
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.
Definitely not!
We can not allow the user to pick which RBAC feature to check for.
This would need a whitelist at least, but .. what's the value of pressed
in question here?
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.
@himdel I'm simply copying what's done in reconfigure.rb, which was the primary model for these changes (since both resize and reconfigure use the same UI, exposed as 'reconfigure') -- also, grepping for this, this seems to be a very common pattern. If this isn't the right way to do this, what exactly should be done here? Part of what makes these forms difficult is that the same form has to be used both for the initial request (in the context of the instance/VM ui) as well as by an admin on editing the request (in the context of the requests UI).
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.
Yes, sorry, it's a pattern we're trying very hard to get rid of.
So... please fix this, by working on this you are in a better position to know the possible privileges and values for params[:pressed]
than anyone else looking at it later.
Something like..
case params[:pressed]
when "your_new_thing"
assert_privileges("your_new_thing")
else
assert_privileges("instance_resize")
end
would be enough.
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.
OK. That works for me.
recs = find_checked_items | ||
assert_privileges(params[:pressed]) | ||
# if coming in to edit from miq_request list view | ||
recs = checked_or_params |
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.
dead code? recs
is never used before it is overwritten
EDIT: never mind, but is the
- recs = find_checked_items
+ recs = checked_or_params
relevant?
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'm fairly certain this wasn't working right before the change. Before this change, this didn't work for editing requests, just for new ones. Also, checked_or_params is what is used in reconfigure.rb in the equivalent line of code.
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.
Ah, ok, the difference is that checked_or_params
will also return params[:id]
when no checkboxes are found.
Just making sure this was the intended result.
recs = [params[:id].to_i] if recs.blank? | ||
@record = find_record_with_rbac(VmOrTemplate, recs.first) # Set the VM object | ||
@record ||= find_record_with_rbac(VmOrTemplate, recs.first) # Set the VM object |
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 breaks any code where @record was previously set, are you sure none such exists?
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.
@record may have been set a few lines above, in which case we want to keep it. This is to handle the case where it was not set. There is a possible edge case if @record is not set above within this method but is already set before -- we could handle that by setting @record to nil before the if block that optionally sets it.
@@ -33,14 +43,18 @@ def resize | |||
) | |||
end | |||
@sb[:explorer] = @explorer | |||
@request_id = params[:req_id] ? params[:req_id] : nil |
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 just @request_id = params[:req_id]
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.
fixing this...
I still have a big issue here with the id renames. Before: formId/params[:id] was the id of the record being edited (and there was no mention of requests) Now: params[:id] is an id of the request, and objectId is the new original id I'm sorry but why would you do that? Why not just add a new thing, called requestId and make it clear? More to the point, can you still fix this please? Otherwise we need to go through all the code to make sure the right id is not being depended on by any other piece of code. |
@@ -18,7 +19,7 @@ | |||
.col-md-8 | |||
%select{:name => 'flavor_id', | |||
'ng-model' => 'vm.vmCloudModel.flavor_id', | |||
'ng-options' => 'flavor.id as flavor.name for flavor in vm.flavors track by flavor.id', | |||
'ng-options' => 'flavor.id as flavor.name for flavor in vm.flavors', | |||
:miqrequired => true, | |||
:checkchange => true} |
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.
checkchange
should not be used with form-changed
, you should be able to remove each checkchange here now :)
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.
ok...
@himdel As for the record/request ID thing, having gone through this again, it's become a bit clearer (again, with this review taking six months, some of the details are a bit fuzzy to me right now). The basic summary is this: resize and reconfigure backend actions were required to work within the same front end UI framework. That was the starting requirement for all of this. Reconfigure actually works for both creating and editing requests, and for the existing reconfigure functionality (which I'm not modifying at all) uses the request ID as the ID (since that's the actual object being created and modified). Given all of this, the only straightforward way to get them to work together within the constraints I was working under was to follow the design of the existing working form as much as possible. If I had been free to decouple them and create a separate "resize" action, exposed to the UI as a separate action, this whole thing would have gone differently. |
@sseago I'm sorry ... I get what you're saying but... correct me if I'm wrong but: Statement 1: I think that's true because... - ManageIQ.angular.app.value('vmCloudResizeFormId', '#{@record.id}');
+ ManageIQ.angular.app.value('vmCloudResizeFormId', '#{@request_id || "new"}');
+ ManageIQ.angular.app.value('objectId', '#{@record.id}'); and - $http.get('/vm_cloud/resize_form_fields/' + vmCloudResizeFormId)
+ $http.get('/vm_cloud/resize_form_fields/' + vmCloudResizeFormId + '?objectId=' + vm.objectId) Statement 2: I think that's true just because it does and it wasn't :). Result |
@himdel I don't believe that it breaks existing functionality because 1) for the 'edit' case, it didn't work before anyway and 2) for the 'new' case, everything that was needed to be changed to reflect the change in meaning of :id should be done already. This change was to bring the partially broken resize UI functionality in line with the fully working reconfigure UI functionality. Do you see anything that looks like it is broken with this change? We've tested the 'new' and 'edit' cases with this PR and both seem to be fully functional. |
What didn't work, resize or reconfigure? If resize, my point still stands.
Still not sure what to test actually, the description is not really telling me anything. |
@sseago Maybe what I'm missing could be this.. The screen that's using 'vmCloudResizeFormController' does say "Reconfigure" but maybe this screen is actually resize-only and there is a separate reconfigure screen that does not use any of the changes in your PR? If that were so, it is possible that those id changes would indeed not affect reconfigure at all. |
@himdel Reconfigure and Resize use two different views and two different angular controllers (and different controller methods, |
Aah, @mansam thanks, that helps! :) Ok, risking it. I still think it's a very bad idea to call the same But, it does seem to work. |
Aaah, but I was too rash, sorry :(. @sseago You promised to fix all the other review comments and didn't. So, please create a PR to fix:
(Or should we just revert for now?) (@simaishi Please don't backport without the second PR - #4182) |
Ah, thanks @mansam .. we'll address the remaining issues in #4182 (thanks @ZitaNemeckova ! :)) |
Unfortunately @himdel was right. It no longer works when you want to edit reconfigure request for Infra VM. New request for Infra VM reconfigure seems to work. EDIT: EDIT2: I was wrong. It's not breaking editing reconfigure request for Infra VM. |
The initial "resize approval workflow" feature work is missing some follow-on work needed to allow admin editing of resize/reconfigure requests before approval.
This PR depends on core PR ManageIQ/manageiq#16381