Skip to content

Commit 5d89d59

Browse files
authored
Fixes project creation with self-assigned contacts (#1209)
For user accounts without any orcid identifier linked, self assignment for project contacts was impossible. This is fixed now. Co-authored-by: KochTobi <[email protected]>
1 parent 145a666 commit 5d89d59

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

project-management/src/main/java/life/qbic/projectmanagement/domain/model/project/Contact.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import jakarta.persistence.Embeddable;
66
import java.util.Objects;
7+
import java.util.Optional;
78

89
/**
910
* Record representing a person reference with name and contact email address
@@ -24,8 +25,6 @@ public class Contact {
2425
public Contact(String fullName, String emailAddress, String oidc, String oidcIssuer) {
2526
requireNonNull(fullName, "fullName must not be null");
2627
requireNonNull(emailAddress, "emailAddress must not be null");
27-
requireNonNull(oidc, "oidc must not be null");
28-
requireNonNull(oidcIssuer, "oidcIssuer must not be null");
2928
if (fullName.isBlank()) {
3029
throw new IllegalArgumentException("A contacts name must not be empty");
3130
}
@@ -50,12 +49,15 @@ public String emailAddress() {
5049
return emailAddress;
5150
}
5251

53-
public String oidc() {
54-
return oidc;
52+
public Optional<OidcInformation> oidcInformation() {
53+
if (oidc == null || oidc.isBlank() || oidcIssuer == null || oidcIssuer.isBlank()) {
54+
return Optional.empty();
55+
}
56+
return Optional.of(new OidcInformation(oidc, oidcIssuer));
5557
}
5658

57-
public String oidcIssuer() {
58-
return oidcIssuer;
59+
public record OidcInformation(String oidcId, String oidcIssuer) {
60+
5961
}
6062

6163
@Override

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/info/ProjectSummaryComponent.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import life.qbic.projectmanagement.application.ProjectOverview.UserInfo;
9191
import life.qbic.projectmanagement.application.api.AsyncProjectService;
9292
import life.qbic.projectmanagement.application.api.AsyncProjectService.AccessDeniedException;
93-
import life.qbic.projectmanagement.application.api.AsyncProjectService.FundingDeletion;
9493
import life.qbic.projectmanagement.application.api.AsyncProjectService.FundingInformation;
9594
import life.qbic.projectmanagement.application.api.AsyncProjectService.FundingInformationCreationRequest;
9695
import life.qbic.projectmanagement.application.api.AsyncProjectService.FundingInformationCreationResponse;
@@ -103,7 +102,6 @@
103102
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectDeletionResponse;
104103
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectManager;
105104
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectResponsible;
106-
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectResponsibleDeletion;
107105
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectResponsibleDeletionRequest;
108106
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectResponsibleDeletionResponse;
109107
import life.qbic.projectmanagement.application.api.AsyncProjectService.ProjectUpdateRequest;
@@ -114,6 +112,7 @@
114112
import life.qbic.projectmanagement.application.experiment.ExperimentInformationService;
115113
import life.qbic.projectmanagement.domain.model.experiment.Experiment;
116114
import life.qbic.projectmanagement.domain.model.project.Contact;
115+
import life.qbic.projectmanagement.domain.model.project.Contact.OidcInformation;
117116
import life.qbic.projectmanagement.domain.model.project.Project;
118117
import life.qbic.projectmanagement.domain.model.project.ProjectCode;
119118
import life.qbic.projectmanagement.domain.model.project.ProjectId;
@@ -227,7 +226,8 @@ private static ProjectInformation convertToInfo(Project project) {
227226

228227
private static life.qbic.datamanager.views.general.contact.Contact convert(Contact contact) {
229228
return new life.qbic.datamanager.views.general.contact.Contact(contact.fullName(),
230-
contact.emailAddress(), contact.oidc(), contact.oidcIssuer());
229+
contact.emailAddress(), contact.oidcInformation().map(OidcInformation::oidcId).orElse(null),
230+
contact.oidcInformation().map(OidcInformation::oidcIssuer).orElse(null));
231231
}
232232

233233
private static Button createButtonWithListener(String label,
@@ -463,20 +463,19 @@ private Div renderContactInfo(Contact contact) {
463463
var email = new Anchor("mailto:" + contact.emailAddress(), contact.emailAddress());
464464
contactInfo.add(name, email);
465465
//Account for contacts without oidc or oidcissuer set
466-
if (contact.oidc() == null || contact.oidcIssuer() == null) {
466+
if (contact.oidcInformation().isEmpty()) {
467467
return contactInfo;
468468
}
469-
if (contact.oidcIssuer().isEmpty() || contact.oidc().isEmpty()) {
470-
return contactInfo;
471-
}
472-
var oidcType = Arrays.stream(OidcType.values())
473-
.filter(ot -> ot.getIssuer().equals(contact.oidcIssuer()))
469+
OidcInformation oidcInformation = contact.oidcInformation().orElseThrow();
470+
var optionalOidcType = Arrays.stream(OidcType.values())
471+
.filter(ot -> ot.getIssuer().equals(oidcInformation.oidcIssuer()))
474472
.findFirst();
475-
if (oidcType.isPresent()) {
476-
String oidcUrl = oidcType.get().getUrlFor(contact.oidc());
477-
Anchor oidcLink = new Anchor(oidcUrl, contact.oidc());
473+
if (optionalOidcType.isPresent()) {
474+
OidcType oidcType = optionalOidcType.orElseThrow();
475+
String oidcUrl = oidcType.getUrlFor(oidcInformation.oidcId());
476+
Anchor oidcLink = new Anchor(oidcUrl, oidcInformation.oidcId());
478477
oidcLink.setTarget(AnchorTarget.BLANK);
479-
OidcLogo oidcLogo = new OidcLogo(oidcType.get());
478+
OidcLogo oidcLogo = new OidcLogo(oidcType);
480479
Span oidcSpan = new Span(oidcLogo, oidcLink);
481480
oidcSpan.addClassNames("gap-02", "flex-align-items-center", "flex-horizontal");
482481
contactInfo.add(oidcSpan);

0 commit comments

Comments
 (0)