Skip to content

Commit 824ffa8

Browse files
Improve logging, text adjustments and test fixes.
1 parent f3f9357 commit 824ffa8

File tree

6 files changed

+51
-36
lines changed

6 files changed

+51
-36
lines changed

config/install/collabora_online.settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ cool:
1313
wopi_proof: true
1414
# Allow fullscreen - Enabled by default for functionality.
1515
allowfullscreen: true
16-
# New File interval on save.
16+
# New file interval on save.
1717
new_file_interval: 0

config/schema/collabora_online.schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ collabora_online.settings:
2929
label: 'Allow full-screen.'
3030
new_file_interval:
3131
type: integer
32-
label: 'New File interval.'
32+
label: 'New file interval.'
3333

3434
key.type.collabora_jwt_hs:
3535
# The key type has no actual configurable settings, but it still needs a

src/Controller/WopiController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,19 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
164164
);
165165

166166
// Entity didn't change but file has been replaced.
167-
$file->setChangedTime($request_time);
168167
$file->save();
169168

170169
$this->logger->info(
171-
'File entity @file_id source @file_uri was replaced with Collabora.<br>
172-
Save reason: @reason<br>',
170+
'The file contents for media @media_id were overwritten with Collabora.<br>
171+
Save reason: @reason<br>
172+
File: @file_id / @file_uri<br>
173+
User ID: @user_id',
173174
[
175+
'@media_id' => $media->id(),
176+
'@reason' => $save_reason,
174177
'@file_id' => $file->id(),
175178
'@file_uri' => $file->getFileUri(),
176-
'@reason' => $save_reason,
179+
'@user_id' => $user->id(),
177180
],
178181
);
179182

@@ -198,14 +201,16 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
198201
'Media entity @media_id was updated with Collabora.<br>
199202
Save reason: @reason<br>
200203
Old file: @old_file_id / @old_file_uri<br>
201-
New file: @new_file_id / @new_file_uri',
204+
New file: @new_file_id / @new_file_uri<br>
205+
User ID: @user_id',
202206
[
203207
'@media_id' => $media->id(),
204208
'@reason' => $save_reason,
205209
'@old_file_id' => $file->id(),
206210
'@old_file_uri' => $file->getFileUri(),
207211
'@new_file_id' => $new_file->id(),
208212
'@new_file_uri' => $new_file->getFileUri(),
213+
'@user_id' => $user->id(),
209214
],
210215
);
211216

src/Form/ConfigForm.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
9393

9494
$form['new_file_interval'] = [
9595
'#type' => 'number',
96-
'#title' => $this->t('New File interval'),
96+
'#title' => $this->t('Create new file on save after…'),
9797
'#default_value' => $cool_settings['new_file_interval'] ?? 0,
9898
'#field_suffix' => $this->t('seconds'),
9999
'#min' => 0,
100-
'#description' => $this->t('Minimum interval of time required to create a new File upon save. A value of 0 will not create any entity.'),
100+
'#description' => $this->t('Period during which a save operation will overwrite the existing file, rather than creating a new file.<br>
101+
If the value is 0, the existing file will always be overwritten, and no new file will be created.<br>
102+
This applies equally to autosave, the editor\'s save button, and the close button.'),
101103
'#required' => TRUE,
102104
];
103105

