Skip to content

Commit

Permalink
Merge pull request #259 from AgenceBio/maud/login_agri
Browse files Browse the repository at this point in the history
Connexion agriculteur (v0)
  • Loading branch information
jillro authored Nov 14, 2023
2 parents bcd942e + e888ea5 commit 2b85b22
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 257 deletions.
9 changes: 9 additions & 0 deletions src/cartobio-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ export async function searchOperators (input) {
return data
}

/**
* @return {Promise<undefined>}
*/
export async function getUserOperators () {
const { data } = await cartobioApi.get(`/v2/operators`)

return data
}

/**
* @param {string} pacage
* @returns {Promise<FeatureCollection>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<div>
<Spinner v-if="isVerifying">Vérification des informations en cours</Spinner>

<Spinner v-else-if="(!isVerifying && isLogged && permissions.isOc)">Chargement de votre liste clients…</Spinner>
<Spinner v-else-if="(!isVerifying && isLogged && (permissions.isOc || permissions.isAgri))">Chargement de vos exploitations…</Spinner>

<div class="fr-connect-group" v-else-if="!isLogged">
<p>
L'accès à CartoBio s'effectue avec l'aide de votre compte Agence Bio&nbsp;:
</p>

<button class="fr-connect fr-connect--agence-bio" @click="router.push('/login/agencebio?mode=certification')">
<button class="fr-connect fr-connect--agence-bio" @click="router.push('/login/agencebio')">
<span class="fr-connect__login">S'identifier avec</span>
<span class="fr-connect__brand">Agence Bio</span>
</button>
Expand All @@ -26,8 +26,9 @@
<h3 class="fr-alert__title">Droits d'accès inadaptés</h3>
<p>
Votre connexion a correctement abouti.
Malheureusement nous ne sommes pas en mesure de vous identifier comme
étant une personne travaillant au sein d'une organisme de certification.
Malheureusement nous ne sommes pas en mesure de vous identifier comme un
operateur agricole ou une personne travaillant au sein d'une organisme
de certification.
</p>

<p>
Expand Down Expand Up @@ -79,6 +80,10 @@ onMounted(async () => {
router.replace('/login')
}
if (permissions.isAgri) {
router.replace('/exploitations')
}
if (permissions.isOc) {
router.replace(route.query.returnto || '/certification/exploitations')
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/MainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
<nav class="fr-nav" role="navigation" aria-label="Menu principal">
<ul class="fr-nav__list">
<li class="fr-nav__item">
<router-link to="/exploitation/parcellaire" class="fr-nav__link">
Mon parcellaire
<router-link to="/exploitations" class="fr-nav__link">
Mes exploitations
</router-link>
</li>
<li class="fr-nav__item">
Expand Down
74 changes: 74 additions & 0 deletions src/components/Operator/Exploitations.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<div>
<h2 class="fr-h3">
Sélectionner mon exploitation
</h2>

<section class="fr-grid-row fr-grid-row--gutters" v-if="hasOperators">
<article class="fr-col-12 fr-col-md-4" v-for="operator in operators" :key="operator.id">
<div class="fr-card fr-card--horizontal">
<div class="fr-card__body">
<div class="fr-card__content">
<h4 class="fr-card__title">{{ operator.nom }}</h4>
<div class="fr-card__desc">
<ul class="list-unstyled">
<li v-if="operator.commune"><strong>Siège</strong> : {{ operator.commune }} ({{ operator.departement }})</li>
<li v-if="operator.denominationCourante && operator.denominationCourante !== operator.nom"><b>Dénomination courante</b> : {{ operator.denominationCourante }}</li>
<li v-if="operator.siret"><b>SIRET</b> : {{ operator.siret }}</li>
<li v-if="operator.numeroPacage"><b>PACAGE</b> : {{ operator.numeroPacage }}</li>
<li><b>Numéro Bio</b> : {{ operator.numeroBio }}</li>
<li><b>Date d'engagement</b> : {{ operator.dateEngagement }}</li>
</ul>
</div>
<div class="fr-card__start">
<ul class="fr-tags-group">
<li>
<p class="fr-badge fr-badge--success fr-icon-medal-fill">vérifié</p>
</li>
</ul>
</div>
</div>

<div class="fr-card__footer">
<ul class="fr-btns-group fr-btns-group--inline-lg">
<li>
<router-link class="fr-btn" :to="`/exploitations/${operator.id}`">
Voir cette exploitation
</router-link>
</li>
</ul>
</div>
</div>
</div>
</article>
</section>
</div>
</template>

<script setup>
import { computed, ref } from 'vue'
import { getUserOperators } from "@/cartobio-api.js"
const operators = ref((await getUserOperators()).operators)
const hasOperators = computed(() => Boolean(operators.value.length))
</script>

<style scoped>
span[aria-selected="true"] {
font-weight: bold;
}
.help span:not(:last-of-type)::after {
content: ", ";
}
.list-unstyled {
--ul-type: none;
--ul-start: 0;
}
.fr-alert--waiting::before {
mask-image: url(@gouvfr/dsfr/icons/system/time-fill.svg);
}
</style>
161 changes: 0 additions & 161 deletions src/components/Operator/Login.vue

This file was deleted.

9 changes: 3 additions & 6 deletions src/components/OperatorSetup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

<script setup>
import { computed, provide, ref, toRaw, unref, watchEffect } from 'vue'
import { storeToRefs } from 'pinia'
import ImportPreview from '@/components/OperatorSetup/ImportPre.vue'
import { createOperatorRecord } from '@/cartobio-api.js'
import { now } from '@/components/dates.js'
import featureSources from '@/components/OperatorSetup/index.js'
import { useUserStore } from '@/stores/user.js'
import { useRecordStore } from "@/stores/index.js"
const emit = defineEmits(['source:change', 'import:start', 'import:preview', 'import:complete', 'import:error'])
Expand All @@ -47,8 +46,7 @@ provide('featureCollection', featureCollection)
provide('importWarnings', importWarnings)
provide('extraMetadata', extraMetadata)
const userStore = useUserStore()
const { user } = storeToRefs(userStore)
const { record } = useRecordStore()
const hasFeatureCollection = computed(() => featureCollection.value?.features)
const provenance = computed(() => window.location.host)
Expand All @@ -75,14 +73,13 @@ function handleCancel () {
}
async function handleUpload () {
const { id: operatorId, numeroBio, organismeCertificateur } = user.value
const { id: operatorId, numeroBio, organismeCertificateur } = record.operator
const { id: ocId, nom: ocLabel } = organismeCertificateur
const geojson = toRaw(featureCollection.value)
const source = toRaw(featureSource.value)
try {
// @todo ensure this comes from an operator store, and not a user store (userId != operatorId)
const record = await createOperatorRecord(operatorId, {
geojson,
ocId,
Expand Down
8 changes: 3 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import App from './App.vue'
import { version } from "../package.json"
import { usePermissions } from "@/stores/permissions.js"
import { getOperatorParcelles } from "@/cartobio-api.js"
import { ROLES } from "@/stores/user.js"

const { VUE_APP_MATOMO_SITE_ID:siteId = '245', VUE_APP_API_ENDPOINT } = import.meta.env
const { VUE_APP_SENTRY_DSN } = import.meta.env
Expand Down Expand Up @@ -118,17 +117,16 @@ router.isReady().then(() => {

router.beforeEach(async (to, from) => {

Check warning on line 118 in src/main.js

View workflow job for this annotation

GitHub Actions / tests

'from' is defined but never used

Check warning on line 118 in src/main.js

View workflow job for this annotation

GitHub Actions / tests

'from' is defined but never used

Check warning on line 118 in src/main.js

View workflow job for this annotation

GitHub Actions / deploy

'from' is defined but never used

Check warning on line 118 in src/main.js

View workflow job for this annotation

GitHub Actions / deploy

'from' is defined but never used
// Preload store for checking permissions
if (to.params.id || userStore.roles.includes(ROLES.OPERATEUR)) {
if (to.params.id) {
const recordStore = useRecordStore()
const record = await getOperatorParcelles(to.params.id || userStore.user.id)
const record = await getOperatorParcelles(to.params.id)
recordStore.replace(record)
}

if (to.path === '/login/agencebio') {
// forwards the user selected tab to the callback URI
// this way, we come back to the same tab
const qs = new URLSearchParams({ ...to.query, returnto: from.redirectedFrom?.fullPath ?? '/certification/exploitations' })
window.location = `${VUE_APP_API_ENDPOINT}/auth-provider/agencebio/login?${qs.toString()}`
window.location = `${VUE_APP_API_ENDPOINT}/auth-provider/agencebio/login`
return false
}

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions src/pages/exploitations/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<route lang="yaml">
meta:
requiredRoles: ['agri']
seo:
title: Mes exploitations
</route>

<template>
<div class="fr-container fr-my-5w">
<div class="fr-grid-row">
<div class="fr-col-12">
<Exploitations />
</div>
</div>
</div>
</template>

<script setup>
import Exploitations from '@/components/Operator/Exploitations.vue'
</script>
Loading

0 comments on commit 2b85b22

Please sign in to comment.