diff --git a/coral/types/api.d.ts b/coral/types/api.d.ts index e555a2b1e3..55fac5f576 100644 --- a/coral/types/api.d.ts +++ b/coral/types/api.d.ts @@ -1762,26 +1762,26 @@ export type components = { password?: string; accountFound?: boolean; }; - ActivityLog: { + ActivityLogModel: { /** Format: int32 */ - req_no?: number; - /** Format: int32 */ - tenantId?: number; - activityName?: string; - activityType?: string; + req_no: number; + activityName: string; + activityType: string; /** Format: date-time */ - activityTime?: string; - activityTimeString?: string; - details?: string; - user?: string; + activityTime: string; + activityTimeString: string; + details: string; + user: string; + team: string; /** Format: int32 */ - teamId?: number; - env?: string; - envName?: string; - team?: string; - totalNoPages?: string; - currentPage?: string; - allPageNos?: string[]; + teamId: number; + env: string; + /** Format: int32 */ + tenantId: number; + envName: string; + totalNoPages: string; + allPageNos: string[]; + currentPage: string; }; AclsCountPerEnv: { status?: string; @@ -4247,7 +4247,7 @@ export type operations = { /** @description OK */ 200: { content: { - "application/json": components["schemas"]["ActivityLog"][]; + "application/json": components["schemas"]["ActivityLogModel"][]; }; }; }; diff --git a/core/pom.xml b/core/pom.xml index dec91c4c9b..699dc22014 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -36,7 +36,7 @@ 5.10.0 1.33 1.4 - 2.3.0 + 2.2.0 120 diff --git a/core/src/main/java/io/aiven/klaw/controller/UiConfigController.java b/core/src/main/java/io/aiven/klaw/controller/UiConfigController.java index c8c846c869..3a3906d954 100644 --- a/core/src/main/java/io/aiven/klaw/controller/UiConfigController.java +++ b/core/src/main/java/io/aiven/klaw/controller/UiConfigController.java @@ -1,6 +1,6 @@ package io.aiven.klaw.controller; -import io.aiven.klaw.dao.ActivityLog; +import io.aiven.klaw.model.ActivityLogModel; import io.aiven.klaw.model.ApiResponse; import io.aiven.klaw.model.response.DbAuthInfo; import io.aiven.klaw.service.UiConfigControllerService; @@ -50,7 +50,7 @@ public ResponseEntity sendMessageToAdmin( value = "/getActivityLogPerEnv", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE}) - public ResponseEntity> showActivityLog( + public ResponseEntity> showActivityLog( @RequestParam(value = "env", defaultValue = "") String env, @RequestParam("pageNo") String pageNo, @RequestParam(value = "currentPage", defaultValue = "") String currentPage) { diff --git a/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java b/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java index 4e79b7b5d5..7ec7c86f63 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java +++ b/core/src/main/java/io/aiven/klaw/helpers/HandleDbRequests.java @@ -57,6 +57,15 @@ public interface HandleDbRequests { String insertMetrics(KwMetrics kwMetrics); + void insertIntoActivityLog( + String requestType, + int tenantId, + String operationType, + int teamId, + String details, + String envId, + String requestor); + /*--------------------Select */ List getAllTopicsByTopicNameAndTeamIdAndTenantId( diff --git a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java index 43052572ef..022d65dc4c 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java +++ b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/HandleDbRequestsJdbc.java @@ -123,6 +123,19 @@ public String insertMetrics(KwMetrics kwMetrics) { return jdbcInsertHelper.insertMetrics(kwMetrics); } + @Override + public void insertIntoActivityLog( + String requestType, + int tenantId, + String operationType, + int teamId, + String details, + String envId, + String requestor) { + jdbcInsertHelper.insertIntoActivityLog( + requestType, tenantId, operationType, teamId, details, envId, requestor); + } + @Override public List getAllTopicsByTopicNameAndTeamIdAndTenantId( String topicName, int teamId, int tenantId) { diff --git a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java index c0d9666829..c972253900 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java +++ b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java @@ -108,24 +108,7 @@ public synchronized Map insertIntoRequestTopic(TopicRequest topi topicRequest.setRequesttime((new Timestamp(System.currentTimeMillis()))); topicRequestsRepo.save(topicRequest); - UserInfo userInfo = jdbcSelectHelper.selectUserInfo(topicRequest.getRequestor()); - - ActivityLog activityLog = new ActivityLog(); - activityLog.setReq_no(getNextActivityLogRequestId(topicRequest.getTenantId())); - activityLog.setActivityName("TopicRequest"); - activityLog.setActivityType(topicRequest.getRequestOperationType()); - activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); - activityLog.setTeamId(userInfo.getTeamId()); - activityLog.setDetails(topicRequest.getTopicname()); - activityLog.setUser(topicRequest.getRequestor()); - activityLog.setEnv(topicRequest.getEnvironment()); - activityLog.setTenantId(topicRequest.getTenantId()); - - if (ApiResultStatus.SUCCESS.value.equals(insertIntoActivityLog(activityLog))) { - hashMap.put("result", ApiResultStatus.SUCCESS.value); - } else { - hashMap.put("result", ApiResultStatus.FAILURE.value); - } + hashMap.put("result", ApiResultStatus.SUCCESS.value); return hashMap; } @@ -144,25 +127,7 @@ public synchronized Map insertIntoRequestConnector( connectorRequest.setRequesttime((new Timestamp(System.currentTimeMillis()))); kafkaConnectorRequestsRepo.save(connectorRequest); - UserInfo userInfo = jdbcSelectHelper.selectUserInfo(connectorRequest.getRequestor()); - - ActivityLog activityLog = new ActivityLog(); - activityLog.setReq_no(getNextActivityLogRequestId(connectorRequest.getTenantId())); - activityLog.setActivityName("ConnectorRequest"); - activityLog.setActivityType(connectorRequest.getRequestOperationType()); - activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); - activityLog.setTeamId(userInfo.getTeamId()); - activityLog.setDetails( - connectorRequest.getConnectorName() + "," + connectorRequest.getRequestOperationType()); - activityLog.setUser(connectorRequest.getRequestor()); - activityLog.setEnv(connectorRequest.getEnvironment()); - activityLog.setTenantId(connectorRequest.getTenantId()); - - if (ApiResultStatus.SUCCESS.value.equals(insertIntoActivityLog(activityLog))) { - hashMap.put("result", ApiResultStatus.SUCCESS.value); - } else { - hashMap.put("result", ApiResultStatus.FAILURE.value); - } + hashMap.put("result", ApiResultStatus.SUCCESS.value); return hashMap; } @@ -254,28 +219,6 @@ synchronized Map insertIntoRequestAcl(AclRequests aclReq) { aclReq.setRequestingteam(userInfo.getTeamId()); aclRequestsRepo.save(aclReq); - ActivityLog activityLog = new ActivityLog(); - activityLog.setReq_no(getNextActivityLogRequestId(aclReq.getTenantId())); - activityLog.setActivityName("AclRequest"); - activityLog.setActivityType(aclReq.getRequestOperationType()); - activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); - activityLog.setTeamId(userInfo.getTeamId()); - activityLog.setDetails( - aclReq.getAcl_ip() - + "-" - + aclReq.getTopicname() - + "-" - + aclReq.getAcl_ssl() - + "-" - + aclReq.getConsumergroup() - + "-" - + aclReq.getAclType()); - activityLog.setUser(aclReq.getRequestor()); - activityLog.setEnv(aclReq.getEnvironment()); - activityLog.setTenantId(aclReq.getTenantId()); - - // Insert into acl activity log - insertIntoActivityLog(activityLog); hashMap.put("result", ApiResultStatus.SUCCESS.value); return hashMap; } @@ -294,22 +237,6 @@ synchronized Map insertIntoOperationalRequests( operationalRequest.setRequesttime(new Timestamp(System.currentTimeMillis())); operationalRequestsRepo.save(operationalRequest); - UserInfo userInfo = jdbcSelectHelper.selectUserInfo(operationalRequest.getRequestor()); - - ActivityLog activityLog = new ActivityLog(); - activityLog.setReq_no(getNextActivityLogRequestId(operationalRequest.getTenantId())); - activityLog.setActivityName("OperationalRequest"); - activityLog.setActivityType(operationalRequest.getOperationalRequestType().value); - activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); - activityLog.setTeamId(userInfo.getTeamId()); - activityLog.setDetails( - operationalRequest.getTopicname() + "-" + operationalRequest.getConsumerGroup()); - activityLog.setUser(operationalRequest.getRequestor()); - activityLog.setEnv(operationalRequest.getEnvironment()); - activityLog.setTenantId(operationalRequest.getTenantId()); - - // Insert into acl activity log - insertIntoActivityLog(activityLog); hashMap.put("result", ApiResultStatus.SUCCESS.value); return hashMap; } @@ -340,22 +267,6 @@ public synchronized String insertIntoRequestSchema(SchemaRequest schemaRequest) schemaRequestRepo.save(schemaRequest); - UserInfo userInfo = jdbcSelectHelper.selectUserInfo(schemaRequest.getRequestor()); - - ActivityLog activityLog = new ActivityLog(); - activityLog.setReq_no(getNextActivityLogRequestId(schemaRequest.getTenantId())); - activityLog.setActivityName("SchemaRequest"); - activityLog.setActivityType("new"); - activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); - activityLog.setTeamId(userInfo.getTeamId()); - activityLog.setDetails(schemaRequest.getTopicname() + "-" + schemaRequest.getRemarks()); - activityLog.setUser(schemaRequest.getRequestor()); - activityLog.setEnv(schemaRequest.getEnvironment()); - activityLog.setTenantId(schemaRequest.getTenantId()); - - // Insert into acl activity log - insertIntoActivityLog(activityLog); - return ApiResultStatus.SUCCESS.value; } @@ -626,4 +537,25 @@ public String insertProductDetails(ProductDetails productDetails) { productDetailsRepo.save(productDetails); return ApiResultStatus.SUCCESS.value; } + + public void insertIntoActivityLog( + String requestType, + int tenantId, + String operationType, + int teamId, + String details, + String envId, + String requestor) { + ActivityLog activityLog = new ActivityLog(); + activityLog.setReq_no(getNextActivityLogRequestId(tenantId)); + activityLog.setActivityName(requestType + " Request"); + activityLog.setActivityType(operationType); + activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); + activityLog.setTeamId(teamId); + activityLog.setDetails(details); + activityLog.setUser(requestor); + activityLog.setEnv(envId); + activityLog.setTenantId(tenantId); + insertIntoActivityLog(activityLog); + } } diff --git a/core/src/main/java/io/aiven/klaw/model/ActivityLogModel.java b/core/src/main/java/io/aiven/klaw/model/ActivityLogModel.java index c087baab7e..8f0b421099 100644 --- a/core/src/main/java/io/aiven/klaw/model/ActivityLogModel.java +++ b/core/src/main/java/io/aiven/klaw/model/ActivityLogModel.java @@ -1,5 +1,6 @@ package io.aiven.klaw.model; +import jakarta.validation.constraints.NotNull; import java.io.Serializable; import java.sql.Timestamp; import java.util.List; @@ -12,25 +13,33 @@ @ToString public class ActivityLogModel implements Serializable { - private Integer req_no; + @NotNull private Integer req_no; - private String activityName; + @NotNull private String activityName; - private String activityType; + @NotNull private String activityType; - private Timestamp activityTime; + @NotNull private Timestamp activityTime; - private String activityTimeString; + @NotNull private String activityTimeString; - private String details; + @NotNull private String details; - private String user; + @NotNull private String user; - private String team; + @NotNull private String team; - private String env; + @NotNull private Integer teamId; - private String totalNoPages; + @NotNull private String env; - private List allPageNos; + @NotNull private int tenantId; + + @NotNull private String envName; + + @NotNull private String totalNoPages; + + @NotNull private List allPageNos; + + @NotNull private String currentPage; } diff --git a/core/src/main/java/io/aiven/klaw/service/AclControllerService.java b/core/src/main/java/io/aiven/klaw/service/AclControllerService.java index 45dff26f56..68ac90aad7 100644 --- a/core/src/main/java/io/aiven/klaw/service/AclControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/AclControllerService.java @@ -666,12 +666,30 @@ public ApiResponse approveAclRequests(String req_no) if (!updateAclReqStatus.equals(ApiResultStatus.SUCCESS.value)) { notifyUserType = ACL_REQUEST_FAILURE; } else { - saveToTopicHistory(userDetails, tenantId, aclReq); + updateAuditAndHistory(userDetails, tenantId, dbHandle, aclReq); } return emailAndReturnClaimUpdate(aclReq, dbHandle, notifyUserType, updateAclReqStatus); } + private void updateAuditAndHistory( + String userDetails, int tenantId, HandleDbRequests dbHandle, AclRequests aclReq) { + saveToTopicHistory(userDetails, tenantId, aclReq); + dbHandle.insertIntoActivityLog( + RequestEntityType.ACL.value, + tenantId, + aclReq.getRequestOperationType(), + aclReq.getTeamId(), + aclReq.getTopicname() + + "-" + + aclReq.getAclType() + + (aclReq.getAcl_ip() != null ? aclReq.getAcl_ip() + "-" : "") + + (aclReq.getAcl_ssl() != null ? aclReq.getAcl_ssl() + "-" : "") + + (aclReq.getConsumergroup() != null ? aclReq.getConsumergroup() : ""), + aclReq.getEnvironment(), + aclReq.getRequestor()); + } + private ApiResponse approveClaimAcl( AclRequests aclReq, String userDetails, int tenantId, HandleDbRequests dbHandle) throws KlawException, KlawBadRequestException { diff --git a/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java b/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java index b58f6ef607..cfcbdf1967 100644 --- a/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java @@ -38,6 +38,7 @@ import io.aiven.klaw.model.enums.Order; import io.aiven.klaw.model.enums.PermissionType; import io.aiven.klaw.model.enums.PromotionStatusType; +import io.aiven.klaw.model.enums.RequestEntityType; import io.aiven.klaw.model.enums.RequestOperationType; import io.aiven.klaw.model.enums.RequestStatus; import io.aiven.klaw.model.requests.KafkaConnectorModel; @@ -709,8 +710,8 @@ public ApiResponse approveConnectorRequests(String connectorId) tenantId); if (Objects.equals(updateConnectorReqStatus, ApiResultStatus.SUCCESS.value)) { - setConnectorHistory(connectorRequest, userDetails, tenantId); updateConnectorReqStatus = dbHandle.updateConnectorRequest(connectorRequest, userDetails); + updateAuditAndHistory(userDetails, tenantId, connectorRequest, dbHandle); mailService.sendMail( connectorRequest.getConnectorName(), null, @@ -728,6 +729,22 @@ public ApiResponse approveConnectorRequests(String connectorId) : ApiResponse.notOk(updateConnectorReqStatus); } + private void updateAuditAndHistory( + String userDetails, + int tenantId, + KafkaConnectorRequest connectorRequest, + HandleDbRequests dbHandle) { + setConnectorHistory(connectorRequest, userDetails, tenantId); + dbHandle.insertIntoActivityLog( + RequestEntityType.CONNECTOR.value, + tenantId, + connectorRequest.getRequestOperationType(), + connectorRequest.getTeamId(), + "Connector : " + connectorRequest.getConnectorName(), + connectorRequest.getEnvironment(), + connectorRequest.getRequestor()); + } + private void setConnectorHistory( KafkaConnectorRequest connectorRequest, String userName, int tenantId) { try { diff --git a/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java b/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java index a81c6870c6..b17b04b724 100644 --- a/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java +++ b/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java @@ -25,6 +25,7 @@ import io.aiven.klaw.model.enums.OperationalRequestType; import io.aiven.klaw.model.enums.Order; import io.aiven.klaw.model.enums.PermissionType; +import io.aiven.klaw.model.enums.RequestEntityType; import io.aiven.klaw.model.enums.RequestStatus; import io.aiven.klaw.model.requests.ConsumerOffsetResetRequestModel; import io.aiven.klaw.model.response.EnvIdInfo; @@ -442,6 +443,20 @@ public ApiResponse approveOperationalRequests(String reqId) { dbHandle.updateOperationalChangeRequest( operationalRequest, userName, RequestStatus.APPROVED); + dbHandle.insertIntoActivityLog( + RequestEntityType.OPERATIONAL.value, + tenantId, + OperationalRequestType.RESET_CONSUMER_OFFSETS.value, + operationalRequest.getRequestingTeamId(), + "Topic : " + + operationalRequest.getTopicname() + + " ConsumerGroup : " + + operationalRequest.getConsumerGroup() + + " ResetType :" + + operationalRequest.getOffsetResetType(), + operationalRequest.getEnvironment(), + operationalRequest.getRequestor()); + mailService.sendMail( operationalRequest.getTopicname(), offsetResetDetails, diff --git a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java index 2dfc716f27..a9ffaf0832 100644 --- a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java @@ -267,7 +267,8 @@ public ApiResponse execSchemaRequests(String avroSchemaId) throws KlawException } String responseDb = dbHandle.updateSchemaRequest(schemaRequest, userDetails); if (responseDb.equals(ApiResultStatus.SUCCESS.value)) { - saveToTopicHistory(userDetails, tenantId, schemaRequest); + updateAuditAndHistory( + userDetails, tenantId, schemaRequest, dbHandle, registerSchemaCustomResponse); } // send mail to producers and consumers @@ -300,6 +301,28 @@ public ApiResponse execSchemaRequests(String avroSchemaId) throws KlawException } } + private void updateAuditAndHistory( + String userDetails, + int tenantId, + SchemaRequest schemaRequest, + HandleDbRequests dbHandle, + Map registerSchemaCustomResponse) { + saveToTopicHistory(userDetails, tenantId, schemaRequest); + dbHandle.insertIntoActivityLog( + RequestEntityType.SCHEMA.value, + tenantId, + schemaRequest.getRequestOperationType(), + schemaRequest.getTeamId(), + "Topic : " + + schemaRequest.getTopicname() + + " version : " + + registerSchemaCustomResponse.get("version") + + " id : " + + registerSchemaCustomResponse.get("id"), + schemaRequest.getEnvironment(), + schemaRequest.getRequestor()); + } + public void notifySubscribers(SchemaRequest schemaRequest, int tenantId) { String topic = schemaRequest.getTopicname(); String schemaRequestEnvironment = schemaRequest.getEnvironment(); diff --git a/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java b/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java index 846a6bf5f1..ea272303cb 100644 --- a/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java @@ -794,7 +794,7 @@ private String invokeClusterApiForTopicRequest( updateTopicReqStatus = Objects.requireNonNull(response.getBody()).getMessage(); if (response.getBody().isSuccess()) { - saveToTopicHistory(userName, tenantId, topicRequest); + updateAuditAndHistory(userName, tenantId, topicRequest, dbHandle); updateTopicReqStatus = dbHandle.updateTopicRequest(topicRequest, userName).getResultStatus(); mailService.sendMail( @@ -812,6 +812,19 @@ private String invokeClusterApiForTopicRequest( return updateTopicReqStatus; } + private void updateAuditAndHistory( + String userName, int tenantId, TopicRequest topicRequest, HandleDbRequests dbHandle) { + saveToTopicHistory(userName, tenantId, topicRequest); + dbHandle.insertIntoActivityLog( + RequestEntityType.TOPIC.value, + tenantId, + topicRequest.getRequestOperationType(), + topicRequest.getTeamId(), + RequestEntityType.TOPIC.value + " : " + topicRequest.getTopicname(), + topicRequest.getEnvironment(), + topicRequest.getRequestor()); + } + private void saveToTopicHistory(String userName, int tenantId, TopicRequest topicRequest) { List topicHistoryList = commonUtilsService.saveTopicHistory( diff --git a/core/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java b/core/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java index e481b3ab51..da3ccdb781 100644 --- a/core/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java @@ -1,16 +1,20 @@ package io.aiven.klaw.service; import static io.aiven.klaw.model.enums.AuthenticationType.DATABASE; +import static org.springframework.beans.BeanUtils.copyProperties; import io.aiven.klaw.config.ManageDatabase; import io.aiven.klaw.dao.ActivityLog; import io.aiven.klaw.dao.Env; import io.aiven.klaw.helpers.Pager; +import io.aiven.klaw.model.ActivityLogModel; import io.aiven.klaw.model.ApiResponse; import io.aiven.klaw.model.enums.PermissionType; +import io.aiven.klaw.model.enums.RequestEntityType; import io.aiven.klaw.model.response.DbAuthInfo; import java.util.*; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; @@ -43,7 +47,7 @@ private String getUserName() { return mailService.getUserName(getPrincipal()); } - public List showActivityLog(String env, String pageNo, String currentPage) { + public List showActivityLog(String env, String pageNo, String currentPage) { log.debug("showActivityLog {} {}", env, pageNo); String userName = getUserName(); List origActivityList; @@ -66,27 +70,29 @@ public List showActivityLog(String env, String pageNo, String curre currentPage, origActivityList, (pageContext, activityLog) -> { - activityLog.setEnvName( + ActivityLogModel activityLogModel = new ActivityLogModel(); + copyProperties(activityLog, activityLogModel); + activityLogModel.setEnvName( getEnvName(activityLog.getEnv(), activityLog.getActivityName(), tenantId)); - activityLog.setDetails(activityLog.getDetails().replaceAll("null", "")); - activityLog.setAllPageNos(pageContext.getAllPageNos()); - activityLog.setTotalNoPages(pageContext.getTotalPages()); - activityLog.setCurrentPage(pageContext.getPageNo()); - activityLog.setTeam( + activityLogModel.setDetails(activityLog.getDetails().replaceAll("null", "")); + activityLogModel.setAllPageNos(pageContext.getAllPageNos()); + activityLogModel.setTotalNoPages(pageContext.getTotalPages()); + activityLogModel.setCurrentPage(pageContext.getPageNo()); + activityLogModel.setTeam( manageDatabase.getTeamNameFromTeamId(tenantId, activityLog.getTeamId())); - return activityLog; + return activityLogModel; }); } public String getEnvName(String envId, String activityName, int tenantId) { Optional envFound; - if ("SchemaRequest".equals(activityName)) { + if (StringUtils.containsIgnoreCase(activityName, RequestEntityType.SCHEMA.value)) { envFound = manageDatabase.getSchemaRegEnvList(tenantId).stream() .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); - } else if ("ConnectorRequest".equals(activityName)) { + } else if (StringUtils.containsIgnoreCase(activityName, RequestEntityType.CONNECTOR.value)) { envFound = manageDatabase.getKafkaConnectEnvList(tenantId).stream() .filter(env -> Objects.equals(env.getId(), envId)) diff --git a/core/src/main/resources/static/js/showActivityLog.js b/core/src/main/resources/static/js/showActivityLog.js index 211398381b..4bd0039c19 100644 --- a/core/src/main/resources/static/js/showActivityLog.js +++ b/core/src/main/resources/static/js/showActivityLog.js @@ -213,9 +213,11 @@ app.controller("showActivityLogCtrl", function($scope, $http, $location, $window $scope.getActivityLog = function(pageNoSelected) { var serviceInput = {}; - - if($scope.resultPageSelected && $scope.resultPageSelected == pageNoSelected) - return; + if($scope.resultPageSelected && $scope.resultPageSelected === pageNoSelected){ + if(!$scope.getActivityLog.envId){ + return; + } + } //serviceInput['clusterType'] = $scope.getTopics.clusterType.value; serviceInput['env'] = $scope.getActivityLog.envId; diff --git a/core/src/main/resources/templates/activityLog.html b/core/src/main/resources/templates/activityLog.html index c3eadeee4a..5c5db98f09 100644 --- a/core/src/main/resources/templates/activityLog.html +++ b/core/src/main/resources/templates/activityLog.html @@ -486,26 +486,11 @@

Shortcuts

-
+
Activity
{{ resultBrowset.activityName }}
-
-
Activity
- {{ resultBrowset.activityName }} - -
-
-
Activity
- {{ resultBrowset.activityName }} - -
-
-
Activity
- {{ resultBrowset.activityName }} - -
Environment
diff --git a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java index 58ec689661..b5f51eddaa 100644 --- a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java +++ b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java @@ -21,6 +21,7 @@ import io.aiven.klaw.dao.AclRequests; import io.aiven.klaw.dao.EnvTag; import io.aiven.klaw.model.AclInfo; +import io.aiven.klaw.model.ActivityLogModel; import io.aiven.klaw.model.ApiResponse; import io.aiven.klaw.model.KwPropertiesModel; import io.aiven.klaw.model.ResourceHistory; @@ -462,6 +463,23 @@ public void approveTopic() throws Exception { ApiResponse response1 = OBJECT_MAPPER.readValue(response, new TypeReference<>() {}); assertThat(response1.isSuccess()).isTrue(); + + response = + mvc.perform( + MockMvcRequestBuilders.get("/getActivityLogPerEnv") + .with(user(user2).password(PASSWORD)) + .param("env", "1") + .param("pageNo", "1") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + + List response2 = OBJECT_MAPPER.readValue(response, new TypeReference<>() {}); + assertThat(response2.size()).isEqualTo(1); + assertThat(response2.get(0).getDetails()).contains(topicName); } @Test diff --git a/core/src/test/java/io/aiven/klaw/UtilMethods.java b/core/src/test/java/io/aiven/klaw/UtilMethods.java index 20aeb38849..26ea18aa05 100644 --- a/core/src/test/java/io/aiven/klaw/UtilMethods.java +++ b/core/src/test/java/io/aiven/klaw/UtilMethods.java @@ -187,6 +187,14 @@ public List getLogs() { return activityLogs; } + public List getLogModels() { + List activityLogs = new ArrayList<>(); + ActivityLogModel activityLog = new ActivityLogModel(); + activityLog.setActivityTime(new Timestamp(System.currentTimeMillis())); + activityLogs.add(activityLog); + return activityLogs; + } + public Topic getTopic(String topicName) { Topic topic = new Topic(); topic.setTeamId(3); diff --git a/core/src/test/java/io/aiven/klaw/controller/UiConfigControllerTest.java b/core/src/test/java/io/aiven/klaw/controller/UiConfigControllerTest.java index ebfad368cb..c62ca91e5e 100644 --- a/core/src/test/java/io/aiven/klaw/controller/UiConfigControllerTest.java +++ b/core/src/test/java/io/aiven/klaw/controller/UiConfigControllerTest.java @@ -9,8 +9,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.aiven.klaw.UtilMethods; -import io.aiven.klaw.dao.ActivityLog; import io.aiven.klaw.dao.Team; +import io.aiven.klaw.model.ActivityLogModel; import io.aiven.klaw.model.ApiResponse; import io.aiven.klaw.model.enums.ApiResultStatus; import io.aiven.klaw.model.enums.KafkaClustersType; @@ -391,7 +391,7 @@ public void getMyProfileInfo() throws Exception { @Test @Order(20) public void showActivityLog() throws Exception { - List activityLogs = utilMethods.getLogs(); + List activityLogs = utilMethods.getLogModels(); when(uiConfigControllerService.showActivityLog(anyString(), anyString(), anyString())) .thenReturn(activityLogs); diff --git a/core/src/test/java/io/aiven/klaw/service/AclControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/AclControllerServiceTest.java index 33b269ba2e..b06e7658cd 100644 --- a/core/src/test/java/io/aiven/klaw/service/AclControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/AclControllerServiceTest.java @@ -1101,6 +1101,7 @@ private AclRequests getAclRequestDao() { aclReq.setReq_no(112); aclReq.setEnvironment("1"); aclReq.setRequestor("kwuserb"); + aclReq.setTeamId(1001); aclReq.setRequestStatus(RequestStatus.CREATED.value); aclReq.setAcl_ip("1.2.3.4"); aclReq.setAclIpPrincipleType(AclIPPrincipleType.IP_ADDRESS); diff --git a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java index f4e1ca506d..6c8ae48c5c 100644 --- a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java @@ -212,6 +212,7 @@ public void execSchemaRequestsSuccess() throws KlawException { schemaRequest.setRequestor("kwuserb"); schemaRequest.setEnvironment("1"); schemaRequest.setTopicname("topic"); + schemaRequest.setTeamId(1001); stubUserInfo(); when(handleDbRequests.getSchemaRequest(anyInt(), anyInt())).thenReturn(schemaRequest); diff --git a/openapi.yaml b/openapi.yaml index f441c384a1..68814752ad 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -5268,7 +5268,7 @@ "schema" : { "type" : "array", "items" : { - "$ref" : "#/components/schemas/ActivityLog" + "$ref" : "#/components/schemas/ActivityLogModel" } } } @@ -6865,7 +6865,7 @@ }, "approvalType" : { "type" : "string", - "enum" : [ "RESOURCE_TEAM_OWNER", "ACL_TEAM_OWNER", "TEAM" ] + "enum" : [ "TOPIC_TEAM_OWNER", "CONNECTOR_TEAM_OWNER", "ACL_TEAM_OWNER", "TEAM" ] }, "requiredApprover" : { "type" : "string" @@ -9403,16 +9403,12 @@ } } }, - "ActivityLog" : { + "ActivityLogModel" : { "properties" : { "req_no" : { "type" : "integer", "format" : "int32" }, - "tenantId" : { - "type" : "integer", - "format" : "int32" - }, "activityName" : { "type" : "string" }, @@ -9432,6 +9428,9 @@ "user" : { "type" : "string" }, + "team" : { + "type" : "string" + }, "teamId" : { "type" : "integer", "format" : "int32" @@ -9439,25 +9438,27 @@ "env" : { "type" : "string" }, - "envName" : { - "type" : "string" + "tenantId" : { + "type" : "integer", + "format" : "int32" }, - "team" : { + "envName" : { "type" : "string" }, "totalNoPages" : { "type" : "string" }, - "currentPage" : { - "type" : "string" - }, "allPageNos" : { "type" : "array", "items" : { "type" : "string" } + }, + "currentPage" : { + "type" : "string" } - } + }, + "required" : [ "activityName", "activityTime", "activityTimeString", "activityType", "allPageNos", "currentPage", "details", "env", "envName", "req_no", "team", "teamId", "tenantId", "totalNoPages", "user" ] }, "AclsCountPerEnv" : { "properties" : {