1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-14 00:59:06 +00:00

Merge branch 'fix-protected-fields-in-data-sync' into 'develop'

Fix protected field validation of data sync forms

Closes 

See merge request 
This commit is contained in:
Bram Wiepjes 2025-03-03 12:27:41 +00:00
commit 3080c78118
7 changed files with 53 additions and 54 deletions
changelog/entries/unreleased/bug
enterprise/web-frontend/modules/baserow_enterprise/components/dataSync
web-frontend/modules/database/components/dataSync

View file

@ -0,0 +1,8 @@
{
"type": "bug",
"message": "Fix protected fields in the data sync forms.",
"domain": "database",
"issue_number": 3191,
"bullet_points": [],
"created_at": "2025-02-27"
}

View file

@ -47,16 +47,8 @@
:helper-text="$t('githubIssuesDataSync.apiTokenHelper')" :helper-text="$t('githubIssuesDataSync.apiTokenHelper')"
small-label small-label
:protected-edit="update" :protected-edit="update"
@enabled-protected-edit="allowedValues.push('github_issues_api_token')" @enabled-protected-edit="values.github_issues_api_token = ''"
@disable-protected-edit=" @disable-protected-edit="values.github_issues_api_token = undefined"
;[
allowedValues.splice(
allowedValues.indexOf('github_issues_api_token'),
1
),
delete values['github_issues_api_token'],
]
"
> >
<FormInput <FormInput
v-model="v$.values.github_issues_api_token.$model" v-model="v$.values.github_issues_api_token.$model"
@ -96,15 +88,16 @@ export default {
return { v$: useVuelidate({ $lazy: true }) } return { v$: useVuelidate({ $lazy: true }) }
}, },
data() { data() {
const allowedValues = ['github_issues_owner', 'github_issues_repo']
if (!this.update) {
allowedValues.push('github_issues_api_token')
}
return { return {
allowedValues: ['github_issues_owner', 'github_issues_repo'], allowedValues: [
'github_issues_owner',
'github_issues_repo',
'github_issues_api_token',
],
values: { values: {
github_issues_owner: '', github_issues_owner: '',
github_issues_repo: '', github_issues_repo: '',
github_issues_api_token: this.update ? undefined : '',
}, },
} }
}, },
@ -127,7 +120,7 @@ export default {
required: helpers.withMessage( required: helpers.withMessage(
this.$t('error.requiredField'), this.$t('error.requiredField'),
requiredIf(() => { requiredIf(() => {
return this.allowedValues.includes('github_issues_api_token') return this.values.github_issues_api_token !== undefined
}) })
), ),
}, },

View file

@ -48,13 +48,8 @@
:helper-text="$t('gitlabIssuesDataSync.accessTokenHelper')" :helper-text="$t('gitlabIssuesDataSync.accessTokenHelper')"
small-label small-label
:protected-edit="update" :protected-edit="update"
@enabled-protected-edit="allowedValues.push('gitlab_access_token')" @enabled-protected-edit="values.gitlab_access_token = ''"
@disable-protected-edit=" @disable-protected-edit="values.gitlab_access_token = undefined"
;[
allowedValues.splice(allowedValues.indexOf('gitlab_access_token'), 1),
delete values['gitlab_access_token'],
]
"
> >
<FormInput <FormInput
v-model="v$.values.gitlab_access_token.$model" v-model="v$.values.gitlab_access_token.$model"
@ -93,15 +88,17 @@ export default {
return { v$: useVuelidate({ $lazy: true }) } return { v$: useVuelidate({ $lazy: true }) }
}, },
data() { data() {
const allowedValues = ['gitlab_url', 'gitlab_project_id'] const allowedValues = [
if (!this.update) { 'gitlab_url',
allowedValues.push('gitlab_access_token') 'gitlab_project_id',
} 'gitlab_access_token',
]
return { return {
allowedValues, allowedValues,
values: { values: {
gitlab_url: 'https://gitlab.com', gitlab_url: 'https://gitlab.com',
gitlab_project_id: '', gitlab_project_id: '',
gitlab_access_token: this.update ? undefined : '',
}, },
} }
}, },
@ -125,7 +122,7 @@ export default {
required: helpers.withMessage( required: helpers.withMessage(
this.$t('error.requiredField'), this.$t('error.requiredField'),
requiredIf(() => { requiredIf(() => {
return this.allowedValues.includes('gitlab_access_token') return this.values.gitlab_access_token !== undefined
}) })
), ),
}, },

View file

@ -8,6 +8,8 @@
:helper-text="$t('hubspotContactsDataSync.accessTokenHelper')" :helper-text="$t('hubspotContactsDataSync.accessTokenHelper')"
:protected-edit="update" :protected-edit="update"
small-label small-label
@enabled-protected-edit="values.hubspot_access_token = ''"
@disable-protected-edit="values.hubspot_access_token = undefined"
> >
<FormInput <FormInput
v-model="v$.values.hubspot_access_token.$model" v-model="v$.values.hubspot_access_token.$model"
@ -49,7 +51,7 @@ export default {
return { return {
allowedValues: ['hubspot_access_token'], allowedValues: ['hubspot_access_token'],
values: { values: {
hubspot_access_token: '', hubspot_access_token: this.update ? undefined : '',
}, },
} }
}, },

