fix plan-users persist on clone
This commit is contained in:
parent
bb880632c2
commit
788cef46cd
|
@ -18,6 +18,7 @@ import gr.cite.tools.validation.ValidationFailure;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.opencdmp.authorization.AuthorizationFlags;
|
import org.opencdmp.authorization.AuthorizationFlags;
|
||||||
import org.opencdmp.authorization.Permission;
|
import org.opencdmp.authorization.Permission;
|
||||||
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
|
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
|
||||||
|
@ -734,19 +735,21 @@ public class PlanServiceImpl implements PlanService {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
UUID currentUserId = this.userScope.getUserId();
|
UUID currentUserId = this.userScope.getUserId();
|
||||||
boolean currentUserIsInPlan = planUsers.stream().anyMatch(u -> u.getUserId() == currentUserId);
|
|
||||||
if (!currentUserIsInPlan) {
|
|
||||||
PlanUserEntity newUser = new PlanUserEntity();
|
|
||||||
newUser.setId(UUID.randomUUID());
|
|
||||||
newUser.setPlanId(newPlan.getId());
|
|
||||||
newUser.setUserId(currentUserId);
|
|
||||||
newUser.setRole(PlanUserRole.Owner);
|
|
||||||
newUser.setCreatedAt(Instant.now());
|
|
||||||
newUser.setUpdatedAt(Instant.now());
|
|
||||||
newUser.setIsActive(IsActive.Active);
|
|
||||||
|
|
||||||
this.entityManager.persist(newUser);
|
boolean isCurrentUserInPlan = planUsers.stream().anyMatch(u -> u.getUserId().equals(currentUserId));
|
||||||
|
|
||||||
|
if (!isCurrentUserInPlan) {
|
||||||
|
this.addOwner(newPlan);
|
||||||
|
} else {
|
||||||
|
PlanUserEntity currentPlanUser = planUsers.stream().filter(u -> u.getUserId().equals(currentUserId)).toList().getFirst();
|
||||||
|
|
||||||
|
boolean isCurrentUserOwner = PlanUserRole.Owner.equals(currentPlanUser.getRole());
|
||||||
|
if (!isCurrentUserOwner) {
|
||||||
|
planUsers.remove(currentPlanUser);
|
||||||
|
this.addOwner(newPlan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PlanUserEntity planUser : planUsers) {
|
for (PlanUserEntity planUser : planUsers) {
|
||||||
PlanUserEntity newUser = new PlanUserEntity();
|
PlanUserEntity newUser = new PlanUserEntity();
|
||||||
newUser.setId(UUID.randomUUID());
|
newUser.setId(UUID.randomUUID());
|
||||||
|
|
Loading…
Reference in New Issue