@open-commune/web 0.2.14 → 0.2.15
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/app.config.ts +7 -0
- package/components/data/lists/data-table.vue +203 -0
- package/components/data/lists/row-actions.vue +41 -0
- package/components/elements/badges/status-badge.vue +23 -0
- package/components/elements/media/media-image.vue +26 -0
- package/components/forms/fields/input-files-media.vue +87 -0
- package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
- package/components/forms/{inputs → fields}/input-search.vue +8 -2
- package/components/forms/fields/input-text-area.vue +86 -0
- package/components/forms/fields/input-text.vue +47 -0
- package/components/forms/fields/select-enum.vue +69 -0
- package/components/forms/handlers/handler-collections.vue +100 -170
- package/components/forms/handlers/handler-list.vue +187 -0
- package/components/forms/handlers/handler-members.vue +171 -0
- package/components/forms/handlers/handler-password-reset.vue +45 -0
- package/components/forms/handlers/handler-roles.vue +28 -166
- package/components/forms/handlers/handler-sessions.vue +77 -0
- package/components/forms/handlers/handler-tokens.vue +54 -69
- package/components/forms/layouts/form-default.vue +99 -0
- package/components/forms/layouts/form.vue +4 -0
- package/components/forms/layouts/forms-layout.vue +236 -0
- package/components/forms/layouts/forms-section.vue +186 -0
- package/components/forms/layouts/layout.vue +4 -0
- package/components/forms/layouts/modal.vue +4 -0
- package/components/forms/layouts/section.vue +4 -0
- package/components/layout/shell/shell-account-menu.vue +10 -2
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-auth.ts +56 -2
- package/composables/core/domains/use-definitions.ts +18 -5
- package/composables/core/domains/use-entries.ts +113 -3
- package/composables/core/domains/use-media.ts +24 -1
- package/composables/core/domains/use-members.ts +68 -0
- package/composables/core/domains/use-organization.ts +53 -0
- package/composables/use-models.js +1 -7
- package/constants/errors.ts +28 -0
- package/constants/forms/account.ts +62 -0
- package/constants/forms/collections.ts +39 -0
- package/constants/forms/members.ts +40 -0
- package/constants/forms/organization.ts +188 -0
- package/constants/forms/tokens.ts +15 -0
- package/constants/roles.ts +57 -0
- package/constants/settings.ts +26 -0
- package/constants/statuses.ts +8 -5
- package/package.json +3 -3
- package/pages/[collection]/index.vue +92 -79
- package/pages/account.vue +40 -0
- package/pages/settings.vue +26 -181
- package/plugins/01.validation.client.ts +23 -0
- package/store/layout/workspace.js +4 -28
- package/utils/colors.ts +26 -0
- package/utils/errors.ts +13 -0
- package/utils/forms.ts +67 -0
- package/utils/list-columns.ts +90 -0
- package/utils/settings.ts +38 -0
- package/utils/statuses.ts +4 -0
- package/models/role.js +0 -66
- package/models/token.js +0 -56
- package/models/user.js +0 -97
- package/pages/management/index.vue +0 -15
- package/pages/management/members.vue +0 -176
- package/pages/management/organizations.vue +0 -192
- package/pages/management/roles.vue +0 -183
- /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
|
@@ -1,32 +1,8 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
|
+
import { ROLES } from '~/constants/roles'
|
|
2
3
|
|
|
3
|
-
// Single-tenant : les permissions dérivent du rôle Open Commune de l'utilisateur
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// `redacteur` reprend EXACTEMENT le rôle legacy « Éditeur de contenu », que
|
|
7
|
-
// portaient tous les agents des collectivités. La première version n'avait
|
|
8
|
-
// retenu que les records : les agents perdaient la publication du site, la
|
|
9
|
-
// médiathèque et la lecture des collections — le bouton « Publier » avait donc
|
|
10
|
-
// disparu pour tous sauf les comptes admin.
|
|
11
|
-
const ROLE_PERMISSIONS = {
|
|
12
|
-
admin: ['manage:all'],
|
|
13
|
-
redacteur: [
|
|
14
|
-
'entrance:self',
|
|
15
|
-
'read:organizations',
|
|
16
|
-
'read:collections',
|
|
17
|
-
'read:records',
|
|
18
|
-
'create:records',
|
|
19
|
-
'update:records',
|
|
20
|
-
'delete:records',
|
|
21
|
-
'publish:records',
|
|
22
|
-
'read:media',
|
|
23
|
-
'create:media',
|
|
24
|
-
'update:media',
|
|
25
|
-
'delete:media',
|
|
26
|
-
'read:deployments',
|
|
27
|
-
'create:deployments'
|
|
28
|
-
]
|
|
29
|
-
}
|
|
4
|
+
// Single-tenant : les permissions dérivent du rôle Open Commune de l'utilisateur,
|
|
5
|
+
// déclaré une seule fois dans `constants/roles` (l'écran Rôles lit la même liste).
|
|
30
6
|
|
|
31
7
|
export const useWorkspaceStore = defineStore('layout/workspace', () => {
|
|
32
8
|
const $session = useSession()
|
|
@@ -50,7 +26,7 @@ export const useWorkspaceStore = defineStore('layout/workspace', () => {
|
|
|
50
26
|
const user = $session.user.value
|
|
51
27
|
$abilities.assignAbilities([
|
|
52
28
|
'entrance:self',
|
|
53
|
-
...(
|
|
29
|
+
...(ROLES.find(({ id }) => id === user?.role)?.permissions ?? [])
|
|
54
30
|
])
|
|
55
31
|
}
|
|
56
32
|
|
package/utils/colors.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A neutral fill for a label without a colour, or with a white one. */
|
|
2
|
+
const FALLBACK = '#e5e7eb';
|
|
3
|
+
|
|
4
|
+
const channelsOf = (color: string): number[] | undefined => {
|
|
5
|
+
const hex = color.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)?.[1];
|
|
6
|
+
if (!hex) return color.match(/\d+/g)?.map(Number);
|
|
7
|
+
const full = hex.length === 3 ? [...hex].map((c) => c + c).join('') : hex;
|
|
8
|
+
return [full.slice(0, 2), full.slice(2, 4), full.slice(4, 6)].map((part) => parseInt(part, 16));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The fill an editor chose for a label, and the ink that reads on it: black
|
|
13
|
+
* on a light colour, white on a dark one (relative luminance, WCAG).
|
|
14
|
+
*/
|
|
15
|
+
export const swatchOf = (value?: string | null) => {
|
|
16
|
+
const color = (value ?? '').trim();
|
|
17
|
+
const backgroundColor =
|
|
18
|
+
!color || ['#ffffff', '#fff', 'white'].includes(color.toLowerCase()) ? FALLBACK : color;
|
|
19
|
+
const [r, g, b] = channelsOf(backgroundColor) ?? [];
|
|
20
|
+
const light =
|
|
21
|
+
r === undefined ||
|
|
22
|
+
g === undefined ||
|
|
23
|
+
b === undefined ||
|
|
24
|
+
(r * 0.299 + g * 0.587 + b * 0.114) / 255 > 0.5;
|
|
25
|
+
return { backgroundColor, color: light ? '#000' : '#fff' };
|
|
26
|
+
};
|
package/utils/errors.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isErrorType } from '@open-commune/core/dtos';
|
|
2
|
+
import { REFUSALS } from '~/constants/errors';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What the core said when it refused, in the admin's words. The core sends
|
|
6
|
+
* the `type` of its domain error beside the transport code. A failure that is
|
|
7
|
+
* not one of its refusals (the network, an unexpected crash) answers with the
|
|
8
|
+
* caller's sentence.
|
|
9
|
+
*/
|
|
10
|
+
export const refusalOf = (error: unknown, fallback: string): string => {
|
|
11
|
+
const type = (error as { data?: { type?: unknown } } | undefined)?.data?.type;
|
|
12
|
+
return isErrorType(type) ? REFUSALS[type] : fallback;
|
|
13
|
+
};
|
package/utils/forms.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cloneFnJSON, objectPick } from '@vueuse/core';
|
|
2
|
+
import type { FormControl } from '~/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Controls that own their data and edit no value: the admin tables, the
|
|
6
|
+
* members, the roles. They get neither a field nor a place in a form's state.
|
|
7
|
+
*/
|
|
8
|
+
const STANDALONE_CONTROLS = new Set([
|
|
9
|
+
'handler-collections',
|
|
10
|
+
'handler-members',
|
|
11
|
+
'handler-password-reset',
|
|
12
|
+
'handler-roles',
|
|
13
|
+
'handler-sessions',
|
|
14
|
+
'handler-tokens',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
export const isStandalone = ({ component }: FormControl) => STANDALONE_CONTROLS.has(component);
|
|
18
|
+
|
|
19
|
+
/** The properties a described form edits, in the order it shows them. */
|
|
20
|
+
export const propertiesOf = (controls: FormControl[] = []) =>
|
|
21
|
+
controls
|
|
22
|
+
.filter((control) => control.property && !isStandalone(control))
|
|
23
|
+
.map(({ property }) => property as string);
|
|
24
|
+
|
|
25
|
+
type Values = Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compared as JSON, the way the values travel: `null` and an absent value
|
|
29
|
+
* are the same emptiness, and a ProseMirror document is compared in depth.
|
|
30
|
+
*/
|
|
31
|
+
export const sameValue = (left: unknown, right: unknown) =>
|
|
32
|
+
JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* What a form starts from: the record's own value for each property it edits,
|
|
36
|
+
* copied, so typing never writes into the cache the record came from. An entry
|
|
37
|
+
* keeps its declared fields in `data`; a form knows only one level.
|
|
38
|
+
*/
|
|
39
|
+
export const valuesOf = (record: Values | null | undefined, properties: string[]): Values => {
|
|
40
|
+
const flat = { ...(record ?? {}), ...((record?.data as Values | undefined) ?? {}) };
|
|
41
|
+
return cloneFnJSON(objectPick(flat, properties));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** What differs from where the form started: the only thing a save sends. */
|
|
45
|
+
export const changesOf = (state: Values, baseline: Values): Values =>
|
|
46
|
+
Object.fromEntries(
|
|
47
|
+
Object.entries(state).filter(([property, value]) => !sameValue(value, baseline[property])),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** A Zod object, as far as a form needs to know one. */
|
|
51
|
+
interface ObjectSchema {
|
|
52
|
+
shape: Record<string, unknown>;
|
|
53
|
+
pick: (keys: Record<string, true>) => unknown;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The server's own schema, narrowed to what ONE form edits: a card of the
|
|
58
|
+
* settings saves two fields of the organization, not the organization. A
|
|
59
|
+
* property the schema does not know is left to the server alone.
|
|
60
|
+
*/
|
|
61
|
+
export const narrowSchema = (schema: unknown, properties: string[]) => {
|
|
62
|
+
const object = schema as ObjectSchema | undefined;
|
|
63
|
+
if (!object?.shape || typeof object.pick !== 'function') return undefined;
|
|
64
|
+
const known = properties.filter((property) => property in object.shape);
|
|
65
|
+
if (!known.length) return undefined;
|
|
66
|
+
return object.pick(Object.fromEntries(known.map((property) => [property, true as const])));
|
|
67
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** What the listing reads of a definition, as the core sends it. */
|
|
2
|
+
interface CollectionDefinition {
|
|
3
|
+
slug: string;
|
|
4
|
+
fields?: FieldDefinition[];
|
|
5
|
+
editor?: unknown;
|
|
6
|
+
display?: { headers?: StoredHeader[] } | null;
|
|
7
|
+
}
|
|
8
|
+
/** A column as the stored `display` of a collection states it. */
|
|
9
|
+
interface StoredHeader {
|
|
10
|
+
property?: string;
|
|
11
|
+
component?: string;
|
|
12
|
+
componentOptions?: { titleKey?: string; descriptionKey?: string };
|
|
13
|
+
}
|
|
14
|
+
interface FieldDefinition {
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* What a collection's listing shows, derived from the collection's own
|
|
21
|
+
* definition — so each collection of each instance gets what its fields
|
|
22
|
+
* justify, and nothing is written anywhere by hand.
|
|
23
|
+
*
|
|
24
|
+
* The `display` config stored beside each collection said nothing the
|
|
25
|
+
* definition did not already say, and stated a column that stood empty
|
|
26
|
+
* wherever a collection has no relation at all.
|
|
27
|
+
*
|
|
28
|
+
* Meant to go: the keys are to be DECLARED on the definition (a nullable
|
|
29
|
+
* `listing: { cover?, labels? }` block), not guessed from its fields.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** The keys `data-table` needs to draw the rows of one collection. */
|
|
33
|
+
export interface ListingKeys {
|
|
34
|
+
/** Field holding the cover shown in the summary. Empty: no thumbnail. */
|
|
35
|
+
coverKey: string;
|
|
36
|
+
/** Field holding the linked entries. Empty: no column of labels. */
|
|
37
|
+
labelsKey: string;
|
|
38
|
+
/** Fields the summary reads its two lines from. */
|
|
39
|
+
titleKey: string;
|
|
40
|
+
descriptionKey: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Which collections a relation field declares, read from the stored editor. */
|
|
44
|
+
const targetsByField = (collection?: CollectionDefinition): Map<string, string[]> => {
|
|
45
|
+
const targets = new Map<string, string[]>();
|
|
46
|
+
const walk = (node: unknown): void => {
|
|
47
|
+
if (Array.isArray(node)) {
|
|
48
|
+
node.forEach(walk);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!node || typeof node !== 'object') return;
|
|
52
|
+
const descriptor = node as { property?: string; componentOptions?: { collections?: unknown } };
|
|
53
|
+
if (descriptor.property && Array.isArray(descriptor.componentOptions?.collections)) {
|
|
54
|
+
targets.set(descriptor.property, descriptor.componentOptions.collections as string[]);
|
|
55
|
+
}
|
|
56
|
+
for (const value of Object.values(node)) walk(value);
|
|
57
|
+
};
|
|
58
|
+
walk(collection?.editor ?? {});
|
|
59
|
+
return targets;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const listingKeysFor = (collection?: CollectionDefinition): ListingKeys => {
|
|
63
|
+
const fields = collection?.fields ?? [];
|
|
64
|
+
const cover = fields.find(({ type }) => type === 'media');
|
|
65
|
+
const targets = targetsByField(collection);
|
|
66
|
+
|
|
67
|
+
const related = fields.find(({ name, type }) => {
|
|
68
|
+
if (type !== 'relation') return false;
|
|
69
|
+
// `records` is the projection of the entry's free links, not a field of
|
|
70
|
+
// its own: the column would repeat what the entry page already shows.
|
|
71
|
+
if (name === 'records') return false;
|
|
72
|
+
// A collection relating to ITSELF — themes to their parent — gets no
|
|
73
|
+
// column out of it: it would repeat its own name.
|
|
74
|
+
const aimed = targets.get(name) ?? [];
|
|
75
|
+
return name !== collection?.slug && !aimed.includes(collection?.slug ?? '');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// What the collection's stored `display` already says wins: an instance
|
|
79
|
+
// that chose its description field, or its column of labels, keeps them.
|
|
80
|
+
const headers = collection?.display?.headers ?? [];
|
|
81
|
+
const summary = headers.find(({ component }) => component === 'data-summary')?.componentOptions;
|
|
82
|
+
const labels = headers.find(({ component }) => component === 'data-label')?.property;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
coverKey: cover?.name ?? '',
|
|
86
|
+
labelsKey: labels ?? related?.name ?? '',
|
|
87
|
+
titleKey: summary?.titleKey ?? 'title',
|
|
88
|
+
descriptionKey: summary?.descriptionKey ?? 'description',
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SETTINGS_SECTIONS } from '~/constants/settings';
|
|
2
|
+
import type { FormTab, LayerSettingsSection, SettingsSection } from '~/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a settings section lives — the values it reads are in
|
|
6
|
+
* `constants/settings.ts`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** URL of one section; the first one lands on a bare `/settings`. */
|
|
10
|
+
export const sectionRoute = (slug: string): string =>
|
|
11
|
+
slug ? `/settings?section=${slug}` : '/settings';
|
|
12
|
+
|
|
13
|
+
/** Section title for a URL slug, falling back to the first section. */
|
|
14
|
+
export const sectionTitleFromSlug = (
|
|
15
|
+
slug: string,
|
|
16
|
+
sections: readonly SettingsSection[] = SETTINGS_SECTIONS,
|
|
17
|
+
): string => (sections.find((section) => section.slug === slug) ?? sections[0]!).title;
|
|
18
|
+
|
|
19
|
+
/** A layer's section, as the tab the settings form draws. */
|
|
20
|
+
export const layerSectionTab = ({
|
|
21
|
+
label,
|
|
22
|
+
description,
|
|
23
|
+
component,
|
|
24
|
+
}: LayerSettingsSection): FormTab => ({
|
|
25
|
+
icon: '',
|
|
26
|
+
sections: [
|
|
27
|
+
{
|
|
28
|
+
componentOptions: {
|
|
29
|
+
title: label,
|
|
30
|
+
description,
|
|
31
|
+
attributes: [{ componentOptions: {}, component }],
|
|
32
|
+
noAction: true,
|
|
33
|
+
},
|
|
34
|
+
component: 'form-section-default',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
title: label,
|
|
38
|
+
});
|
package/models/role.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Role Model
|
|
2
|
-
import { Model } from 'pinia-orm'
|
|
3
|
-
import ModelAPI from '~/models/_factory'
|
|
4
|
-
|
|
5
|
-
const _roleModel = class Role extends Model {
|
|
6
|
-
// This is the name used as module name of the Vuex Store.
|
|
7
|
-
static entity = 'Role'
|
|
8
|
-
static primaryKey = '_id'
|
|
9
|
-
|
|
10
|
-
// List of all fields (schema) of the post model. `this.attr` is used
|
|
11
|
-
// for the generic field type. The argument is the default value.
|
|
12
|
-
static fields () {
|
|
13
|
-
return {
|
|
14
|
-
_id: this.attr(null),
|
|
15
|
-
name: this.attr(''),
|
|
16
|
-
description: this.attr(''),
|
|
17
|
-
permissions: this.attr([]),
|
|
18
|
-
onlyOwn: this.attr(false),
|
|
19
|
-
mfa: this.attr(false),
|
|
20
|
-
createdBy: this.attr({}),
|
|
21
|
-
updatedBy: this.attr({}),
|
|
22
|
-
createdAt: this.attr(0),
|
|
23
|
-
updatedAt: this.attr(0)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Les rôles paramétrables du legacy sont remplacés par le modèle fixe Open Commune
|
|
30
|
-
* (admin / redacteur). La liste est statique ; le CRUD est inerte.
|
|
31
|
-
*/
|
|
32
|
-
const ROLES = [
|
|
33
|
-
{
|
|
34
|
-
_id: 'admin',
|
|
35
|
-
name: 'Administrateur',
|
|
36
|
-
description: 'Accès complet : contenus, médias, membres et réglages.',
|
|
37
|
-
permissions: ['manage:all']
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
_id: 'redacteur',
|
|
41
|
-
name: 'Rédacteur',
|
|
42
|
-
description: 'Gestion des contenus et des médias.',
|
|
43
|
-
permissions: ['entrance:self', 'read:records', 'create:records', 'update:records', 'delete:records']
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
const _roleAPI = class RoleAPI extends ModelAPI {
|
|
48
|
-
async list() {
|
|
49
|
-
this.repo.save(ROLES)
|
|
50
|
-
return this.repo.query().all()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async create() {
|
|
54
|
-
throw new Error('E_ROLES_FIXED')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async update() {
|
|
58
|
-
throw new Error('E_ROLES_FIXED')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async remove() {
|
|
62
|
-
throw new Error('E_ROLES_FIXED')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default { model: _roleModel, api: _roleAPI }
|
package/models/token.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// Token Model
|
|
2
|
-
import { Model } from 'pinia-orm'
|
|
3
|
-
import ModelAPI from '~/models/_factory'
|
|
4
|
-
|
|
5
|
-
const _tokenModel = class Token extends Model {
|
|
6
|
-
// This is the name used as module name of the Vuex Store.
|
|
7
|
-
static entity = 'Token'
|
|
8
|
-
static primaryKey = '_id'
|
|
9
|
-
|
|
10
|
-
// List of all fields (schema) of the post model. `this.attr` is used
|
|
11
|
-
// for the generic field type. The argument is the default value.
|
|
12
|
-
static fields () {
|
|
13
|
-
return {
|
|
14
|
-
_id: this.attr(null),
|
|
15
|
-
name: this.attr(''),
|
|
16
|
-
token: this.attr(''),
|
|
17
|
-
lastEntrance: this.attr(0),
|
|
18
|
-
organization: this.attr({}),
|
|
19
|
-
createdBy: this.attr({}),
|
|
20
|
-
createdAt: this.attr(0),
|
|
21
|
-
updatedAt: this.attr(0)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const _tokenAPI = class TokenAPI extends ModelAPI {
|
|
27
|
-
async list() {
|
|
28
|
-
const tokens = await this.trpc.apiTokens.list.query()
|
|
29
|
-
// Les tokens sont désormais stockés hachés : la valeur en clair n'est
|
|
30
|
-
// visible qu'à la création (différence assumée vs legacy plaintext).
|
|
31
|
-
this.repo.save(
|
|
32
|
-
tokens
|
|
33
|
-
.filter((token) => !token.revokedAt)
|
|
34
|
-
.map((token) => ({
|
|
35
|
-
_id: token.id,
|
|
36
|
-
name: token.name,
|
|
37
|
-
lastEntrance: token.lastUsedAt ?? 0,
|
|
38
|
-
createdAt: token.createdAt
|
|
39
|
-
}))
|
|
40
|
-
)
|
|
41
|
-
return this.repo.query().all()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async create(record) {
|
|
45
|
-
const created = await this.trpc.apiTokens.create.mutate({ name: record.name })
|
|
46
|
-
this.repo.save({ _id: created.id, name: created.name, token: created.token })
|
|
47
|
-
return this.repo.find(created.id)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async remove(_id) {
|
|
51
|
-
await this.trpc.apiTokens.revoke.mutate({ id: _id })
|
|
52
|
-
return this.repo.destroy(_id)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default { model: _tokenModel, api: _tokenAPI }
|
package/models/user.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// User Model
|
|
2
|
-
import { Model } from 'pinia-orm'
|
|
3
|
-
import ModelAPI from '~/models/_factory'
|
|
4
|
-
|
|
5
|
-
const _userModel = class User extends Model {
|
|
6
|
-
// This is the name used as module name of the Vuex Store.
|
|
7
|
-
static entity = 'User'
|
|
8
|
-
static primaryKey = '_id'
|
|
9
|
-
|
|
10
|
-
// List of all fields (schema) of the post model. `this.attr` is used
|
|
11
|
-
// for the generic field type. The argument is the default value.
|
|
12
|
-
static fields () {
|
|
13
|
-
return {
|
|
14
|
-
_id: this.attr(null),
|
|
15
|
-
firstName: this.attr(''),
|
|
16
|
-
lastName: this.attr(''),
|
|
17
|
-
phone: this.attr(''),
|
|
18
|
-
emailAddress: this.attr(''),
|
|
19
|
-
emailStatus: this.attr(''),
|
|
20
|
-
emailChangeCandidate: this.attr(''),
|
|
21
|
-
avatar: this.attr({}),
|
|
22
|
-
role: this.attr(''),
|
|
23
|
-
organizations: this.attr([]),
|
|
24
|
-
permissions: this.attr([]),
|
|
25
|
-
createdBy: this.attr({}),
|
|
26
|
-
updatedBy: this.attr({}),
|
|
27
|
-
createdAt: this.attr(0),
|
|
28
|
-
updatedAt: this.attr(0)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get full name of the user.
|
|
34
|
-
*/
|
|
35
|
-
get fullName () {
|
|
36
|
-
return [this.firstName, this.lastName].join(' ')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** PublicUser Open Commune { id, email, name, role } → user legacy. */
|
|
41
|
-
function userToLegacy(user) {
|
|
42
|
-
return {
|
|
43
|
-
_id: user.id,
|
|
44
|
-
firstName: user.name ?? '',
|
|
45
|
-
lastName: '',
|
|
46
|
-
emailAddress: user.email,
|
|
47
|
-
emailStatus: 'confirmed',
|
|
48
|
-
role: user.role,
|
|
49
|
-
organizations: [],
|
|
50
|
-
permissions: []
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const _userAPI = class UserAPI extends ModelAPI {
|
|
55
|
-
async list() {
|
|
56
|
-
const users = await this.trpc.users.list.query()
|
|
57
|
-
this.repo.save(users.map(userToLegacy))
|
|
58
|
-
return this.repo.query().all()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async read(_id) {
|
|
62
|
-
const user = await this.trpc.users.get.query({ id: _id })
|
|
63
|
-
this.repo.save(userToLegacy(user))
|
|
64
|
-
return this.repo.find(_id)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* La création directe n'existe plus : on émet une INVITATION (le lien est
|
|
69
|
-
* affiché à l'admin tant que l'envoi de mails — tâche 9.9 — n'est pas porté).
|
|
70
|
-
* Retourne { token, expiresAt } en plus de rafraîchir la liste.
|
|
71
|
-
*/
|
|
72
|
-
async create(record) {
|
|
73
|
-
const invitation = await this.trpc.users.invite.mutate({
|
|
74
|
-
email: record.emailAddress,
|
|
75
|
-
role: record.role || 'redacteur'
|
|
76
|
-
})
|
|
77
|
-
return invitation
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async update(_id, record) {
|
|
81
|
-
const data = {}
|
|
82
|
-
if (record.firstName !== undefined || record.lastName !== undefined) {
|
|
83
|
-
data.name = [record.firstName, record.lastName].filter(Boolean).join(' ')
|
|
84
|
-
}
|
|
85
|
-
if (record.role !== undefined) data.role = record.role
|
|
86
|
-
const user = await this.trpc.users.update.mutate({ id: _id, data })
|
|
87
|
-
this.repo.save(userToLegacy(user))
|
|
88
|
-
return this.repo.find(_id)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async remove(_id) {
|
|
92
|
-
await this.trpc.users.remove.mutate({ id: _id })
|
|
93
|
-
return this.repo.destroy(_id)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default { model: _userModel, api: _userAPI }
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="relative block w-full">
|
|
3
|
-
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script setup>
|
|
8
|
-
definePageMeta({
|
|
9
|
-
permissions: ['manage:all'],
|
|
10
|
-
headings: {
|
|
11
|
-
title: 'Bienvenue',
|
|
12
|
-
description: 'Cette section est réservée aux administrateurs.'
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
</script>
|