Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#202] Fix RoleGroup persistence context
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Dec 10, 2024
1 parent c4ee42a commit cd47a66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cz.cvut.kbss.study.rest.dto.RawJson;
import cz.cvut.kbss.study.rest.util.RestUtils;
import cz.cvut.kbss.study.persistence.data.DataLoader;
import cz.cvut.kbss.study.service.UserService;
import cz.cvut.kbss.study.service.security.SecurityUtils;
import cz.cvut.kbss.study.util.ConfigParam;
import cz.cvut.kbss.study.util.Utils;
Expand Down Expand Up @@ -44,16 +45,17 @@ public class FormGenService {

private final Environment environment;

private final SecurityUtils securityUtils;
private final UserService userService;

public FormGenService(FormGenDao formGenDao,
DataLoader dataLoader,
Environment environment,
SecurityUtils securityUtils) {
SecurityUtils securityUtils,
UserService userService) {
this.formGenDao = formGenDao;
this.dataLoader = dataLoader;
this.environment = environment;
this.securityUtils = securityUtils;
this.userService = userService;
}

@PostConstruct
Expand All @@ -72,7 +74,7 @@ private void loadConfiguration() {
*/
public RawJson generateForm(PatientRecord record) {
Objects.requireNonNull(record);
final User author = securityUtils.getCurrentUser();
final User author = userService.findCurrentUser();
if (author.getInstitution() != null) {
author.getInstitution().setMembers(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cz.cvut.kbss.study.service.repository;

import cz.cvut.kbss.jopa.model.EntityManager;
import cz.cvut.kbss.study.exception.EntityExistsException;
import cz.cvut.kbss.study.exception.NotFoundException;
import cz.cvut.kbss.study.exception.ValidationException;
import cz.cvut.kbss.study.model.Institution;
import cz.cvut.kbss.study.model.User;
import cz.cvut.kbss.study.model.Vocabulary;
import cz.cvut.kbss.study.persistence.dao.GenericDao;
import cz.cvut.kbss.study.persistence.dao.PatientRecordDao;
import cz.cvut.kbss.study.persistence.dao.UserDao;
Expand Down Expand Up @@ -46,18 +46,22 @@ public class RepositoryUserService extends BaseRepositoryService<User> implement

private final ConfigReader config;

private final EntityManager em;

public RepositoryUserService(SecurityUtils securityUtils,
PasswordEncoder passwordEncoder,
UserDao userDao,
PatientRecordDao patientRecordDao,
EmailService email,
ConfigReader config) {
ConfigReader config,
EntityManager em) {
this.securityUtils = securityUtils;
this.passwordEncoder = passwordEncoder;
this.userDao = userDao;
this.patientRecordDao = patientRecordDao;
this.email = email;
this.config = config;
this.em = em;
}

@Override
Expand All @@ -79,7 +83,9 @@ public User getCurrentUser() {
@Transactional(readOnly = true)
@Override
public User findCurrentUser() {
return userDao.findByUsername(securityUtils.getCurrentUser().getUsername());
User currentUser = securityUtils.getCurrentUser();
em.detach(currentUser);
return userDao.findByUsername(currentUser.getUsername());
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit cd47a66

Please sign in to comment.