@tekkare/romulus 0.1.355 → 0.1.357
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/components/ProjectAddButton.vue +4 -1
- package/layer/app/components/panels/OipPanelProjects.vue +5 -2
- package/layer/app/components/project/AddButton.vue +4 -0
- package/layer/app/components/project/Guided.vue +20 -9
- package/layer/app/components/project/NewButton.vue +5 -3
- package/layer/app/composables/useOipLicences.ts +49 -0
- package/layer/app/oip-defaults/projects.ts +22 -1
- package/layer/app/utils/oipLicences.ts +120 -0
- package/layer/server/api/oip/me/licences.get.ts +32 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -44,6 +44,8 @@ const props = withDefaults(
|
|
|
44
44
|
creating?: boolean
|
|
45
45
|
/** La fiche est archivee dans ce projet (v-model:archived). */
|
|
46
46
|
archived?: boolean
|
|
47
|
+
/** Faux : pas de formulaire « nouveau projet » (licence sans droit de creer). */
|
|
48
|
+
canCreate?: boolean
|
|
47
49
|
lang?: 'fr' | 'en'
|
|
48
50
|
}>(),
|
|
49
51
|
{
|
|
@@ -58,6 +60,7 @@ const props = withDefaults(
|
|
|
58
60
|
projectsLoading: false,
|
|
59
61
|
projectsFailed: false,
|
|
60
62
|
creating: false,
|
|
63
|
+
canCreate: true,
|
|
61
64
|
archived: false,
|
|
62
65
|
lang: 'fr',
|
|
63
66
|
},
|
|
@@ -212,7 +215,7 @@ function create() {
|
|
|
212
215
|
</button>
|
|
213
216
|
<p v-if="!projects.length" class="rm-project-add__muted">{{ T.none }}</p>
|
|
214
217
|
</template>
|
|
215
|
-
<form class="rm-project-add__create" @submit.prevent="create">
|
|
218
|
+
<form v-if="canCreate" class="rm-project-add__create" @submit.prevent="create">
|
|
216
219
|
<RmInput v-model="draft" :placeholder="T.newName" />
|
|
217
220
|
<RmButton type="submit" variant="primary" size="sm" :loading="creating">{{ T.create }}</RmButton>
|
|
218
221
|
</form>
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
@pin="pin"
|
|
35
35
|
@create="onCreate"
|
|
36
36
|
>
|
|
37
|
-
|
|
37
|
+
<!-- Sans droit de creer (licence) : pas de « Nouveau projet ». -->
|
|
38
|
+
<template v-if="!canCreate" #new><span /></template>
|
|
39
|
+
<template v-else-if="button" #new="{ openForm }">
|
|
38
40
|
<!-- Branche sur le layer : les memes gestes que « Mes projets » (creation
|
|
39
41
|
libre dans la meme fenetre, nom et description, ou creation guidee). -->
|
|
40
42
|
<component :is="button" size="sm" @free="own ? (dialogOpen = true) : openForm()" />
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
import type { Component } from "vue";
|
|
56
58
|
import ProjectNewButton from "../project/NewButton.vue";
|
|
57
59
|
import type { RmProject } from "@tekkare/romulus/utils/projects";
|
|
58
|
-
import { PROJECTS_PATH, PROJECTS_UPSELL, useProjectsAccess } from "#oip-projects";
|
|
60
|
+
import { PROJECTS_PATH, PROJECTS_UPSELL, useProjectsAccess, useProjectsCreateAccess } from "#oip-projects";
|
|
59
61
|
|
|
60
62
|
const props = withDefaults(
|
|
61
63
|
defineProps<{
|
|
@@ -110,6 +112,7 @@ const creating = ref(false);
|
|
|
110
112
|
const wired = props.projects === undefined;
|
|
111
113
|
const own = wired ? useProjects() : null;
|
|
112
114
|
const allowed = useProjectsAccess();
|
|
115
|
+
const canCreate = useProjectsCreateAccess();
|
|
113
116
|
// Importe, pas resolu par son nom : un composant du layer n'est pas enregistre
|
|
114
117
|
// globalement, `resolveComponent` rendait une chaine et le panneau retombait
|
|
115
118
|
// sur son seul formulaire du nom.
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
:projects-loading="projects.pending.value"
|
|
21
21
|
:projects-failed="!!projects.failure.value"
|
|
22
22
|
:creating="creating"
|
|
23
|
+
:can-create="canCreate"
|
|
23
24
|
:lang="projects.lang.value"
|
|
24
25
|
@toggle="toggle"
|
|
25
26
|
@pick="projects.load()"
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
|
|
32
33
|
<script setup lang="ts">
|
|
33
34
|
import type { ProjectResourceId } from "../../composables/useProjects";
|
|
35
|
+
import { useProjectsCreateAccess } from "#oip-projects";
|
|
34
36
|
|
|
35
37
|
const props = defineProps<{
|
|
36
38
|
/** `_id` Elasticsearch du document, cf. useOipProjectKinds. Une liste quand la carte en porte plusieurs. */
|
|
@@ -47,6 +49,8 @@ const projects = useProjects();
|
|
|
47
49
|
|
|
48
50
|
const busy = ref(false);
|
|
49
51
|
const creating = ref(false);
|
|
52
|
+
/** Sans droit de creer (licence) : on range dans un projet existant, sans en creer. */
|
|
53
|
+
const canCreate = useProjectsCreateAccess();
|
|
50
54
|
const archived = ref(false);
|
|
51
55
|
const error = ref("");
|
|
52
56
|
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
{{ tr("Tous", "All") }}
|
|
133
133
|
</button>
|
|
134
134
|
<button
|
|
135
|
-
v-for="entry in
|
|
135
|
+
v-for="entry in allowedCountries"
|
|
136
136
|
:key="entry.code"
|
|
137
137
|
type="button"
|
|
138
138
|
class="prj_gd_country"
|
|
@@ -418,7 +418,7 @@
|
|
|
418
418
|
|
|
419
419
|
<script setup lang="ts">
|
|
420
420
|
import { rmPanelRegister } from "@tekkare/romulus/utils/panels";
|
|
421
|
-
import { PROJECT_GUIDED_BLOCKS } from "#oip-projects";
|
|
421
|
+
import { PROJECT_GUIDED_BLOCKS, useGuidedCountries } from "#oip-projects";
|
|
422
422
|
import {
|
|
423
423
|
GUIDED_BLOCKS,
|
|
424
424
|
GUIDED_COUNTRIES,
|
|
@@ -463,14 +463,25 @@ const KIND_META: Record<GuidedMatchKind, { label: { fr: string; en: string }; he
|
|
|
463
463
|
/** Les blocs que l'app propose (`PROJECT_GUIDED_BLOCKS`), dans l'ordre du layer. */
|
|
464
464
|
const blocks = computed<GuidedBlock[]>(() => GUIDED_BLOCKS.filter((block) => (PROJECT_GUIDED_BLOCKS ?? []).includes(block.key)));
|
|
465
465
|
|
|
466
|
-
/** Les pays
|
|
466
|
+
/** Les pays que la licence ouvre ; `null` : tous. */
|
|
467
|
+
const licensed = useGuidedCountries();
|
|
468
|
+
/** Les pays proposes : ceux de la creation guidee que la licence ouvre. */
|
|
469
|
+
const allowedCountries = computed(() =>
|
|
470
|
+
GUIDED_COUNTRIES.filter((entry) => !licensed.value || licensed.value.includes(entry.code)),
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
/** Les pays choisis a l'etape des sujets ; vide : tous ceux de la licence. */
|
|
467
474
|
const countries = ref<GuidedCountry[]>([]);
|
|
475
|
+
/** Les pays effectivement cherches : le choix, sinon tous ceux de la licence. */
|
|
476
|
+
const searchedCountries = computed<GuidedCountry[]>(() =>
|
|
477
|
+
countries.value.length ? countries.value : licensed.value ? allowedCountries.value.map((entry) => entry.code) : [],
|
|
478
|
+
);
|
|
468
479
|
function toggleCountry(code: GuidedCountry) {
|
|
469
480
|
countries.value = countries.value.includes(code) ? countries.value.filter((entry) => entry !== code) : [...countries.value, code];
|
|
470
481
|
}
|
|
471
|
-
const inCountries = (type: string) => !
|
|
482
|
+
const inCountries = (type: string) => !searchedCountries.value.length || searchedCountries.value.includes(guidedFamilyCountry(type));
|
|
472
483
|
/** Plusieurs pays en jeu : le libelle d'une famille d'un autre pays que la France le dit. */
|
|
473
|
-
const manyCountries = computed(() =>
|
|
484
|
+
const manyCountries = computed(() => searchedCountries.value.length !== 1);
|
|
474
485
|
|
|
475
486
|
const step = ref<Step>("subjects");
|
|
476
487
|
const stepIndex = computed(() => STEPS.findIndex((entry) => entry.key === step.value));
|
|
@@ -593,7 +604,7 @@ const sortedTypes = (block: GuidedBlock) =>
|
|
|
593
604
|
const countLabel = (count: number) => (count ? tr(`${count} fiches`, `${count} records`) : tr("rien trouvé", "nothing found"));
|
|
594
605
|
|
|
595
606
|
function startSearch() {
|
|
596
|
-
const key = [...subjects.value.map((subject) => subject.key).sort(), ...[...
|
|
607
|
+
const key = [...subjects.value.map((subject) => subject.key).sort(), ...[...searchedCountries.value].sort()].join("|");
|
|
597
608
|
if (key === searchedKey) return;
|
|
598
609
|
searchedKey = key;
|
|
599
610
|
states.value = {};
|
|
@@ -605,7 +616,7 @@ function startSearch() {
|
|
|
605
616
|
states.value = { ...states.value, [type]: state };
|
|
606
617
|
// Une famille qui repond se coche si elle a des fiches, sauf choix deja fait.
|
|
607
618
|
if (!state.loading && families[type] === undefined) families[type] = state.rows.length > 0;
|
|
608
|
-
}, [...
|
|
619
|
+
}, [...searchedCountries.value]).finally(() => {
|
|
609
620
|
if (searchedKey === mine) searching.value = false;
|
|
610
621
|
});
|
|
611
622
|
}
|
|
@@ -674,8 +685,8 @@ function propose() {
|
|
|
674
685
|
? `${tr("Médicaments", "Drugs")}${sep}${drugs.map((subject) => withHint(subject.label, subject.focus === "brand" ? subject.hint.toLowerCase() : subject.hint, subject.focus === "molecule")).join(", ")}.`
|
|
675
686
|
: "",
|
|
676
687
|
`${tr("Périmètre", "Scope")}${sep}${
|
|
677
|
-
|
|
678
|
-
?
|
|
688
|
+
searchedCountries.value.length
|
|
689
|
+
? searchedCountries.value.map((code) => GUIDED_COUNTRIES.find((entry) => entry.code === code)?.label[lang.value]).join(", ")
|
|
679
690
|
: tr("tous les pays", "all countries")
|
|
680
691
|
}.`,
|
|
681
692
|
followed.length ? `${tr("Sources suivies", "Followed sources")}${sep}${followed.join(", ")}.` : "",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
page « Mes projets », pour que les deux proposent les memes choix.
|
|
12
12
|
-->
|
|
13
13
|
<template>
|
|
14
|
-
<span ref="anchor" class="prj_pnb">
|
|
14
|
+
<span v-if="canCreate" ref="anchor" class="prj_pnb">
|
|
15
15
|
<RmButton
|
|
16
16
|
variant="primary"
|
|
17
17
|
:size="size"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
</span>
|
|
25
25
|
|
|
26
26
|
<RmPopover
|
|
27
|
-
v-if="guided"
|
|
27
|
+
v-if="guided && canCreate"
|
|
28
28
|
v-model="choosing"
|
|
29
29
|
:anchor="anchor"
|
|
30
30
|
:label="en ? 'New project' : 'Nouveau projet'"
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</template>
|
|
62
62
|
|
|
63
63
|
<script setup lang="ts">
|
|
64
|
-
import { PROJECT_ASSISTANT, PROJECT_GUIDED_BLOCKS } from "#oip-projects";
|
|
64
|
+
import { PROJECT_ASSISTANT, PROJECT_GUIDED_BLOCKS, useProjectsCreateAccess } from "#oip-projects";
|
|
65
65
|
import { defineAsyncComponent } from "vue";
|
|
66
66
|
|
|
67
67
|
withDefaults(
|
|
@@ -85,6 +85,8 @@ const guided = PROJECT_GUIDED_BLOCKS?.length ? defineAsyncComponent(() => import
|
|
|
85
85
|
const anchor = ref<HTMLElement | null>(null);
|
|
86
86
|
const choosing = ref(false);
|
|
87
87
|
const guiding = ref(false);
|
|
88
|
+
/** Sans droit de creer (licence), le bouton ne s'affiche pas. */
|
|
89
|
+
const canCreate = useProjectsCreateAccess();
|
|
88
90
|
|
|
89
91
|
function startFree() {
|
|
90
92
|
choosing.value = false;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
oipCanCreateProjects,
|
|
3
|
+
oipHealthcareScopes,
|
|
4
|
+
oipLicensedCountries,
|
|
5
|
+
type OipLicence,
|
|
6
|
+
type OipLicenceAccess,
|
|
7
|
+
} from "../utils/oipLicences";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Les licences du lecteur et ce qu'elles lui ouvrent, les memes dans toutes
|
|
11
|
+
* les apps (cf. utils/oipLicences). Lues une fois par session sur
|
|
12
|
+
* `/api/oip/me/licences` (route du layer), partagees par `useState`.
|
|
13
|
+
*
|
|
14
|
+
* Tant qu'elles ne sont pas lues, rien n'est ferme : pas de bouton qui
|
|
15
|
+
* apparait puis disparait pour le cas courant, et une lecture qui echoue ne
|
|
16
|
+
* coupe pas les projets (la Virtual Lab API refuse elle-meme ce qui doit
|
|
17
|
+
* l'etre).
|
|
18
|
+
*/
|
|
19
|
+
export function useOipLicences() {
|
|
20
|
+
const state = useState<{ admin: boolean; licences: OipLicence[] } | null>("oip:licences", () => null);
|
|
21
|
+
const pending = useState<boolean>("oip:licences:pending", () => false);
|
|
22
|
+
const { status } = useAuth();
|
|
23
|
+
|
|
24
|
+
if (import.meta.client && state.value === null && !pending.value && status.value === "authenticated") {
|
|
25
|
+
pending.value = true;
|
|
26
|
+
$fetch<{ isPlatformAdmin: boolean; licences: OipLicence[] }>("/api/oip/me/licences")
|
|
27
|
+
.then((response) => {
|
|
28
|
+
state.value = { admin: response?.isPlatformAdmin === true, licences: response?.licences ?? [] };
|
|
29
|
+
})
|
|
30
|
+
.catch(() => {})
|
|
31
|
+
.finally(() => {
|
|
32
|
+
pending.value = false;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const loaded = computed(() => state.value !== null);
|
|
37
|
+
const access = computed<OipLicenceAccess>(() => ({
|
|
38
|
+
admin: state.value?.admin ?? false,
|
|
39
|
+
scopes: oipHealthcareScopes(state.value?.licences ?? []),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
/** Creer un projet (France ou Global Healthcare). Vrai tant que les licences ne sont pas lues. */
|
|
43
|
+
const canCreateProjects = computed(() => !loaded.value || oipCanCreateProjects(access.value));
|
|
44
|
+
|
|
45
|
+
/** Les pays ouverts (codes ISO) ; `null` : tous, ou licences pas encore lues. */
|
|
46
|
+
const countries = computed(() => (loaded.value ? oipLicensedCountries(access.value) : null));
|
|
47
|
+
|
|
48
|
+
return { loaded, access, canCreateProjects, countries };
|
|
49
|
+
}
|
|
@@ -19,7 +19,8 @@ import type { RmExportSheet } from "@tekkare/romulus/utils/export";
|
|
|
19
19
|
import type { RmDashboardModel, RmDashboardWidget, RmWidgetContext, RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
20
20
|
import { rmAddableWidgets, rmNewWidgetId } from "@tekkare/romulus/utils/dashboard";
|
|
21
21
|
import type { ProjectInboxItem, ProjectSuggestion } from "../types/projects";
|
|
22
|
-
import type { GuidedBlockKey } from "../oip-guided/families";
|
|
22
|
+
import type { GuidedBlockKey, GuidedCountry } from "../oip-guided/families";
|
|
23
|
+
import { useOipLicences } from "../composables/useOipLicences";
|
|
23
24
|
import { oipProjectBrands } from "../oip-drugs/dashboardWidgets";
|
|
24
25
|
|
|
25
26
|
type Lang = "fr" | "en";
|
|
@@ -57,6 +58,26 @@ export function useProjectsAccess(): Ref<boolean> | ComputedRef<boolean> {
|
|
|
57
58
|
return computed(() => true);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/**
|
|
62
|
+
* L'utilisateur peut-il creer un projet ? Par defaut, la lecture des licences
|
|
63
|
+
* commune a toutes les apps (useOipLicences) : France ou Global Healthcare.
|
|
64
|
+
* Faux : pas de « Nouveau projet », ni dans la page, ni dans le rail, ni dans
|
|
65
|
+
* le bouton Projet d'une carte ; les projets partages restent lisibles.
|
|
66
|
+
*/
|
|
67
|
+
export function useProjectsCreateAccess(): Ref<boolean> | ComputedRef<boolean> {
|
|
68
|
+
return useOipLicences().canCreateProjects;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Les pays que la creation guidee propose et cherche. Par defaut, ceux des
|
|
73
|
+
* licences Healthcare du lecteur (useOipLicences) ; `null` : tous ceux que la
|
|
74
|
+
* creation guidee connait (Global Healthcare, admin plateforme).
|
|
75
|
+
*/
|
|
76
|
+
export function useGuidedCountries(): Ref<GuidedCountry[] | null> | ComputedRef<GuidedCountry[] | null> {
|
|
77
|
+
const { countries } = useOipLicences();
|
|
78
|
+
return computed(() => (countries.value ? (countries.value as GuidedCountry[]) : null));
|
|
79
|
+
}
|
|
80
|
+
|
|
60
81
|
/** Ce qui remplace les projets sans acces, avec la prop `feature` ({ fr, en }). */
|
|
61
82
|
export const PROJECTS_UPSELL: Component | null = null;
|
|
62
83
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* La lecture des licences, la meme dans toutes les apps OIP.
|
|
3
|
+
*
|
|
4
|
+
* Une licence est lue par son produit (slug, nom, categorie), telle que la
|
|
5
|
+
* Virtual Lab API la rend sur `/me/summary`. Seul le produit Healthcare se
|
|
6
|
+
* vend par pays, et son nom le dit : « France OIP Healthcare »
|
|
7
|
+
* (`france-oip-healthcare`) ouvre la France, « Global OIP Healthcare »
|
|
8
|
+
* (`global-oip-healthcare`), sans pays, les ouvre tous. Aucun autre produit
|
|
9
|
+
* n'ouvre de pays, quel que soit son nom : « France RLD » ou « France
|
|
10
|
+
* Sunshine Act » sont des applications thematiques, pas la France (meme
|
|
11
|
+
* regle que les cadenas du hub d'OIP 7, cf. son utils/menuAccess).
|
|
12
|
+
*
|
|
13
|
+
* Pur : sert au client (useOipLicences) comme a une app qui veut la meme
|
|
14
|
+
* regle ailleurs (`@tekkare/romulus/layer-utils/oipLicences`).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Une licence telle que `/me/summary` la rend ; les champs varient selon l'endpoint. */
|
|
18
|
+
export interface OipLicence {
|
|
19
|
+
productSlug?: string;
|
|
20
|
+
productName?: string;
|
|
21
|
+
product?: string | { slug?: string; name?: string; category?: string };
|
|
22
|
+
category?: string;
|
|
23
|
+
status?: string;
|
|
24
|
+
expiresAt?: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Une licence en cours : active, et sans fin ou pas encore echue. */
|
|
28
|
+
export function oipLicenceUsable(licence: OipLicence): boolean {
|
|
29
|
+
if (licence?.status && licence.status !== "active") return false;
|
|
30
|
+
if (!licence?.expiresAt) return true;
|
|
31
|
+
return new Date(licence.expiresAt) > new Date();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Le produit d'une licence en mots minuscules separes d'un espace (« france oip healthcare »). */
|
|
35
|
+
export function oipLicenceText(licence: OipLicence): string {
|
|
36
|
+
const product = licence?.product;
|
|
37
|
+
return [
|
|
38
|
+
typeof product === "string" ? product : product?.slug,
|
|
39
|
+
typeof product === "object" ? product?.name : undefined,
|
|
40
|
+
licence?.productSlug,
|
|
41
|
+
licence?.productName,
|
|
42
|
+
]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.join(" ")
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.normalize("NFD")
|
|
47
|
+
.replace(/[̀-ͯ]/g, "")
|
|
48
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
49
|
+
.trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Les mots d'un pays dans un nom de produit, et son code ISO alpha-2. */
|
|
53
|
+
export const OIP_LICENCE_COUNTRY_WORDS: Record<string, string> = {
|
|
54
|
+
france: "fr",
|
|
55
|
+
italy: "it",
|
|
56
|
+
italie: "it",
|
|
57
|
+
germany: "de",
|
|
58
|
+
allemagne: "de",
|
|
59
|
+
spain: "es",
|
|
60
|
+
espagne: "es",
|
|
61
|
+
australia: "au",
|
|
62
|
+
australie: "au",
|
|
63
|
+
"new zealand": "nz",
|
|
64
|
+
"nouvelle zelande": "nz",
|
|
65
|
+
"united kingdom": "gb",
|
|
66
|
+
uk: "gb",
|
|
67
|
+
japan: "jp",
|
|
68
|
+
japon: "jp",
|
|
69
|
+
"south korea": "kr",
|
|
70
|
+
korea: "kr",
|
|
71
|
+
canada: "ca",
|
|
72
|
+
brazil: "br",
|
|
73
|
+
"united states": "us",
|
|
74
|
+
usa: "us",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Ce qu'une licence Healthcare ouvre : des pays (codes ISO), ou tous. */
|
|
78
|
+
export interface OipHealthcareScope {
|
|
79
|
+
global: boolean;
|
|
80
|
+
countries: string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Les licences Healthcare en cours, et les pays que chacune ouvre. */
|
|
84
|
+
export function oipHealthcareScopes(licences: OipLicence[]): OipHealthcareScope[] {
|
|
85
|
+
const scopes: OipHealthcareScope[] = [];
|
|
86
|
+
for (const licence of licences ?? []) {
|
|
87
|
+
if (!oipLicenceUsable(licence)) continue;
|
|
88
|
+
const text = ` ${oipLicenceText(licence)} `;
|
|
89
|
+
// Mot entier : « healthcareplus » n'est pas Healthcare.
|
|
90
|
+
if (!text.includes(" healthcare ")) continue;
|
|
91
|
+
const countries = [...new Set(Object.entries(OIP_LICENCE_COUNTRY_WORDS).filter(([word]) => text.includes(` ${word} `)).map(([, code]) => code))];
|
|
92
|
+
scopes.push({ global: !countries.length, countries });
|
|
93
|
+
}
|
|
94
|
+
return scopes;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Ce que les licences d'un lecteur lui ouvrent, cote projets. */
|
|
98
|
+
export interface OipLicenceAccess {
|
|
99
|
+
/** Admin plateforme (adresse @tekkare.com) : tout est ouvert. */
|
|
100
|
+
admin: boolean;
|
|
101
|
+
scopes: OipHealthcareScope[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creer un projet demande France ou Global Healthcare : un workspace qui n'a
|
|
106
|
+
* que des produits thematiques (RealLifeData, Sunshine Act) lit les projets
|
|
107
|
+
* partages sans en creer.
|
|
108
|
+
*/
|
|
109
|
+
export function oipCanCreateProjects(access: OipLicenceAccess): boolean {
|
|
110
|
+
return access.admin || access.scopes.some((scope) => scope.global || scope.countries.includes("fr"));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Les pays qu'une recherche peut couvrir : `null` pour tous (admin, Global
|
|
115
|
+
* Healthcare), sinon ceux que nomment les licences Healthcare.
|
|
116
|
+
*/
|
|
117
|
+
export function oipLicensedCountries(access: OipLicenceAccess): string[] | null {
|
|
118
|
+
if (access.admin || access.scopes.some((scope) => scope.global)) return null;
|
|
119
|
+
return [...new Set(access.scopes.flatMap((scope) => scope.countries))];
|
|
120
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createError, defineEventHandler } from "h3";
|
|
2
|
+
import { requireOipSession } from "../../../utils/oipAuth";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GET /api/oip/me/licences, servi par le layer OIP : les licences du lecteur
|
|
6
|
+
* et s'il est admin plateforme, lues sur `/me/summary` de la Virtual Lab API
|
|
7
|
+
* avec son propre jeton. Le client en tire ce qu'elles ouvrent
|
|
8
|
+
* (utils/oipLicences), la meme regle dans toutes les apps. Ne rend que ce
|
|
9
|
+
* qu'il faut a cette lecture : produit, statut, echeance.
|
|
10
|
+
*/
|
|
11
|
+
export default defineEventHandler(async (event) => {
|
|
12
|
+
const token = await requireOipSession(event);
|
|
13
|
+
const base = String(useRuntimeConfig().public.apiBase || "").replace(/\/$/, "");
|
|
14
|
+
let summary: any;
|
|
15
|
+
try {
|
|
16
|
+
summary = await $fetch(`${base}/me/summary`, { headers: { Authorization: `Bearer ${token}` } });
|
|
17
|
+
} catch (error: any) {
|
|
18
|
+
throw createError({ status: error?.response?.status === 401 ? 401 : 502, message: "Licences unavailable" });
|
|
19
|
+
}
|
|
20
|
+
const licences = (summary?.licenses ?? []).map((licence: any) => ({
|
|
21
|
+
productSlug: licence?.productSlug,
|
|
22
|
+
productName: licence?.productName,
|
|
23
|
+
product:
|
|
24
|
+
typeof licence?.product === "string"
|
|
25
|
+
? licence.product
|
|
26
|
+
: { slug: licence?.product?.slug, name: licence?.product?.name, category: licence?.product?.category },
|
|
27
|
+
category: licence?.category,
|
|
28
|
+
status: licence?.status,
|
|
29
|
+
expiresAt: licence?.expiresAt ?? null,
|
|
30
|
+
}));
|
|
31
|
+
return { isPlatformAdmin: summary?.user?.isPlatformAdmin === true, licences };
|
|
32
|
+
});
|