|
|
@@ -592,12 +592,19 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* /!\ Danger zone /!\
|
|
|
*
|
|
|
+ * Supprime définitivement une organisation, ses données, ses fichiers, son site internet, et son profil Dolibarr.
|
|
|
+ *
|
|
|
+ * Pour éviter une suppression accidentelle, cette méthode ne doit pouvoir être exécutée que si la requête a été
|
|
|
+ * envoyée depuis le localhost.
|
|
|
+ *
|
|
|
* @param OrganizationDeletionRequest $organizationDeletionRequest
|
|
|
- * @return void
|
|
|
+ * @return OrganizationDeletionRequest
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function delete(OrganizationDeletionRequest $organizationDeletionRequest): OrganizationDeletionRequest
|
|
|
{
|
|
|
+ $this->preventIfNotLocalhost();
|
|
|
+
|
|
|
$organization = $this->organizationRepository->find($organizationDeletionRequest->getOrganizationId());
|
|
|
|
|
|
$this->logger->info(
|
|
|
@@ -677,6 +684,23 @@ class OrganizationFactory
|
|
|
return $organizationDeletionRequest;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Lève une exception si la méthode a été appelée dans le cadre d'un appel API originaire d'un hôte
|
|
|
+ * différent de localhost.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function preventIfNotLocalhost(): void
|
|
|
+ {
|
|
|
+ if (
|
|
|
+ $_SERVER &&
|
|
|
+ $_SERVER['APP_ENV'] !== 'docker' &&
|
|
|
+ $_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR']
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException("This operation is restricted to localhost");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Supprime tous les Access d'une organisation, ainsi que la Person
|
|
|
* rattachée (si celle-ci n'est pas liée à d'autres Access)
|