mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
filter backup offerings by domain id
This commit is contained in:
parent
30ce1217cc
commit
39dacc300e
@ -25,7 +25,7 @@ import org.apache.cloudstack.api.response.ListResponse;
|
|||||||
import org.apache.cloudstack.backup.BackupOffering;
|
import org.apache.cloudstack.backup.BackupOffering;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
|
|
||||||
public abstract class BaseBackupListCmd extends BaseListCmd {
|
public abstract class BaseBackupListCmd extends BaseListAccountResourcesCmd {
|
||||||
|
|
||||||
protected void setupResponseBackupOfferingsList(final List<BackupOffering> offerings, final Integer count) {
|
protected void setupResponseBackupOfferingsList(final List<BackupOffering> offerings, final Integer count) {
|
||||||
final ListResponse<BackupOfferingResponse> response = new ListResponse<>();
|
final ListResponse<BackupOfferingResponse> response = new ListResponse<>();
|
||||||
|
|||||||
@ -357,6 +357,7 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
|
|||||||
final Long offeringId = cmd.getOfferingId();
|
final Long offeringId = cmd.getOfferingId();
|
||||||
final Long zoneId = cmd.getZoneId();
|
final Long zoneId = cmd.getZoneId();
|
||||||
final String keyword = cmd.getKeyword();
|
final String keyword = cmd.getKeyword();
|
||||||
|
Long domainId = cmd.getDomainId();
|
||||||
|
|
||||||
if (offeringId != null) {
|
if (offeringId != null) {
|
||||||
BackupOfferingVO offering = backupOfferingDao.findById(offeringId);
|
BackupOfferingVO offering = backupOfferingDao.findById(offeringId);
|
||||||
@ -370,8 +371,13 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
|
|||||||
SearchBuilder<BackupOfferingVO> sb = backupOfferingDao.createSearchBuilder();
|
SearchBuilder<BackupOfferingVO> sb = backupOfferingDao.createSearchBuilder();
|
||||||
sb.and("zone_id", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
sb.and("zone_id", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
CallContext ctx = CallContext.current();
|
CallContext ctx = CallContext.current();
|
||||||
final Account caller = ctx.getCallingAccount();
|
final Account caller = ctx.getCallingAccount();
|
||||||
|
if (Account.Type.ADMIN != caller.getType() && domainId == null) {
|
||||||
|
domainId = caller.getDomainId();
|
||||||
|
}
|
||||||
|
|
||||||
if (Account.Type.NORMAL == caller.getType()) {
|
if (Account.Type.NORMAL == caller.getType()) {
|
||||||
sb.and("user_backups_allowed", sb.entity().isUserDrivenBackupAllowed(), SearchCriteria.Op.EQ);
|
sb.and("user_backups_allowed", sb.entity().isUserDrivenBackupAllowed(), SearchCriteria.Op.EQ);
|
||||||
}
|
}
|
||||||
@ -384,13 +390,36 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
|
|||||||
if (keyword != null) {
|
if (keyword != null) {
|
||||||
sc.setParameters("name", "%" + keyword + "%");
|
sc.setParameters("name", "%" + keyword + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Account.Type.NORMAL == caller.getType()) {
|
if (Account.Type.NORMAL == caller.getType()) {
|
||||||
sc.setParameters("user_backups_allowed", true);
|
sc.setParameters("user_backups_allowed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<List<BackupOfferingVO>, Integer> result = backupOfferingDao.searchAndCount(sc, searchFilter);
|
Pair<List<BackupOfferingVO>, Integer> result = backupOfferingDao.searchAndCount(sc, searchFilter);
|
||||||
|
|
||||||
|
if (domainId != null) {
|
||||||
|
List<BackupOfferingVO> filteredOfferings = new ArrayList<>();
|
||||||
|
for (BackupOfferingVO offering : result.first()) {
|
||||||
|
List<Long> offeringDomains = backupOfferingDetailsDao.findDomainIds(offering.getId());
|
||||||
|
if (offeringDomains.isEmpty() || offeringDomains.contains(domainId) || containsParentDomain(offeringDomains, domainId)) {
|
||||||
|
filteredOfferings.add(offering);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Pair<>(new ArrayList<>(filteredOfferings), filteredOfferings.size());
|
||||||
|
}
|
||||||
|
|
||||||
return new Pair<>(new ArrayList<>(result.first()), result.second());
|
return new Pair<>(new ArrayList<>(result.first()), result.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean containsParentDomain(List<Long> offeringDomains, Long domainId) {
|
||||||
|
for (Long offeringDomainId : offeringDomains) {
|
||||||
|
if (domainDao.isChildDomain(offeringDomainId, domainId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteBackupOffering(final Long offeringId) {
|
public boolean deleteBackupOffering(final Long offeringId) {
|
||||||
final BackupOfferingVO offering = backupOfferingDao.findById(offeringId);
|
final BackupOfferingVO offering = backupOfferingDao.findById(offeringId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user