private static models.Upload getUpload(Long id) { if (id == null) { Validation.addError(null, "Missing upload id"); prepareForErrorRedirect(); index(); } models.Upload upload = models.Upload.findById(id); if (upload == null) { Validation.addError(null, "Invalid upload id"); prepareForErrorRedirect(); index(); } User user = getUser(); if (upload.owner != user && !user.isAdmin) { Validation.addError(null, "You are not authorised to view this upload"); prepareForErrorRedirect(); index(); } return upload; }
public static void delete(Long id) throws IOException { models.Upload upload = getUpload(id); File uploadsDir = Util.getUploadDir(id); upload.delete(); FileUtils.deleteDirectory(uploadsDir); MyCache.evictUploadsForOwner(upload.owner); flash("message", "Upload repository deleted"); index(); }