Skip to content

Commit

Permalink
gchqgh-3358 Fix audit events for user prefs screen
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed May 22, 2023
1 parent b1569d8 commit f1a58ac
Show file tree
Hide file tree
Showing 36 changed files with 655 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void configure() {
RestResourcesBinder.create(binder())
.bind(GlobalConfigResourceImpl.class);
RestResourcesBinder.create(binder())
.bind(UserUserPreferencesResourceImpl.class);
.bind(UserPreferencesResourceImpl.class);

HasSystemInfoBinder.create(binder())
.bind(AppConfigSystemInfo.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package stroom.config.global.impl;

import stroom.config.global.shared.UserPreferencesResource;
import stroom.event.logging.api.StroomEventLoggingService;
import stroom.event.logging.api.StroomEventLoggingUtil;
import stroom.event.logging.rs.api.AutoLogged;
import stroom.event.logging.rs.api.AutoLogged.OperationType;
import stroom.ui.config.shared.UserPreferences;

import event.logging.ComplexLoggedOutcome;
import event.logging.UpdateEventAction;

import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Provider;

@AutoLogged
public class UserPreferencesResourceImpl implements UserPreferencesResource {

private final Provider<UserPreferencesService> preferencesServiceProvider;
private final Provider<StroomEventLoggingService> stroomEventLoggingServiceProvider;

@Inject
UserPreferencesResourceImpl(final Provider<UserPreferencesService> preferencesServiceProvider,
final Provider<StroomEventLoggingService> stroomEventLoggingServiceProvider) {

this.preferencesServiceProvider = Objects.requireNonNull(preferencesServiceProvider);
this.stroomEventLoggingServiceProvider = stroomEventLoggingServiceProvider;
}

@Override
public UserPreferences fetch() {
return preferencesServiceProvider.get().fetch();
}

@AutoLogged(OperationType.MANUALLY_LOGGED)
@Override
public boolean update(final UserPreferences userPreferences) {
final UserPreferencesService userPreferencesService = preferencesServiceProvider.get();
final UserPreferences beforePreferences = userPreferencesService.fetch();

final StroomEventLoggingService stroomEventLoggingService = stroomEventLoggingServiceProvider.get();
final boolean result = stroomEventLoggingService.loggedWorkBuilder()
.withTypeId(StroomEventLoggingUtil.buildTypeId(this, "update"))
.withDescription("Updating own user preferences")
.withDefaultEventAction(UpdateEventAction.builder()
.withBefore(stroomEventLoggingService.convertToMulti(beforePreferences))
.withAfter(stroomEventLoggingService.convertToMulti(userPreferences))
.build())
.withComplexLoggedResult(updateEventAction -> {
final boolean didUpdate = userPreferencesService.update(userPreferences) > 0;

if (didUpdate) {
return ComplexLoggedOutcome.success(didUpdate, updateEventAction);
} else {
return ComplexLoggedOutcome.failure(
didUpdate, updateEventAction, "No rows updated");
}
})
.getResultAndLog();

return result;
}

@Override
public UserPreferences setDefaultUserPreferences(final UserPreferences userPreferences) {
return preferencesServiceProvider.get().setDefaultUserPreferences(userPreferences);
}

@AutoLogged(OperationType.UPDATE)
@Override
public UserPreferences resetToDefaultUserPreferences() {
preferencesServiceProvider.get().delete();
return preferencesServiceProvider.get().fetch();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ public AnalyticRuleDoc(@JsonProperty("type") final String type,
this.processSettings = processSettings;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
public static DocRef.TypedBuilder buildDocRef() {
return DocRef.builder(DOCUMENT_TYPE);
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@Path(UserPreferencesResource.BASE_PATH)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface UserPreferencesResource extends RestResource, DirectRestService {
public interface UserPreferencesResource
extends RestResource, DirectRestService {

String BASE_PATH = "/preferences" + ResourcePaths.V1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public DashboardDoc(@JsonProperty("type") final String type,
this.dashboardConfig = dashboardConfig;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
public static DocRef.TypedBuilder buildDocRef() {
return DocRef.builder(DOCUMENT_TYPE);
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public DataRetentionRules(@JsonProperty("type") final String type,
this.rules = rules;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public DictionaryDoc(@JsonProperty("type") final String type,
this.imports = imports;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ public FeedDoc(@JsonProperty("type") final String type,
this.status = status;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ public IndexDoc(@JsonProperty("type") final String type,
}
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public KafkaConfigDoc(@JsonProperty("type") final String type,
this.data = data;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public PipelineDoc(@JsonProperty("type") final String type,
this.pipelineData = pipelineData;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public TextConverterDoc(@JsonProperty("type") final String type,
}
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public XsltDoc(@JsonProperty("type") final String type,
this.data = data;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
17 changes: 17 additions & 0 deletions stroom-core-shared/src/main/java/stroom/query/shared/QueryDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package stroom.query.shared;

import stroom.docref.DocRef;
import stroom.docstore.shared.Doc;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down Expand Up @@ -66,6 +67,22 @@ public QueryDoc(@JsonProperty("type") final String type,
this.query = query;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
public static DocRef.TypedBuilder buildDocRef() {
return DocRef.builder(DOCUMENT_TYPE);
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public ReceiveDataRules(@JsonProperty("type") final String type,
this.rules = rules;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public ScriptDoc(@JsonProperty("type") final String type,
this.data = data;
}

/**
* @return A new {@link DocRef} for this document's type with the supplied uuid.
*/
public static DocRef getDocRef(final String uuid) {
return DocRef.builder(DOCUMENT_TYPE)
.uuid(uuid)
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
Expand Down
Loading

0 comments on commit f1a58ac

Please sign in to comment.