Skip to content

Commit

Permalink
change birth year to 1900 if user is not admin. (#2162)
Browse files Browse the repository at this point in the history
* change birth year to 1900 if user is not amdin.

* revert changes

---------

Co-authored-by: estradaw <estradaw@objectcomputing>
  • Loading branch information
borinquenkid and estradaw authored Apr 3, 2024
1 parent a04d645 commit 2b108e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
Expand Down Expand Up @@ -343,6 +341,13 @@ public void setExcluded(@Nullable Boolean excluded) {
this.excluded = excluded;
}

@Transient
public void clearBirthYear() {
if (Objects.nonNull(this.birthDate)) {
birthDate = birthDate.withYear(1900);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Set<MemberProfile> findByValues(String firstName, String lastName, String title,
List<MemberProfile> findAll();

List<MemberProfile> getSupervisorsForId(UUID id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ public MemberProfileServicesImpl(MemberProfileRepository memberProfileRepository

@Override
public MemberProfile getById(@NotNull UUID id) {
Optional<MemberProfile> memberProfile = memberProfileRepository.findById(id);
if (memberProfile.isEmpty()) {
Optional<MemberProfile> optional = memberProfileRepository.findById(id);
if (optional.isEmpty()) {
throw new NotFoundException("No member profile for id " + id);
}
return memberProfile.get();
MemberProfile memberProfile = optional.get();
if (!currentUserServices.isAdmin()) {
memberProfile.clearBirthYear();
}
return memberProfile;
}

@Override
Expand All @@ -70,7 +74,11 @@ public Set<MemberProfile> findByValues(@Nullable String firstName,
@Nullable Boolean terminated) {
HashSet<MemberProfile> memberProfiles = new HashSet<>(memberProfileRepository.search(firstName, null, lastName, null, title,
nullSafeUUIDToString(pdlId), workEmail, nullSafeUUIDToString(supervisorId), terminated));

if (!currentUserServices.isAdmin()) {
for (MemberProfile memberProfile : memberProfiles) {
memberProfile.clearBirthYear();
}
}
return memberProfiles;
}

Expand Down Expand Up @@ -139,6 +147,13 @@ public List<MemberProfile> findAll() {
@Override
@Cacheable
public List<MemberProfile> getSupervisorsForId(UUID id) {
return memberProfileRepository.findSupervisorsForId(id);
List<MemberProfile> supervisorsForId = memberProfileRepository.findSupervisorsForId(id);
if (!currentUserServices.isAdmin()) {
for (MemberProfile memberProfile : supervisorsForId) {
memberProfile.clearBirthYear();
}
}
return supervisorsForId;
}

}

0 comments on commit 2b108e8

Please sign in to comment.