class FinanceChecksNotesAddNoteController {

    @PreAuthorize("hasPermission(#projectId, 'org.innovateuk.ifs.project.resource.ProjectCompositeId', 'ACCESS_FINANCE_CHECKS_NOTES_SECTION')")
    @PostMapping(params = "removeAttachment")
    public String removeAttachment(@P("projectId")@PathVariable Long projectId,
                                   @PathVariable Long organisationId,
                                   @RequestParam(value = "removeAttachment") final Long attachmentId,
                                   @ModelAttribute(FORM_ATTR) FinanceChecksNotesAddNoteForm form,
                                   @SuppressWarnings("unused") BindingResult bindingResult,
                                   ValidationHandler validationHandler,
                                   UserResource loggedInUser,
                                   HttpServletRequest request,
                                   HttpServletResponse response,
                                   Model model) {
        if (postParametersMatchOrigin(request, projectId, organisationId, loggedInUser.getId())) {
            List<Long> attachments = loadAttachmentsFromCookie(request, projectId, organisationId);
            if (attachments.contains(attachmentId)) {
                financeCheckService.deleteFile(attachmentId)
                        .andOnSuccess(() -> attachments.remove(attachments.indexOf(attachmentId)));
            }
            saveAttachmentsToCookie(response, attachments, projectId, organisationId);
            saveFormToCookie(response, projectId, organisationId, form);

            return redirectTo(rootView(projectId, organisationId));
        } else {
            throw new ObjectNotFoundException();
        }
    }

}