View file

@ -49,13 +49,8 @@
small-label small-label
class="margin-bottom-2" class="margin-bottom-2"
:protected-edit="update" :protected-edit="update"
@enabled-protected-edit="allowedValues.push('jira_api_token')" @enabled-protected-edit="values.jira_api_token = ''"
@disable-protected-edit=" @disable-protected-edit="values.jira_api_token = undefined"
;[
allowedValues.splice(allowedValues.indexOf('jira_api_token'), 1),
delete values['jira_api_token'],
]
"
> >
<template #label>{{ $t('jiraIssuesDataSync.apiToken') }}</template> <template #label>{{ $t('jiraIssuesDataSync.apiToken') }}</template>
<FormInput <FormInput
@ -111,17 +106,19 @@ export default {
return { v$: useVuelidate({ $lazy: true }) } return { v$: useVuelidate({ $lazy: true }) }
}, },
data() { data() {
const allowedValues = ['jira_url', 'jira_username', 'jira_project_key'] const allowedValues = [
if (!this.update) { 'jira_url',
allowedValues.push('jira_api_token') 'jira_username',
} 'jira_project_key',
'jira_api_token',
]
return { return {
allowedValues, allowedValues,
values: { values: {
jira_url: '', jira_url: '',
jira_username: '', jira_username: '',
jira_project_key: '', jira_project_key: '',
jira_api_token: '', jira_api_token: this.update ? undefined : '',
}, },
} }
}, },
@ -145,7 +142,7 @@ export default {
required: helpers.withMessage( required: helpers.withMessage(
this.$t('error.requiredField'), this.$t('error.requiredField'),
requiredIf(() => { requiredIf(() => {
return this.allowedValues.includes('gitlab_access_token') return this.values.jira_api_token !== undefined
}) })
), ),
}, },

View file

@ -118,7 +118,13 @@ export default {
} }
}, },
async submitted(values) { async submitted(values) {
await this.update(this.table, values, this.syncTableValue) // Remove the `undefined` values, because those contain not updated secrets that
// are only meant to be included in the update request if they've changed
// because they're not exposed by the backend.
const valuesWithoutUndefined = Object.fromEntries(
Object.entries(values).filter(([_, v]) => v !== undefined)
)
await this.update(this.table, valuesWithoutUndefined, this.syncTableValue)
if (!this.syncTableValue) { if (!this.syncTableValue) {
this.completed = true this.completed = true
} }

View file

@ -35,13 +35,8 @@
small-label small-label
:protected-edit="update && field.protectedEdit" :protected-edit="update && field.protectedEdit"
class="margin-bottom-2" class="margin-bottom-2"
@enabled-protected-edit="allowedValues.push(field.name)" @enabled-protected-edit="values.postgresql_password = ''"
@disable-protected-edit=" @disable-protected-edit="values.postgresql_password = undefined"
;[
allowedValues.splice(allowedValues.indexOf(field.name), 1),
delete values[field.name],
]
"
> >
<template #label>{{ <template #label>{{
$t(`postgreSQLDataSync.${field.translationPrefix}`) $t(`postgreSQLDataSync.${field.translationPrefix}`)
@ -129,13 +124,11 @@ export default {
'postgresql_username', 'postgresql_username',
'postgresql_port', 'postgresql_port',
'postgresql_database', 'postgresql_database',
'postgresql_password',
'postgresql_schema', 'postgresql_schema',
'postgresql_table', 'postgresql_table',
'postgresql_sslmode', 'postgresql_sslmode',
] ]
if (!this.update) {
allowedValues.push('postgresql_password')
}
return { return {
allowedValues, allowedValues,
values: { values: {
@ -143,6 +136,9 @@ export default {
postgresql_username: '', postgresql_username: '',
postgresql_port: '5432', postgresql_port: '5432',
postgresql_database: '', postgresql_database: '',
// If `undefined`, it's not included in the patch update request, and will then
// not be changed.
postgresql_password: this.update ? undefined : '',
postgresql_schema: 'public', postgresql_schema: 'public',
postgresql_table: '', postgresql_table: '',
postgresql_sslmode: 'prefer', postgresql_sslmode: 'prefer',
@ -176,7 +172,7 @@ export default {
required: helpers.withMessage( required: helpers.withMessage(
this.$t('error.requiredField'), this.$t('error.requiredField'),
requiredIf(() => { requiredIf(() => {
return this.allowedValues.includes('postgresql_password') return this.values.postgresql_password !== undefined
}) })
), ),
}, },