fix(clips): remove redundant auth checks
This commit is contained in:
@@ -66,9 +66,7 @@ public class ClipController {
|
|||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ResponseEntity<APIResponse<String>> deleteClip(@PathVariable Long id) {
|
public ResponseEntity<APIResponse<String>> deleteClip(@PathVariable Long id) {
|
||||||
if (!clipService.deleteClip(id)) {
|
clipService.deleteClip(id);
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
new APIResponse<>(
|
new APIResponse<>(
|
||||||
|
|||||||
@@ -97,10 +97,6 @@ public class ClipService {
|
|||||||
public Clip updateClip(Long id, ClipUpdateRequest newFields) {
|
public Clip updateClip(Long id, ClipUpdateRequest newFields) {
|
||||||
Clip clip = getClipById(id);
|
Clip clip = getClipById(id);
|
||||||
|
|
||||||
if (!isAuthenticatedForClip(clip)) {
|
|
||||||
throw new NotAuthenticated("You are not authorized to access clip: " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newFields.title() != null) {
|
if (newFields.title() != null) {
|
||||||
clip.setTitle(newFields.title());
|
clip.setTitle(newFields.title());
|
||||||
}
|
}
|
||||||
@@ -116,22 +112,15 @@ public class ClipService {
|
|||||||
* Deletes a clip and its associated files from disk.
|
* Deletes a clip and its associated files from disk.
|
||||||
*
|
*
|
||||||
* @param id the ID of the clip to delete
|
* @param id the ID of the clip to delete
|
||||||
* @return {@code true} on success; always throws rather than returning {@code false}
|
|
||||||
* @throws ClipNotFound if no clip with {@code id} exists
|
* @throws ClipNotFound if no clip with {@code id} exists
|
||||||
* @throws NotAuthenticated if the current user does not own the clip
|
* @throws NotAuthenticated if the current user does not own the clip
|
||||||
*/
|
*/
|
||||||
public boolean deleteClip(Long id) {
|
public void deleteClip(Long id) {
|
||||||
Clip clip = getClipById(id);
|
Clip clip = getClipById(id);
|
||||||
|
|
||||||
if (!isAuthenticatedForClip(clip)) {
|
|
||||||
throw new NotAuthenticated("You are not authorized to delete this clip");
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteClipFiles(clip);
|
deleteClipFiles(clip);
|
||||||
clipRepository.delete(clip);
|
clipRepository.delete(clip);
|
||||||
|
|
||||||
logger.info("Clip with ID {} deleted successfully", id);
|
logger.info("Clip with ID {} deleted successfully", id);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,15 +149,11 @@ public class ClipService {
|
|||||||
public Resource downloadClip(Long id) {
|
public Resource downloadClip(Long id) {
|
||||||
Clip clip = getClipById(id);
|
Clip clip = getClipById(id);
|
||||||
|
|
||||||
if (!isAuthenticatedForClip(clip)) {
|
|
||||||
throw new NotAuthenticated("Not authenticated for this clip");
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = clip.getVideoPath();
|
String path = clip.getVideoPath();
|
||||||
Path file = directoryService.resolvePath(path);
|
Path file = directoryService.resolvePath(path);
|
||||||
|
|
||||||
if (!Files.exists(file)) {
|
if (!Files.exists(file)) {
|
||||||
throw new JobNotFound("Clip file not found");
|
throw new ClipNotFound("Clip file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FileSystemResource(file);
|
return new FileSystemResource(file);
|
||||||
@@ -185,10 +170,6 @@ public class ClipService {
|
|||||||
public Resource downloadThumbnail(Long id) {
|
public Resource downloadThumbnail(Long id) {
|
||||||
Clip clip = getClipById(id);
|
Clip clip = getClipById(id);
|
||||||
|
|
||||||
if (!isAuthenticatedForClip(clip)) {
|
|
||||||
throw new NotAuthenticated("Not authenticated for this clip thumbnail");
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = clip.getThumbnailPath();
|
String path = clip.getThumbnailPath();
|
||||||
Path file = directoryService.resolvePath(path);
|
Path file = directoryService.resolvePath(path);
|
||||||
|
|
||||||
|
|||||||
@@ -112,18 +112,15 @@ public class VodService {
|
|||||||
* Deletes a VoD and its associated files from disk.
|
* Deletes a VoD and its associated files from disk.
|
||||||
*
|
*
|
||||||
* @param id the ID of the VoD to delete
|
* @param id the ID of the VoD to delete
|
||||||
* @return {@code true} on success; always throws rather than returning {@code false}
|
|
||||||
* @throws VodNotFound if no VoD with {@code id} exists
|
* @throws VodNotFound if no VoD with {@code id} exists
|
||||||
* @throws NotAuthenticated if the current user does not own the VoD
|
* @throws NotAuthenticated if the current user does not own the VoD
|
||||||
*/
|
*/
|
||||||
public boolean deleteVod(Long id) {
|
public void deleteVod(Long id) {
|
||||||
Vod vod = getVodById(id);
|
Vod vod = getVodById(id);
|
||||||
|
|
||||||
deleteVodFiles(vod);
|
deleteVodFiles(vod);
|
||||||
vodRepository.delete(vod);
|
vodRepository.delete(vod);
|
||||||
|
|
||||||
logger.info("Vod with ID {} deleted successfully", id);
|
logger.info("Vod with ID {} deleted successfully", id);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user