Skip to content

Commit

Permalink
fix: remove useless check on user id
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras committed Jun 19, 2024
1 parent 5eb761b commit 3275471
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,9 @@ public ResponseEntity<Object> postCampaign(@RequestBody CampaignContextDto campa
public ResponseEntity<List<CampaignDto>> getListCampaign() {
String userId = authenticatedUserService.getCurrentUserId();
log.info("User {} : GET related campaigns", userId);
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
List<CampaignDto> lstCampaigns = campaignService.getListCampaign(userId);
log.info("User {} -> {} related campaigns found", userId, lstCampaigns.size());
return new ResponseEntity<>(lstCampaigns, HttpStatus.OK);
}
List<CampaignDto> lstCampaigns = campaignService.getListCampaign(userId);
log.info("User {} -> {} related campaigns found", userId, lstCampaigns.size());
return new ResponseEntity<>(lstCampaigns, HttpStatus.OK);
}

/**
Expand All @@ -109,15 +104,11 @@ public ResponseEntity<List<CampaignDto>> getListCampaign() {
public ResponseEntity<List<CampaignDto>> getAllCampaigns() {
String userId = authenticatedUserService.getCurrentUserId();
log.info("User {} : GET all campaigns", userId);
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
List<CampaignDto> lstCampaigns = campaignService.getAllCampaigns();
log.info("User {}, GET all campaigns ({} campaigns found) resulting in 200", userId,
lstCampaigns.size());
return new ResponseEntity<>(lstCampaigns, HttpStatus.OK);
}
List<CampaignDto> lstCampaigns = campaignService.getAllCampaigns();
log.info("User {}, GET all campaigns ({} campaigns found) resulting in 200", userId,
lstCampaigns.size());
return new ResponseEntity<>(lstCampaigns, HttpStatus.OK);

}

/**
Expand All @@ -131,10 +122,6 @@ public ResponseEntity<List<CampaignDto>> getAllCampaigns() {
@GetMapping(path = Constants.API_INTERVIEWER_CAMPAIGNS)
public ResponseEntity<List<CampaignDto>> getInterviewerCampaigns() {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("Interviewer {} : GET related campaigns", userId);
List<CampaignDto> lstCampaigns = campaignService.getInterviewerCampaigns(userId);
log.info("Interviewer {} : returned {} campaigns, resulting in 200", userId, lstCampaigns.size());
Expand All @@ -155,10 +142,6 @@ public ResponseEntity<List<CampaignDto>> getInterviewerCampaigns() {
@GetMapping(path = Constants.API_CAMPAIGN_ID_INTERVIEWERS)
public ResponseEntity<List<InterviewerDto>> getListInterviewers(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] interviewers ", userId, id);
List<InterviewerDto> lstInterviewer;
try {
Expand Down Expand Up @@ -188,10 +171,6 @@ public ResponseEntity<List<InterviewerDto>> getListInterviewers(@PathVariable(va
@GetMapping(path = Constants.API_CAMPAIGN_ID_VISIBILITIES)
public ResponseEntity<List<VisibilityContextDto>> getVisibilities(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] visibilities ", userId, id);
if (!campaignService.findById(id).isPresent()) {
log.warn("Can't find visibilities : campaign {} is missing", id);
Expand Down Expand Up @@ -219,10 +198,6 @@ public ResponseEntity<List<VisibilityContextDto>> getVisibilities(@PathVariable(
@GetMapping(path = Constants.API_CAMPAIGN_ID_SU_ABANDONED)
public ResponseEntity<CountDto> getNbSUAbandoned(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] abandoned survey-units ", userId, id);
CountDto nbSUAbandoned;
try {
Expand All @@ -249,10 +224,6 @@ public ResponseEntity<CountDto> getNbSUAbandoned(@PathVariable(value = "id") Str
@GetMapping(path = Constants.API_CAMPAIGN_ID_SU_NOTATTRIBUTED)
public ResponseEntity<CountDto> getNbSUNotAttributed(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] not attributed survey-units ", userId, id);
CountDto nbSUNotAttributed;
try {
Expand Down Expand Up @@ -280,10 +251,6 @@ public ResponseEntity<Object> putVisibilityDate(
@PathVariable(value = "idCampaign") String idCampaign,
@PathVariable(value = "idOu") String idOu) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.info(NO_USER_ID);
return new ResponseEntity<>(NO_USER_ID, HttpStatus.FORBIDDEN);
}
log.info("{} try to change OU[{}] visibility on campaign[{}] ", userId, idOu, idCampaign);
HttpStatus returnCode = campaignService.updateVisibility(idCampaign, idOu, visibilityUpdated);
log.info("PUT visibility with CampaignId {} for Organizational Unit {} resulting in {}", idCampaign,
Expand Down Expand Up @@ -337,9 +304,6 @@ public ResponseEntity<Object> putCampaign(@PathVariable(value = "id") String id,
String userId = authenticatedUserService.getCurrentUserId();
log.info("{} try to update campaign {} collection dates", userId, id);

if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
HttpStatus returnCode = campaignService.updateCampaign(id, campaign);
log.info("PUT campaign with id {} resulting in {}", id, returnCode.value());
return new ResponseEntity<>(returnCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,16 @@ public ResponseEntity<ClosingCauseCountDto> getClosingCauseCount(
String userId = authenticatedUserService.getCurrentUserId();
List<String> associatedOrgUnits = utilsService.getRelatedOrganizationUnits(userId);

if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
ClosingCauseCountDto closingCountDto;
try {
closingCountDto = closingCauseService.getClosingCauseCount(userId, id, idep, date,
associatedOrgUnits);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get ClosingCauseCount resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get ClosingCauseCount resulting in 200");
return new ResponseEntity<>(closingCountDto, HttpStatus.OK);
ClosingCauseCountDto closingCountDto;
try {
closingCountDto = closingCauseService.getClosingCauseCount(userId, id, idep, date,
associatedOrgUnits);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get ClosingCauseCount resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

log.info("Get ClosingCauseCount resulting in 200");
return new ResponseEntity<>(closingCountDto, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,17 @@ public class ContactOutcomeController {
public ResponseEntity<ContactOutcomeTypeCountDto> getNbSUNotAttributedContactOutcomes(
@PathVariable(value = "id") String id, @RequestParam(required = false, name = "date") Long date) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
ContactOutcomeTypeCountDto contactOutcomes;
try {
contactOutcomes = contactOutcomeService.getNbSUNotAttributedContactOutcomes(userId, id, date);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get Contact-outcomes count for non attributted SUs resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get Contact-outcomes count for non attributted SUs resulting in 200");
return new ResponseEntity<>(contactOutcomes, HttpStatus.OK);
ContactOutcomeTypeCountDto contactOutcomes;
try {
contactOutcomes = contactOutcomeService.getNbSUNotAttributedContactOutcomes(userId, id, date);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get Contact-outcomes count for non attributted SUs resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get Contact-outcomes count for non attributted SUs resulting in 200");
return new ResponseEntity<>(contactOutcomes, HttpStatus.OK);

}

/**
Expand All @@ -75,18 +72,15 @@ public ResponseEntity<ContactOutcomeTypeCountDto> getNbSUNotAttributedContactOut
public ResponseEntity<List<ContactOutcomeTypeCountDto>> getCampaignsContactOutcomeTypeCount(
@RequestParam(required = false, name = "date") Long date) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
List<ContactOutcomeTypeCountDto> listContactOutcomeTypeCountDto = contactOutcomeService
.getContactOutcomeTypeCountByCampaign(userId, date);
if (listContactOutcomeTypeCountDto == null) {
log.info("Get contactOutcomeTypeCount resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get contactOutcomeTypeCount resulting in 200");
return new ResponseEntity<>(listContactOutcomeTypeCountDto, HttpStatus.OK);

List<ContactOutcomeTypeCountDto> listContactOutcomeTypeCountDto = contactOutcomeService
.getContactOutcomeTypeCountByCampaign(userId, date);
if (listContactOutcomeTypeCountDto == null) {
log.info("Get contactOutcomeTypeCount resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get contactOutcomeTypeCount resulting in 200");
return new ResponseEntity<>(listContactOutcomeTypeCountDto, HttpStatus.OK);
}

/**
Expand All @@ -104,20 +98,16 @@ public ResponseEntity<List<ContactOutcomeTypeCountDto>> getCampaignsContactOutco
public ResponseEntity<ContactOutcomeTypeCountCampaignDto> getContactOutcomeTypeCountByCampaign(
@PathVariable(value = "id") String id, @RequestParam(required = false, name = "date") Long date) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
ContactOutcomeTypeCountCampaignDto stateCountCampaignDto;
try {
stateCountCampaignDto = contactOutcomeService.getContactOutcomeCountTypeByCampaign(userId, id, date);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get contact-outcome type count resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get contact-outcome type count resulting in 200");
return new ResponseEntity<>(stateCountCampaignDto, HttpStatus.OK);
ContactOutcomeTypeCountCampaignDto stateCountCampaignDto;
try {
stateCountCampaignDto = contactOutcomeService.getContactOutcomeCountTypeByCampaign(userId, id, date);
} catch (NotFoundException e) {
log.error(e.getMessage());
log.info("Get contact-outcome type count resulting in 404");
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
log.info("Get contact-outcome type count resulting in 200");
return new ResponseEntity<>(stateCountCampaignDto, HttpStatus.OK);
}

/**
Expand All @@ -135,9 +125,6 @@ public ResponseEntity<ContactOutcomeTypeCountDto> getContactOuctomeByCampaignAnd
@PathVariable(value = "id") String id, @PathVariable(value = "idep") String idep,
@RequestParam(required = false, name = "date") Long date) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
ContactOutcomeTypeCountDto cotd;
try {
cotd = contactOutcomeService.getContactOutcomeByInterviewerAndCampaign(userId, id, idep, date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public ResponseEntity<String> postInterviewers(@RequestBody List<InterviewerCont
@GetMapping(path = Constants.API_INTERVIEWERS)
public ResponseEntity<Set<InterviewerDto>> getListInterviewers() {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
Set<InterviewerDto> lstInterviewer = interviewerService.getListInterviewers(userId);
if (lstInterviewer == null) {
log.info("Get interviewers resulting in 404");
Expand All @@ -85,10 +82,6 @@ public ResponseEntity<Set<InterviewerDto>> getListInterviewers() {
@GetMapping(path = Constants.API_INTERVIEWER_ID)
public ResponseEntity<InterviewerContextDto> getInterviewer(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.info("{} -> Get interviewer [{}] resulting in 403 : unknown user", userId, id);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
Optional<InterviewerContextDto> interviewer = interviewerService.findDtoById(id);
if (interviewer.isEmpty()) {
log.info("{} -> Get interviewer [{}] resulting in 404", userId, id);
Expand All @@ -103,9 +96,6 @@ public ResponseEntity<InterviewerContextDto> getInterviewer(@PathVariable(value
@GetMapping(path = Constants.API_ADMIN_INTERVIEWERS)
public ResponseEntity<List<InterviewerContextDto>> getCompleteListInterviewers() {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
List<InterviewerContextDto> lstInterviewer = interviewerService.getCompleteListInterviewers();
if (lstInterviewer.isEmpty()) {
log.info("{} -> Get all interviewers resulting in 404 : no interviewers", userId);
Expand All @@ -120,9 +110,6 @@ public ResponseEntity<List<InterviewerContextDto>> getCompleteListInterviewers()
@GetMapping(path = Constants.API_INTERVIEWER_ID_CAMPAIGNS)
public ResponseEntity<List<CampaignDto>> getListCampaigns(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
Optional<List<CampaignDto>> list = interviewerService.findCampaignsOfInterviewer(id);
if (!list.isPresent()) {
log.info("{} -> Get interviewer campaigns resulting in 404", userId);
Expand All @@ -139,8 +126,6 @@ public ResponseEntity<InterviewerContextDto> updateInterviewer(
@PathVariable(value = "id") String id,
@RequestBody InterviewerContextDto interviewer) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId))
return new ResponseEntity<>(HttpStatus.FORBIDDEN);

if (id == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
Expand All @@ -160,10 +145,6 @@ public ResponseEntity<InterviewerContextDto> updateInterviewer(
@DeleteMapping(path = Constants.API_INTERVIEWER_ID)
public ResponseEntity<Object> deleteInterviewer(@PathVariable(value = "id") String id) {
String userId = authenticatedUserService.getCurrentUserId();
if (StringUtils.isBlank(userId)) {
log.warn("{} : DELETE interviewer with id {} resulting in 403.", userId, id);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}

if (id == null) {
log.warn("{} : no interviewerId provided : resulting in 400.", userId);
Expand Down
Loading

0 comments on commit 3275471

Please sign in to comment.