/** * 파일의 목록을 가져온다. * * <p>이슈, 게시물, 댓글을 볼 때, 첨부된 파일들의 목록을 보여주기 위해 이슈, 게시물, 댓글을 편집할 때, 첨부된 파일들의 목록 및 사용자 파일들의 목록을 보여주기 * 위해 * * <p>로그인한 사용자의 파일들의 목록을 {@code tempFiles} 프로퍼티로 넘겨준다. 첨부 파일들의 목록을 {@code attachments} 프로퍼티로 넘겨준다. * 첨부 파일들 중 로그인한 사용자가 읽기 권한을 갖지 못한 것이 하나라도 있다면 403 Forbidden 으로 응답한다. * * @return json 포맷으로 된 파일 목록을 본문으로 하는 응답. 다음고 같은 형식이다. {@code {tempFiles: 사용자 파일 목록, attachments: * 첨부 파일 목록 }} */ public static Result getFileList() { Map<String, List<Map<String, String>>> files = new HashMap<String, List<Map<String, String>>>(); // Get files from the user's area. List<Map<String, String>> userFiles = new ArrayList<Map<String, String>>(); for (Attachment attach : Attachment.findByContainer(UserApp.currentUser().asResource())) { userFiles.add(extractFileMetaDataFromAttachementAsMap(attach)); } files.put("tempFiles", userFiles); // Get attached files only if the user has permission to read it. Map<String, String[]> query = request().queryString(); String containerType = HttpUtil.getFirstValueFromQuery(query, "containerType"); String containerId = HttpUtil.getFirstValueFromQuery(query, "containerId"); if (containerType != null && containerId != null) { List<Map<String, String>> attachments = new ArrayList<Map<String, String>>(); for (Attachment attach : Attachment.findByContainer( ResourceType.valueOf(containerType), Long.parseLong(containerId))) { if (!AccessControl.isAllowed(UserApp.currentUser(), attach.asResource(), Operation.READ)) { return forbidden(); } attachments.add(extractFileMetaDataFromAttachementAsMap(attach)); } files.put("attachments", attachments); } // Return the list of files as JSON. response().setHeader("Content-Type", "application/json"); return ok(toJson(files)); }