Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audit log bugs #5006

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
import java.util.Collection;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand Down Expand Up @@ -72,8 +72,17 @@ public Object around(ProceedingJoinPoint pjp, ApolloAuditLog auditLog) throws Th
}
}
if (entityName != null && fieldName != null) {
String matchedValue = String.valueOf(arg);
api.appendDataInfluence("AnyMatched", entityName, fieldName, matchedValue);
// if arg is a collection
if (arg instanceof Collection) {
for (Object o : ((Collection<?>) arg).toArray()) {
String matchedValue = String.valueOf(o);
api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue);
}
}
else {
String matchedValue = String.valueOf(arg);
api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void appendDataInfluence(String entityName, String entityId, String field
OpType type = traceContext.tracer().getActiveSpan().getOpType();
ApolloAuditLogDataInfluence.Builder builder = ApolloAuditLogDataInfluence.builder().spanId(spanId)
.entityName(entityName).entityId(entityId).fieldName(fieldName);
if (type == null) {
return;
}
switch (type) {
case CREATE:
case UPDATE:
Expand Down Expand Up @@ -106,7 +109,7 @@ public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition)
f.setAccessible(true);
String val = String.valueOf(f.get(e));
String fieldName = f.getAnnotation(ApolloAuditLogDataInfluenceTableField.class).fieldName();
appendDataInfluence(tableId, tableName, fieldName, val);
appendDataInfluence(tableName, tableId, fieldName, val);
}
} catch (IllegalAccessException ex) {
throw new IllegalArgumentException("failed append data influence, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testAppendDataInfluences() {
api.appendDataInfluences(entities, MockDataInfluenceEntity.class);

Mockito.verify(api, Mockito.times(entityNum))
.appendDataInfluence(Mockito.anyString(), Mockito.eq("MockTableName"), Mockito.eq("MarkedAttribute"),
.appendDataInfluence(Mockito.eq("MockTableName"), Mockito.any(), Mockito.eq("MarkedAttribute"),
Mockito.any());
}

Expand Down
24 changes: 14 additions & 10 deletions apollo-portal/src/main/resources/static/audit_log_trace_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,35 @@ <h4 style="word-break: break-all;">
<div id="dataInfluenceEntity" class="padding-top-5">
<div>
<div style="font-size: 12pt; word-break: break-all">
{{'ApolloAuditLog.DataInfluence.EntityName' | translate}}: {{dataInfluenceEntity[0].name}}
{{'ApolloAuditLog.DataInfluence.EntityName' | translate}}: {{dataInfluenceEntity[1].name}}
</div>
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[0].id != 'AnyMatched'">
{{'ApolloAuditLog.DataInfluence.EntityId' | translate}}: {{dataInfluenceEntity[0].id}}
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[1].id != 'AnyMatched'">
{{'ApolloAuditLog.DataInfluence.EntityId' | translate}}: {{dataInfluenceEntity[1].id}}
</div>
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[0].id == 'AnyMatched'">
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[1].id == 'AnyMatched'">
{{'ApolloAuditLog.DataInfluence.AnyMatchedEntityId' | translate}}
</div>
</div>
<hr style="margin: 5px"/>
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[0].id != 'AnyMatched'">
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[1].id != 'AnyMatched'">
{{'ApolloAuditLog.DataInfluence.Fields' | translate}}:
</div>
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[0].id == 'AnyMatched'">
<div style="font-size: 12pt; word-break: break-all" ng-show="dataInfluenceEntity[1].id == 'AnyMatched'">
{{'ApolloAuditLog.DataInfluence.MatchedFields' | translate}}:
</div>
<div ng-repeat="dataInfluence in dataInfluenceEntity[1]"
<div ng-repeat="dataInfluence in dataInfluenceEntity[1].dtoList"
class="cursor-pointer"
ng-click="showRelatedDataInfluence(dataInfluence.influenceEntityName,dataInfluence.influenceEntityId,dataInfluence.fieldName)">
<div class="audit-field" style="font-size: 12pt; word-break: break-all; padding-bottom: 5px; padding-top: 5px"
ng-show="dataInfluenceEntity[0].id != 'AnyMatched'">
ng-show="dataInfluenceEntity[1].id != 'AnyMatched' && dataInfluence.fieldNewValue">
{{dataInfluence.fieldName}} ==> {{dataInfluence.fieldNewValue}}
</div>
<div class="audit-field" style="font-size: 12pt; word-break: break-all; padding-bottom: 5px; padding-top: 5px"
ng-show="dataInfluenceEntity[0].id == 'AnyMatched'">
ng-show="dataInfluenceEntity[1].id != 'AnyMatched' && !dataInfluence.fieldNewValue">
{{dataInfluence.fieldName}} : {{dataInfluence.fieldOldValue}} ==> (deleted)
</div>
<div class="audit-field" style="font-size: 12pt; word-break: break-all; padding-bottom: 5px; padding-top: 5px"
ng-show="dataInfluenceEntity[1].id == 'AnyMatched'">
{{dataInfluence.fieldName}} <==
{{showingDetail.logDTO.opType == 'DELETE' ? dataInfluence.fieldOldValue : dataInfluence.fieldNewValue}}
</div>
Expand Down Expand Up @@ -158,7 +162,7 @@ <h4 ng-show="relatedDataInfluences && relatedDataInfluences.length > 0"
</thead>
<tbody>
<tr ng-repeat="di in relatedDataInfluences">
<td class="cursor-pointer" style="width: 50%" ng-click="showText(di.fieldNewValue)">{{ di.fieldNewValue }}</td>
<td class="cursor-pointer" style="width: 50%" ng-click="showText(di.fieldNewValue)">{{ di.fieldNewValue ? di.fieldNewValue : '(deleted)' }}</td>
<td class="cursor-pointer" style="width: 50%" ng-click="showText(di.happenedTime)">{{ di.happenedTime | date: 'yyyy-MM-dd HH:mm:ss' }}</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ function auditLogTraceDetailController($scope, $location, $window, $translate, t
name: dto.influenceEntityName,
id: dto.influenceEntityId
};
if (!entityMap.has(key)) {
entityMap.set(key, []);
var keyString = JSON.stringify(key);
var value = {
name: dto.influenceEntityName,
id: dto.influenceEntityId,
dtoList: []
};
if (!entityMap.has(keyString)) {
entityMap.set(keyString, value);
}
entityMap.get(key).push(dto);
entityMap.get(keyString).dtoList.push(dto);
});
$scope.dataInfluenceEntities = Array.from(entityMap);
}
Expand Down
Loading