Skip to content

Commit

Permalink
LKSM Projects: Container Filtering & Storage issues (#3870)
Browse files Browse the repository at this point in the history
  • Loading branch information
XingY authored Nov 29, 2022
1 parent 1ad8e07 commit 88c0e42
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions api/src/org/labkey/api/audit/AuditLogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ default AuditTypeProvider getAuditProvider(String eventType)
@Nullable
<K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId);

@Nullable
<K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId, @Nullable ContainerFilter cf);

<K extends AuditTypeEvent> List<K> getAuditEvents(Container container, User user, String eventType, @Nullable SimpleFilter filter, @Nullable Sort sort);

<K extends AuditTypeEvent> List<K> getAuditEvents(Container container, User user, String eventType, @Nullable SimpleFilter filter, @Nullable Sort sort, @Nullable ContainerFilter cf);
Expand Down
6 changes: 6 additions & 0 deletions api/src/org/labkey/api/audit/DefaultAuditProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, i
return null;
}

@Override
public <K extends AuditTypeEvent> @Nullable K getAuditEvent(User user, String eventType, int rowId, @Nullable ContainerFilter cf)
{
return null;
}

@Override
public <K extends AuditTypeEvent> List<K> getAuditEvents(Container container, User user, String eventType, @Nullable SimpleFilter filter, @Nullable Sort sort)
{
Expand Down
27 changes: 26 additions & 1 deletion audit/src/org/labkey/audit/AuditController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.labkey.audit;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.action.ApiSimpleResponse;
import org.labkey.api.action.QueryViewAction;
Expand Down Expand Up @@ -246,11 +248,22 @@ public void addNavTrail(NavTree root)
@RequiresPermission(ReadPermission.class)
public static class GetDetailedAuditChangesAction extends ReadOnlyApiAction<AuditChangesForm>
{
private @NotNull ContainerFilter getContainerFilter(AuditChangesForm form) throws IllegalArgumentException
{
Container container = getContainer();
User user = getUser();

if (!StringUtils.isEmpty(form.getContainerFilter()))
return ContainerFilter.Type.valueOf(form.getContainerFilter()).create(container, user);

return ContainerFilter.Type.Current.create(container, user);
}

@Override
public Object execute(AuditChangesForm form, BindException errors)
{
ApiSimpleResponse response = new ApiSimpleResponse();
DetailedAuditTypeEvent event = AuditLogService.get().getAuditEvent(getUser(), form.getAuditEventType(), form.getAuditRowId());
DetailedAuditTypeEvent event = AuditLogService.get().getAuditEvent(getUser(), form.getAuditEventType(), form.getAuditRowId(), getContainerFilter(form));

if (event != null)
{
Expand Down Expand Up @@ -328,6 +341,7 @@ public static class AuditChangesForm
{
private int auditRowId;
private String auditEventType;
private String _containerFilter;

public int getAuditRowId()
{
Expand All @@ -348,6 +362,17 @@ public void setAuditEventType(String auditEventType)
{
this.auditEventType = auditEventType;
}

public String getContainerFilter()
{
return _containerFilter;
}

public void setContainerFilter(String containerFilter)
{
_containerFilter = containerFilter;
}

}

@RequiresPermission(ReadPermission.class)
Expand Down
7 changes: 7 additions & 0 deletions audit/src/org/labkey/audit/AuditLogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, i
return LogManager.get().getAuditEvent(user, eventType, rowId);
}

@Nullable
@Override
public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId, @Nullable ContainerFilter cf)
{
return LogManager.get().getAuditEvent(user, eventType, rowId, cf);
}

@Override
public <K extends AuditTypeEvent> List<K> getAuditEvents(Container container, User user, String eventType, @Nullable SimpleFilter filter, @Nullable Sort sort)
{
Expand Down
10 changes: 8 additions & 2 deletions audit/src/org/labkey/audit/model/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public <K extends AuditTypeEvent> void insertEvents(User user, List<K> events)
}

@Nullable
public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId)
public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId, @Nullable ContainerFilter cf)
{
AuditTypeProvider provider = AuditLogService.get().getAuditProvider(eventType);
if (provider != null)
Expand All @@ -192,7 +192,7 @@ public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, i

if (schema != null)
{
TableInfo table = schema.getTable(provider.getEventName());
TableInfo table = schema.getTable(provider.getEventName(), cf);
TableSelector selector = new TableSelector(table, null, null);

return (K)selector.getObject(rowId, provider.getEventClass());
Expand All @@ -201,6 +201,12 @@ public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, i
return null;
}

@Nullable
public <K extends AuditTypeEvent> K getAuditEvent(User user, String eventType, int rowId)
{
return getAuditEvent(user, eventType, rowId, null);
}

public <K extends AuditTypeEvent> List<K> getAuditEvents(Container container, User user, String eventType, @Nullable SimpleFilter filter, @Nullable Sort sort)
{
return getAuditEvents(container, user, eventType, filter, sort, null);
Expand Down

0 comments on commit 88c0e42

Please sign in to comment.