Bläddra i källkod

add Api route and secure operations

Olivier Massot 1 år sedan
förälder
incheckning
cbcd05ed6d

+ 8 - 0
ot_admin/Classes/Command/DeleteUserCreatedPagesCommand.php

@@ -61,6 +61,14 @@ class DeleteUserCreatedPagesCommand extends Command
 
         $io = new SymfonyStyle($input, $output);
 
+        if (
+            !$io->confirm("Are you sure you want to delete all the pages created " .
+                "by the users? (organization id: " . $org_id . ")")
+        ) {
+            $io->error("Aborting.");
+            return 1;
+        }
+
         $rootUid = $this->siteController->deleteUserCreatedPagesAction($org_id);
 
         $io->success(sprintf("The website with root uid " . $rootUid . " had its user-created pages deleted."));

+ 20 - 0
ot_admin/Classes/Http/ApiController.php

@@ -478,4 +478,24 @@ class ApiController implements LoggerAwareInterface
 
         return new JsonResponse($results);
     }
+
+    public function deleteUserCreatedPagesAction(ServerRequest $request): JsonResponse
+    {
+        $this->assertIpAllowed();
+
+        $organizationId = $this->getOrganizationId($request);
+
+        $this->preventIfIsDubious();
+        $this->preventOnMissingConfirmationToken($organizationId);
+
+        $rootUid = $this->siteController->deleteUserCreatedPagesAction($organizationId);
+
+        return new JsonResponse(
+            [
+                'organization_id' => $organizationId,
+                'msg' => "The website with root uid " . $rootUid . " had its user-created pages deleted.",
+                'root_uid' => $rootUid
+            ]
+        );
+    }
 }

+ 5 - 0
ot_admin/Configuration/Backend/Routes.php

@@ -56,5 +56,10 @@ return [
         'path' => '/otadmin/scan',
         'target' => ApiController::class . '::scanAllAction',
         'access' => 'public'
+    ],
+    'delete-user-created-pages' => [
+        'path' => '/otadmin/delete-user-created-pages',
+        'target' => ApiController::class . '::deleteUserCreatedPagesAction',
+        'access' => 'public'
     ]
 ];