CLOUDSTACK-3101:

fix listDiskOffering to not display offerings to the normal users with forDisplay=false. But display them to ROOT Admin irrespective of the flag.
Added display flag in the updateVolume/offeirng commands
Signed off by : nitin mehta<nitin.mehta@citrix.com>
This commit is contained in:
Nitin Mehta 2013-10-04 18:19:07 -07:00
parent b3c178480b
commit a6852a340d
6 changed files with 33 additions and 7 deletions

View File

@ -84,7 +84,7 @@ public interface VolumeApiService {
Snapshot allocSnapshot(Long volumeId, Long policyId)
throws ResourceAllocationException;
Volume updateVolume(long volumeId, String path, String state, Long storageId);
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume);
/**
* Extracts the volume to a particular location.

View File

@ -49,6 +49,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the disk offering, integer")
private Integer sortKey;
@Parameter(name=ApiConstants.DISPLAY_OFFERING, type=CommandType.BOOLEAN, description="an optional field, whether to display the offering to the end user or not.")
private Boolean displayOffering;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -69,8 +72,11 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
return sortKey;
}
public Boolean getDisplayOffering() {
return displayOffering;
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -54,6 +54,9 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="The state of the volume", since="4.3")
private String state;
@Parameter(name=ApiConstants.DISPLAY_VOLUME, type=CommandType.BOOLEAN, description="an optional field, whether to the display the volume to the end user or not.")
private Boolean displayVolume;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -73,9 +76,12 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
public String getState() {
return state;
}
/////////////////////////////////////////////////////
public Boolean getDisplayVolume() {
return displayVolume;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -126,7 +132,7 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
@Override
public void execute(){
CallContext.current().setEventDetails("Volume Id: "+getId());
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId());
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume());
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
response.setResponseName(getCommandName());

View File

@ -2252,6 +2252,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long domainId = cmd.getDomainId();
Boolean isRootAdmin = _accountMgr.isRootAdmin(account.getType());
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the disk offering
// associated with this domain
@ -2260,6 +2261,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
// check if the user's domain == do's domain || user's domain is
// a child of so's domain for non-root users
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
if(!isRootAdmin){
sc.addAnd("displayOffering", SearchCriteria.Op.EQ, 1);
}
return _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
} else {
throw new PermissionDeniedException("The account:" + account.getAccountName()
@ -2292,6 +2296,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
spc.addOr("domainId", SearchCriteria.Op.NULL); // include public
// offering as where
sc.addAnd("domainId", SearchCriteria.Op.SC, spc);
sc.addAnd("displayOffering", SearchCriteria.Op.EQ, 1);
sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); // non-root
// users should
// not see

View File

@ -2310,6 +2310,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
String name = cmd.getDiskOfferingName();
String displayText = cmd.getDisplayText();
Integer sortKey = cmd.getSortKey();
Boolean displayDiskOffering = cmd.getDisplayOffering();
// Check if diskOffering exists
DiskOffering diskOfferingHandle = _entityMgr.findById(DiskOffering.class, diskOfferingId);
@ -2318,7 +2319,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
}
boolean updateNeeded = (name != null || displayText != null || sortKey != null);
boolean updateNeeded = (name != null || displayText != null || sortKey != null || displayDiskOffering != null);
if (!updateNeeded) {
return _diskOfferingDao.findById(diskOfferingId);
}
@ -2337,6 +2338,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
diskOffering.setSortKey(sortKey);
}
if(displayDiskOffering != null){
diskOffering.setDisplayOffering(displayDiskOffering);
}
// Note: tag editing commented out for now;keeping the code intact,
// might need to re-enable in next releases
// if (tags != null)

View File

@ -1115,12 +1115,16 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPDATE, eventDescription = "updating volume", async = true)
public Volume updateVolume(long volumeId, String path, String state, Long storageId) {
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume) {
VolumeVO volume = _volumeDao.findById(volumeId);
if (path != null) {
volume.setPath(path);
}
if (displayVolume != null) {
volume.setDisplayVolume(displayVolume);
}
if (state != null) {
try {