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

feat: Refactoring of CurrentUserService and introduction of UserDetails and more #15727

Merged
merged 143 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
b8b7e0f
feat: upgrade to Spring 6
netroms Nov 16, 2023
bac10b3
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 17, 2023
5e993f5
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 17, 2023
cf27a0d
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 17, 2023
f8c3322
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 17, 2023
7bcdd88
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 17, 2023
31a91fc
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 20, 2023
f1d6eb1
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 20, 2023
6e9f4bd
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 21, 2023
cfe4799
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 21, 2023
51c9da8
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 24, 2023
1188bf8
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 24, 2023
ebeb68b
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 24, 2023
b511a76
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 24, 2023
7412881
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 24, 2023
0774efc
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 27, 2023
7753fd5
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 27, 2023
5549711
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 27, 2023
fa10f2a
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 28, 2023
8ffe40d
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 28, 2023
2a00613
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Nov 28, 2023
820008d
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 28, 2023
5080701
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 28, 2023
7306448
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 28, 2023
d176298
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 29, 2023
e1088e8
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 29, 2023
f799d82
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 30, 2023
15d5520
feat: Migrate away from deprecated Spring Security configuration
netroms Nov 30, 2023
0ebb0bd
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 1, 2023
859e9b9
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 1, 2023
d12c917
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 1, 2023
7972846
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 1, 2023
fcddc55
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 1, 2023
11ed376
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 4, 2023
b62161b
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 5, 2023
dbbd327
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 5, 2023
1cdff28
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 5, 2023
47d2d48
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 5, 2023
63b72cf
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 5, 2023
7dd48c2
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 5, 2023
6163c6e
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 6, 2023
18812f9
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
e525a3c
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
71c1155
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
72d386d
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
e33f796
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
08acbf4
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
de629b0
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 6, 2023
0f42647
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
d798dd3
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
ac6ea6e
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 6, 2023
5129e77
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
cf94d68
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 6, 2023
f73600b
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 7, 2023
738e0ce
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 8, 2023
bb7ec4f
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 8, 2023
0c94399
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 11, 2023
cffd5a7
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
7f70f94
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
5a79e64
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
c54133a
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
83e2874
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 11, 2023
eb29d00
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
c7864d5
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 11, 2023
154f44c
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
f67e691
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 12, 2023
943edae
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
25893b0
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
0cbbbff
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
34ac34d
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
fd53fd8
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
edcf118
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 12, 2023
313d020
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 12, 2023
5582578
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 12, 2023
8f17084
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
c994ecf
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 13, 2023
6eb1977
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
e210624
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
489d530
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
0035fb2
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
99ca77b
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
34130c3
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
490ee24
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 13, 2023
5e06971
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
9511a5f
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 13, 2023
b4036ed
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 18, 2023
d943e7e
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 18, 2023
efa1e55
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 18, 2023
6965817
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 18, 2023
acdb711
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 18, 2023
7821c30
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 18, 2023
d8111bc
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 18, 2023
e96523a
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 18, 2023
3878fcd
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 19, 2023
2850ed5
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 19, 2023
fe9054c
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 19, 2023
9bc9cc5
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 19, 2023
0b1a8ef
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 19, 2023
66845a7
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 19, 2023
3ed365f
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 20, 2023
099762e
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 20, 2023
6e19257
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 20, 2023
e46e514
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 20, 2023
d9d6abb
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 20, 2023
dc2ac81
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 20, 2023
cad081e
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 20, 2023
2f35912
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 21, 2023
5b23ebf
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 21, 2023
57a7012
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 21, 2023
d8ff11c
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 22, 2023
85f0f34
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Dec 22, 2023
52d762f
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 22, 2023
be56c69
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 22, 2023
b9f422c
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 22, 2023
ef9b692
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 22, 2023
3b06857
feat: Migrate away from deprecated Spring Security configuration
netroms Dec 23, 2023
00e01d5
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 5, 2024
3cada37
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 5, 2024
9cebcc1
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 5, 2024
0dee335
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 5, 2024
4413148
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 5, 2024
e863948
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 5, 2024
2adf7e3
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 5, 2024
334591b
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 8, 2024
bd85560
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 8, 2024
ddce543
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 8, 2024
93c4a7e
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 8, 2024
67f4f99
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 9, 2024
188f6b8
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 9, 2024
bc9725b
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 9, 2024
44f11a5
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 10, 2024
ed06e9b
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 10, 2024
8e7db87
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 10, 2024
6158438
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 10, 2024
f12e8ed
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 2024
88f80dd
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 2024
3ff3bd6
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 11, 2024
cc44756
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 11, 2024
ab02eb9
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 2024
c0aeb7a
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 2024
e7b60db
Merge branch 'master' of github.com:dhis2/dhis2-core into DHIS2-16169…
netroms Jan 11, 2024
f1f234e
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 2024
1ab6228
feat: Migrate away from deprecated Spring Security configuration
netroms Jan 11, 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 @@ -192,7 +192,7 @@
@Nonnull Class<T> type,
@Nonnull Attribute attribute,
@Nonnull String value,
@CheckForNull User userInfo);
@CheckForNull String username);
Dismissed Show dismissed Hide dismissed

