4444
4545import com .cloud .domain .Domain ;
4646import com .cloud .exception .PermissionDeniedException ;
47+ import com .cloud .projects .ProjectVO ;
4748import com .cloud .projects .dao .ProjectDao ;
4849import com .cloud .user .User ;
4950import com .cloud .user .UserVO ;
@@ -162,6 +163,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
162163
163164 private final Class <?>[] assignableClasses = {GenericPresetVariable .class , ComputingResources .class };
164165
166+ private Set <Account .Type > accountTypesThatCanListAllQuotaSummaries = Sets .newHashSet (Account .Type .ADMIN , Account .Type .DOMAIN_ADMIN );
167+
165168 @ Override
166169 public QuotaTariffResponse createQuotaTariffResponse (QuotaTariffVO tariff , boolean returnActivationRule ) {
167170 final QuotaTariffResponse response = new QuotaTariffResponse ();
@@ -189,12 +192,31 @@ public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff, boole
189192 public Pair <List <QuotaSummaryResponse >, Integer > createQuotaSummaryResponse (QuotaSummaryCmd cmd ) {
190193 Account caller = CallContext .current ().getCallingAccount ();
191194
192- Long accountId = caller .getId ();
193- if (caller .getType () != Account .Type .NORMAL ) {
194- accountId = cmd .getEntityOwnerId ();
195- if (accountId == -1 ) {
196- accountId = null ;
197- }
195+ if (cmd .getProjectId () != null && !cmd .isListAll () && accountTypesThatCanListAllQuotaSummaries .contains (caller .getType ())) {
196+ ProjectVO projectVO = projectDao .findById (cmd .getProjectId ());
197+ Long projectAccountId = projectVO .getProjectAccountId ();
198+ return getQuotaSummaryResponse (projectAccountId , null , null , null , cmd );
199+ }
200+
201+ else if (cmd .getAccountId () != null && !cmd .isListAll () && accountTypesThatCanListAllQuotaSummaries .contains (caller .getType ())) {
202+ return getQuotaSummaryResponse (cmd .getAccountId (), null , null , null , cmd );
203+ }
204+
205+ else if (cmd .getDomainId () != null && !cmd .isListAll () && accountTypesThatCanListAllQuotaSummaries .contains (caller .getType ())) {
206+ return getQuotaSummaryResponse (null , null , cmd .getDomainId (), null , cmd );
207+ }
208+
209+ else if (!accountTypesThatCanListAllQuotaSummaries .contains (caller .getType ()) || !cmd .isListAll ()) {
210+ return getQuotaSummaryResponse (caller .getAccountId (), null , null , null , cmd );
211+ }
212+
213+ return getQuotaSummaryResponseWithListAll (cmd , caller );
214+ }
215+
216+ protected Pair <List <QuotaSummaryResponse >, Integer > getQuotaSummaryResponseWithListAll (QuotaSummaryCmd cmd , Account caller ) {
217+ Long accountId = cmd .getEntityOwnerId ();
218+ if (accountId == -1 ) {
219+ accountId = null ;
198220 }
199221
200222 Long domainId = cmd .getDomainId ();
@@ -215,6 +237,7 @@ public Pair<List<QuotaSummaryResponse>, Integer> createQuotaSummaryResponse(Quot
215237 return getQuotaSummaryResponse (accountId , keyword , domainId , domainPath , cmd );
216238 }
217239
240+
218241 protected Long getAccountIdByAccountName (String accountName , Long domainId , Account caller ) {
219242 if (ObjectUtils .anyNull (accountName , domainId )) {
220243 return null ;
0 commit comments