Skip to content

Commit fddb388

Browse files
authored
Merge pull request #2858 from objectcomputing/bugfix-2814/url-decode-payload
URL decode the payload.
2 parents 25a2caa + 7a0889d commit fddb388

File tree

3 files changed

+72
-67
lines changed

3 files changed

+72
-67
lines changed

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

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,34 +159,47 @@ public HttpResponse<PulseResponse> externalPulseResponse(
159159
// DEBUG Only
160160
LOG.info("Request has been verified");
161161

162-
PulseResponseCreateDTO pulseResponseDTO =
163-
SlackPulseResponseConverter.get(memberProfileServices,
164-
requestBody);
162+
// Convert the request body to a map of values.
163+
FormUrlEncodedDecoder formUrlEncodedDecoder =
164+
new FormUrlEncodedDecoder();
165+
Map<String, Object> body =
166+
formUrlEncodedDecoder.decode(requestBody,
167+
StandardCharsets.UTF_8);
165168

166-
// DEBUG Only
167-
LOG.info("Request has been converted");
168-
169-
// Create the pulse response
170-
PulseResponse pulseResponse = pulseResponseServices.unsecureSave(
171-
new PulseResponse(
172-
pulseResponseDTO.getInternalScore(),
173-
pulseResponseDTO.getExternalScore(),
174-
pulseResponseDTO.getSubmissionDate(),
175-
pulseResponseDTO.getTeamMemberId(),
176-
pulseResponseDTO.getInternalFeelings(),
177-
pulseResponseDTO.getExternalFeelings()
178-
)
179-
);
180-
181-
if (pulseResponse == null) {
182-
return HttpResponse.status(HttpStatus.CONFLICT,
183-
"Already submitted today");
169+
final String key = "payload";
170+
if (body.containsKey(key)) {
171+
PulseResponseCreateDTO pulseResponseDTO =
172+
SlackPulseResponseConverter.get(memberProfileServices,
173+
(String)body.get(key));
174+
175+
// DEBUG Only
176+
LOG.info("Request has been converted");
177+
178+
// Create the pulse response
179+
PulseResponse pulseResponse =
180+
pulseResponseServices.unsecureSave(
181+
new PulseResponse(
182+
pulseResponseDTO.getInternalScore(),
183+
pulseResponseDTO.getExternalScore(),
184+
pulseResponseDTO.getSubmissionDate(),
185+
pulseResponseDTO.getTeamMemberId(),
186+
pulseResponseDTO.getInternalFeelings(),
187+
pulseResponseDTO.getExternalFeelings()
188+
)
189+
);
190+
191+
if (pulseResponse == null) {
192+
return HttpResponse.status(HttpStatus.CONFLICT,
193+
"Already submitted today");
194+
} else {
195+
return HttpResponse.created(pulseResponse)
196+
.headers(headers -> headers.location(
197+
URI.create(String.format("%s/%s",
198+
request.getPath(),
199+
pulseResponse.getId()))));
200+
}
184201
} else {
185-
return HttpResponse.created(pulseResponse)
186-
.headers(headers -> headers.location(
187-
URI.create(String.format("%s/%s",
188-
request.getPath(),
189-
pulseResponse.getId()))));
202+
return HttpResponse.unprocessableEntity();
190203
}
191204
} else {
192205
return HttpResponse.unauthorized();

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

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,42 @@ public class SlackPulseResponseConverter {
2020

2121
public static PulseResponseCreateDTO get(
2222
MemberProfileServices memberProfileServices, String body) {
23-
final String key = "payload=";
24-
final int start = body.indexOf(key);
25-
if (start >= 0) {
26-
try {
27-
// Get the map of values from the string body
28-
final ObjectMapper mapper = new ObjectMapper();
29-
final Map<String, Object> map =
30-
mapper.readValue(body.substring(start + key.length()),
31-
new TypeReference<>() {});
32-
final Map<String, Object> view =
33-
(Map<String, Object>)map.get("view");
34-
final Map<String, Object> state =
35-
(Map<String, Object>)view.get("state");
36-
final Map<String, Object> values =
37-
(Map<String, Object>)state.get("values");
23+
try {
24+
// Get the map of values from the string body
25+
final ObjectMapper mapper = new ObjectMapper();
26+
final Map<String, Object> map =
27+
mapper.readValue(body, new TypeReference<>() {});
28+
final Map<String, Object> view =
29+
(Map<String, Object>)map.get("view");
30+
final Map<String, Object> state =
31+
(Map<String, Object>)view.get("state");
32+
final Map<String, Object> values =
33+
(Map<String, Object>)state.get("values");
3834

39-
// Create the pulse DTO and fill in the values.
40-
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
41-
response.setTeamMemberId(lookupUser(memberProfileServices, map));
42-
response.setSubmissionDate(LocalDate.now());
35+
// Create the pulse DTO and fill in the values.
36+
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
37+
response.setTeamMemberId(lookupUser(memberProfileServices, map));
38+
response.setSubmissionDate(LocalDate.now());
4339

44-
response.setInternalScore(Integer.parseInt(
45-
getMappedValue(values, "internalScore", true)));
46-
response.setInternalFeelings(
47-
getMappedValue(values, "internalFeelings", false));
40+
response.setInternalScore(Integer.parseInt(
41+
getMappedValue(values, "internalScore", true)));
42+
response.setInternalFeelings(
43+
getMappedValue(values, "internalFeelings", false));
4844

49-
String score = getMappedValue(values, "externalScore", false);
50-
if (!score.isEmpty()) {
51-
response.setExternalScore(Integer.parseInt(score));
52-
}
53-
response.setExternalFeelings(
54-
getMappedValue(values, "externalFeelings", false));
55-
56-
return response;
57-
} catch(JsonProcessingException ex) {
58-
LOG.error(ex.getMessage());
59-
throw new BadArgException(ex.getMessage());
60-
} catch(NumberFormatException ex) {
61-
LOG.error(ex.getMessage());
62-
throw new BadArgException("Pulse scores must be integers");
45+
String score = getMappedValue(values, "externalScore", false);
46+
if (!score.isEmpty()) {
47+
response.setExternalScore(Integer.parseInt(score));
6348
}
64-
} else {
65-
LOG.error(body);
66-
throw new BadArgException("Invalid pulse response body");
49+
response.setExternalFeelings(
50+
getMappedValue(values, "externalFeelings", false));
51+
52+
return response;
53+
} catch(JsonProcessingException ex) {
54+
LOG.error(ex.getMessage());
55+
throw new BadArgException(ex.getMessage());
56+
} catch(NumberFormatException ex) {
57+
LOG.error(ex.getMessage());
58+
throw new BadArgException("Pulse scores must be integers");
6759
}
6860
}
6961

web-ui/src/pages/CheckinsReportPage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const CheckinsReportPage = () => {
4141

4242
// Set the report date to today less one month on first load
4343
useEffect(() => {
44-
setReportDate(new Date(new Date().setMonth(new Date().getMonth() - 1)));
44+
setReportDate(new Date(2024, 9, 1));
4545
}, []);
4646

4747
const handleQuarterClick = evt => {

0 commit comments

Comments
 (0)