Skip to content

Commit 03b888a

Browse files
authored
Merge pull request #6888 from LibreSign/refactor/files-list-config-prefixes
refactor: files list config prefixes
2 parents 566f4c0 + 163408e commit 03b888a

10 files changed

Lines changed: 89 additions & 273 deletions

File tree

lib/Migration/Version17001Date20260210000000.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
namespace OCA\Libresign\Migration;
1010

1111
use OCA\Libresign\AppInfo\Application;
12+
use OCP\DB\QueryBuilder\IQueryBuilder;
1213
use OCP\IAppConfig;
14+
use OCP\IConfig;
15+
use OCP\IDBConnection;
1316
use OCP\Migration\IOutput;
1417
use OCP\Migration\SimpleMigrationStep;
1518

@@ -20,6 +23,14 @@
2023
* - telegram → telegramToken
2124
* - whatsapp → whatsappToken
2225
* - xmpp → xmppToken
26+
*
27+
* Also migrate files list config keys to use prefixed naming:
28+
* - grid_view → files_list_grid_view
29+
* - signer_identify_tab → files_list_signer_identify_tab
30+
* - sorting_mode → files_list_sorting_mode
31+
* - sorting_direction → files_list_sorting_direction
32+
* - filter_modified → files_list_filter_modified
33+
* - filter_status → files_list_filter_status
2334
*/
2435
class Version17001Date20260210000000 extends SimpleMigrationStep {
2536
private const LEGACY_MAPPING = [
@@ -30,8 +41,19 @@ class Version17001Date20260210000000 extends SimpleMigrationStep {
3041
'xmpp' => 'xmppToken',
3142
];
3243

44+
private const USER_CONFIG_MIGRATIONS = [
45+
'grid_view' => 'files_list_grid_view',
46+
'signer_identify_tab' => 'files_list_signer_identify_tab',
47+
'sorting_mode' => 'files_list_sorting_mode',
48+
'sorting_direction' => 'files_list_sorting_direction',
49+
'filter_modified' => 'files_list_filter_modified',
50+
'filter_status' => 'files_list_filter_status',
51+
];
52+
3353
public function __construct(
3454
private IAppConfig $appConfig,
55+
private IConfig $config,
56+
private IDBConnection $db,
3557
) {
3658
}
3759

@@ -91,5 +113,47 @@ function ($methodName) use (&$updated) {
91113
$this->appConfig->setValueArray(Application::APP_ID, 'identify_methods', $identifyMethods);
92114
$output->info('Updated signature method names to new format with Token suffix');
93115
}
116+
117+
$this->migrateUserConfigs($output);
118+
}
119+
120+
private function migrateUserConfigs(IOutput $output): void {
121+
$oldKeys = array_keys(self::USER_CONFIG_MIGRATIONS);
122+
$query = $this->db->getQueryBuilder();
123+
$query->selectDistinct('userid')
124+
->from('preferences')
125+
->where($query->expr()->eq('appid', $query->createNamedParameter(Application::APP_ID)))
126+
->andWhere($query->expr()->in('configkey', $query->createNamedParameter($oldKeys, IQueryBuilder::PARAM_STR_ARRAY)));
127+
128+
$result = $query->executeQuery();
129+
$userIds = $result->fetchAll(\PDO::FETCH_COLUMN);
130+
131+
if (empty($userIds)) {
132+
return;
133+
}
134+
135+
$migratedCount = 0;
136+
$output->info('Migrating files list config keys for ' . count($userIds) . ' users...');
137+
138+
foreach ($userIds as $userId) {
139+
foreach (self::USER_CONFIG_MIGRATIONS as $oldKey => $newKey) {
140+
$oldValue = $this->config->getUserValue($userId, Application::APP_ID, $oldKey, null);
141+
$newValue = $this->config->getUserValue($userId, Application::APP_ID, $newKey, null);
142+
143+
// If old key has a value and new key is empty, migrate
144+
if ($oldValue !== null && $oldValue !== '' && ($newValue === null || $newValue === '')) {
145+
$this->config->setUserValue($userId, Application::APP_ID, $newKey, $oldValue);
146+
$this->config->deleteUserValue($userId, Application::APP_ID, $oldKey);
147+
$migratedCount++;
148+
} elseif ($oldValue !== null && $oldValue !== '' && $newValue !== null && $newValue !== '') {
149+
// Both exist, just delete the old one
150+
$this->config->deleteUserValue($userId, Application::APP_ID, $oldKey);
151+
}
152+
}
153+
}
154+
155+
if ($migratedCount > 0) {
156+
$output->info("Migrated $migratedCount config keys to new prefixed format");
157+
}
94158
}
95159
}