@CheckForNull
<T extends IdentifiableObject> T search(@Nonnull Class<T> type, @Nonnull String query);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.user;

import static com.google.common.base.Preconditions.checkNotNull;

import org.hisp.dhis.cache.Cache;
import org.hisp.dhis.cache.CacheProvider;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("org.hisp.dhis.user.CurrentUserGroupService")
public class CurrentUserGroupService {

private final Cache<CurrentUserGroupInfo> currentUserGroupInfoCache;

private final UserService userService;
public CurrentUserGroupService(UserService userService, CacheProvider cacheProvider) {
checkNotNull(cacheProvider);
checkNotNull(cacheProvider);

this.userService = userService;
this.currentUserGroupInfoCache = cacheProvider.createCurrentUserGroupInfoCache();
}

@Transactional(readOnly = true)
public CurrentUserGroupInfo getCurrentUserGroupsInfo() {
CurrentUserDetails user = CurrentUserUtil.getCurrentUserDetails();
return user == null ? null : getCurrentUserGroupsInfo(user.getUid());
}

@Transactional(readOnly = true)
public CurrentUserGroupInfo getCurrentUserGroupsInfo(String userUID) {
return currentUserGroupInfoCache.get(userUID, userService::getCurrentUserGroupInfo);
}

@Transactional(readOnly = true)
public void invalidateUserGroupCache(String userUID) {
try {
currentUserGroupInfoCache.invalidate(userUID);
} catch (NullPointerException exception) {
// Ignore if key doesn't exist
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hisp.dhis.cache.Cache;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.hibernate.annotations.QueryHints;
import org.hisp.dhis.cache.CacheProvider;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.springframework.context.annotation.Lazy;
Expand All @@ -50,19 +52,37 @@
*/
@Service("org.hisp.dhis.user.CurrentUserService")
public class CurrentUserService {
private final UserStore userStore;

private final Cache<CurrentUserGroupInfo> currentUserGroupInfoCache;
// private final Cache<CurrentUserGroupInfo> currentUserGroupInfoCache;

// private final UserStore userService;
private final SessionRegistry sessionRegistry;
private final EntityManager entityManager;

public CurrentUserService(
@Lazy UserStore userStore, CacheProvider cacheProvider, SessionRegistry sessionRegistry) {
checkNotNull(userStore);
public CurrentUserService(SessionRegistry sessionRegistry, EntityManager entityManager) {

this.userStore = userStore;
this.currentUserGroupInfoCache = cacheProvider.createCurrentUserGroupInfoCache();
// this.currentUserGroupInfoCache = cacheProvider.createCurrentUserGroupInfoCache();
this.sessionRegistry = sessionRegistry;
this.entityManager = entityManager;
}

private User getUserByUsername(String username, boolean ignoreCase) {
if (username == null) {
return null;
}

String hql =
ignoreCase
? "from User u where lower(u.username) = lower(:username)"
: "from User u where u.username = :username";

TypedQuery<User> typedQuery = entityManager.createQuery(hql, User.class);
typedQuery.setParameter("username", username);
typedQuery.setHint(QueryHints.CACHEABLE, true);

return typedQuery.getSingleResult();
// return QueryUtils.getSingleResult(typedQuery);

}

/**
Expand All @@ -77,7 +97,7 @@ public String getCurrentUsername() {
public User getCurrentUser() {
String username = CurrentUserUtil.getCurrentUsername();

return userStore.getUserByUsername(username, false);
return getUserByUsername(username, false);
}

@Transactional(readOnly = true)
Expand All @@ -101,27 +121,6 @@ public boolean currentUserIsAuthorized(String auth) {
return user != null && user.isAuthorized(auth);
}

@Transactional(readOnly = true)
public CurrentUserGroupInfo getCurrentUserGroupsInfo() {
CurrentUserDetails user = CurrentUserUtil.getCurrentUserDetails();

return user == null ? null : getCurrentUserGroupsInfo(user.getUid());
}

@Transactional(readOnly = true)
public CurrentUserGroupInfo getCurrentUserGroupsInfo(String userUID) {
return currentUserGroupInfoCache.get(userUID, key -> userStore.getCurrentUserGroupInfo(key));
}

@Transactional(readOnly = true)
public void invalidateUserGroupCache(String userUID) {
try {
currentUserGroupInfoCache.invalidate(userUID);
} catch (NullPointerException exception) {
// Ignore if key doesn't exist
}
}

public CurrentUserDetailsImpl getCurrentUserPrincipal(String uid) {
return sessionRegistry.getAllPrincipals().stream()
.map(CurrentUserDetailsImpl.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,10 @@ boolean canCurrentUserCanModify(
* @param activeUsername the username of the user to set as active
*/
void setActiveLinkedAccounts(@Nonnull User actingUser, @Nonnull String activeUsername);

CurrentUserGroupInfo getCurrentUserGroupsInfo();

CurrentUserGroupInfo getCurrentUserGroupInfo(String userUID);

void invalidateUserGroupCache(String userUID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Lazy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

Expand All @@ -54,14 +55,12 @@ public HibernateAnalyticsTableHookStore(
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
entityManager,
jdbcTemplate,
publisher,
AnalyticsTableHook.class,
currentUserService,
aclService,
false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
import org.hisp.dhis.user.CurrentUserGroupInfo;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;

@RequiredArgsConstructor
public abstract class AbstractOrganisationUnitAssociationsQueryBuilder {
private final CurrentUserService currentUserService;
private final UserService userService;

private static final String SHARING_OUTER_QUERY_BEGIN =
"select " + " inner_query_alias.uid, " + " inner_query_alias.agg_ou_uid " + "from (";
Expand Down Expand Up @@ -142,7 +143,7 @@ private String innerQueryProvider(
}

private String getSharingConditions(String access) {
CurrentUserGroupInfo currentUserGroupInfo = currentUserService.getCurrentUserGroupsInfo();
CurrentUserGroupInfo currentUserGroupInfo = userService.getCurrentUserGroupsInfo();
return String.join(
" or ",
getOwnerCondition(currentUserGroupInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserService;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -48,7 +49,7 @@ public class CategoryOptionOrganisationUnitAssociationsQueryBuilder
private final String baseTableName = "categoryoption";

public CategoryOptionOrganisationUnitAssociationsQueryBuilder(
CurrentUserService currentUserService) {
super(currentUserService);
UserService userService) {
super(userService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserService;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -47,7 +48,7 @@ public class DataSetOrganisationUnitAssociationsQueryBuilder
@Getter(AccessLevel.PROTECTED)
private final String baseTableName = "dataset";

public DataSetOrganisationUnitAssociationsQueryBuilder(CurrentUserService currentUserService) {
public DataSetOrganisationUnitAssociationsQueryBuilder(UserService currentUserService) {
super(currentUserService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserService;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -47,7 +48,7 @@ public class ProgramOrganisationUnitAssociationsQueryBuilder
@Getter(AccessLevel.PROTECTED)
private final String baseTableName = "program";

public ProgramOrganisationUnitAssociationsQueryBuilder(CurrentUserService currentUserService) {
public ProgramOrganisationUnitAssociationsQueryBuilder(UserService currentUserService) {
super(currentUserService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.hisp.dhis.association.ProgramOrganisationUnitAssociationsQueryBuilder;
import org.hisp.dhis.cache.CacheProvider;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
Expand All @@ -44,31 +45,31 @@ public class JdbcOrgUnitAssociationStoreConfiguration {

@Bean("jdbcProgramOrgUnitAssociationsStore")
public JdbcOrgUnitAssociationsStore jdbcProgramOrgUnitAssociationStore(
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate) {
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate, UserService userService) {
return new JdbcOrgUnitAssociationsStore(
currentUserService,
jdbcTemplate,
new ProgramOrganisationUnitAssociationsQueryBuilder(currentUserService),
new ProgramOrganisationUnitAssociationsQueryBuilder(userService),
cacheProvider.createProgramOrgUnitAssociationCache());
}

@Bean("jdbcCategoryOptionOrgUnitAssociationsStore")
public JdbcOrgUnitAssociationsStore jdbcCategoryOptionOrgUnitAssociationStore(
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate) {
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate, UserService userService) {
return new JdbcOrgUnitAssociationsStore(
currentUserService,
jdbcTemplate,
new CategoryOptionOrganisationUnitAssociationsQueryBuilder(currentUserService),
new CategoryOptionOrganisationUnitAssociationsQueryBuilder(userService),
cacheProvider.createCatOptOrgUnitAssociationCache());
}

@Bean("jdbcDataSetOrgUnitAssociationsStore")
public JdbcOrgUnitAssociationsStore jdbcDataSetOrgUnitAssociationStore(
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate) {
CurrentUserService currentUserService, JdbcTemplate jdbcTemplate, UserService userService) {
return new JdbcOrgUnitAssociationsStore(
currentUserService,
jdbcTemplate,
new DataSetOrganisationUnitAssociationsQueryBuilder(currentUserService),
new DataSetOrganisationUnitAssociationsQueryBuilder(userService),
cacheProvider.createDataSetOrgUnitAssociationCache());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ public HibernateAttributeStore(
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
entityManager,
jdbcTemplate,
publisher,
Attribute.class,
currentUserService,
aclService,
true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ public HibernateCategoryComboStore(
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
entityManager,
jdbcTemplate,
publisher,
CategoryCombo.class,
currentUserService,
aclService,
true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ public HibernateCategoryOptionComboStore(
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService,
DbmsManager dbmsManager) {
super(
entityManager,
jdbcTemplate,
publisher,
CategoryOptionCombo.class,
currentUserService,
aclService,
true);
this.dbmsManager = dbmsManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ public HibernateCategoryOptionGroupSetStore(
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
entityManager,
jdbcTemplate,
publisher,
CategoryOptionGroupSet.class,
currentUserService,
aclService,
true);
}
Expand Down
Loading
Loading