@tekkare/romulus 0.1.316 → 0.1.317
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/layer/app/components/OipShell.vue +18 -3
- package/layer/app/composables/useOipAdminAccess.ts +37 -0
- package/layer/app/utils/oipRail.ts +8 -2
- package/layer/server/api/oip/admin-access.get.ts +9 -0
- package/layer/server/api/oip/metadata.get.ts +3 -3
- package/layer/server/api/oip/metadata.patch.ts +2 -2
- package/layer/server/api/oip/note-options.get.ts +2 -2
- package/layer/server/api/oip/note.get.ts +2 -2
- package/layer/server/api/oip/notes.patch.ts +2 -2
- package/layer/server/api/oip/sources.patch.ts +5 -4
- package/layer/server/api/oip/stats.get.ts +1 -1
- package/layer/server/utils/oipGuards.ts +40 -13
- package/layer/server/utils/oipPosthog.ts +2 -2
- package/layer/server/utils/oipWorkspaces.ts +2 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -85,7 +85,11 @@ const props = withDefaults(
|
|
|
85
85
|
* sort grisee. Objet vide : le rail ne propose rien (rapports, artefacts).
|
|
86
86
|
*/
|
|
87
87
|
tiles?: OipRailTileStates;
|
|
88
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Sert les tuiles reservees aux superadmins (metadonnees, templates). Le
|
|
90
|
+
* shell les ouvre aussi de lui-meme a qui est superadmin ou product
|
|
91
|
+
* manager (useOipAdminAccess), sans attendre l'app.
|
|
92
|
+
*/
|
|
89
93
|
superAdmin?: boolean;
|
|
90
94
|
/** Utilisateur connecte, pour le profil en haut du rail. */
|
|
91
95
|
userName?: string;
|
|
@@ -337,9 +341,20 @@ onMounted(() => {
|
|
|
337
341
|
});
|
|
338
342
|
onBeforeUnmount(() => window.removeEventListener("focus", refreshInbox));
|
|
339
343
|
|
|
344
|
+
// Droits admin lus par le layer : un product manager voit l'outillage admin
|
|
345
|
+
// sans que chaque app ait a le brancher.
|
|
346
|
+
const adminAccess = useOipAdminAccess();
|
|
347
|
+
const isSuperAdmin = computed(() => props.superAdmin || adminAccess.isSuperAdmin.value);
|
|
348
|
+
const canAdmin = computed(() => isSuperAdmin.value || adminAccess.canAdmin.value);
|
|
349
|
+
const { status: authStatus } = useAuth();
|
|
350
|
+
onMounted(() => adminAccess.load());
|
|
351
|
+
watch(authStatus, (s) => s === "authenticated" && adminAccess.load());
|
|
352
|
+
|
|
340
353
|
const baseTiles = computed<(OipRailTile & { ownCount?: boolean })[]>(() => {
|
|
341
354
|
if (!Object.keys(props.tiles).length) return [];
|
|
342
|
-
return OIP_RAIL_TILES.filter(
|
|
355
|
+
return OIP_RAIL_TILES.filter(
|
|
356
|
+
(entry) => !entry.admin || (entry.superAdminOnly ? isSuperAdmin.value : canAdmin.value),
|
|
357
|
+
).map((entry) => {
|
|
343
358
|
// Une tuile du cadre est servie sauf si l'ecran la refuse (`false`).
|
|
344
359
|
const state = props.tiles[entry.key] ?? !!entry.frame;
|
|
345
360
|
const extra = {
|
|
@@ -610,7 +625,7 @@ const tekkareLogo = tekkareLogoRaw.replaceAll('fill="#2100AD"', 'fill="currentCo
|
|
|
610
625
|
:is="LAYER_PANELS[openKey as OipRailTileKey]"
|
|
611
626
|
v-else-if="openKey && LAYER_PANELS[openKey as OipRailTileKey]"
|
|
612
627
|
:app-key="appKey"
|
|
613
|
-
:super-admin="
|
|
628
|
+
:super-admin="canAdmin"
|
|
614
629
|
v-bind="panelProps[openKey as OipRailTileKey] ?? {}"
|
|
615
630
|
@close="tool = null"
|
|
616
631
|
/>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOipAdminAccess - le lecteur voit-il l'outillage admin du rail ?
|
|
3
|
+
*
|
|
4
|
+
* Oui s'il est superadmin, ou product manager d'au moins un produit
|
|
5
|
+
* (`managedProducts` de GET /me, nomme par un superadmin). Lu une fois par
|
|
6
|
+
* session par /api/oip/admin-access ; chaque route admin revalide le droit,
|
|
7
|
+
* cacher une tuile ne protege rien.
|
|
8
|
+
*
|
|
9
|
+
* Les templates restent aux superadmins (`isSuperAdmin`) : ils passent par
|
|
10
|
+
* des routes `/superadmin/*` de la Virtual Lab qu'un PM ne peut pas appeler.
|
|
11
|
+
*/
|
|
12
|
+
type ManagedProduct = { id: string; slug: string; name: string };
|
|
13
|
+
|
|
14
|
+
export const useOipAdminAccess = () => {
|
|
15
|
+
const isSuperAdmin = useState<boolean>("oip-admin:isSuperAdmin", () => false);
|
|
16
|
+
const managedProducts = useState<ManagedProduct[]>("oip-admin:managedProducts", () => []);
|
|
17
|
+
const loaded = useState<boolean>("oip-admin:loaded", () => false);
|
|
18
|
+
const { status } = useAuth();
|
|
19
|
+
|
|
20
|
+
const isProductManager = computed(() => managedProducts.value.length > 0);
|
|
21
|
+
const canAdmin = computed(() => isSuperAdmin.value || isProductManager.value);
|
|
22
|
+
|
|
23
|
+
async function load() {
|
|
24
|
+
if (loaded.value || !import.meta.client || status.value !== "authenticated") return;
|
|
25
|
+
loaded.value = true;
|
|
26
|
+
try {
|
|
27
|
+
const res = await $fetch<{ isSuperAdmin: boolean; managedProducts: ManagedProduct[] }>("/api/oip/admin-access");
|
|
28
|
+
isSuperAdmin.value = !!res?.isSuperAdmin;
|
|
29
|
+
managedProducts.value = res?.managedProducts ?? [];
|
|
30
|
+
} catch {
|
|
31
|
+
isSuperAdmin.value = false;
|
|
32
|
+
managedProducts.value = [];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { isSuperAdmin, managedProducts, isProductManager, canAdmin, load };
|
|
37
|
+
};
|
|
@@ -28,8 +28,13 @@ export type OipRailEntry = {
|
|
|
28
28
|
icon: string;
|
|
29
29
|
/** Lue en onglet d'un panneau commun avec les autres membres du groupe. */
|
|
30
30
|
group?: OipRailGroupKey;
|
|
31
|
-
/**
|
|
31
|
+
/** Outillage admin : superadmins et product managers. */
|
|
32
32
|
admin?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Superadmins seuls : la tuile passe par des routes `/superadmin/*` de la
|
|
35
|
+
* Virtual Lab qu'un product manager ne peut pas appeler.
|
|
36
|
+
*/
|
|
37
|
+
superAdminOnly?: boolean;
|
|
33
38
|
/** Toujours servie, quel que soit l'ecran : elle ne depend pas de la page. */
|
|
34
39
|
frame?: boolean;
|
|
35
40
|
/** Sa pastille reste sur son onglet, sans s'ajouter a celle du groupe. */
|
|
@@ -44,7 +49,7 @@ export type OipRailEntry = {
|
|
|
44
49
|
export const OIP_RAIL_GROUPS: Record<OipRailGroupKey, { label: { fr: string; en: string }; icon?: string }> = {
|
|
45
50
|
Documentation: { label: { fr: "À propos de l'app", en: "About the app" }, icon: "info" },
|
|
46
51
|
ViewsAlerts: { label: { fr: "Vues et alertes", en: "Views and alerts" } },
|
|
47
|
-
// Outillage
|
|
52
|
+
// Outillage admin : ses membres sont `admin`, le groupe n'existe que pour eux.
|
|
48
53
|
Admin: { label: { fr: "Admin", en: "Admin" }, icon: "shield-check" },
|
|
49
54
|
};
|
|
50
55
|
|
|
@@ -68,6 +73,7 @@ export const OIP_RAIL_TILES: OipRailEntry[] = [
|
|
|
68
73
|
icon: "magic-wand",
|
|
69
74
|
group: "ViewsAlerts",
|
|
70
75
|
admin: true,
|
|
76
|
+
superAdminOnly: true,
|
|
71
77
|
},
|
|
72
78
|
{ key: "Export", label: { fr: "Export", en: "Export" }, icon: "export" },
|
|
73
79
|
{ key: "Projects", label: { fr: "Projets", en: "Projects" }, icon: "folder-simple" },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GET /api/oip/admin-access, servi par le layer OIP : les droits
|
|
5
|
+
* d'administration du lecteur (superadmin, produits dont il est product
|
|
6
|
+
* manager), pour poser les tuiles admin du rail. Chaque route admin revalide
|
|
7
|
+
* de son cote (assertOipAdmin).
|
|
8
|
+
*/
|
|
9
|
+
export default defineEventHandler((event) => oipAdminAccess(event));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
|
-
import {
|
|
2
|
+
import { assertOipAdmin, oipAppUrls } from "../../utils/oipGuards";
|
|
3
3
|
import type { Metadata, MetadataTranslation } from "../../../app/types/metadata";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,7 +12,7 @@ import type { Metadata, MetadataTranslation } from "../../../app/types/metadata"
|
|
|
12
12
|
* collection est commune a tout le portail, et un sujet d'une autre app ne
|
|
13
13
|
* regarde pas celle-ci.
|
|
14
14
|
*
|
|
15
|
-
* Reservee aux superadmins, comme la correction : c'est un outil de relecture
|
|
15
|
+
* Reservee aux admins (superadmins, product managers), comme la correction : c'est un outil de relecture
|
|
16
16
|
* du referentiel, pas une information de lecture.
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ function translations(rows: any[] | null | undefined, name: string, description:
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export default defineEventHandler(async (event): Promise<Metadata> => {
|
|
29
|
-
await
|
|
29
|
+
await assertOipAdmin(event);
|
|
30
30
|
const appUrls = oipAppUrls();
|
|
31
31
|
|
|
32
32
|
const config = useRuntimeConfig();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineEventHandler } from "h3";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
assertOipAdmin,
|
|
5
5
|
oipAppUrls,
|
|
6
6
|
oipCheckRateLimit,
|
|
7
7
|
oipClientIp,
|
|
@@ -65,7 +65,7 @@ const schema = z
|
|
|
65
65
|
export default defineEventHandler(async (event) => {
|
|
66
66
|
oipCheckRateLimit(`metadata-write:${oipClientIp(event)}`, 30, 15 * 60 * 1000);
|
|
67
67
|
|
|
68
|
-
await
|
|
68
|
+
await assertOipAdmin(event);
|
|
69
69
|
const appUrl = oipAppUrls()[0];
|
|
70
70
|
|
|
71
71
|
const body = await oipValidateBody(event, schema);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
|
-
import {
|
|
2
|
+
import { assertOipAdmin as assertAdmin, oipAppUrls } from "../../utils/oipGuards";
|
|
3
3
|
import type { NoteOptions } from "../../../app/notes/types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -28,7 +28,7 @@ function pickLabel(rows: any[] | null | undefined, code: string) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export default defineEventHandler(async (event): Promise<NoteOptions> => {
|
|
31
|
-
await
|
|
31
|
+
await assertAdmin(event);
|
|
32
32
|
|
|
33
33
|
const config = useRuntimeConfig();
|
|
34
34
|
const notesUrl = (config.directusNotesUrl as string | undefined)?.replace(/\/+$/, "");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { assertOipAdmin as assertAdmin } from "../../utils/oipGuards";
|
|
4
4
|
import { oipParseNoteContent as parseNoteContent } from "../../utils/oipNoteMarkup";
|
|
5
5
|
import type { AdminNote, AdminNoteTranslation } from "../../../app/notes/types";
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ interface DirectusTranslation {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export default defineEventHandler(async (event): Promise<AdminNote> => {
|
|
37
|
-
await
|
|
37
|
+
await assertAdmin(event);
|
|
38
38
|
|
|
39
39
|
const parsed = schema.safeParse(getQuery(event));
|
|
40
40
|
if (!parsed.success) throw createError({ status: 400, message: "A note id is required" });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineEventHandler } from "h3";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
assertOipAdmin as assertAdmin,
|
|
5
5
|
oipCheckRateLimit as checkRateLimit,
|
|
6
6
|
oipClientIp as getClientIp,
|
|
7
7
|
oipValidateBody as validateBody,
|
|
@@ -80,7 +80,7 @@ const schema = z.object({
|
|
|
80
80
|
export default defineEventHandler(async (event) => {
|
|
81
81
|
checkRateLimit(`notes-write:${getClientIp(event)}`, 30, 15 * 60 * 1000);
|
|
82
82
|
|
|
83
|
-
await
|
|
83
|
+
await assertAdmin(event);
|
|
84
84
|
|
|
85
85
|
const body = await validateBody(event, schema);
|
|
86
86
|
const config = useRuntimeConfig();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineEventHandler } from "h3";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
assertOipAdmin as assertAdmin,
|
|
5
5
|
oipCheckRateLimit as checkRateLimit,
|
|
6
6
|
oipClientIp as getClientIp,
|
|
7
7
|
oipValidateBody as validateBody,
|
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
*
|
|
21
21
|
* L'autorisation est revalidee ICI, pas seulement a l'affichage du crayon :
|
|
22
22
|
* cacher un bouton ne protege rien, la requete se fabrique a la main. Le droit
|
|
23
|
-
* est
|
|
24
|
-
* le jeton de l'utilisateur, jamais avec celui
|
|
23
|
+
* est celui de l'outillage admin du rail (superadmin ou product manager, cf.
|
|
24
|
+
* assertOipAdmin), demande avec le jeton de l'utilisateur, jamais avec celui
|
|
25
|
+
* du serveur.
|
|
25
26
|
*
|
|
26
27
|
* Le jeton Directus d'ecriture est distinct de celui des rapports : il ne porte
|
|
27
28
|
* que `update` sur les sources et les fournisseurs, plus `create` sur leurs
|
|
@@ -72,7 +73,7 @@ const schema = z.object({
|
|
|
72
73
|
export default defineEventHandler(async (event) => {
|
|
73
74
|
checkRateLimit(`sources-write:${getClientIp(event)}`, 30, 15 * 60 * 1000);
|
|
74
75
|
|
|
75
|
-
await
|
|
76
|
+
await assertAdmin(event);
|
|
76
77
|
|
|
77
78
|
const body = await validateBody(event, schema);
|
|
78
79
|
const config = useRuntimeConfig();
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
*
|
|
25
25
|
* Cle PostHog et perimetre commun : cf. oipStatsContext.
|
|
26
26
|
*
|
|
27
|
-
* Reservee aux superadmins, comme les metadonnees.
|
|
27
|
+
* Reservee aux admins (superadmins, product managers), comme les metadonnees.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
// Large : chaque fiche (une marque, une association) est une page, et le
|
|
@@ -5,33 +5,60 @@ import { getOipAccessToken } from "./oipAuth";
|
|
|
5
5
|
// Garde-fous partages par les routes d'ecriture /api/oip/*. Prefixes `oip`
|
|
6
6
|
// pour ne pas masquer les helpers des apps (utils serveur auto-importes).
|
|
7
7
|
|
|
8
|
+
/** Produit dont l'appelant est product manager, tel que GET /me le rend. */
|
|
9
|
+
export type OipManagedProduct = { id: string; slug: string; name: string };
|
|
10
|
+
|
|
11
|
+
export type OipAdminAccess = { isSuperAdmin: boolean; managedProducts: OipManagedProduct[] };
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
14
|
+
* Les deux droits d'administration du lecteur, demandes avec son jeton :
|
|
15
|
+
* - `isSuperAdmin` (`/superadmin/me`), celui de la console d'OIP 7 ;
|
|
16
|
+
* - `managedProducts` (GET /me), les produits dont il est product manager.
|
|
17
|
+
* Le role ne donne aucun droit dans la Virtual Lab : ce sont les apps qui
|
|
18
|
+
* lui ouvrent l'outillage admin du rail.
|
|
19
|
+
*
|
|
20
|
+
* Un appel qui echoue vaut refus, jamais droit.
|
|
12
21
|
*
|
|
13
22
|
* L'URL de la Virtual Lab vient de `runtimeConfig.oipVirtualLabApiUrl`, sinon
|
|
14
23
|
* de l'env VIRTUAL_LAB_API_URL.
|
|
15
24
|
*/
|
|
16
|
-
export async function
|
|
25
|
+
export async function oipAdminAccess(event: H3Event): Promise<OipAdminAccess> {
|
|
17
26
|
const token = await getOipAccessToken(event);
|
|
18
27
|
if (!token) throw createError({ status: 401, message: "Not authenticated" });
|
|
19
28
|
|
|
20
29
|
const apiUrl = (useRuntimeConfig().oipVirtualLabApiUrl as string) || process.env.VIRTUAL_LAB_API_URL;
|
|
21
30
|
if (!apiUrl) throw createError({ status: 500, message: "VIRTUAL_LAB_API_URL is not set" });
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
+
const headers = { Authorization: `Bearer ${token}` };
|
|
33
|
+
const [superMe, me] = await Promise.all([
|
|
34
|
+
$fetch<{ isSuperAdmin?: boolean }>(`${apiUrl}/superadmin/me`, { headers }).catch(() => null),
|
|
35
|
+
$fetch<{ managedProducts?: OipManagedProduct[] }>(`${apiUrl}/me`, { headers }).catch(() => null),
|
|
36
|
+
]);
|
|
37
|
+
return {
|
|
38
|
+
isSuperAdmin: !!superMe?.isSuperAdmin,
|
|
39
|
+
managedProducts: Array.isArray(me?.managedProducts) ? me.managedProducts : [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Le droit de la console d'OIP 7, revalide a chaque requete : cacher un
|
|
45
|
+
* crayon dans l'interface ne protege rien. Pour ce qui passe par une route
|
|
46
|
+
* `/superadmin/*` de la Virtual Lab (templates), qu'un PM ne peut pas appeler.
|
|
47
|
+
*/
|
|
48
|
+
export async function assertOipSuperAdmin(event: H3Event) {
|
|
49
|
+
const { isSuperAdmin } = await oipAdminAccess(event);
|
|
32
50
|
if (!isSuperAdmin) throw createError({ status: 403, message: "Superadmin required" });
|
|
33
51
|
}
|
|
34
52
|
|
|
53
|
+
/**
|
|
54
|
+
* L'outillage admin du rail (statistiques, metadonnees, correction des notes
|
|
55
|
+
* et des sources) : superadmin ou product manager d'au moins un produit.
|
|
56
|
+
*/
|
|
57
|
+
export async function assertOipAdmin(event: H3Event) {
|
|
58
|
+
const { isSuperAdmin, managedProducts } = await oipAdminAccess(event);
|
|
59
|
+
if (!isSuperAdmin && !managedProducts.length) throw createError({ status: 403, message: "Admin required" });
|
|
60
|
+
}
|
|
61
|
+
|
|
35
62
|
/**
|
|
36
63
|
* Les `prod_url` de l'app dans le portail OIP 7 (fiche OipApplication) : la
|
|
37
64
|
* collection est commune a tout le portail, une app s'y reconnait par la.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
import type { OipStatsPeriod } from "../../app/types/stats";
|
|
3
|
-
import {
|
|
3
|
+
import { assertOipAdmin, oipAppUrls } from "./oipGuards";
|
|
4
4
|
|
|
5
5
|
// Socle des routes /api/oip/stats* (panneau « Statistiques ») : droit, cle
|
|
6
6
|
// PostHog, perimetre de l'app et appel HogQL. Prefixe `oip` pour ne pas
|
|
@@ -44,7 +44,7 @@ export function oipStatsNormalize(path: string) {
|
|
|
44
44
|
* POSTHOG_PROJECT_ID. La cle ne quitte jamais le serveur.
|
|
45
45
|
*/
|
|
46
46
|
export async function oipStatsContext(event: H3Event) {
|
|
47
|
-
await
|
|
47
|
+
await assertOipAdmin(event);
|
|
48
48
|
|
|
49
49
|
const config = useRuntimeConfig();
|
|
50
50
|
const key =
|
|
@@ -15,7 +15,8 @@ let cache: { at: number; names: Map<string, string> } | null = null;
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Id vers nom de tous les workspaces, lus par `/superadmin/workspaces` avec le
|
|
18
|
-
* jeton de l'appelant
|
|
18
|
+
* jeton de l'appelant, gardes dix minutes. La route est reservee aux
|
|
19
|
+
* superadmins : pour un product manager elle refuse, et comme en cas
|
|
19
20
|
* d'echec, une table vide : les statistiques restent lisibles sans les noms.
|
|
20
21
|
*/
|
|
21
22
|
export async function oipWorkspaceNames(event: H3Event): Promise<Map<string, string>> {
|