Example #1
0
  /**
   * 파일의 목록을 가져온다.
   *
   * <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));
  }
Example #2
0
 private static String cannotCreateMessage(User user, Project project, ResourceType resourceType) {
   Lang lang = Lang.apply(user.getPreferredLanguage());
   String resourceTypeName = resourceType.getName(lang);
   return Messages.get(lang, "viaEmail.error.cannotCreate", user, resourceTypeName, project);
 }
Example #3
0
  /**
   * 이 객체를 리소스로 반환한다.
   *
   * <p>when: 권한검사시 사용
   *
   * @return 리소스
   */
  @Override
  public Resource asResource() {
    boolean isContainerProject = containerType.equals(ResourceType.PROJECT);
    final Project project;
    final Resource container;

    if (isContainerProject) {
      project = Project.find.byId(Long.parseLong(containerId));
      if (project == null) {
        throw new RuntimeException(messageForLosingProject());
      }
      container = project.asResource();
    } else {
      container = Resource.get(containerType, containerId);
      if (!(container instanceof GlobalResource)) {
        project = container.getProject();
        if (project == null) {
          throw new RuntimeException(messageForLosingProject());
        }
      } else {
        project = null;
      }
    }

    if (project != null) {
      return new Resource() {
        @Override
        public String getId() {
          return id.toString();
        }

        @Override
        public Project getProject() {
          return project;
        }

        @Override
        public ResourceType getType() {
          return ResourceType.ATTACHMENT;
        }

        @Override
        public Resource getContainer() {
          return container;
        }
      };
    } else {
      return new GlobalResource() {
        @Override
        public String getId() {
          return id.toString();
        }

        @Override
        public ResourceType getType() {
          return ResourceType.ATTACHMENT;
        }

        @Override
        public Resource getContainer() {
          return container;
        }
      };
    }
  }