tests/src/Functional/ConfigFormTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testConfigForm(): void {
6060
$assert_session->fieldValueEquals('WOPI host URL', 'https://localhost/');
6161
$assert_session->fieldValueEquals('JWT private key', '');
6262
$assert_session->fieldValueEquals('Access Token Expiration', '86400');
63-
$assert_session->fieldValueEquals('New File interval', '0');
63+
$assert_session->fieldValueEquals('Create new file on save after…', '0');
6464
$assert_session->checkboxNotChecked('Disable TLS certificate check for COOL.');
6565
$assert_session->checkboxChecked('Verify proof header and timestamp in incoming WOPI requests.');
6666
$assert_session->checkboxChecked('Allow COOL to use fullscreen mode.');
@@ -94,8 +94,8 @@ public function testConfigForm(): void {
9494
->setValue('collabora_test');
9595
$assert_session->fieldExists('Access Token Expiration')
9696
->setValue('3600');
97-
$assert_session->fieldExists('New File interval')
98-
->setValue(value: '300');
97+
$assert_session->fieldExists('Create new file on save after…')
98+
->setValue('300');
9999
$assert_session->fieldExists('Disable TLS certificate check for COOL.')
100100
->check();
101101
$assert_session->fieldExists('Verify proof header and timestamp in incoming WOPI requests.')
@@ -112,7 +112,7 @@ public function testConfigForm(): void {
112112
$assert_session->fieldValueEquals('WOPI host URL', 'http://wopihost.com/');
113113
$assert_session->fieldValueEquals('JWT private key', 'collabora_test');
114114
$assert_session->fieldValueEquals('Access Token Expiration', '3600');
115-
$assert_session->fieldValueEquals('New File interval', '300');
115+
$assert_session->fieldValueEquals('Create new file on save after…', '300');
116116
$assert_session->checkboxChecked('Disable TLS certificate check for COOL.');
117117
$assert_session->checkboxNotChecked('Verify proof header and timestamp in incoming WOPI requests.');
118118
$assert_session->checkboxNotChecked('Allow COOL to use fullscreen mode.');
@@ -123,15 +123,15 @@ public function testConfigForm(): void {
123123
$assert_session->fieldExists('WOPI host URL')->setValue('');
124124
$assert_session->fieldExists('JWT private key')->setValue('');
125125
$assert_session->fieldExists('Access Token Expiration')->setValue('');
126-
$assert_session->fieldExists('New File interval')->setValue('');
126+
$assert_session->fieldExists('Create new file on save after…')->setValue('');
127127
$assert_session->fieldExists('Disable TLS certificate check for COOL.')->uncheck();
128128
$assert_session->fieldExists('Allow COOL to use fullscreen mode.')->uncheck();
129129
$assert_session->buttonExists('Save configuration')->press();
130130
$assert_session->statusMessageContains('Collabora Online server URL field is required.', 'error');
131131
$assert_session->statusMessageContains('WOPI host URL field is required.', 'error');
132132
$assert_session->statusMessageContains('JWT private key field is required.', 'error');
133133
$assert_session->statusMessageContains('Access Token Expiration field is required.', 'error');
134-
$assert_session->statusMessageContains('New File interval', 'error');
134+
$assert_session->statusMessageContains('Create new file on save after… field is required.', 'error');
135135

136136
// Test validation of bad form values.
137137
$this->drupalGet(Url::fromRoute('collabora-online.settings'));
@@ -140,12 +140,12 @@ public function testConfigForm(): void {
140140
$assert_session->fieldExists('WOPI host URL')->setValue('any-other-value');
141141
// Set invalid values for numeric field.
142142
$assert_session->fieldExists('Access Token Expiration')->setValue('text');
143-
$assert_session->fieldExists('New File interval')->setValue('text');
143+
$assert_session->fieldExists('Create new file on save after…')->setValue('text');
144144
$assert_session->buttonExists('Save configuration')->press();
145145
$assert_session->statusMessageContains('The URL /internal is not valid.', 'error');
146146
$assert_session->statusMessageContains('The URL any-other-value is not valid.', 'error');
147-
$assert_session->statusMessageNotContains('Access Token Expiration must be a number.', 'status');
148-
$assert_session->statusMessageNotContains('New File interval', 'status');
147+
$assert_session->statusMessageContains('Access Token Expiration must be a number.', 'error');
148+
$assert_session->statusMessageContains('Create new file on save after… must be a number.', 'error');
149149

150150
// Test form with no configuration.
151151
\Drupal::configFactory()->getEditable('collabora_online.settings')->setData([])->save();
@@ -154,7 +154,7 @@ public function testConfigForm(): void {
154154
$assert_session->fieldValueEquals('WOPI host URL', '');
155155
$assert_session->fieldValueEquals('JWT private key', '');
156156
$assert_session->fieldValueEquals('Access Token Expiration', '0');
157-
$assert_session->fieldValueEquals('New File interval', '0');
157+
$assert_session->fieldValueEquals('Create new file on save after…', '0');
158158
$assert_session->checkboxNotChecked('Disable TLS certificate check for COOL.');
159159
$assert_session->checkboxChecked('Verify proof header and timestamp in incoming WOPI requests.');
160160
$assert_session->checkboxNotChecked('Allow COOL to use fullscreen mode.');

tests/src/Kernel/Controller/WopiControllerTest.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ public function testWopiPutFile(): void {
143143
}
144144

145145
/**
146-
* Tests new File creation on successful requests.
146+
* Tests new file creation on successful requests.
147147
*
148148
* @covers ::wopiPutFile
149149
*/
150150
public function testWopiPutFileNewFile(): void {
151151
// Change configuration to 300 seconds and attempt a save immediately after.
152-
// File was created just before, so no new File.
152+
// File was created just before, so no new file.
153153
$wopi_settings = \Drupal::configFactory()->getEditable('collabora_online.settings');
154154
$wopi_settings->set('cool.new_file_interval', 300)->save();
155155
$this->doTestWopiPutFile();
@@ -158,12 +158,12 @@ public function testWopiPutFileNewFile(): void {
158158
\Drupal::time()->setTime('+100 seconds');
159159
$this->doTestWopiPutFile();
160160

161-
// Wait more than 300 seconds to trigger the File creation.
162-
\Drupal::time()->setTime('+301 seconds');
163-
$this->doTestWopiPutFile(new_file: TRUE);
161+
// Wait more than 300 seconds to trigger the file creation.
162+
\Drupal::time()->setTime('+305 seconds');
163+
$this->doTestWopiPutfile(new_file: TRUE);
164164

165165
// Multiple sequential calls under the configured time does not prevent the
166-
// creation of the File.
166+
// creation of the file.
167167
\Drupal::time()->setTime('+295 seconds');
168168
$this->doTestWopiPutFile();
169169
\Drupal::time()->setTime('+295 seconds');
@@ -173,12 +173,12 @@ public function testWopiPutFileNewFile(): void {
173173
\Drupal::time()->setTime('+295 seconds');
174174
$this->doTestWopiPutFile(new_file: TRUE);
175175

176-
// Configured interval of 0 won't create any File.
176+
// Configured interval of 0 won't create any file.
177177
$wopi_settings->set('cool.new_file_interval', 0)->save();
178178
\Drupal::time()->setTime('+5 seconds');
179179
$this->doTestWopiPutFile();
180180

181-
// Empty value on the configuration won't create any File.
181+
// Empty value on the configuration won't create any file.
182182
$wopi_settings->set('cool.new_file_interval', '')->save();
183183
\Drupal::time()->setTime('+5 seconds');
184184
$this->doTestWopiPutFile();
@@ -193,7 +193,7 @@ public function testWopiPutFileNewFile(): void {
193193
* Request headers.
194194
* @param string $reason_message
195195
* Reason message expected to appear in the log and in the revision log.
196-
* @param string $new_file
196+
* @param bool $new_file
197197
* New file is expected.
198198
*/
199199
protected function doTestWopiPutFile(
@@ -203,6 +203,8 @@ protected function doTestWopiPutFile(
203203
): void {
204204
$new_file_content = "File content " . str_repeat('m', rand(0, 999)) . '.';
205205
$old_file = $this->loadCurrentMediaFile();
206+
$old_file_id = $old_file->id();
207+
$old_file_uri = $old_file->getFileUri();
206208
$this->logger->reset();
207209
$request = $this->createRequest(
208210
'/contents',
@@ -230,18 +232,22 @@ protected function doTestWopiPutFile(
230232
$this->assertSame(strlen($new_file_content), $file->getSize());
231233

232234
if (!$new_file) {
233-
// The URI remains the same, and no File entity has been created.
234-
$this->assertSame($old_file->id(), $file->id());
235-
$this->assertSame($file->getFileUri(), $file->getFileUri());
235+
// The URI remains the same, and no file entity has been created.
236+
$this->assertSame($old_file_id, $file->id());
237+
$this->assertSame($old_file_uri, $file->getFileUri());
236238

237239
$this->assertLogMessage(
238240
RfcLogLevel::INFO,
239-
'File entity @file_id source @file_uri was replaced with Collabora.<br>
240-
Save reason: @reason<br>',
241+
'The file contents for media @media_id were overwritten with Collabora.<br>
242+
Save reason: @reason<br>
243+
File: @file_id / @file_uri<br>
244+
User ID: @user_id',
241245
[
246+
'@media_id' => $media->id(),
247+
'@reason' => $reason_message,
242248
'@file_id' => $file->id(),
243249
'@file_uri' => $file->getFileUri(),
244-
'@reason' => $reason_message,
250+
'@user_id' => $this->user->id(),
245251
],
246252
);
247253

@@ -250,7 +256,7 @@ protected function doTestWopiPutFile(
250256

251257
$i = $this->getCounterValue();
252258
// Assert that a new file was created.
253-
$this->assertGreaterThan((int) $old_file->id(), (int) $file->id());
259+
$this->assertGreaterThan((int) $old_file_id, (int) $file->id());
254260
// The file uri is fully predictable in the context of this test.
255261
// Each new file version gets a new number suffix.
256262
// There is no repeated suffix like "test_0_0_0_0.txt".
@@ -268,14 +274,16 @@ protected function doTestWopiPutFile(
268274
'Media entity @media_id was updated with Collabora.<br>
269275
Save reason: @reason<br>
270276
Old file: @old_file_id / @old_file_uri<br>
271-
New file: @new_file_id / @new_file_uri',
277+
New file: @new_file_id / @new_file_uri<br>
278+
User ID: @user_id',
272279
[
273280
'@media_id' => $this->media->id(),
274281
'@reason' => $reason_message,
275282
'@old_file_id' => $old_file->id(),
276283
'@old_file_uri' => $old_file->getFileUri(),
277284
'@new_file_id' => $file->id(),
278285
'@new_file_uri' => $file->getFileUri(),
286+
'@user_id' => $this->user->id(),
279287
],
280288
);
281289
}

0 commit comments

Comments
 (0)