From bbc13c0721b813d2c6b0e0dabc3e86493048fe54 Mon Sep 17 00:00:00 2001 From: Martin Lowe <martin.lowe@eclipse-foundation.org> Date: Wed, 5 Mar 2025 14:38:47 -0500 Subject: [PATCH] feat: add ability to convert EF user object to public view from model To better support blanking of private fields, a method has been added to the EF user model that takes the same actions the profile API would when sanitizing the model. --- .../efservices/api/models/EfUser.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/efservices/src/main/java/org/eclipsefoundation/efservices/api/models/EfUser.java b/efservices/src/main/java/org/eclipsefoundation/efservices/api/models/EfUser.java index f1e21522..6c4a91bc 100644 --- a/efservices/src/main/java/org/eclipsefoundation/efservices/api/models/EfUser.java +++ b/efservices/src/main/java/org/eclipsefoundation/efservices/api/models/EfUser.java @@ -27,18 +27,18 @@ import io.soabase.recordbuilder.core.RecordBuilder; @RecordBuilder public record EfUser(String uid, String name, String picture, String mail, Eca eca, Boolean isCommitter, String firstName, String lastName, String fullName, Map<String, PublisherAgreement> publisherAgreements, String githubHandle, String twitterHandle, String org, - Integer orgId, String jobTitle, String website, String mxid, Country country, String bio, List<String> interests, List<Email> mailHistory, - List<String> mailAlternate, String ecaUrl, String projectsUrl, String gerritUrl, String mailinglistUrl, String mpcFavoritesUrl, - @JsonIgnore Boolean isBot) { + Integer orgId, String jobTitle, String website, String mxid, Country country, String bio, List<String> interests, + List<Email> mailHistory, List<String> mailAlternate, String ecaUrl, String projectsUrl, String gerritUrl, String mailinglistUrl, + String mpcFavoritesUrl, @JsonIgnore Boolean isBot) { /** * */ public EfUser(String uid, String name, String picture, String mail, Eca eca, Boolean isCommitter, String firstName, String lastName, String fullName, Map<String, PublisherAgreement> publisherAgreements, String githubHandle, String twitterHandle, String org, - Integer orgId, String jobTitle, String website, String mxid, Country country, String bio, List<String> interests, List<Email> mailHistory, - List<String> mailAlternate, String ecaUrl, String projectsUrl, String gerritUrl, String mailinglistUrl, String mpcFavoritesUrl, - Boolean isBot) { + Integer orgId, String jobTitle, String website, String mxid, Country country, String bio, List<String> interests, + List<Email> mailHistory, List<String> mailAlternate, String ecaUrl, String projectsUrl, String gerritUrl, String mailinglistUrl, + String mpcFavoritesUrl, Boolean isBot) { this.uid = Objects.requireNonNull(uid); this.name = Objects.requireNonNull(name); this.picture = Objects.requireNonNull(picture); @@ -69,6 +69,22 @@ public record EfUser(String uid, String name, String picture, String mail, Eca e this.isBot = isBot; } + /** + * Converts the user profile to the restricted public view. + * + * @return current user profile, with the private data blanked out. + */ + public EfUser getPublicProfile() { + return EfUserBuilder + .builder(this) + .mail("") + .mxid("") + .country(EfUserCountryBuilder.builder().code(null).name(null).build()) + .mailAlternate(Collections.emptyList()) + .mailHistory(Collections.emptyList()) + .build(); + } + public static EfUser createBotStub(String name, String mail) { return EfUserBuilder .builder() -- GitLab