Skip to content

Commit 6975f56

Browse files
authored
Merge pull request #2824 from objectcomputing/bugfix-2823/anonymous-pulse-causes-error
Check for a null member id when checking pulse permissions.
2 parents 293ae85 + 88254e2 commit 6975f56

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServicesImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ public Set<PulseResponse> findByFields(UUID teamMemberId, LocalDate dateFrom, Lo
133133
// The current user can view the pulse response if they are the team member who submitted the pulse response
134134
// or if they are the supervisor of the team member who submitted the pulse response
135135
private boolean canViewDueToReportingHierarchy(PulseResponse pulse, UUID currentUserId) {
136-
return pulse.getTeamMemberId().equals(currentUserId) ||
137-
isSubordinateTo(pulse.getTeamMemberId(), currentUserId);
136+
UUID id = pulse.getTeamMemberId();
137+
return id != null &&
138+
(id.equals(currentUserId) || isSubordinateTo(id, currentUserId));
138139
}
139140

140141
private boolean isSubordinateTo(UUID reportMember, UUID currentUserId) {

server/src/test/java/com/objectcomputing/checkins/services/fixture/PulseResponseFixture.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ default PulseResponse createADefaultPulseResponse(MemberProfile memberprofile) {
1010
return getPulseResponseRepository().save(new PulseResponse(0, 0, LocalDate.now(),
1111
memberprofile.getId(), "internalfeelings", "externalfeelings"));
1212
}
13+
14+
default PulseResponse createADefaultAnonymousPulseResponse() {
15+
return getPulseResponseRepository().save(new PulseResponse(0, 0, LocalDate.now(),
16+
null, "internalfeelings", "externalfeelings"));
17+
}
1318
}

server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,22 @@ void testGetFindByfindBySubmissionDateBetween() {
286286
assertEquals(Set.of(pulseResponse), response.body());
287287
}
288288

289+
@Test
290+
void testAnonymousGetFindByfindBySubmissionDateBetween() {
291+
MemberProfile memberProfile = createADefaultMemberProfile();
292+
293+
PulseResponse pulseResponse = createADefaultAnonymousPulseResponse();
294+
295+
LocalDate testDateFrom = LocalDate.of(2019, 1, 1);
296+
LocalDate testDateTo = Util.MAX.toLocalDate();
297+
298+
final HttpRequest<?> request = HttpRequest.GET(String.format("/?dateFrom=%tF&dateTo=%tF", testDateFrom, testDateTo)).basicAuth(memberProfile.getWorkEmail(), ADMIN_ROLE);
299+
final HttpResponse<Set<PulseResponse>> response = client.toBlocking().exchange(request, Argument.setOf(PulseResponse.class));
300+
301+
assertEquals(HttpStatus.OK, response.getStatus());
302+
assertEquals(Set.of(pulseResponse), response.body());
303+
}
304+
289305
@Test
290306
void testGetFindById() {
291307

0 commit comments

Comments
 (0)