Skip to content

Commit a9805b5

Browse files
committed
Fix events generated to set Username, Account and Domain of the caller correctly
1 parent a90a7f6 commit a9805b5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,9 +1456,9 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
14561456
logger.debug("Updating user with Id: " + user.getUuid());
14571457

14581458
validateAndUpdateApiAndSecretKeyIfNeeded(updateUserCmd, user);
1459+
validateAndUpdateUserApiKeyAccess(updateUserCmd, user);
14591460
Account account = retrieveAndValidateAccount(user);
14601461

1461-
validateAndUpdateUserApiKeyAccess(updateUserCmd, user, account);
14621462
validateAndUpdateFirstNameIfNeeded(updateUserCmd, user);
14631463
validateAndUpdateLastNameIfNeeded(updateUserCmd, user);
14641464
validateAndUpdateUsernameIfNeeded(updateUserCmd, user, account);
@@ -1676,12 +1676,16 @@ protected void validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd updateUser
16761676
user.setSecretKey(secretKey);
16771677
}
16781678

1679-
protected void validateAndUpdateUserApiKeyAccess(UpdateUserCmd updateUserCmd, UserVO user, Account account) {
1679+
protected void validateAndUpdateUserApiKeyAccess(UpdateUserCmd updateUserCmd, UserVO user) {
16801680
if (updateUserCmd.getApiKeyAccess() != null) {
16811681
try {
16821682
ApiConstants.ApiKeyAccess access = ApiConstants.ApiKeyAccess.valueOf(updateUserCmd.getApiKeyAccess().toUpperCase());
16831683
user.setApiKeyAccess(access.toBoolean());
1684-
ActionEventUtils.onActionEvent(user.getId(), account.getAccountId(), account.getDomainId(), EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the user to " + access.toString(), user.getId(), ApiCommandResourceType.User.toString());
1684+
Long callingUserId = CallContext.current().getCallingUserId();
1685+
Account callingAccount = CallContext.current().getCallingAccount();
1686+
ActionEventUtils.onActionEvent(callingUserId, callingAccount.getAccountId(), callingAccount.getDomainId(),
1687+
EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the User to " + access.toString(),
1688+
user.getId(), ApiCommandResourceType.User.toString());
16851689
} catch (IllegalArgumentException ex) {
16861690
throw new InvalidParameterValueException("ApiKeyAccess value can only be Enabled/Disabled/Inherit");
16871691
}
@@ -1693,7 +1697,11 @@ protected void validateAndUpdateAccountApiKeyAccess(UpdateAccountCmd updateAccou
16931697
try {
16941698
ApiConstants.ApiKeyAccess access = ApiConstants.ApiKeyAccess.valueOf(updateAccountCmd.getApiKeyAccess().toUpperCase());
16951699
account.setApiKeyAccess(access.toBoolean());
1696-
ActionEventUtils.onActionEvent(User.UID_ADMIN, account.getAccountId(), account.getDomainId(), EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the account to " + access.toString(), account.getId(), ApiCommandResourceType.Account.toString());
1700+
Long callingUserId = CallContext.current().getCallingUserId();
1701+
Account callingAccount = CallContext.current().getCallingAccount();
1702+
ActionEventUtils.onActionEvent(callingUserId, callingAccount.getAccountId(), callingAccount.getDomainId(),
1703+
EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the Account to " + access.toString(),
1704+
account.getId(), ApiCommandResourceType.Account.toString());
16971705
} catch (IllegalArgumentException ex) {
16981706
throw new InvalidParameterValueException("ApiKeyAccess value can only be Enabled/Disabled/Inherit");
16991707
}

server/src/test/java/com/cloud/user/AccountManagerImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public void validateAndUpdatUserApiKeyAccess() {
520520
Mockito.anyLong(),
521521
Mockito.anyString(), Mockito.anyString(),
522522
Mockito.anyLong(), Mockito.anyString())).thenReturn(1L);
523-
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock, accountMock);
523+
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock);
524524
}
525525

526526
Mockito.verify(userVoMock).setApiKeyAccess(true);
@@ -529,7 +529,7 @@ public void validateAndUpdatUserApiKeyAccess() {
529529
@Test(expected = InvalidParameterValueException.class)
530530
public void validateAndUpdatUserApiKeyAccessInvalidParameter() {
531531
Mockito.doReturn("False").when(UpdateUserCmdMock).getApiKeyAccess();
532-
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock, accountMock);
532+
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock);
533533
}
534534

535535
@Test

0 commit comments

Comments
 (0)