aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Controller/TemplateController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Controller/TemplateController.php')
-rw-r--r--apps/files/lib/Controller/TemplateController.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/apps/files/lib/Controller/TemplateController.php b/apps/files/lib/Controller/TemplateController.php
index d04d86760e6..645350010ec 100644
--- a/apps/files/lib/Controller/TemplateController.php
+++ b/apps/files/lib/Controller/TemplateController.php
@@ -26,13 +26,21 @@ declare(strict_types=1);
*/
namespace OCA\Files\Controller;
+use OCA\Files\ResponseDefinitions;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCSController;
use OCP\Files\GenericFileException;
use OCP\Files\Template\ITemplateManager;
+use OCP\Files\Template\TemplateFileCreator;
use OCP\IRequest;
+/**
+ * @psalm-import-type FilesTemplate from ResponseDefinitions
+ * @psalm-import-type FilesTemplateFile from ResponseDefinitions
+ * @psalm-import-type FilesTemplateFileCreator from ResponseDefinitions
+ */
class TemplateController extends OCSController {
protected $templateManager;
@@ -43,6 +51,10 @@ class TemplateController extends OCSController {
/**
* @NoAdminRequired
+ *
+ * List the available templates
+ *
+ * @return DataResponse<Http::STATUS_OK, array<FilesTemplateFileCreator>, array{}>
*/
public function list(): DataResponse {
return new DataResponse($this->templateManager->listTemplates());
@@ -50,7 +62,17 @@ class TemplateController extends OCSController {
/**
* @NoAdminRequired
- * @throws OCSForbiddenException
+ *
+ * Create a template
+ *
+ * @param string $filePath Path of the file
+ * @param string $templatePath Name of the template
+ * @param string $templateType Type of the template
+ *
+ * @return DataResponse<Http::STATUS_OK, FilesTemplateFile, array{}>
+ * @throws OCSForbiddenException Creating template is not allowed
+ *
+ * 200: Template created successfully
*/
public function create(string $filePath, string $templatePath = '', string $templateType = 'user'): DataResponse {
try {
@@ -62,13 +84,24 @@ class TemplateController extends OCSController {
/**
* @NoAdminRequired
+ *
+ * Initialize the template directory
+ *
+ * @param string $templatePath Path of the template directory
+ * @param bool $copySystemTemplates Whether to copy the system templates to the template directory
+ *
+ * @return DataResponse<Http::STATUS_OK, array{template_path: string, templates: FilesTemplateFileCreator[]}, array{}>
+ * @throws OCSForbiddenException Initializing the template directory is not allowed
+ *
+ * 200: Template directory initialized successfully
*/
public function path(string $templatePath = '', bool $copySystemTemplates = false) {
try {
+ /** @var string $templatePath */
$templatePath = $this->templateManager->initializeTemplateDirectory($templatePath, null, $copySystemTemplates);
return new DataResponse([
'template_path' => $templatePath,
- 'templates' => $this->templateManager->listCreators()
+ 'templates' => array_map(fn(TemplateFileCreator $creator) => $creator->jsonSerialize(), $this->templateManager->listCreators()),
]);
} catch (\Exception $e) {
throw new OCSForbiddenException($e->getMessage());