예제 #1
0
  /**
   * @param id
   * @param sensitive
   * @return
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango','Site',#siteId, @userService.getConnected())")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource/{id}/toggle/sensitive/{sensitive}",
      method = RequestMethod.PUT)
  @ResponseBody
  public Map<String, String> toggleSensitiveResource(
      @PathVariable("id") String id,
      @PathVariable("sensitive") boolean sensitive,
      @PathVariable("siteId") String siteId) {

    Map<String, String> result = new HashMap<>();
    boolean toggled = false;

    BenderResource resource = benderService.getResourceById(id, null);
    if (resource != null) {

      resource.setSensitive(sensitive);
      // enregistrement de la ressource dans une base mongo
      provider.persist(resource);
      toggled = true;
    }
    result.put("toggled", String.valueOf(toggled));
    return result;
  }
예제 #2
0
  /**
   * @param resourceDTO
   * @param siteId
   * @param id
   * @param response
   * @param comment
   * @return
   * @throws com.sfr.tiilta.client.exception.ValidationException
   * @throws java.io.IOException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasBenderPermission('TemplatingDjango', 'Site' , #siteId, @userService.getConnected(), #id)")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource/{id}",
      method = RequestMethod.PUT,
      headers = {"content-type=application/json"})
  public ResponseEntity<BenderResource> updateResource(
      @RequestBody @Valid BenderResource resourceDTO,
      @PathVariable("siteId") String siteId,
      @PathVariable("id") String id,
      HttpServletResponse response,
      @RequestParam(value = "comment", required = false) String comment)
      throws ValidationException, IOException {

    ResponseEntity<BenderResource> result =
        new ResponseEntity<>(null, new HttpHeaders(), HttpStatus.BAD_REQUEST);

    boolean isSaved = false;

    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("le site est inconnu");
    }

    if (resourceDTO != null) {

      User user = userService.getConnected();
      BenderResource originResource = benderService.getResourceById(id, null);

      if (originResource == null) {
        throw new ValidationException("Le fichier n'existe pas");
      }

      resourceDTO.setModifiedBy(user.getName());
      resourceDTO.setUpdateDate(new Date());
      resourceDTO.setSite(siteId);

      // Admin only fields
      if (!tiiltaAuthorization.hasPermission(
          Permission.Admin, Subject.Site, siteId, userService.getConnected())) {

        resourceDTO.setSensitive(originResource.isSensitive());
        resourceDTO.setExecutable(originResource.isExecutable());
        resourceDTO.setExecutorType(originResource.getExecutorType());
      }
      benderService.persist(resourceDTO);

      // récupération de la resource sauvegardée avec la dernière version dans SVN
      result =
          new ResponseEntity<>(
              this.getResourceById(id, null, siteId), new HttpHeaders(), HttpStatus.OK);
    }
    return result;
  }
예제 #3
0
  /**
   * @param resourceDTO
   * @param siteId
   * @param comment
   * @return
   * @throws IOException
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource",
      method = RequestMethod.POST,
      headers = {"content-type=application/json"})
  public ResponseEntity<BenderResource> createResource(
      @RequestBody @Valid BenderResource resourceDTO,
      @PathVariable("siteId") String siteId,
      @RequestParam(value = "comment", required = false) String comment)
      throws IOException, ValidationException {

    ResponseEntity<BenderResource> result =
        new ResponseEntity<>(null, new HttpHeaders(), HttpStatus.BAD_REQUEST);

    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    }

    User user = userService.getConnected();
    resourceDTO.setSite(siteId);
    resourceDTO.setCreationDate(new Date());
    resourceDTO.setUpdateDate(new Date());
    // set Resource Path
    // format path with Path.get
    resourceDTO.setPath(
        Paths.get(
                resourceDTO.getPath()
                    + File.separator
                    + resourceDTO.getName()
                    + "."
                    + StringUtils.lowerCase(resourceDTO.getType()))
            .toString());
    BenderResource createdResource = benderService.persist(resourceDTO);
    if (createdResource != null)
      result =
          new ResponseEntity<>(
              this.getResourceById(createdResource.getId(), null, siteId),
              new HttpHeaders(),
              HttpStatus.OK);

    return result;
  }
예제 #4
0
  /**
   * @param siteId
   * @param id
   * @return
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/{id}/revisions", method = RequestMethod.GET)
  @ResponseBody
  public List<EntityVersionInfo> getListRevision(
      @PathVariable("siteId") String siteId, @PathVariable("id") String id)
      throws ValidationException {

    List<EntityVersionInfo> versionBeans = new ArrayList<>();
    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    }

    BenderResource resourceDTO = new BenderResource();
    resourceDTO = benderService.getResourceById(id, null);
    if (resourceDTO != null) {

      versionBeans.addAll(
          benderService.getListRevision(site.getEditoRootPath(), resourceDTO.getPath(), 10l));
    }
    return versionBeans;
  }