dmp user changes

This commit is contained in:
Efstratios Giannopoulos 2024-03-21 18:44:19 +02:00
parent efd6f5df47
commit 598e27bf74
5 changed files with 21 additions and 14 deletions

View File

@ -190,7 +190,7 @@ public class DmpServiceImpl implements DmpService {
this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates()); this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates());
if (!isUpdate || userScope.isSet()) { if (!isUpdate && userScope.isSet()) {
this.addOwner(data); this.addOwner(data);
if (model.getUsers() == null) model.setUsers(new ArrayList<>()); if (model.getUsers() == null) model.setUsers(new ArrayList<>());
if (model.getUsers().stream().noneMatch(x-> x.getUser() != null && x.getUser().equals(this.userScope.getUserIdSafe()) && DmpUserRole.Owner.equals(x.getRole()))) model.getUsers().add(this.createOwnerPersist()); if (model.getUsers().stream().noneMatch(x-> x.getUser() != null && x.getUser().equals(this.userScope.getUserIdSafe()) && DmpUserRole.Owner.equals(x.getRole()))) model.getUsers().add(this.createOwnerPersist());
@ -203,10 +203,7 @@ public class DmpServiceImpl implements DmpService {
this.annotationEntityTouchedIntegrationEventHandler.handle(AnnotationEntityTouchedIntegrationEventHandler.buildEventFromPersistModel(model)); this.annotationEntityTouchedIntegrationEventHandler.handle(AnnotationEntityTouchedIntegrationEventHandler.buildEventFromPersistModel(model));
this.sendNotification(data); this.sendNotification(data);
this.assignUsers(data.getId(), this.inviteUserOrAssignUsers(data.getId(), model.getUsers(), false), null, false);
if (!this.conventionService.isListNullOrEmpty(model.getUsers())){
this.inviteUserOrAssignUsers(data.getId(), model.getUsers());
}
this.elasticService.persistDmp(data); this.elasticService.persistDmp(data);
@ -566,6 +563,8 @@ public class DmpServiceImpl implements DmpService {
public List<DmpUser> assignUsers(UUID dmpId, List<DmpUserPersist> model, FieldSet fieldSet, boolean disableDelete) throws InvalidApplicationException, IOException { public List<DmpUser> assignUsers(UUID dmpId, List<DmpUserPersist> model, FieldSet fieldSet, boolean disableDelete) throws InvalidApplicationException, IOException {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(dmpId)), Permission.AssignDmpUsers); this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(dmpId)), Permission.AssignDmpUsers);
if (model == null || model.stream().noneMatch(x-> x.getUser() != null && DmpUserRole.Owner.equals(x.getRole()))) throw new MyApplicationException("At least one owner required");
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, dmpId); DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, dmpId);
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
@ -576,7 +575,7 @@ public class DmpServiceImpl implements DmpService {
List<UUID> updatedCreatedIds = new ArrayList<>(); List<UUID> updatedCreatedIds = new ArrayList<>();
for (DmpUserPersist dmpUser : model) { for (DmpUserPersist dmpUser : model) {
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmpId) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null); DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmpId) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole()) && Objects.equals(dmpUser.getSectionId(), x.getSectionId())).findFirst().orElse(null);
if (dmpUserEntity == null){ if (dmpUserEntity == null){
dmpUserEntity = new DmpUserEntity(); dmpUserEntity = new DmpUserEntity();
dmpUserEntity.setId(UUID.randomUUID()); dmpUserEntity.setId(UUID.randomUUID());
@ -589,10 +588,10 @@ public class DmpServiceImpl implements DmpService {
dmpUserEntity.setIsActive(IsActive.Active); dmpUserEntity.setIsActive(IsActive.Active);
this.entityManager.persist(dmpUserEntity); this.entityManager.persist(dmpUserEntity);
} }
updatedCreatedIds.add(dmpUserEntity.getUserId()); updatedCreatedIds.add(dmpUserEntity.getId());
} }
List<DmpUserEntity> toDelete = existingUsers.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getUserId()))).collect(Collectors.toList()); List<DmpUserEntity> toDelete = existingUsers.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
if (!toDelete.isEmpty() && !disableDelete) this.deleterFactory.deleter(DmpUserDeleter.class).delete(toDelete); if (!toDelete.isEmpty() && !disableDelete) this.deleterFactory.deleter(DmpUserDeleter.class).delete(toDelete);
this.entityManager.flush(); this.entityManager.flush();
@ -957,6 +956,12 @@ public class DmpServiceImpl implements DmpService {
// invites // invites
public void inviteUserOrAssignUsers(UUID id, List<DmpUserPersist> users) throws InvalidApplicationException, JAXBException, IOException { public void inviteUserOrAssignUsers(UUID id, List<DmpUserPersist> users) throws InvalidApplicationException, JAXBException, IOException {
this.inviteUserOrAssignUsers(id, users, true);
}
private List<DmpUserPersist> inviteUserOrAssignUsers(UUID id, List<DmpUserPersist> users, boolean persistUsers) throws InvalidApplicationException, JAXBException, IOException {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.InviteDmpUsers); this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.InviteDmpUsers);
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).ids(id).first(); DmpEntity dmp = this.queryFactory.query(DmpQuery.class).ids(id).first();
@ -986,7 +991,8 @@ public class DmpServiceImpl implements DmpService {
} }
} }
if(!usersToAssign.isEmpty()) this.assignUsers(id, usersToAssign, null, true); if(!usersToAssign.isEmpty() && persistUsers) this.assignUsers(id, usersToAssign, null, true);
return usersToAssign;
} }
private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException { private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException {

View File

@ -1,4 +1,5 @@
export enum DmpVersionStatus { export enum DmpVersionStatus {
Current = 0, Current = 0,
Previous = 1 Previous = 1,
NotFinalized = 2
} }

View File

@ -178,7 +178,7 @@ export class DescriptionTemplateService {
if (excludedGroupIds && excludedGroupIds.length > 0) { lookup.excludedGroupIds = excludedGroupIds; } if (excludedGroupIds && excludedGroupIds.length > 0) { lookup.excludedGroupIds = excludedGroupIds; }
lookup.isActive = [IsActive.Active]; lookup.isActive = [IsActive.Active];
lookup.versionStatuses = [DescriptionTemplateVersionStatus.Current]; lookup.versionStatuses = [DescriptionTemplateVersionStatus.Current, DescriptionTemplateVersionStatus.NotFinalized];
lookup.statuses = [DescriptionTemplateStatus.Finalized]; lookup.statuses = [DescriptionTemplateStatus.Finalized];
lookup.project = { lookup.project = {
fields: [ fields: [

View File

@ -179,7 +179,7 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
this.selectedBlueprint = data?.blueprint; this.selectedBlueprint = data?.blueprint;
this.isDeleted = data ? data.isActive === IsActive.Inactive : false; this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
if (data) { if (data && data.id) {
const descriptionSectionPermissionResolverModel: DescriptionSectionPermissionResolver = { const descriptionSectionPermissionResolverModel: DescriptionSectionPermissionResolver = {
dmpId: data.id, dmpId: data.id,
sectionIds: data?.blueprint?.definition?.sections?.map(x => x.id), sectionIds: data?.blueprint?.definition?.sections?.map(x => x.id),

View File

@ -103,7 +103,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
this.lookup.groupIds = [Guid.parse(this.groupId)]; this.lookup.groupIds = [Guid.parse(this.groupId)];
this.lookup.versionStatuses = null; this.lookup.versionStatuses = null;
} else { } else {
this.lookup.versionStatuses = [DmpVersionStatus.Current]; this.lookup.versionStatuses = [DmpVersionStatus.Current, DmpVersionStatus.NotFinalized];
} }
this.refresh(this.lookup); this.refresh(this.lookup);