Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions cypress/e2e/templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ describe('User templates', function() {
{ index: 'ContentControls.ByIndex.4', type: 'checkbox', alias: '', checked: false },
]

// Intercept the initial templates request to ensure it does not get the fields yet
cy.intercept(
'GET',
'**/apps/files/api/v1/templates',
(req) => req.continue(),
).as('templatesRequest')

// Intercept the POST request to verify the correct fields are submitted
cy.intercept('POST', '**/templates/create', (req) => {
const templateFields = Object.values(req.body.templateFields)

expect(templateFields[0].content).to.equal(fields[0].content)
expect(templateFields[1].content).to.equal(fields[1].content)

req.continue()
}).as('reqFillFields')

cy.visit('/apps/files')

// Create a new document
Expand All @@ -205,21 +222,19 @@ describe('User templates', function() {
cy.get('input[data-cy-files-new-node-dialog-input=""]').type('FileFromTemplateWithFields')
cy.get('button[data-cy-files-new-node-dialog-submit=""]').click()

// Ensure the template fields array is of length 0, meaning no fields were fetched
cy.wait('@templatesRequest').then(({ response }) => {
const templates = response.body.ocs.data
const template = templates[1].templates[0]

expect(template.fields.length).to.equal(0)
})

// Choose the document template
cy.get('form.templates-picker__form').as('templatePicker')
cy.get('@templatePicker').contains('document').click()
cy.get('@templatePicker').find('input[type="submit"]').click()

// Intercept the POST request to verify the correct fields are submitted
cy.intercept('POST', '**/templates/create', (req) => {
const templateFields = Object.values(req.body.templateFields)

expect(templateFields[0].content).to.equal(fields[0].content)
expect(templateFields[1].content).to.equal(fields[1].content)

req.continue()
}).as('reqFillFields')

cy.submitTemplateFields(fields)

// Wait for the response and collect the file ID of the created file
Expand Down
11 changes: 8 additions & 3 deletions lib/Listener/BeforeGetTemplatesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ public function handle(Event $event): void {
return;
}

/** @psalm-suppress RedundantCondition */
if (method_exists($event, 'shouldGetFields') && !$event->shouldGetFields()) {
return;
}

foreach ($event->getTemplates() as $template) {
$templateFileId = $template->jsonSerialize()['fileid'];
$fields = $this->templateFieldService->extractFields($templateFileId);
$templateId = $template->jsonSerialize()['fileid'];
$fields = $this->templateFieldService->extractFields($templateId);

$template->setFields($fields);
}
}
Expand Down
Loading