@RequestMapping(method = RequestMethod.GET)
 public AnnouncementsAdminView all(
     Model model,
     @PathVariable ExecutionCourse executionCourse,
     @RequestParam(required = false, defaultValue = "1") int page) {
   Professorship professorship = executionCourse.getProfessorship(AccessControl.getPerson());
   AccessControl.check(
       person -> professorship != null && professorship.getPermissions().getAnnouncements());
   List<Post> announcements = getAnnouncements(executionCourse.getSite());
   model.addAttribute("executionCourse", executionCourse);
   int pages = IntMath.divide(announcements.size(), PER_PAGE, RoundingMode.CEILING);
   if (page < 1) {
     page = 1;
   }
   if (page > pages) {
     page = pages;
   }
   model.addAttribute("currentPage", page);
   model.addAttribute("pages", pages);
   model.addAttribute(
       "announcements",
       announcements
           .stream()
           .skip((page - 1) * PER_PAGE)
           .limit(PER_PAGE)
           .collect(Collectors.toList()));
   model.addAttribute("professorship", professorship);
   return new AnnouncementsAdminView();
 }
 @RequestMapping(value = "{postSlug}/delete", method = RequestMethod.POST)
 public RedirectView delete(
     @PathVariable ExecutionCourse executionCourse, @PathVariable String postSlug) {
   Post post = executionCourse.getSite().postForSlug(postSlug);
   atomic(() -> post.delete());
   return viewAll(executionCourse);
 }
 @RequestMapping(value = "{postSlug}/edit", method = RequestMethod.POST)
 public RedirectView edit(
     @PathVariable ExecutionCourse executionCourse,
     @PathVariable String postSlug,
     @RequestParam LocalizedString name,
     @RequestParam LocalizedString body) {
   Post post = executionCourse.getSite().postForSlug(postSlug);
   atomic(
       () -> {
         post.setName(Post.sanitize(name));
         post.setBody(Post.sanitize(body));
       });
   return viewAll(executionCourse);
 }
 @RequestMapping(value = "create", method = RequestMethod.POST)
 public RedirectView create(
     @PathVariable ExecutionCourse executionCourse,
     @RequestParam LocalizedString name,
     @RequestParam LocalizedString body)
     throws Exception {
   Site site = executionCourse.getSite();
   atomic(
       () ->
           Post.create(
               site,
               null,
               Post.sanitize(name),
               Post.sanitize(body),
               announcementsCategory(site),
               true,
               getUser()));
   return viewAll(executionCourse);
 }
  @RequestMapping(
      value = "{postSlug}/addFile.json",
      method = RequestMethod.POST,
      produces = "application/json")
  public @ResponseBody String addFileJson(
      Model model,
      @PathVariable ExecutionCourse executionCourse,
      @PathVariable(value = "postSlug") String slugPost,
      @RequestParam("attachment") MultipartFile[] attachments)
      throws IOException {
    Site s = executionCourse.getSite();

    AdminSites.canEdit(s);

    Post p = s.postForSlug(slugPost);
    JsonArray array = new JsonArray();

    Arrays.asList(attachments)
        .stream()
        .map(
            (attachment) -> {
              GroupBasedFile f = null;
              try {
                f = addFile(attachment, p);
              } catch (IOException e) {
                e.printStackTrace();
              }
              JsonObject obj = new JsonObject();
              obj.addProperty("displayname", f.getDisplayName());
              obj.addProperty("filename", f.getFilename());
              obj.addProperty("url", FileDownloadServlet.getDownloadUrl(f));
              return obj;
            })
        .forEach(x -> array.add(x));

    return array.toString();
  }