Skip to content

Commit

Permalink
refactor: disable allowing a user to set a receipt as private (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Apr 3, 2024
1 parent 61989ad commit a0e2490
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 42 deletions.
5 changes: 4 additions & 1 deletion src/components/ProofActionMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-icon>mdi-dots-vertical</v-icon>
<v-menu activator="parent" scroll-strategy="close" transition="slide-y-transition">
<v-list>
<v-list-item :slim="true" prepend-icon="mdi-pencil" @click="openEditDialog" :disabled="!proofIsReceipt">{{ $t('Common.Edit') }}</v-list-item>
<v-list-item v-if="proofIsPrivateReceipt" :slim="true" prepend-icon="mdi-pencil" @click="openEditDialog" :disabled="!proofIsReceipt">{{ $t('Common.Edit') }}</v-list-item>
<v-list-item :slim="true" prepend-icon="mdi-delete" @click="openDeleteConfirmationDialog" :disabled="!userCanDeleteProof">{{ $t('Common.Delete') }}</v-list-item>
</v-list>
</v-menu>
Expand Down Expand Up @@ -65,6 +65,9 @@ export default {
proofIsReceipt() {
return this.proof.type === 'RECEIPT'
},
proofIsPrivateReceipt() {
return this.proofIsReceipt && !this.proof.is_public
},
userCanDeleteProof() {
// user must be proof owner
// and proof must not have any prices
Expand Down
8 changes: 4 additions & 4 deletions src/components/ProofEditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<v-divider></v-divider>

<v-card-text v-if="proof.type === 'RECEIPT'">
<v-card-text v-if="proofIsReceipt">
<h3>{{ $t('ProofDetail.Privacy') }}</h3>
<v-switch
v-model="isPublic"
Expand All @@ -17,9 +17,6 @@
:label="isPublic ? $t('ProofDetail.Public') : $t('ProofDetail.Private')"
hide-details
></v-switch>
<p class="text-caption text-warning">
<i>{{ $t('ProofEdit.PrivateWarning') }}</i>
</p>
</v-card-text>

<v-divider></v-divider>
Expand Down Expand Up @@ -51,6 +48,9 @@ export default {
},
emits: ['update', 'close'],
computed: {
proofIsReceipt() {
return this.proof.type === 'RECEIPT'
},
},
mounted() {
this.isPublic = this.proof.is_public
Expand Down
8 changes: 7 additions & 1 deletion src/components/ProofFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<v-row>
<v-col :cols="userIsProofOwner ? '11' : '12'">
<ProofTypeChip class="mr-1" :proof="proof"></ProofTypeChip>
<ProofPrivateChip v-if="proof.type === 'RECEIPT'" class="mr-1" :proof="proof"></ProofPrivateChip>
<ProofPrivateChip v-if="proofIsPrivateReceipt" class="mr-1" :proof="proof"></ProofPrivateChip>
<PriceCountChip :count="proof.price_count" :withLabel="true" @click="goToProof()"></PriceCountChip>
<RelativeDateTimeChip :dateTime="proof.created"></RelativeDateTimeChip>
</v-col>
Expand Down Expand Up @@ -42,6 +42,12 @@ export default {
},
userIsProofOwner() {
return this.username && (this.proof.owner === this.username)
},
proofIsReceipt() {
return this.proof.type === 'RECEIPT'
},
proofIsPrivateReceipt() {
return this.proofIsReceipt && !this.proof.is_public
}
},
methods: {
Expand Down
1 change: 0 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@
},
"ProofEdit": {
"Title": "Edit a proof",
"PrivateWarning": "When setting your proof to Private, it will be hidden from public view. We recommend hiding any personal information by redacting or folding the document, if possible.",
"Save": "Save",
"Success": "Proof edited!"
},
Expand Down
35 changes: 0 additions & 35 deletions src/views/AddPriceMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,7 @@
<h3 class="mb-1">{{ $t('ProofDetail.Privacy') }}</h3>
<p class="text-caption text-warning">
<i>{{ $t('AddPriceMultiple.ProofDetails.ReceiptWarning') }}</i>
<i>{{ $t('AddPriceMultiple.ProofDetails.PrivateWarning') }}</i>
</p>
<div v-if="proofFormFilled">
<v-switch
v-model="proofIsPublic"
density="compact"
color="green"
inset
hide-details
@change="updateIsPublicProof">
<template v-slot:label>
<v-icon start size="small" :icon="proofIsPublic ? 'mdi-lock-open-check' : 'mdi-lock-alert'" :color="proofIsPublic ? 'green' : 'red'"></v-icon>
<span :class="proofIsPublic ? 'text-green' : 'text-red'">
{{ proofIsPublic ? $t('ProofDetail.Public') : $t('ProofDetail.Private') }}
</span>
</template>
</v-switch>
</div>
</v-col>
</v-row>
</v-card-text>
Expand Down Expand Up @@ -376,7 +359,6 @@ export default {
userRecentProofsDialog: false,
proofSelectedSuccessMessage: false,
proofisSelected: false,
proofIsPublic: true,
// location data
locationSelector: false,
locationSelectedDisplayName: '',
Expand Down Expand Up @@ -490,7 +472,6 @@ export default {
this.proofImagePreview = this.getProofUrl(selectedProof)
this.proofSelectedSuccessMessage = true
this.proofisSelected = true
this.proofIsPublic = selectedProof.is_public
},
getProofUrl(proof) {
return 'https://prices.openfoodfacts.org/img/0002/qU59gK8PQw.webp'
Expand Down Expand Up @@ -528,7 +509,6 @@ export default {
const store = useAppStore()
store.addProof(data)
this.addPriceMultipleForm.proof_id = data['id']
this.proofIsPublic = data['is_public']
this.proofImagePreview = URL.createObjectURL(proofImageCompressed)
this.proofSuccessMessage = true
} else {
Expand All @@ -550,21 +530,6 @@ export default {
// console.log('Compress complete')
// })
},
updateIsPublicProof() {
const params = {
is_public: this.proofIsPublic
}
api
.updateProof(this.addPriceMultipleForm.proof_id, params)
.then((response) => {
// if response.status == 204
const store = useAppStore()
store.updateProof(this.addPriceMultipleForm.proof_id, params)
})
.catch((error) => {
console.log(error)
})
},
clearProof() {
this.proofImage = null
this.proofImagePreview = null
Expand Down

0 comments on commit a0e2490

Please sign in to comment.