Skip to content

Commit 6e43e3b

Browse files
authored
Merge pull request #4713 from nextcloud/fix/templates-loading
2 parents 24ffd04 + 32c3327 commit 6e43e3b

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

cypress/e2e/templates.spec.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ describe('User templates', function() {
192192
{ index: 'ContentControls.ByIndex.4', type: 'checkbox', alias: '', checked: false },
193193
]
194194

195+
// Intercept the initial templates request to ensure it does not get the fields yet
196+
cy.intercept(
197+
'GET',
198+
'**/apps/files/api/v1/templates',
199+
(req) => req.continue(),
200+
).as('templatesRequest')
201+
202+
// Intercept the POST request to verify the correct fields are submitted
203+
cy.intercept('POST', '**/templates/create', (req) => {
204+
const templateFields = Object.values(req.body.templateFields)
205+
206+
expect(templateFields[0].content).to.equal(fields[0].content)
207+
expect(templateFields[1].content).to.equal(fields[1].content)
208+
209+
req.continue()
210+
}).as('reqFillFields')
211+
195212
cy.visit('/apps/files')
196213

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

225+
// Ensure the template fields array is of length 0, meaning no fields were fetched
226+
cy.wait('@templatesRequest').then(({ response }) => {
227+
const templates = response.body.ocs.data
228+
const template = templates[1].templates[0]
229+
230+
expect(template.fields.length).to.equal(0)
231+
})
232+
208233
// Choose the document template
209234
cy.get('form.templates-picker__form').as('templatePicker')
210235
cy.get('@templatePicker').contains('document').click()
211236
cy.get('@templatePicker').find('input[type="submit"]').click()
212237

213-
// Intercept the POST request to verify the correct fields are submitted
214-
cy.intercept('POST', '**/templates/create', (req) => {
215-
const templateFields = Object.values(req.body.templateFields)
216-
217-
expect(templateFields[0].content).to.equal(fields[0].content)
218-
expect(templateFields[1].content).to.equal(fields[1].content)
219-
220-
req.continue()
221-
}).as('reqFillFields')
222-
223238
cy.submitTemplateFields(fields)
224239

225240
// Wait for the response and collect the file ID of the created file

lib/Listener/BeforeGetTemplatesListener.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ public function handle(Event $event): void {
2424
return;
2525
}
2626

27+
/** @psalm-suppress RedundantCondition */
28+
if (method_exists($event, 'shouldGetFields') && !$event->shouldGetFields()) {
29+
return;
30+
}
31+
2732
foreach ($event->getTemplates() as $template) {
28-
$templateFileId = $template->jsonSerialize()['fileid'];
29-
$fields = $this->templateFieldService->extractFields($templateFileId);
30-
33+
$templateId = $template->jsonSerialize()['fileid'];
34+
$fields = $this->templateFieldService->extractFields($templateId);
35+
3136
$template->setFields($fields);
3237
}
3338
}

0 commit comments

Comments
 (0)