lib/Service/AccountService.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function getCertificateEngineName(): string {
191191
* @return array<string, mixed>
192192
*/
193193
public function getConfig(?IUser $user = null): array {
194+
194195
$info['identificationDocumentsFlow'] = $this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false);
195196
$info['hasSignatureFile'] = $this->hasSignatureFile($user);
196197
$info['phoneNumber'] = $this->getPhoneNumber($user);
@@ -199,24 +200,24 @@ public function getConfig(?IUser $user = null): array {
199200
$info['id_docs_sort'] = $this->getUserConfigIdDocsSort($user);
200201
$info['crl_filters'] = $this->getUserConfigCrlFilters($user);
201202
$info['crl_sort'] = $this->getUserConfigCrlSort($user);
202-
$info['grid_view'] = $this->getUserConfigByKey('grid_view', $user) === '1';
203-
$info['signer_identify_tab'] = $this->getUserConfigByKey('signer_identify_tab', $user);
204-
$info['sorting_mode'] = $this->getUserConfigByKey('sorting_mode', $user) ?: 'name';
205-
$info['sorting_direction'] = $this->getUserConfigByKey('sorting_direction', $user) ?: 'asc';
203+
$info['files_list_grid_view'] = $this->getUserConfigByKey('files_list_grid_view', $user) === '1';
204+
$info['files_list_signer_identify_tab'] = $this->getUserConfigByKey('files_list_signer_identify_tab', $user);
205+
$info['files_list_sorting_mode'] = $this->getUserConfigByKey('files_list_sorting_mode', $user) ?: 'name';
206+
$info['files_list_sorting_direction'] = $this->getUserConfigByKey('files_list_sorting_direction', $user) ?: 'asc';
206207

207208
return array_filter($info);
208209
}
209210

210211
public function getConfigFilters(?IUser $user = null): array {
211-
$info['filter_modified'] = $this->getUserConfigByKey('filter_modified', $user);
212-
$info['filter_status'] = $this->getUserConfigByKey('filter_status', $user);
212+
$info['files_list_filter_modified'] = $this->getUserConfigByKey('files_list_filter_modified', $user);
213+
$info['files_list_filter_status'] = $this->getUserConfigByKey('files_list_filter_status', $user);
213214

214215
return $info;
215216
}
216217

217218
public function getConfigSorting(?IUser $user = null): array {
218-
$info['sorting_mode'] = $this->getUserConfigByKey('sorting_mode', $user) ?: 'name';
219-
$info['sorting_direction'] = $this->getUserConfigByKey('sorting_direction', $user) ?: 'asc';
219+
$info['files_list_sorting_mode'] = $this->getUserConfigByKey('files_list_sorting_mode', $user) ?: 'name';
220+
$info['files_list_sorting_direction'] = $this->getUserConfigByKey('files_list_sorting_direction', $user) ?: 'asc';
220221

221222
return $info;
222223
}

src/components/RightSidebar/RequestSignatureTab.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ export default {
674674
subscribe('libresign:edit-signer', this.editSigner)
675675
this.filesStore.disableIdentifySigner()
676676
677-
this.activeTab = this.userConfigStore.signer_identify_tab || ''
677+
this.activeTab = this.userConfigStore.files_list_signer_identify_tab || ''
678678
679679
this.adminSignatureFlow = loadState('libresign', 'signature_flow', 'none')
680680
@@ -709,7 +709,7 @@ export default {
709709
}, 1000)
710710
711711
this.debouncedTabChange = debounce((tabId) => {
712-
this.userConfigStore.update('signer_identify_tab', tabId)
712+
this.userConfigStore.update('files_list_signer_identify_tab', tabId)
713713
}, 500)
714714
},
715715
methods: {
@@ -866,7 +866,7 @@ export default {
866866
},
867867
addSigner() {
868868
this.signerToEdit = {}
869-
this.activeTab = this.userConfigStore.signer_identify_tab || ''
869+
this.activeTab = this.userConfigStore.files_list_signer_identify_tab || ''
870870
this.filesStore.enableIdentifySigner()
871871
},
872872
editSigner(signer) {

src/store/filesSorting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export const useFilesSortingStore = defineStore('filesSorting', {
4343

4444
async saveSorting() {
4545
try {
46-
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'sorting_mode' }), {
46+
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'files_list_sorting_mode' }), {
4747
value: this.sortingMode,
4848
})
49-
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'sorting_direction' }), {
49+
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'files_list_sorting_direction' }), {
5050
value: this.sortingDirection,
5151
})
5252
} catch (error) {

src/tests/store/filesSorting.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ vi.mock('@nextcloud/event-bus', () => ({
1717
}))
1818

1919
vi.mock('@nextcloud/initial-state', () => ({
20-
loadState: () => ({ sorting_mode: 'created_at', sorting_direction: 'desc' }),
20+
loadState: () => ({ files_list_sorting_mode: 'name', files_list_sorting_direction: 'asc' }),
2121
}))
2222

2323
vi.mock('@nextcloud/axios', () => ({
@@ -85,11 +85,11 @@ describe('filesSorting store', () => {
8585

8686
expect(putMock).toHaveBeenCalledTimes(2)
8787
expect(putMock).toHaveBeenCalledWith(
88-
'/apps/libresign/api/v1/account/config/sorting_mode',
88+
'/apps/libresign/api/v1/account/config/files_list_sorting_mode',
8989
{ value: 'created_at' }
9090
)
9191
expect(putMock).toHaveBeenCalledWith(
92-
'/apps/libresign/api/v1/account/config/sorting_direction',
92+
'/apps/libresign/api/v1/account/config/files_list_sorting_direction',
9393
{ value: 'desc' }
9494
)
9595
})

src/views/FilesList/FileEntry/FileEntryPreview.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export default {
8787
const url = new URL(previewUrl)
8888
8989
// Request tiny previews
90-
url.searchParams.set('x', this.userConfigStore.grid_view ? '128' : '32')
91-
url.searchParams.set('y', this.userConfigStore.grid_view ? '128' : '32')
90+
url.searchParams.set('x', this.userConfigStore.files_list_grid_view ? '128' : '32')
91+
url.searchParams.set('y', this.userConfigStore.files_list_grid_view ? '128' : '32')
9292
url.searchParams.set('mimeFallback', 'true')
9393
9494
// Handle cropping

src/views/FilesList/FilesList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
type="tertiary"
3333
@click="toggleGridView">
3434
<template #icon>
35-
<ListViewIcon v-if="userConfigStore.grid_view" />
35+
<ListViewIcon v-if="userConfigStore.files_list_grid_view" />
3636
<ViewGridIcon v-else />
3737
</template>
3838
</NcButton>
@@ -136,7 +136,7 @@ export default {
136136
return HomeSvg
137137
},
138138
gridViewButtonLabel() {
139-
return this.userConfigStore.grid_view
139+
return this.userConfigStore.files_list_grid_view
140140
? t('libresign', 'Switch to list view')
141141
: t('libresign', 'Switch to grid view')
142142
},
@@ -165,7 +165,7 @@ export default {
165165
this.filesStore.updateAllFiles()
166166
},
167167
toggleGridView() {
168-
this.userConfigStore.update('grid_view', !this.userConfigStore.grid_view)
168+
this.userConfigStore.update('files_list_grid_view', !this.userConfigStore.files_list_grid_view)
169169
},
170170
checkAndOpenFileFromUri() {
171171
const uuid = this.$route.query.uuid

src/views/FilesList/FilesListVirtual.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<template>
66
<VirtualList ref="table"
7-
:data-component="userConfigStore.grid_view ? FileEntryGrid : FileEntry"
7+
:data-component="userConfigStore.files_list_grid_view ? FileEntryGrid : FileEntry"
88
:loading="loading"
99
:caption="caption">
1010
<template #filters>

src/views/FilesList/VirtualList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<template>
66
<div class="files-list"
7-
:class="{ 'files-list--grid': userConfigStore.grid_view }"
7+
:class="{ 'files-list--grid': userConfigStore.files_list_grid_view }"
88
data-cy-files-list>
99
<div class="files-list__filters">
1010
<slot name="filters" />
@@ -38,7 +38,7 @@
3838
</thead>
3939
<!-- Body -->
4040
<tbody class="files-list__tbody"
41-
:class="userConfigStore.grid_view ? 'files-list__tbody--grid' : 'files-list__tbody--list'"
41+
:class="userConfigStore.files_list_grid_view ? 'files-list__tbody--grid' : 'files-list__tbody--list'"
4242
data-cy-files-list-tbody>
4343
<component :is="dataComponent"
4444
v-for="(item) in filesStore.filesSorted()"

0 commit comments

Comments
 (0)