From a5f88db6801d62e147febd8bca76dcc64d22e2d6 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 5 Jan 2024 15:33:27 +0200 Subject: [PATCH] fix dmp invitation dialog --- .../service/tenant/TenantServiceImpl.java | 5 +-- .../controllers/v2/DescriptionController.java | 3 -- dmp-frontend/src/app/core/model/user/user.ts | 6 ++++ .../app/core/services/user/user.service.ts | 7 +++- .../dmp-invitation-dialog.component.html | 2 +- .../dmp-invitation-dialog.component.scss | 2 +- .../dialog/dmp-invitation-dialog.component.ts | 32 +++++++++++++++---- .../ui/dmp/overview/dmp-overview.component.ts | 22 ++++++------- 8 files changed, 51 insertions(+), 28 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java index 8d14c33b3..b05211a6a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java @@ -29,7 +29,6 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import gr.cite.tools.validation.ValidationService; import jakarta.persistence.EntityManager; import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; @@ -68,7 +67,6 @@ public class TenantServiceImpl implements TenantService { private final ResponseUtilsService responseUtilsService; private final XmlHandlingService xmlHandlingService; private final ErrorThesaurusProperties errors; - private final ValidationService validationService; private final EncryptionService encryptionService; private final TenantProperties properties; @@ -84,7 +82,7 @@ public class TenantServiceImpl implements TenantService { ResponseUtilsService responseUtilsService, XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors, - ValidationService validationService, EncryptionService encryptionService, TenantProperties properties) { + EncryptionService encryptionService, TenantProperties properties) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -95,7 +93,6 @@ public class TenantServiceImpl implements TenantService { this.responseUtilsService = responseUtilsService; this.xmlHandlingService = xmlHandlingService; this.errors = errors; - this.validationService = validationService; this.encryptionService = encryptionService; this.properties = properties; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java index e9c4aa2f0..757a2d9d1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java @@ -7,7 +7,6 @@ import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.validation.ValidationFilterAnnotation; -import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.model.Description; import eu.eudat.model.Dmp; import eu.eudat.model.PublicDescription; @@ -21,8 +20,6 @@ import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DmpQuery; import eu.eudat.query.lookup.DescriptionLookup; import eu.eudat.service.description.DescriptionService; -import eu.eudat.service.description.DescriptionServiceImpl; -import eu.eudat.service.dmp.DmpService; import eu.eudat.service.elastic.ElasticQueryHelperService; import eu.eudat.service.transformer.FileTransformerService; import gr.cite.tools.auditing.AuditService; diff --git a/dmp-frontend/src/app/core/model/user/user.ts b/dmp-frontend/src/app/core/model/user/user.ts index 8e95be828..40d3f965d 100644 --- a/dmp-frontend/src/app/core/model/user/user.ts +++ b/dmp-frontend/src/app/core/model/user/user.ts @@ -63,3 +63,9 @@ export interface UserCredential { user: User; createdAt: Date; } + +export interface DmpAssociatedUser { + id: Guid; + name: string; + email: string; +} diff --git a/dmp-frontend/src/app/core/services/user/user.service.ts b/dmp-frontend/src/app/core/services/user/user.service.ts index 2506ba5ec..ba382f705 100644 --- a/dmp-frontend/src/app/core/services/user/user.service.ts +++ b/dmp-frontend/src/app/core/services/user/user.service.ts @@ -1,7 +1,7 @@ import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { IsActive } from '@app/core/common/enum/is-active.enum'; -import { User, UserPersist, UserRolePatchPersist } from '@app/core/model/user/user'; +import { DmpAssociatedUser, User, UserPersist, UserRolePatchPersist } from '@app/core/model/user/user'; import { UserLookup } from '@app/core/query/user.lookup'; import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; @@ -31,6 +31,11 @@ export class UserService { return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); } + queryDmpAssociated(q: UserLookup): Observable> { + const url = `${this.apiBase}/dmp-associated/query`; + return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); + } + getSingle(id: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/${id}`; const options = { params: { f: reqFields } }; diff --git a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.html b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.html index a38fae529..a706a3dd4 100644 --- a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.html +++ b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.html @@ -21,7 +21,7 @@ {{enumUtils.toDmpUserRoleString(dmpUserRoleEnum.Owner)}} - {{enumUtils.toDmpUserRoleString(dmpUserRoleEnum.Member)}} + {{enumUtils.toDmpUserRoleString(dmpUserRoleEnum.User)}} diff --git a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.scss b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.scss index 78ac33791..2e0d5a2a7 100644 --- a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.scss +++ b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.scss @@ -73,7 +73,7 @@ } .select-role { - width: 20% !important; + width: 50% !important; font-size: 14px; color: #848484; height: min-content; diff --git a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts index 3378c5425..a67400936 100644 --- a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts +++ b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts @@ -6,8 +6,8 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; import { DmpUserRole } from '@app/core/common/enum/dmp-user-role'; import { IsActive } from '@app/core/common/enum/is-active.enum'; -import { DmpUserInvitePersist } from '@app/core/model/dmp/dmp'; -import { User } from '@app/core/model/user/user'; +import { DmpUserInvitePersist, DmpUserInviteTypePersist } from '@app/core/model/dmp/dmp'; +import { DmpAssociatedUser, User } from '@app/core/model/user/user'; import { UserLookup } from '@app/core/query/user.lookup'; import { DmpService } from '@app/core/services/dmp/dmp.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; @@ -43,7 +43,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni titleFn: (item) => typeof (item) === 'string' ? item : item.name, subtitleFn: (item) => item.email, valueAssign: (item) => { - const result = typeof (item) === 'string' ? item : item.email; + const result = typeof (item) === 'string' ? item : item.id; return result; }, autoSelectFirstOptionOnBlur: true, @@ -79,7 +79,26 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni send() { if (!this.formGroup.valid) { return; } - const value: DmpUserInvitePersist = this.formGroup.value; + let inviteTypeValues: DmpUserInviteTypePersist[] = []; + this.formGroup.get('users').value.forEach(x => { + let inviteType: DmpUserInviteTypePersist; + if (!(/^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/).test(x)) { + inviteType = { + userId: null, + email: x + }; + }else{ + inviteType = { + userId: Guid.parse(x), + email: null + }; + } + inviteTypeValues.push(inviteType) + }) + const value: DmpUserInvitePersist = { + role: this.formGroup.get('role').value, + users: inviteTypeValues + } // invitationObject.users.push(...(this.formGroup.get('users').value).filter(user => typeof (user) === 'string').map(email => ({ email: email, name: email }))); // invitationObject.users.push(...(this.formGroup.get('users').value).filter(user => typeof (user) !== 'string')); // this.emails.forEach(email => { @@ -101,8 +120,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni this.dialogRef.close(); } - filterUsers(like: string): Observable { - //TODO: refactor. Change with a service that provides a list of the users assosiated with your account. + filterUsers(like: string): Observable { const lookup: UserLookup = new UserLookup(); lookup.page = { size: 100, offset: 0 }; // if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } @@ -116,7 +134,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni }; lookup.order = { items: [nameof(x => x.name)] }; if (like) { lookup.like = this.filterService.transformLike(like); } - return this.userService.query(lookup).pipe(takeUntil(this._destroyed), map(x => x.items)); + return this.userService.queryDmpAssociated(lookup).pipe(takeUntil(this._destroyed), map(x => x.items)); } hasValue(): boolean { diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index 0d4a216e1..bb0b23b4b 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -37,6 +37,7 @@ import { TranslateService } from '@ngx-translate/core'; import * as FileSaver from 'file-saver'; import { takeUntil } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; +import { DmpInvitationDialogComponent } from '../invitation/dialog/dmp-invitation-dialog.component'; @Component({ selector: 'app-dmp-overview', @@ -558,17 +559,16 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { } openShareDialog(rowId: any, rowName: any) { - //TODO: add this - // const dialogRef = this.dialog.open(DmpInvitationDialogComponent, { - // // height: '250px', - // // width: '700px', - // autoFocus: false, - // restoreFocus: false, - // data: { - // dmpId: rowId, - // dmpName: rowName - // } - // }); + const dialogRef = this.dialog.open(DmpInvitationDialogComponent, { + // height: '250px', + // width: '700px', + autoFocus: false, + restoreFocus: false, + data: { + dmpId: rowId, + dmpName: rowName + } + }); } selectDoi(entityDoi: EntityDoi) {