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

refactor: system and user settings as value objects [DHIS2-18061] #18649

Merged
merged 52 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
48add8f
refactor: user and system settings as immutable value objects [DHIS2-…
jbee Sep 18, 2024
31ba78e
refactor: UserSettingKey gone
jbee Sep 23, 2024
a039ded
fix: compiles again
jbee Sep 23, 2024
1431b11
chore: code format
jbee Sep 23, 2024
a17783a
refactor: unify naming
jbee Sep 23, 2024
986d33e
chore: code format
jbee Sep 23, 2024
045879f
chore: delete unused class
jbee Sep 23, 2024
f187c62
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Sep 23, 2024
3e75e64
refactor: implement settings and tests
jbee Sep 23, 2024
b10582c
fix: value conversions
jbee Sep 23, 2024
4d2ec3f
fix: empty settings init and translations without user context
jbee Sep 23, 2024
033055d
fix: dependencies and user settings access
jbee Sep 23, 2024
05e232e
fix: mock test setup
jbee Sep 23, 2024
7e90aef
fix: mock test setup
jbee Sep 23, 2024
5139793
fix: mock test setup
jbee Sep 24, 2024
8d2237c
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Sep 24, 2024
f0d57c8
fix: mock test setup
jbee Sep 24, 2024
985fab1
fix: mock test setup
jbee Sep 24, 2024
e9a2c51
fix: hibernate mapping requirements
jbee Sep 24, 2024
2b7c15c
fix: system settings persistence layer
jbee Sep 25, 2024
984c63a
fix: maven dependencies
jbee Sep 25, 2024
4505d61
fix: flyway script - decryption
jbee Sep 25, 2024
08c141c
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Sep 25, 2024
e9babff
fix: settings persistence and serialisation
jbee Sep 26, 2024
ced0a75
fix: tests - user setting value persistence
jbee Sep 26, 2024
6980e93
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Sep 26, 2024
c9b301c
fix: system settings API
jbee Sep 26, 2024
39f99c6
fix: ignore empty settings in LazySettings set
jbee Sep 26, 2024
7abc91e
chore: rename service methods to reflect map character
jbee Sep 26, 2024
ca11689
refactor: UserSettings no longer in UserDetails
jbee Oct 2, 2024
d5c8ceb
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Oct 2, 2024
cf90986
fix: settings to JSON enums and session event listener
jbee Oct 2, 2024
ffe4ca5
fix: AnalyticsServiceTest asserts
jbee Oct 2, 2024
a9c6fc5
fix: H2 integration tests
jbee Oct 2, 2024
89275b7
fix: failing tests
jbee Oct 2, 2024
0324e6b
fix: revert exception change
jbee Oct 2, 2024
2088892
fixed: analytics system settings usage null cases
jbee Oct 3, 2024
2f93242
fix: mock tests
jbee Oct 3, 2024
bb89157
fix: settings vs settings translations API and e2e tests
jbee Oct 3, 2024
273c440
Merge remote-tracking branch 'upstream/master' into DHIS2-18061
jbee Oct 3, 2024
6eecd90
chore: rename
jbee Oct 3, 2024
ae4563b
chore: extracted ThreadUserSettings to manage the per thread state
jbee Oct 3, 2024
963f420
fix: imports
jbee Oct 3, 2024
5ff5faf
fix: mvn dependencies
jbee Oct 3, 2024
001aa1c
fix: use different classloader?
jbee Oct 3, 2024
e2466ab
fix: run events tests first
jbee Oct 3, 2024
2929078
fix: remaining integration tests
jbee Oct 3, 2024
35fe8be
Merge branch 'master' into DHIS2-18061
jbee Oct 3, 2024
06612cf
fix: CodeQL issues
jbee Oct 3, 2024
97026d7
chore: sonar issues
jbee Oct 3, 2024
aa85b92
Merge branch 'master' into DHIS2-18061
jbee Oct 4, 2024
2a79b35
Merge branch 'master' into DHIS2-18061
jbee Oct 7, 2024
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 @@ -77,12 +77,8 @@ public interface CacheProvider {

<V> Cache<V> createCurrentUserGroupInfoCache();

<V> Cache<V> createUserSettingCache();

<V> Cache<V> createAttrOptionComboIdCache();

<V> Cache<V> createSystemSettingCache();

<V> Cache<V> createGoogleAccessTokenCache();

<V> Cache<V> createDataItemsPaginationCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
import org.hisp.dhis.schema.annotation.PropertyTransformer;
import org.hisp.dhis.schema.transformer.UserPropertyTransformer;
import org.hisp.dhis.security.acl.Access;
import org.hisp.dhis.setting.UserSettings;
import org.hisp.dhis.translation.Translatable;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.user.CurrentUserUtil;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserDetails;
import org.hisp.dhis.user.UserSettingKey;
import org.hisp.dhis.user.sharing.Sharing;
import org.hisp.dhis.user.sharing.UserAccess;
import org.hisp.dhis.user.sharing.UserGroupAccess;
Expand Down Expand Up @@ -334,7 +334,7 @@ public void setTranslations(Set<Translation> translations) {
* @return a translated value.
*/
protected String getTranslation(String translationKey, String defaultValue) {
Locale locale = CurrentUserUtil.getUserSetting(UserSettingKey.DB_LOCALE);
Locale locale = UserSettings.getCurrentSettings().getUserDbLocale();

final String defaultTranslation = defaultValue != null ? defaultValue.trim() : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.schema.annotation.Gist;
import org.hisp.dhis.setting.UserSettings;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.user.CurrentUserUtil;
import org.hisp.dhis.user.UserSettingKey;

/**
* Base class for translatable object.
Expand Down Expand Up @@ -95,7 +94,7 @@ public void setTranslations(Set<Translation> translations) {
* @return a translated value.
*/
protected String getTranslation(String translationKey, String defaultValue) {
Locale locale = CurrentUserUtil.getUserSetting(UserSettingKey.DB_LOCALE);
Locale locale = UserSettings.getCurrentSettings().getUserDbLocale();

final String defaultTranslation = defaultValue != null ? defaultValue.trim() : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public DatastoreEntry(String namespace, String key) {
this(namespace, key, null, false);
}

public DatastoreEntry(String namespace, String key, String value) {
this(namespace, key, value, false);
}

public DatastoreEntry(String namespace, String key, String value, boolean encrypted) {
this.namespace = namespace;
this.key = key;
Expand All @@ -83,14 +87,19 @@ public DatastoreEntry(String namespace, String key, String value, boolean encryp
@ToString.Include
@EqualsAndHashCode.Include
public String getValue() {
return encrypted ? getEncryptedValue() : getJbPlainValue();
return isEncryptedInternal() ? getEncryptedValue() : getJbPlainValue();
}

public String getJbPlainValue() {
return !encrypted && value != null ? value : jbPlainValue;
return !isEncryptedInternal() && value != null ? value : jbPlainValue;
}

public String getEncryptedValue() {
return encrypted && value != null ? value : encryptedValue;
return isEncryptedInternal() && value != null ? value : encryptedValue;
}

/** Note: this must use a name that is not also a hibernate mapped property */
private boolean isEncryptedInternal() {
return encrypted != null && encrypted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.user.UserDetails;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.transaction.annotation.Transactional;

/**
* Datastore is a key-value store with namespaces to isolate different collections of key-value
Expand All @@ -56,7 +55,7 @@ public interface DatastoreService {

/**
* @param namespace to check
* @return the protection used or {@null} when unprotected
* @return the protection used or {@code null} when unprotected
*/
@CheckForNull
DatastoreNamespaceProtection getProtection(@Nonnull String namespace);
Expand Down Expand Up @@ -143,9 +142,10 @@ <T> T getEntries(DatastoreQuery query, Function<Stream<DatastoreFields>, T> tran
* @return the KeyJsonValue matching the key and namespace.
* @throws AccessDeniedException when user lacks authority for namespace
*/
@CheckForNull
DatastoreEntry getEntry(String namespace, String key) throws ForbiddenException;

@Transactional(readOnly = true)
@CheckForNull
DatastoreEntry getEntry(String namespace, String key, UserDetails user) throws ForbiddenException;

/**
Expand Down Expand Up @@ -191,14 +191,19 @@ void updateEntry(
*/
void deleteEntry(DatastoreEntry entry);

void deleteEntry(DatastoreEntry entry, UserDetails user);

/**
* Adds a new KeyJsonValue entry or updates the entry if the namespace and key already exists.
*
* @param entry the KeyJsonValue entry to be saved or updated.
* @param entry to be saved or updated
* @throws IllegalArgumentException when the entry value is not valid JSON
*/
void saveOrUpdateEntry(DatastoreEntry entry) throws BadRequestException, ForbiddenException;

void saveOrUpdateEntry(DatastoreEntry entry, UserDetails user)
throws BadRequestException, ForbiddenException;

/**
* Deletes all entries associated with a given namespace.
*
Expand Down
Loading
Loading