Skip to content

Commit 37f4b12

Browse files
committed
fix: routing based on base64 encoding
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 7d0596e commit 37f4b12

File tree

13 files changed

+126
-56
lines changed

13 files changed

+126
-56
lines changed

lib/ContactsMenu/Providers/DetailsProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function process(IEntry $entry) {
8282

8383
$contactsUrl = $this->urlGenerator->getAbsoluteURL(
8484
$this->urlGenerator->linkToRoute('contacts.contacts.direct', [
85-
'contact' => $uid . '~' . $addressBookUri
85+
'contact' => base64_encode($uid . '~' . $addressBookUri),
8686
])
8787
);
8888

lib/Controller/ContactsController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function __construct(
3333
* @param string $uuid
3434
*/
3535
public function direct(string $contact): RedirectResponse {
36+
// Keep compatibility with old routing scheme
37+
if (str_contains($contact, '~')) {
38+
$contact = base64_encode($contact);
39+
}
40+
3641
$url = $this->urlGenerator->getAbsoluteURL(
3742
$this->urlGenerator->linkToRoute('contacts.page.index') . $this->l10n->t('All contacts') . '/' . $contact
3843
);

src/components/AppContent/ChartContent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
transformData() {
3737
const contactsByUid = {}
3838
const contacts = Object.keys(this.contactsList).map(key => {
39-
const [uid, addressbook] = key.split('~')
39+
const [uid, addressbook] = Buffer.from(key, 'base64').toString('utf-8').split('~')
4040
if (!contactsByUid[addressbook]) {
4141
contactsByUid[addressbook] = {}
4242
}

src/components/AppContent/ContactsContent.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ export default {
116116
return this.$store.getters.getSortedContacts
117117
},
118118
119-
selectedContact() {
120-
return this.$route.params.selectedContact
121-
},
122-
123119
/**
124120
* Is this a real group ?
125121
* Aka not a dynamically generated one like `All contacts`

src/components/AppNavigation/GroupNavigationItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ export default {
151151
async onDrop(event, group) {
152152
try {
153153
const contactFromDropData = JSON.parse(event.dataTransfer.getData('item'))
154-
const contactFromStore = this.$store.getters.getContact(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`)
154+
const contactFromStore = this.$store.getters.getContact(Buffer.from(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`, 'utf-8').toString('base64'))
155155
if (contactFromStore && !this.isInGroup(contactFromStore.groups, group.id)) {
156-
const contact = this.$store.getters.getContact(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`)
156+
const contact = this.$store.getters.getContact(Buffer.from(`${contactFromDropData.uid}~${contactFromDropData.addressbookId}`, 'utf-8').toString('base64'))
157157
await this.$store.dispatch('updateContactGroups', {
158158
groupNames: [...contactFromStore.groups, group.id],
159159
contact,

src/components/ContactDetails/ContactDetailsProperty.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default {
296296
}
297297
if (this.propName === 'x-managersname') {
298298
if (this.property.getParameter('uid')) {
299-
return this.property.getParameter('uid') + '~' + this.contact.addressbook.id
299+
return Buffer.from(this.property.getParameter('uid') + '~' + this.contact.addressbook.id, 'utf-8').toString('base64')
300300
}
301301
// Try to find the matching contact by display name
302302
// TODO: this only *shows* the display name but doesn't assign the missing UID

src/components/ContactsList.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ import Merging from './ContactsList/Merging.vue'
8989
import IconCancelRaw from '@mdi/svg/svg/cancel.svg?raw'
9090
// eslint-disable-next-line import/no-unresolved
9191
import IconDeleteRaw from '@mdi/svg/svg/delete-outline.svg'
92+
import RouterMixin from '../mixins/RouterMixin.js'
9293
9394
export default {
9495
name: 'ContactsList',
9596
97+
mixins: [
98+
RouterMixin,
99+
],
100+
96101
components: {
97102
AppContentList,
98103
NcNoteCard,
@@ -153,12 +158,6 @@ export default {
153158
},
154159
155160
computed: {
156-
selectedContact() {
157-
return this.$route.params.selectedContact
158-
},
159-
selectedGroup() {
160-
return this.$route.params.selectedGroup
161-
},
162161
filteredList() {
163162
const contactsList = this.list
164163
.filter(item => this.matchSearch(this.contacts[item.key]))
@@ -242,7 +241,7 @@ export default {
242241
* @param {string} key the contact unique key
243242
*/
244243
scrollToContact(key) {
245-
const item = this.$el.querySelector('#' + btoa(key).slice(0, -2))
244+
const item = this.$el.querySelector('#' + key.slice(0, -2))
246245
247246
// if the item is not visible in the list or barely visible
248247
if (!(item && item.getBoundingClientRect().y > 50)) { // header height

src/components/ContactsList/ContactsListItem.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ import {
4949
NcAvatar,
5050
} from '@nextcloud/vue'
5151
import CheckIcon from 'vue-material-design-icons/Check.vue'
52+
import RouterMixin from '../../mixins/RouterMixin.js'
5253
5354
export default {
5455
name: 'ContactsListItem',
5556
57+
mixins: [
58+
RouterMixin,
59+
],
60+
5661
components: {
5762
ListItem,
5863
NcAvatar,
@@ -86,19 +91,13 @@ export default {
8691
},
8792
8893
computed: {
89-
selectedGroup() {
90-
return this.$route.params.selectedGroup
91-
},
92-
selectedContact() {
93-
return this.$route.params.selectedContact
94-
},
9594
// contact is not draggable when it has not been saved on server as it can't be added to groups/circles before
9695
isDraggable() {
9796
return !!this.source.dav && this.source.addressbook.id !== 'z-server-generated--system'
9897
},
9998
// usable and valid html id for scrollTo
10099
id() {
101-
return window.btoa(this.source.key).slice(0, -2)
100+
return this.source.key.slice(0, -2)
102101
},
103102
getTel() {
104103
return this.source.properties.find(property => property.name === 'tel')?.getFirstValue()

src/mixins/RouterMixin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ export default {
1414
selectedCircle() {
1515
return this.$route.params.selectedCircle
1616
},
17+
selectedChart() {
18+
return this.$route.params.selectedChart
19+
},
1720
},
1821
}

src/models/contact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export default class Contact {
193193
* @memberof Contact
194194
*/
195195
get key() {
196-
return this.uid + '~' + this.addressbook.id
196+
return Buffer.from(this.uid + '~' + this.addressbook.id, 'utf8').toString('base64')
197197
}
198198

199199
/**

0 commit comments

Comments
 (0)