@open-commune/web 0.2.13 → 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 +13 -0
- package/assets/css/main.css +119 -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/entrance-mark.vue +18 -0
- package/components/layout/navigations/primary/dropdown-publish.vue +6 -4
- package/components/layout/shell/shell-account-menu.vue +63 -0
- package/components/layout/shell/shell-header.vue +99 -0
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-auth.ts +162 -0
- 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 -9
- 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/layouts/default.vue +1 -2
- package/layouts/entrance.vue +1 -6
- package/layouts/record.vue +1 -2
- package/middleware/00.light-mode.global.ts +8 -0
- package/nuxt.config.ts +8 -0
- package/package.json +5 -3
- package/pages/[collection]/index.vue +92 -79
- package/pages/account.vue +40 -0
- package/pages/index/index.vue +54 -62
- package/pages/index/password/define/[token].vue +44 -68
- package/pages/index/password/recover/index.vue +43 -54
- package/pages/index/welcome/[token].vue +42 -79
- package/pages/index.vue +6 -37
- package/pages/settings.vue +26 -181
- package/plugins/00.appearance.client.ts +7 -0
- 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/components/layout/navigations/primary.vue +0 -132
- package/models/entrance.js +0 -42
- 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/public/logo-black.svg +0 -1
- package/public/logo-white.svg +0 -1
- /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
|
@@ -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
|
+
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<header class="border-b border-gray-200 relative">
|
|
3
|
-
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:max-w-7xl lg:px-8">
|
|
4
|
-
<div class="py-5 flex items-center justify-between">
|
|
5
|
-
<!-- Single-tenant : identité de la collectivité, sans sélecteur. -->
|
|
6
|
-
<nuxt-link to="/overview" class="flex items-center space-x-3">
|
|
7
|
-
<avatar-circular :place-holder="workspaceStore.workspaceName || 'C'" :media="workspaceStore.workspaceLogo" size="sm" />
|
|
8
|
-
<span class="font-medium">{{ workspaceStore.workspaceName }}</span>
|
|
9
|
-
</nuxt-link>
|
|
10
|
-
<div class="flex flex-row items-center justify-center space-x-2">
|
|
11
|
-
<dropdown-publish v-if="displayPublishButton" class="h-10" />
|
|
12
|
-
<button-secondary class="h-10" icon="lucide:message-circle-question" @click="_openForm()" />
|
|
13
|
-
<button-secondary class="h-10" label="Se déconnecter" @click="_logout()" />
|
|
14
|
-
</div>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:max-w-7xl lg:px-8">
|
|
18
|
-
<div class="hidden sm:block">
|
|
19
|
-
<nav class="-mb-px flex space-x-8 text-gray-500 font-light whitespace-nowrap tracking-wide text-sm" aria-label="Tabs">
|
|
20
|
-
<nuxt-link
|
|
21
|
-
v-for="({ title, route }) in navigationItems"
|
|
22
|
-
:key="route"
|
|
23
|
-
:to="route"
|
|
24
|
-
active-class="text-gray-900 border-b-2 border-gray-900 font-normal"
|
|
25
|
-
class="hover:text-gray-900 hover:font-normal border-transparent py-4 px-1"
|
|
26
|
-
>
|
|
27
|
-
{{ title }}
|
|
28
|
-
</nuxt-link>
|
|
29
|
-
</nav>
|
|
30
|
-
</div>
|
|
31
|
-
<p v-if="demoEnv" class="absolute bg-black rounded-b-lg text-white px-4 text-xs py-0.5">
|
|
32
|
-
beta
|
|
33
|
-
</p>
|
|
34
|
-
</div>
|
|
35
|
-
</header>
|
|
36
|
-
</template>
|
|
37
|
-
|
|
38
|
-
<script setup>
|
|
39
|
-
import { useWorkspaceStore } from '~/store/layout/workspace'
|
|
40
|
-
import avatarCircular from '~/components/elements/avatars/avatar-circular'
|
|
41
|
-
import buttonSecondary from '~/components/elements/buttons/secondary'
|
|
42
|
-
import dropdownPublish from '~/components/layout/navigations/primary/dropdown-publish'
|
|
43
|
-
// import mobileButton from '~/components/template/navigation-section/mobile-section/Button'
|
|
44
|
-
// import mobileMenu from '~/components/template/navigation-section/mobile-section/Menu'
|
|
45
|
-
// import profileDropdown from '~/components/template/navigation-section/ProfileDropdown'
|
|
46
|
-
|
|
47
|
-
const session = useSession()
|
|
48
|
-
const { Collection } = useModels()
|
|
49
|
-
const $ability = useAbility()
|
|
50
|
-
const $router = useRouter()
|
|
51
|
-
const $route = useRoute()
|
|
52
|
-
const $config = useRuntimeConfig()
|
|
53
|
-
|
|
54
|
-
const workspaceStore = useWorkspaceStore()
|
|
55
|
-
|
|
56
|
-
// Prepare constants
|
|
57
|
-
// Single-tenant : les écrans Organisations et Rôles n'ont plus d'objet
|
|
58
|
-
// (une seule collectivité, rôles figés admin/rédacteur) — retirés de la nav.
|
|
59
|
-
const DEFAULT_NAV_ITEMS = [
|
|
60
|
-
{
|
|
61
|
-
title: 'Accueil',
|
|
62
|
-
route: '/overview',
|
|
63
|
-
permission: 'manage:all'
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
title: 'Membres',
|
|
67
|
-
route: '/management/members',
|
|
68
|
-
permission: 'manage:all'
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
const WORKSPACE_NAV_ITEMS = [
|
|
72
|
-
{
|
|
73
|
-
title: 'Accueil',
|
|
74
|
-
route: '/overview',
|
|
75
|
-
permission: ''
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
title: 'Paramètres',
|
|
79
|
-
route: '/settings',
|
|
80
|
-
permission: 'admin:organization'
|
|
81
|
-
}
|
|
82
|
-
]
|
|
83
|
-
|
|
84
|
-
// Prepare computed data
|
|
85
|
-
const displayPublishButton = computed(() => !!workspaceStore.workspaceId
|
|
86
|
-
&& ($ability.can('manage:all')
|
|
87
|
-
|| $ability.can('admin:organization')
|
|
88
|
-
|| $ability.can('create:deployments'))
|
|
89
|
-
)
|
|
90
|
-
const navigationItems = computed(() => {
|
|
91
|
-
const items = []
|
|
92
|
-
// Display sub nav if necessary
|
|
93
|
-
if (workspaceStore.workspaceId) {
|
|
94
|
-
const [overview, ...subItemsRest] = WORKSPACE_NAV_ITEMS
|
|
95
|
-
const collections = Collection.repo.find(workspaceStore.workspaceCollections)
|
|
96
|
-
items.push(
|
|
97
|
-
// Single-tenant : les routes vivent à la racine, sans slug d'organisation.
|
|
98
|
-
...[overview],
|
|
99
|
-
...collections.map(({ name, slug }) => ({ title: name, route: `/${slug}` })),
|
|
100
|
-
...subItemsRest
|
|
101
|
-
)
|
|
102
|
-
} else {
|
|
103
|
-
items.push(...DEFAULT_NAV_ITEMS)
|
|
104
|
-
}
|
|
105
|
-
// Filter on user permissions
|
|
106
|
-
return items.filter(({ permission }) => !permission || $ability.can(permission))
|
|
107
|
-
})
|
|
108
|
-
// L'image d'instance est COMMUNE à tous les clients : rien de spécifique n'y est
|
|
109
|
-
// cuit. L'hôte servi est donc la seule source fiable pour distinguer une démo.
|
|
110
|
-
const demoEnv = computed(() => {
|
|
111
|
-
const host = import.meta.client ? window.location.host : ''
|
|
112
|
-
return host.includes('.beta') || host.includes('localhost')
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
// Prepare methods
|
|
116
|
-
const _openForm = () => {
|
|
117
|
-
// https://forms.fillout.com/t/vjkLG9ZXsLus
|
|
118
|
-
const formUrl = 'https://forms.fillout.com/t/vjkLG9ZXsLus'
|
|
119
|
-
const formWindow = window.open(formUrl, '_blank')
|
|
120
|
-
if (formWindow) {
|
|
121
|
-
// Browser has allowed it to be opened
|
|
122
|
-
formWindow.focus()
|
|
123
|
-
} else {
|
|
124
|
-
// Browser has blocked it
|
|
125
|
-
alert('Please allow popups for this website')
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const _logout = async () => {
|
|
129
|
-
await session.logout()
|
|
130
|
-
$router.replace('/')
|
|
131
|
-
}
|
|
132
|
-
</script>
|
package/models/entrance.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Entrance Model
|
|
2
|
-
import { Model } from 'pinia-orm'
|
|
3
|
-
import ModelAPI from '~/models/_factory'
|
|
4
|
-
|
|
5
|
-
const _entranceModel = class Entrance extends Model {
|
|
6
|
-
// This is the name used as module name of the Vuex Store.
|
|
7
|
-
static entity = 'Entrance'
|
|
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
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const _entranceAPI = class EntranceAPI extends ModelAPI {
|
|
18
|
-
/**
|
|
19
|
-
* Le flux legacy confirm-email → define-password est remplacé par
|
|
20
|
-
* l'acceptation d'invitation Open Commune (une seule étape, publique).
|
|
21
|
-
*/
|
|
22
|
-
async acceptInvitation({ token, name, password }) {
|
|
23
|
-
return this.trpc.auth.acceptInvitation.mutate({ token, name, password })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Mot de passe oublié (9.9) : réponse toujours ok (pas d'énumération). */
|
|
27
|
-
async recoverPassword(emailAddress) {
|
|
28
|
-
return this.trpc.auth.requestPasswordReset.mutate({ email: emailAddress })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Le lien du mail de reset pointe sur /password/define/<token> — même
|
|
32
|
-
* acceptation d'invitation, sans nom (conservé côté serveur). */
|
|
33
|
-
async updatePassword({ token, password }) {
|
|
34
|
-
return this.trpc.auth.acceptInvitation.mutate({ token, password })
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async confirmEmail() {
|
|
38
|
-
throw new Error('E_NOT_AVAILABLE_YET')
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default { model: _entranceModel, api: _entranceAPI }
|
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>
|