|
39 | 39 |
|
40 | 40 | import javax.inject.Inject; |
41 | 41 |
|
42 | | -import com.cloud.utils.DateUtil; |
43 | 42 | import org.apache.cloudstack.api.ApiErrorCode; |
44 | 43 | import org.apache.cloudstack.api.ServerApiException; |
45 | 44 | import org.apache.cloudstack.api.command.QuotaBalanceCmd; |
|
70 | 69 | import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; |
71 | 70 | import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; |
72 | 71 | import org.apache.cloudstack.quota.dao.QuotaTariffDao; |
73 | | -import org.apache.cloudstack.quota.vo.QuotaAccountVO; |
74 | 72 | import org.apache.cloudstack.quota.dao.QuotaUsageDao; |
| 73 | +import org.apache.cloudstack.quota.vo.QuotaAccountVO; |
75 | 74 | import org.apache.cloudstack.quota.vo.QuotaBalanceVO; |
76 | 75 | import org.apache.cloudstack.quota.vo.QuotaCreditsVO; |
77 | 76 | import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; |
78 | 77 | import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; |
79 | 78 | import org.apache.cloudstack.quota.vo.QuotaTariffVO; |
80 | 79 | import org.apache.cloudstack.quota.vo.QuotaUsageVO; |
81 | 80 | import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; |
| 81 | +import org.apache.commons.lang3.ObjectUtils; |
82 | 82 | import org.apache.commons.lang3.StringUtils; |
83 | 83 | import org.apache.commons.lang3.reflect.FieldUtils; |
84 | | -import org.apache.commons.lang3.ObjectUtils; |
85 | | -import org.apache.logging.log4j.Logger; |
86 | 84 | import org.apache.logging.log4j.LogManager; |
| 85 | +import org.apache.logging.log4j.Logger; |
87 | 86 | import org.springframework.stereotype.Component; |
88 | 87 |
|
89 | 88 | import com.cloud.domain.DomainVO; |
90 | 89 | import com.cloud.domain.dao.DomainDao; |
| 90 | +import com.cloud.event.ActionEvent; |
| 91 | +import com.cloud.event.EventTypes; |
91 | 92 | import com.cloud.exception.InvalidParameterValueException; |
| 93 | +import com.cloud.exception.PermissionDeniedException; |
92 | 94 | import com.cloud.user.Account; |
93 | 95 | import com.cloud.user.AccountManager; |
94 | 96 | import com.cloud.user.AccountVO; |
95 | 97 | import com.cloud.user.User; |
96 | 98 | import com.cloud.user.dao.AccountDao; |
97 | 99 | import com.cloud.user.dao.UserDao; |
| 100 | +import com.cloud.utils.DateUtil; |
98 | 101 | import com.cloud.utils.Pair; |
99 | 102 | import com.cloud.utils.db.Filter; |
100 | | -import com.cloud.event.ActionEvent; |
101 | | -import com.cloud.event.EventTypes; |
102 | 103 |
|
103 | 104 | @Component |
104 | 105 | public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { |
@@ -139,6 +140,12 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { |
139 | 140 | @Inject |
140 | 141 | private ApiDiscoveryService apiDiscoveryService; |
141 | 142 |
|
| 143 | + protected void checkActivationRulesAllowed(String activationRule) { |
| 144 | + if (!_quotaService.isJsInterpretationEnabled() && StringUtils.isNotEmpty(activationRule)) { |
| 145 | + throw new PermissionDeniedException("Quota Tariff Activation Rule cannot be set, as Javascript interpretation is disabled in the configuration."); |
| 146 | + } |
| 147 | + } |
| 148 | + |
142 | 149 | @Override |
143 | 150 | public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff, boolean returnActivationRule) { |
144 | 151 | final QuotaTariffResponse response = new QuotaTariffResponse(); |
@@ -440,6 +447,8 @@ public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) { |
440 | 447 | throw new InvalidParameterValueException(String.format("There is no quota tariffs with name [%s].", name)); |
441 | 448 | } |
442 | 449 |
|
| 450 | + checkActivationRulesAllowed(activationRule); |
| 451 | + |
443 | 452 | Date currentQuotaTariffStartDate = currentQuotaTariff.getEffectiveOn(); |
444 | 453 |
|
445 | 454 | currentQuotaTariff.setRemoved(now); |
@@ -696,6 +705,8 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) { |
696 | 705 | throw new InvalidParameterValueException(String.format("A quota tariff with name [%s] already exist.", name)); |
697 | 706 | } |
698 | 707 |
|
| 708 | + checkActivationRulesAllowed(activationRule); |
| 709 | + |
699 | 710 | if (startDate.compareTo(now) < 0) { |
700 | 711 | throw new InvalidParameterValueException(String.format("The value passed as Quota tariff's start date is in the past: [%s]. " + |
701 | 712 | "Please, inform a date in the future or do not pass the parameter to use the current date and time.", startDate)); |
|
0 commit comments