Skip to content

Commit cc38527

Browse files
committed
feat: check if template fields should be extracted
The `BeforeGetTemplatesEvent` now has a property that allows us to check if the templates should be enhanced with fields or not. If so, then we extract the fields, if not, simply do not. Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
1 parent 113d816 commit cc38527

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function __construct(
2020
}
2121

2222
public function handle(Event $event): void {
23-
if (!$event instanceof BeforeGetTemplatesEvent) {
23+
if (!$event instanceof BeforeGetTemplatesEvent || !$event->shouldGetFields()) {
2424
return;
2525
}
2626

2727
foreach ($event->getTemplates() as $template) {
28-
$templateFileId = $template->jsonSerialize()['fileid'];
29-
$fields = $this->templateFieldService->extractFields($templateFileId);
30-
28+
$templateId = $template->jsonSerialize()['fileid'];
29+
$fields = $this->templateFieldService->extractFields($templateId);
30+
3131
$template->setFields($fields);
3232
}
3333
}

0 commit comments

Comments
 (0)