Add preset variable account created (#10200)

This commit is contained in:
Nicole Schmidt 2025-01-29 05:31:17 -03:00 committed by GitHub
parent 3b108b968f
commit 398ffc3b2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View File

@ -17,11 +17,19 @@
package org.apache.cloudstack.quota.activationrule.presetvariables; package org.apache.cloudstack.quota.activationrule.presetvariables;
import com.cloud.utils.DateUtil;
import java.util.Date;
import java.util.TimeZone;
public class Account extends GenericPresetVariable { public class Account extends GenericPresetVariable {
@PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.") @PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.")
private Role role; private Role role;
@PresetVariableDefinition(description = "The date the account was created in GMT. This field will not exist for the first root admin account.")
private String created;
public Role getRole() { public Role getRole() {
return role; return role;
} }
@ -31,4 +39,12 @@ public class Account extends GenericPresetVariable {
fieldNamesToIncludeInToString.add("role"); fieldNamesToIncludeInToString.add("role");
} }
public String getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = DateUtil.displayDateInTimezone(TimeZone.getTimeZone("GMT"), created);
fieldNamesToIncludeInToString.add("created");
}
} }

View File

@ -224,6 +224,7 @@ public class PresetVariableHelper {
Account account = new Account(); Account account = new Account();
account.setId(accountVo.getUuid()); account.setId(accountVo.getUuid());
account.setName(accountVo.getName()); account.setName(accountVo.getName());
account.setCreated(accountVo.getCreated());
setPresetVariableRoleInAccountIfAccountIsNotAProject(accountVo.getType(), accountVo.getRoleId(), account); setPresetVariableRoleInAccountIfAccountIsNotAProject(accountVo.getType(), accountVo.getRoleId(), account);

View File

@ -375,11 +375,12 @@ public class PresetVariableHelperTest {
Account account = getAccountForTests(); Account account = getAccountForTests();
Mockito.doReturn(account.getId()).when(accountVoMock).getUuid(); Mockito.doReturn(account.getId()).when(accountVoMock).getUuid();
Mockito.doReturn(account.getName()).when(accountVoMock).getName(); Mockito.doReturn(account.getName()).when(accountVoMock).getName();
Mockito.doReturn(account.getCreated()).when(accountVoMock).getCreated();
Account result = presetVariableHelperSpy.getPresetVariableAccount(1l); Account result = presetVariableHelperSpy.getPresetVariableAccount(1l);
assertPresetVariableIdAndName(account, result); assertPresetVariableIdAndName(account, result);
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result); validateFieldNamesToIncludeInToString(Arrays.asList("created", "id", "name"), result);
} }
@Test @Test