Skip to content

Commit

Permalink
Use string representation of manager.id, not integer
Browse files Browse the repository at this point in the history
It's unsafe to interpret IDs as integers as they may be too large.
But since API returns them as integers, we rather do a workaround
and override them with string equivalents obtained by parsing the
href string:

```
"href":"http://172.16.117.189:3000/api/providers/123000000000001"
                                                |--- the ID ---|
```

Signed-off-by: Miha Pleško <[email protected]>
  • Loading branch information
miha-plesko committed Sep 6, 2018
1 parent 12f5a03 commit a25207a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
var getStorageManagers = function(data) {
// Can handle list of all managers or a single manager.
vm.storageManagers = data.resources ? data.resources : [data];
vm.storageManagers.forEach(function(manager) { manager.id = idFromHref(manager.href) });
};

var getCloudVolumeFormData = function(data) {
Expand All @@ -240,5 +241,12 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
miqService.sparkleOff();
};

var idFromHref = function(href) {
// Explicitly compare to undefined because 0 could potentially be a valid ID.
if(href === undefined) return 'undefined';
// Parse ID from href, e.g. http://172.16.117.189:3000/api/providers/123000000000001.
return href.toString().replace(/\/$/, '').split('/').slice(-1)[0];
};

init();
}]);
2 changes: 1 addition & 1 deletion app/views/cloud_volume/attach.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId', '#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'ATTACH');
miq_bootstrap('#form_div');
2 changes: 1 addition & 1 deletion app/views/cloud_volume/backup_new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId', '#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'BACKUP_NEW');
miq_bootstrap(jQuery('#form_div'));
2 changes: 1 addition & 1 deletion app/views/cloud_volume/backup_select.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId', '#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'BACKUP_SELECT');
miq_bootstrap(jQuery('#form_div'));
2 changes: 1 addition & 1 deletion app/views/cloud_volume/detach.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId', '#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'DETACH');
miq_bootstrap('#form_div');
2 changes: 1 addition & 1 deletion app/views/cloud_volume/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId', '#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'EDIT');
miq_bootstrap(jQuery('#form_div'));
2 changes: 1 addition & 1 deletion app/views/cloud_volume/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id || "new"}');
ManageIQ.angular.app.value('storageManagerId', #{@storage_manager.try(:id) || "undefined"});
ManageIQ.angular.app.value('storageManagerId', '#{@storage_manager.try(:id) || "undefined"}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'NEW');
miq_bootstrap('#form_div');
2 changes: 1 addition & 1 deletion app/views/cloud_volume/snapshot_new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
ManageIQ.angular.app.value('storageManagerId','#{@volume.ext_management_system.id.to_s}');
ManageIQ.angular.app.value('cloudVolumeFormOperation', 'SNAPSHOT_NEW');
miq_bootstrap(jQuery('#form_div'));

0 comments on commit a25207a

Please sign in to comment.