Skip to content

Commit

Permalink
feat: permission sur l'édition et la suppression de versions
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Jun 21, 2024
1 parent 5677f04 commit d11abc7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
35 changes: 8 additions & 27 deletions src/components/records/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,30 @@ describe("RecordHeader", () => {
describe('Modifier la version', () => {
afterEach(() => userStore.$reset())

it("should print version name field to everybody", async () => {
it("should allow agri when OPERATOR_DRAFT", async () => {
userStore.isAgri = true
let wrapper = mount(AsyncComponent)
await wrapper.find('.edit-version-info').trigger('click')

const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#version_name').exists()).toBe(true)
})

it("should print audit date field only for Certification Body", async () => {
it("should only allow Certification Body after", async () => {
recordStore.update({ certification_state: 'AUDITED', audit_date: '2024-01-01' })
userStore.isOc = false
userStore.isOcCertif = false

let wrapper = mount(AsyncComponent)
await wrapper.find('.edit-version-info').trigger('click')

const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#audit_date').exists()).toBe(false)

userStore.isOc = true
userStore.isOcCertif = true
await flushPromises()
expect(modal.find('#audit_date').exists()).toBe(true)
})

it("should print certification date fields only for Certification Body", async () => {
recordStore.update({ certification_state: 'CERTIFIED', audit_date: '2024-01-01' })
userStore.isOc = false
userStore.isOcCertif = false

let wrapper = mount(AsyncComponent)
await wrapper.find('.edit-version-info').trigger('click')

const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#certification_date_debut').exists()).toBe(false)
expect(modal.find('#certification_date_fin').exists()).toBe(false)
expect(await wrapper.find('.edit-version-info').exists()).toBe(false)

userStore.isOc = true
userStore.isOcCertif = true
wrapper = mount(AsyncComponent)
await wrapper.find('.edit-version-info').trigger('click')
await flushPromises()
console.log(modal.html())
expect(modal.find('#certification_date_debut').exists()).toBe(true)
expect(modal.find('#certification_date_fin').exists()).toBe(true)
const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#audit_date').exists()).toBe(true)
})
})

Expand Down
4 changes: 3 additions & 1 deletion src/components/records/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span class="version-name">{{ record.version_name }}</span>

<button
v-if="!disableActions"
v-if="!disableActions && permissions.canEditVersion"
class="fr-btn fr-btn--tertiary-no-outline fr-icon fr-icon-edit-line edit-version-info"
@click="showEditVersionModal = true"
>
Expand Down Expand Up @@ -90,6 +90,7 @@ import { useOperatorStore } from "@/stores/operator.js"
import { useRecordStore } from "@/stores/record.js"
import { onClickOutside, useOnline } from "@vueuse/core"
import EditVersionModal from "@/components/forms/EditVersionForm.vue"
import { usePermissions } from "@/stores/permissions.js"
const AsyncFeaturesExportModal = defineAsyncComponent(() => import('@/components/records/ExportModal.vue'))
Expand All @@ -108,6 +109,7 @@ const deleteModal = ref(false)
const featuresStore = useFeaturesStore()
const operatorStore = useOperatorStore()
const recordStore = useRecordStore()
const permissions = usePermissions()
const { record } = recordStore
const { operator } = operatorStore
const { collection, hasFeatures } = storeToRefs(featuresStore)
Expand Down
15 changes: 13 additions & 2 deletions src/pages/exploitations/[numeroBio]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ meta:
<td>
<ActionDropdown with-icons :disabled="!isOnline">
<li>
<button type="button" @click.stop.prevent="editVersion(record.record_id)" class="fr-btn fr-btn--tertiary-no-outline fr-icon-edit-line fr-text--sm">
<button
v-if="permissions.isOc || record.certification_state === CertificationState.OPERATOR_DRAFT"
type="button"
@click.stop.prevent="editVersion(record.record_id)"
class="fr-btn fr-btn--tertiary-no-outline fr-icon-edit-line fr-text--sm"
>
Modifier les informations
</button>
</li>
Expand All @@ -171,7 +176,12 @@ meta:
</button>
</li>
<li>
<button type="button" @click.stop.prevent="deleteRecordModal = record.record_id" class="fr-btn fr-btn--tertiary-no-outline fr-icon-delete-line btn--error fr-text--sm">
<button
v-if="permissions.isOc || record.certification_state === CertificationState.OPERATOR_DRAFT"
type="button"
@click.stop.prevent="deleteRecordModal = record.record_id"
class="fr-btn fr-btn--tertiary-no-outline fr-icon-delete-line btn--error fr-text--sm"
>
Supprimer la version
</button>
</li>
Expand Down Expand Up @@ -221,6 +231,7 @@ import { useOnline } from "@vueuse/core"
import { useCartoBioStorage } from "@/stores/storage.js"
import Conflict from "@/components/versions/Conflict.vue"
import { inHa } from "@/utils/features.js"
import { CertificationState } from "@agencebio/cartobio-types"
const operatorStore = useOperatorStore()
const recordStore = useRecordStore()
Expand Down
2 changes: 2 additions & 0 deletions src/stores/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const usePermissions = defineStore('permissions', () => {
const canDeleteParcellaire = canEditParcellaire

const canCreateVersion = computed(() => isOc.value || isAgri.value)
const canEditVersion = computed(() => canEditParcellaire.value)

const canChangeCulture = canEditParcellaire
const canChangeGeometry = canEditParcellaire
Expand Down Expand Up @@ -72,6 +73,7 @@ export const usePermissions = defineStore('permissions', () => {
canDeleteParcellaire,
canEditParcellaire,
canCreateVersion,
canEditVersion,
canChangeCulture,
canChangeGeometry,
canAddParcelleNote,
Expand Down

0 comments on commit d11abc7

Please sign in to comment.