Skip to content

Commit

Permalink
Lazy load StorageManagers upon volume creation
Browse files Browse the repository at this point in the history
When creating a new volume user has to pick what StorageManager is volume
supposed to be created with, hence we perform API request to fetch those.
Problem is we share angular controller with other volume operations (attach,
detach) that don't need this list of all managers and fetching those
anyway results in permission denied error due to fine-grained permission
setting.

For example if we give user only permission to attach/detach volume, but
not to view StorageManagers, then we must not perform the API call as it
results in 403 with red popup.

With this commit we refactor controller so that it now only performs the
API call "fetch storage managers" when we're creating a new volume, and
not just always by default.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1571224

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
  • Loading branch information
miha-plesko committed Aug 28, 2018
1 parent 2cddff2 commit 4ae7295
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -21,18 +21,17 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
vm.newRecord = cloudVolumeFormId === 'new';

miqService.sparkleOn();
API.get('/api/providers?expand=resources&attributes=id,name,supports_block_storage&filter[]=supports_block_storage=true')
.then(getStorageManagers)
.catch(miqService.handleFailure);

if (cloudVolumeFormId !== 'new') {
// Fetch cloud volume data before showing the form.
API.get('/api/cloud_volumes/' + cloudVolumeFormId + '?attributes=ext_management_system.type,availability_zone.ems_ref,base_snapshot.ems_ref')
.then(getCloudVolumeFormData)
.catch(miqService.handleFailure);
} else {
// Initialise the form immediately when creating a new volume.
setForm();
// Fetch StorageManagers that we can even create the new volume for.
API.get('/api/providers?expand=resources&attributes=id,name,supports_block_storage&filter[]=supports_block_storage=true')
.then(getStorageManagers)
.catch(miqService.handleFailure);
}
};

Expand Down Expand Up @@ -219,6 +218,8 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
if (storageManagerId) {
vm.storageManagerChanged(vm.cloudVolumeModel.storage_manager_id);
}

setForm();
};

var getCloudVolumeFormData = function(data) {
Expand Down

0 comments on commit 4ae7295

Please sign in to comment.