Skip to content
Snippets Groups Projects
Commit 278c6b16 authored by Camille Simiand's avatar Camille Simiand
Browse files

User shouldn't be able to edit video url if project doesnt exist

parent 70cc606e
No related branches found
No related tags found
1 merge request!48tuleap-133-change-the-video-url-of-a-capsule
Pipeline #774 passed
......@@ -22,12 +22,18 @@ use ZipArchive;
class ProjectController extends AbstractController
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/project/create", name="create_project", methods={"POST"})
* @throws ZipArchiveNotOpeningException
*/
public function create(
TranslatorInterface $translator,
Capsule $capsule,
string $video_url
): Response {
......@@ -39,7 +45,7 @@ class ProjectController extends AbstractController
if (file_exists($capsule_directory)) {
$this->addFlash(
'warning',
$translator->trans(
$this->translator->trans(
'project.already_exists',
[
'capsule_name' => $capsule_name
......@@ -58,7 +64,7 @@ class ProjectController extends AbstractController
$this->addFlash(
'success',
$translator->trans(
$this->translator->trans(
'capsule.created_success',
[
'capsule_name' => $capsule_name
......@@ -74,7 +80,6 @@ class ProjectController extends AbstractController
* @throws ZipArchiveNotOpeningException
*/
public function duplicate(
TranslatorInterface $translator,
Capsule $capsule,
string $parent_directory,
Filesystem $file_system
......@@ -87,7 +92,7 @@ class ProjectController extends AbstractController
if (file_exists($capsule_directory)) {
$this->addFlash(
'warning',
$translator->trans(
$this->translator->trans(
'project.already_exists',
[
'capsule_name' => $capsule_name
......@@ -104,7 +109,7 @@ class ProjectController extends AbstractController
$this->addFlash(
'success',
$translator->trans(
$this->translator->trans(
'capsule.duplicate.success',
[
'capsule_name' => $capsule_name
......@@ -175,7 +180,6 @@ class ProjectController extends AbstractController
public function editVideoUrl(
int $capsule_id,
Request $request,
TranslatorInterface $translator,
CapsuleRepository $capsule_repository
): Response {
$capsule = $capsule_repository->findOneBy(['id' => $capsule_id]);
......@@ -183,6 +187,24 @@ class ProjectController extends AbstractController
throw new \Exception('The retrieved capsule is not an instance of Capsule.');
}
$file_system = new Filesystem();
$parent_directory_name = $capsule->getLinkPath();
$parent_directory_exists = $file_system->exists('../legacy/' . $parent_directory_name);
if (! $parent_directory_exists) {
$this->addFlash(
'warning',
$this->translator->trans(
'project.not_exist',
[
'capsule_name' => $capsule->getName()
]
)
);
return $this->redirectToRoute('capsule_list');
}
$form = $this->createForm(EditVideoUrlFormType::class);
$form->handleRequest($request);
......@@ -192,11 +214,10 @@ class ProjectController extends AbstractController
chdir('../legacy/');
$this->setVideoUrlNodeAttributeInXMLProjectFile($project_directory, $new_video_url);
// $this->rescheduleProjectAnnotations($project_XML_file_path);
$this->addFlash(
'success',
$translator->trans(
$this->translator->trans(
'capsule.edit.video_url.success'
)
);
......
......@@ -93,7 +93,7 @@ capsule:
project:
already_exists: Project capsule_name already exists so the capsule could not be created
not_exist: The project to duplicate does not exist
not_exist: The project does not exist
preview:
loading: Project loading
......
......@@ -91,7 +91,7 @@ capsule:
project:
already_exists: Le projet capsule_name existe déjà. La capsule n'a pas pu être créée
not_exist: Le projet a dupliquer n'existe pas
not_exist: Le projet n'existe pas
preview:
loading: Projet en cours de chargement
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment