@frigear-nu/users 3.1.3 → 3.1.5
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.d.mts +16 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +16 -15
- package/dist/runtime/access.js +5 -5
- package/dist/runtime/app/pages/admin.vue +21 -4
- package/dist/runtime/app/plugins/offer-locale.client.js +22 -3
- package/dist/runtime/app/tabs/Overview.vue +73 -9
- package/dist/runtime/db/schema.postgresql.d.ts +68 -0
- package/dist/runtime/db/schema.postgresql.js +15 -4
- package/dist/runtime/db/schema.sqlite.d.ts +72 -0
- package/dist/runtime/db/schema.sqlite.js +15 -4
- package/dist/runtime/i18n/lang/da.json +25 -5
- package/dist/runtime/i18n/lang/en.json +25 -5
- package/dist/runtime/server/routes/admin/user.patch.js +16 -5
- package/dist/runtime/server/routes/admin/users.get.js +12 -3
- package/dist/runtime/server/routes/admin/users.post.js +1 -0
- package/dist/runtime/server/routes/me/profile.patch.js +17 -3
- package/dist/runtime/server/schemas.d.ts +7 -0
- package/dist/runtime/server/schemas.js +4 -0
- package/dist/runtime/server/search-index.js +2 -2
- package/dist/runtime/server/user-store.js +2 -1
- package/dist/runtime/server/utils/dto.d.ts +6 -2
- package/dist/runtime/server/utils/dto.js +8 -1
- package/dist/runtime/server/utils/user-refs.d.ts +2 -1
- package/dist/runtime/server/utils/user-refs.js +8 -2
- package/dist/runtime/server/utils/user-search.d.ts +13 -5
- package/dist/runtime/server/utils/user-search.js +13 -1
- package/dist/runtime/utils/api.d.ts +4 -2
- package/dist/runtime/utils/api.js +3 -2
- package/dist/runtime/utils/profile.d.ts +14 -0
- package/dist/runtime/utils/profile.js +8 -0
- package/package.json +10 -10
package/dist/module.d.mts
CHANGED
|
@@ -37,10 +37,18 @@ type ModuleOptions = {
|
|
|
37
37
|
type AdminUserDto = {
|
|
38
38
|
id: number;
|
|
39
39
|
name: string;
|
|
40
|
+
/** What the user likes to be called; shown as "Name (nickname)". */
|
|
41
|
+
nickname: string | null;
|
|
40
42
|
email: string;
|
|
41
43
|
avatar: string | null;
|
|
42
44
|
/** Only in the detail and edit responses, and only for a caller with `users:pii`. */
|
|
43
45
|
phone?: string | null;
|
|
46
|
+
/** The person's id in an external system. Only in the detail and edit responses, and only with `users:pii`. */
|
|
47
|
+
peopleNumber?: string | null;
|
|
48
|
+
/** The user asked not to be photographed as the main subject (crowd shots can still include them). */
|
|
49
|
+
photoOptOut: boolean;
|
|
50
|
+
/** The user asked not to be tagged in posts and photos online. */
|
|
51
|
+
tagOptOut: boolean;
|
|
44
52
|
emailVerifiedAt: string | null;
|
|
45
53
|
lastLoginAt: string | null;
|
|
46
54
|
createdAt: string;
|
|
@@ -49,9 +57,17 @@ type AdminUserDto = {
|
|
|
49
57
|
type ProfileDto = {
|
|
50
58
|
id: number;
|
|
51
59
|
name: string;
|
|
60
|
+
/** What the user likes to be called, or `null`. */
|
|
61
|
+
nickname: string | null;
|
|
52
62
|
email: string;
|
|
53
63
|
avatar: string | null;
|
|
54
64
|
phone: string | null;
|
|
65
|
+
/** The user's id in an external system (e.g. an event's volunteer system), or `null`. */
|
|
66
|
+
peopleNumber: string | null;
|
|
67
|
+
/** No photos with the user as the main subject. Crowd shots where they are not the focus can still include them. */
|
|
68
|
+
photoOptOut: boolean;
|
|
69
|
+
/** No tagging of the user in posts and photos online. */
|
|
70
|
+
tagOptOut: boolean;
|
|
55
71
|
/** The user's language (`da`, `en-GB`), or `null`. Filled from the app's language at sign-in when unset. */
|
|
56
72
|
locale: string | null;
|
|
57
73
|
emailVerifiedAt: string | null;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addComponent, addServerImportsDir, hasNuxtModule, addPlugin,
|
|
2
|
-
import { registerTailwindSource, registerLocales, registerDatabaseTable, registerSearchIndex, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, addServerImportsDir, hasNuxtModule, addPlugin, addNitroPlugin } from '@nuxt/kit';
|
|
2
|
+
import { registerTailwindSource, registerLocales, isClientOnlyApp, registerDatabaseTable, registerSearchIndex, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource, serverModuleDependencies } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { setAuthUserStore, registerAccess } from '@frigear-nu/auth/utils';
|
|
4
4
|
import { resolveAuthMode } from '@frigear-nu/auth/mode';
|
|
5
5
|
import { setNotifyRecipientStore } from '@frigear-nu/notify/utils';
|
|
@@ -12,9 +12,7 @@ const module$1 = defineNuxtModule({
|
|
|
12
12
|
},
|
|
13
13
|
// `@frigear-nu/mcp` is only installed when `settings.mcp` is on.
|
|
14
14
|
moduleDependencies: (nuxt) => ({
|
|
15
|
-
"@nuxthub/core": {
|
|
16
|
-
version: ">=0.0.1"
|
|
17
|
-
},
|
|
15
|
+
...serverModuleDependencies(nuxt, { "@nuxthub/core": { version: ">=0.0.1" } }),
|
|
18
16
|
"@frigear-nu/module-kit": {
|
|
19
17
|
version: ">=0.0.1"
|
|
20
18
|
},
|
|
@@ -39,7 +37,7 @@ const module$1 = defineNuxtModule({
|
|
|
39
37
|
version: ">=0.0.0",
|
|
40
38
|
optional: true
|
|
41
39
|
},
|
|
42
|
-
...nuxt.options.users?.settings?.mcp === true ? { "@frigear-nu/mcp": { version: ">=0.0.1" } } : {}
|
|
40
|
+
...nuxt.options.users?.settings?.mcp === true ? serverModuleDependencies(nuxt, { "@frigear-nu/mcp": { version: ">=0.0.1" } }) : {}
|
|
43
41
|
}),
|
|
44
42
|
async setup(options, nuxt) {
|
|
45
43
|
const resolver = createResolver(import.meta.url);
|
|
@@ -47,6 +45,7 @@ const module$1 = defineNuxtModule({
|
|
|
47
45
|
registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
|
|
48
46
|
const settings = options.settings ?? {};
|
|
49
47
|
const signInHere = resolveAuthMode(nuxt) !== "resource";
|
|
48
|
+
const server = !isClientOnlyApp(nuxt);
|
|
50
49
|
if (!signInHere && settings.verifyEmailChange) {
|
|
51
50
|
console.warn("[@frigear-nu/users] `settings.verifyEmailChange` does nothing with `authentication.mode: 'resource'`: the email address changes at the issuer.");
|
|
52
51
|
}
|
|
@@ -56,10 +55,12 @@ const module$1 = defineNuxtModule({
|
|
|
56
55
|
schema: (dialect) => `./runtime/db/schema.${dialect}`
|
|
57
56
|
});
|
|
58
57
|
registerSearchIndex(nuxt, { name: "users", handler: resolver.resolve("./runtime/server/search-index") });
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (server) {
|
|
59
|
+
setAuthUserStore(nuxt, resolver.resolve("./runtime/server/user-store"));
|
|
60
|
+
setNotifyRecipientStore(nuxt, resolver.resolve("./runtime/server/notify-recipients"));
|
|
61
|
+
nuxt.hook("notify:email:templates", (sources) => sources.push({ dir: resolver.resolve("./runtime/emails") }));
|
|
62
|
+
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
63
|
+
}
|
|
63
64
|
inlineModuleRuntime(nuxt, resolver);
|
|
64
65
|
const selfRoutes = [
|
|
65
66
|
{ method: "patch", path: "me", file: "me/profile.patch" },
|
|
@@ -94,7 +95,7 @@ const module$1 = defineNuxtModule({
|
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
addModuleRoutes(resolver, selfRoutes, { base: "/api/users" });
|
|
97
|
-
if (settings.mcp === true) {
|
|
98
|
+
if (settings.mcp === true && server) {
|
|
98
99
|
const { addMcpDefinitions } = await import('@frigear-nu/mcp/utils');
|
|
99
100
|
addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
|
|
100
101
|
}
|
|
@@ -104,15 +105,15 @@ const module$1 = defineNuxtModule({
|
|
|
104
105
|
nuxt.options.runtimeConfig.users.locales = locales.map((locale) => typeof locale === "string" ? locale : locale.code);
|
|
105
106
|
if (hasNuxtModule("@nuxtjs/i18n", nuxt)) {
|
|
106
107
|
addPlugin({ src: resolver.resolve("./runtime/app/plugins/remember-locale.client"), mode: "client" });
|
|
107
|
-
if (hasNuxtModule("@nuxt/ui", nuxt)) {
|
|
108
|
+
if (hasNuxtModule("@nuxt/ui", nuxt) && resolveAuthMode(nuxt) !== "client") {
|
|
108
109
|
addPlugin({ src: resolver.resolve("./runtime/app/plugins/offer-locale.client"), mode: "client" });
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
if (hasNuxtModule("@frigear-nu/oauth-server", nuxt)) {
|
|
112
|
-
|
|
112
|
+
if (server && hasNuxtModule("@frigear-nu/oauth-server", nuxt)) {
|
|
113
|
+
addNitroPlugin(resolver.resolve("./runtime/server/plugins/oauth-claims"));
|
|
113
114
|
}
|
|
114
115
|
});
|
|
115
|
-
|
|
116
|
+
if (server) addNitroPlugin(resolver.resolve("./runtime/server/plugins/frigear-locale"));
|
|
116
117
|
const withAdmin = !!settings.admin;
|
|
117
118
|
registerAccess(nuxt, usersAccess, withAdmin ? {} : { permissions: USERS_SELF_SERVICE });
|
|
118
119
|
const adminOptions = typeof settings.admin === "object" ? settings.admin : {};
|
package/dist/runtime/access.js
CHANGED
|
@@ -6,8 +6,8 @@ export const usersAccess = defineAccess("users", {
|
|
|
6
6
|
// email address and password are not part of it: they change only in a session
|
|
7
7
|
// (`requireUser(event, { sessionOnly: true })`); staff change another user's email with the session-only
|
|
8
8
|
// `users:manage`.
|
|
9
|
-
"profile:read": { label: "Read your profile", description: "Read your own name, email, avatar and
|
|
10
|
-
"profile:write": { label: "Change your profile", description: "Change your own name, avatar and
|
|
9
|
+
"profile:read": { label: "Read your profile", description: "Read your own name, email, avatar, phone number and other profile details.", implicit: true },
|
|
10
|
+
"profile:write": { label: "Change your profile", description: "Change your own name, nickname, avatar, phone number, people number and photo choices.", implicit: true },
|
|
11
11
|
// Staff permissions (with the admin pages only), granted through roles (`admin: ['*']` covers them). Reads also work
|
|
12
12
|
// for API tokens and OAuth access tokens given them. Deleting a user and anything that touches how someone signs in
|
|
13
13
|
// (their email, sign-in links) is session only. Roles themselves are `@frigear-nu/authorization`'s.
|
|
@@ -16,12 +16,12 @@ export const usersAccess = defineAccess("users", {
|
|
|
16
16
|
// Granted to `admin` by name; give it to other staff roles in the host's `authorization.roles`. It covers an optional
|
|
17
17
|
// phone number on the new user (changing it later is `users:pii`).
|
|
18
18
|
"create": { label: "Add users", description: "Create users and email them an invite link.", grantTo: ["admin"] },
|
|
19
|
-
"update": { label: "Edit users", description: "Change a user's name." },
|
|
19
|
+
"update": { label: "Edit users", description: "Change a user's name and nickname." },
|
|
20
20
|
"delete": { label: "Delete users", description: "Delete users and their sign-in methods.", sessionOnly: true },
|
|
21
21
|
"manage": { label: "Manage sign-in of users", description: "Change or verify a user's email address and email them a sign-in link.", sessionOnly: true },
|
|
22
22
|
// Sensitive (`:pii`): never covered by `users:*` or `*`, only granted by name. Other modules show the phone number
|
|
23
|
-
// under their own `:pii` permission (`crew:pii`, `shifts:pii`).
|
|
24
|
-
"pii": { label: "See users' phone numbers", description: "See and change the phone number of other users.", grantTo: ["admin"] }
|
|
23
|
+
// under their own `:pii` permission (`crew:pii`, `shifts:pii`). The people number (an id in an external system) too.
|
|
24
|
+
"pii": { label: "See users' phone and people numbers", description: "See and change the phone number and people number of other users.", grantTo: ["admin"] }
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
export const USERS_SELF_SERVICE = ["profile:read", "profile:write"];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
|
+
import { userDisplayName } from "../../utils/profile";
|
|
3
4
|
import { ADMIN_USERS_KEY } from "../utils/admin-user";
|
|
4
5
|
import { useUserActions } from "../composables/useUserActions";
|
|
5
6
|
import { computed, emptyCell, errorMessage, h, navigateTo, resolveComponent, tableUi, useFetch, useFormat, useModuleT, useTableQuery, useTableSort } from "#imports";
|
|
@@ -9,7 +10,7 @@ const format = useFormat();
|
|
|
9
10
|
const actions = useUserActions();
|
|
10
11
|
const { page, pageSize, search, sort: sortState, filters, query, filtered, reset } = useTableQuery({
|
|
11
12
|
sort: { id: "createdAt", desc: true },
|
|
12
|
-
filters: { verified: "all", role: "all" }
|
|
13
|
+
filters: { verified: "all", role: "all", mediaOptOut: "all" }
|
|
13
14
|
});
|
|
14
15
|
const sort = useTableSort(null, sortState);
|
|
15
16
|
const { sorting } = sort;
|
|
@@ -32,15 +33,19 @@ const StatusBadge = resolveComponent("StatusBadge");
|
|
|
32
33
|
const TableIdentity = resolveComponent("TableIdentity");
|
|
33
34
|
const RowMenu = resolveComponent("RowMenu");
|
|
34
35
|
const dateCell = (value) => value ? h("time", { datetime: value, title: format.dateTime(value), class: "tabular-nums" }, format.date(value)) : emptyCell();
|
|
36
|
+
const mediaBadges = (user) => [
|
|
37
|
+
user.photoOptOut ? h(StatusBadge, { status: "noPhotos", colors: { nophotos: "warning" }, icon: "i-lucide-camera-off", size: "sm", label: t("admin.media.noPhotos", "No photos") }) : null,
|
|
38
|
+
user.tagOptOut ? h(StatusBadge, { status: "noTagging", colors: { notagging: "warning" }, icon: "i-lucide-tag", size: "sm", label: t("admin.media.noTagging", "No tagging") }) : null
|
|
39
|
+
].filter(Boolean);
|
|
35
40
|
const columns = computed(() => [
|
|
36
41
|
{
|
|
37
42
|
accessorKey: "name",
|
|
38
43
|
header: sort.header("name", t("admin.user", "User")),
|
|
39
44
|
cell: ({ row }) => h(TableIdentity, {
|
|
40
|
-
title: row.original
|
|
45
|
+
title: userDisplayName(row.original),
|
|
41
46
|
description: row.original.email,
|
|
42
47
|
avatar: { alt: row.original.name }
|
|
43
|
-
})
|
|
48
|
+
}, { badges: () => mediaBadges(row.original) })
|
|
44
49
|
},
|
|
45
50
|
...hasRoles.value ? [{
|
|
46
51
|
id: "role",
|
|
@@ -77,6 +82,11 @@ const columns = computed(() => [
|
|
|
77
82
|
cell: ({ row }) => h(RowMenu, { items: actions.menu(row.original), subject: row.original.name })
|
|
78
83
|
}
|
|
79
84
|
]);
|
|
85
|
+
const mediaOptOutOptions = computed(() => [
|
|
86
|
+
{ label: t("admin.media.all", "Any photo choice"), value: "all" },
|
|
87
|
+
{ label: t("admin.media.noPhotos", "No photos"), value: "photo" },
|
|
88
|
+
{ label: t("admin.media.noTagging", "No tagging"), value: "tag" }
|
|
89
|
+
]);
|
|
80
90
|
const verifiedOptions = computed(() => [
|
|
81
91
|
{ label: t("admin.filters.all", "All"), value: "all" },
|
|
82
92
|
{ label: t("admin.filters.verified", "Verified"), value: "true" },
|
|
@@ -115,13 +125,20 @@ const addUser = () => actions.create();
|
|
|
115
125
|
class="w-full max-w-sm"
|
|
116
126
|
icon="i-lucide-search"
|
|
117
127
|
:loading="pending"
|
|
118
|
-
:placeholder="t('admin.search', 'Search name or email...')"
|
|
128
|
+
:placeholder="t('admin.search', 'Search name, nickname or email...')"
|
|
119
129
|
/>
|
|
120
130
|
<USelect
|
|
121
131
|
v-model="filters.verified"
|
|
122
132
|
:items="verifiedOptions"
|
|
123
133
|
class="w-40"
|
|
124
134
|
/>
|
|
135
|
+
<USelect
|
|
136
|
+
v-model="filters.mediaOptOut"
|
|
137
|
+
:items="mediaOptOutOptions"
|
|
138
|
+
:aria-label="t('admin.media.filter', 'Photo choices')"
|
|
139
|
+
class="w-44"
|
|
140
|
+
icon="i-lucide-camera-off"
|
|
141
|
+
/>
|
|
125
142
|
<USelect
|
|
126
143
|
v-if="hasRoles"
|
|
127
144
|
v-model="filters.role"
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { userLocaleOfferKey, userLocaleToOffer } from "../../utils/locale.js";
|
|
2
2
|
import { defineNuxtPlugin, useModuleT, useToast, useUserSession, watch } from "#imports";
|
|
3
|
+
const languageName = (code, inLocale) => {
|
|
4
|
+
try {
|
|
5
|
+
return new Intl.DisplayNames([inLocale], { type: "language" }).of(code);
|
|
6
|
+
} catch {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
3
10
|
export default defineNuxtPlugin({
|
|
4
11
|
name: "users:offer-locale",
|
|
5
12
|
dependsOn: ["i18n:plugin"],
|
|
@@ -9,7 +16,6 @@ export default defineNuxtPlugin({
|
|
|
9
16
|
nuxtApp.hook("app:mounted", () => {
|
|
10
17
|
const { loggedIn, user } = useUserSession();
|
|
11
18
|
const toast = useToast();
|
|
12
|
-
const t = useModuleT("users");
|
|
13
19
|
const offered = /* @__PURE__ */ new Set();
|
|
14
20
|
const answered = (key) => {
|
|
15
21
|
try {
|
|
@@ -24,7 +30,7 @@ export default defineNuxtPlugin({
|
|
|
24
30
|
} catch {
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
|
-
const offer = () => {
|
|
33
|
+
const offer = async () => {
|
|
28
34
|
const current = user.value;
|
|
29
35
|
if (!loggedIn.value || !current) return;
|
|
30
36
|
const locales = i18n.locales.value.map((locale2) => typeof locale2 === "string" ? { code: locale2 } : locale2);
|
|
@@ -33,7 +39,15 @@ export default defineNuxtPlugin({
|
|
|
33
39
|
const key = userLocaleOfferKey(current.id, locale);
|
|
34
40
|
if (offered.has(key) || answered(key)) return;
|
|
35
41
|
offered.add(key);
|
|
42
|
+
try {
|
|
43
|
+
await i18n.loadLocaleMessages?.(locale);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
if (i18n.locale.value === locale) return;
|
|
47
|
+
const t = nuxtApp.runWithContext(() => useModuleT("users", { locale }));
|
|
36
48
|
const language = locales.find((item) => item.code === locale)?.name ?? locale;
|
|
49
|
+
const page = i18n.locale.value;
|
|
50
|
+
const pageLanguage = languageName(page, locale) ?? locales.find((item) => item.code === page)?.name ?? page;
|
|
37
51
|
toast.add({
|
|
38
52
|
"id": "users:offer-locale",
|
|
39
53
|
"title": t("offerLocale.title", "Your language is {language}", { language }),
|
|
@@ -47,6 +61,11 @@ export default defineNuxtPlugin({
|
|
|
47
61
|
remember(key);
|
|
48
62
|
void i18n.setLocale(locale);
|
|
49
63
|
}
|
|
64
|
+
}, {
|
|
65
|
+
// Closes the toast, which remembers the answer like any other close.
|
|
66
|
+
label: t("offerLocale.keep", "Keep {language} for now", { language: pageLanguage }),
|
|
67
|
+
color: "neutral",
|
|
68
|
+
variant: "outline"
|
|
50
69
|
}],
|
|
51
70
|
// Closed by hand or timed out: not offered again this session.
|
|
52
71
|
"onUpdate:open": (open) => {
|
|
@@ -57,7 +76,7 @@ export default defineNuxtPlugin({
|
|
|
57
76
|
let timer;
|
|
58
77
|
watch([loggedIn, () => user.value?.locale, () => i18n.locale.value], () => {
|
|
59
78
|
clearTimeout(timer);
|
|
60
|
-
timer = setTimeout(offer, 1e3);
|
|
79
|
+
timer = setTimeout(() => void offer(), 1e3);
|
|
61
80
|
}, { immediate: true });
|
|
62
81
|
});
|
|
63
82
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
3
|
import { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from "../../utils/phone";
|
|
4
|
+
import { USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH } from "../../utils/profile";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
import { $fetch, computed, reactive, resolveComponent, useAction, useFormat, useModuleT, watch } from "#imports";
|
|
6
7
|
defineOptions({ name: "UsersAdminOverviewTab" });
|
|
@@ -15,14 +16,24 @@ const OverviewWidgets = resolveComponent("WidgetArea");
|
|
|
15
16
|
const overviewWidgets = typeof OverviewWidgets === "string" ? void 0 : OverviewWidgets;
|
|
16
17
|
const schema = z.object({
|
|
17
18
|
name: z.string().trim().min(1, t("admin.nameRequired", "Enter a name.")).max(120),
|
|
19
|
+
nickname: z.string().trim().max(USER_NICKNAME_MAX_LENGTH, t("admin.nicknameTooLong", "Use at most {max} characters.", { max: USER_NICKNAME_MAX_LENGTH })),
|
|
18
20
|
email: z.string().trim().email(t("admin.emailInvalid", "Enter a valid email address.")),
|
|
19
21
|
emailVerified: z.boolean(),
|
|
20
22
|
// The server's rule (`phoneField`): digits, spaces and `+-().`; empty clears it.
|
|
21
|
-
phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("admin.phoneInvalid", "Enter a phone number of digits, spaces and + - ( )."))
|
|
23
|
+
phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("admin.phoneInvalid", "Enter a phone number of digits, spaces and + - ( ).")),
|
|
24
|
+
// The server's rule (`peopleNumberField`): at most 64 characters; empty clears it.
|
|
25
|
+
peopleNumber: z.string().trim().max(USER_PEOPLE_NUMBER_MAX_LENGTH, t("admin.peopleNumberTooLong", "Use at most {max} characters.", { max: USER_PEOPLE_NUMBER_MAX_LENGTH }))
|
|
22
26
|
});
|
|
23
|
-
const form = reactive({ name: "", email: "", emailVerified: false, phone: "" });
|
|
27
|
+
const form = reactive({ name: "", nickname: "", email: "", emailVerified: false, phone: "", peopleNumber: "" });
|
|
24
28
|
function fill(value) {
|
|
25
|
-
Object.assign(form, {
|
|
29
|
+
Object.assign(form, {
|
|
30
|
+
name: value.name,
|
|
31
|
+
nickname: value.nickname ?? "",
|
|
32
|
+
email: value.email,
|
|
33
|
+
emailVerified: !!value.emailVerifiedAt,
|
|
34
|
+
phone: value.phone ?? "",
|
|
35
|
+
peopleNumber: value.peopleNumber ?? ""
|
|
36
|
+
});
|
|
26
37
|
}
|
|
27
38
|
fill(props.user);
|
|
28
39
|
watch(() => props.user, fill);
|
|
@@ -32,21 +43,29 @@ const accountFacts = computed(() => [
|
|
|
32
43
|
{ key: "password", label: t("admin.detail.password", "Password"), value: props.user.hasPassword ? t("admin.detail.set", "Set") : null },
|
|
33
44
|
{ key: "passkeys", label: t("admin.detail.passkeys", "Passkeys"), value: props.user.passkeys }
|
|
34
45
|
]);
|
|
35
|
-
const
|
|
46
|
+
const mediaFacts = computed(() => [
|
|
47
|
+
{ key: "photoOptOut", label: t("admin.media.photos", "Photos"), value: props.user.photoOptOut ? t("admin.media.photosOptOut", "Do not photograph as the main subject") : t("admin.media.allowed", "No objection") },
|
|
48
|
+
{ key: "tagOptOut", label: t("admin.media.tagging", "Tagging online"), value: props.user.tagOptOut ? t("admin.media.taggingOptOut", "Do not tag in posts or photos") : t("admin.media.allowed", "No objection") }
|
|
49
|
+
]);
|
|
50
|
+
const dirty = computed(() => form.name !== props.user.name || form.nickname.trim() !== (props.user.nickname ?? "") || form.email !== props.user.email || form.emailVerified !== !!props.user.emailVerifiedAt || props.user.can.pii && form.phone.trim() !== (props.user.phone ?? "") || props.user.can.pii && form.peopleNumber.trim() !== (props.user.peopleNumber ?? ""));
|
|
36
51
|
async function save(event) {
|
|
37
|
-
const { name, email, emailVerified, phone } = event.data;
|
|
52
|
+
const { name, nickname, email, emailVerified, phone, peopleNumber } = event.data;
|
|
38
53
|
const emailChanged = email !== props.user.email;
|
|
54
|
+
const nicknameChanged = nickname !== (props.user.nickname ?? "");
|
|
39
55
|
const phoneChanged = props.user.can.pii && phone !== (props.user.phone ?? "");
|
|
56
|
+
const peopleNumberChanged = props.user.can.pii && peopleNumber !== (props.user.peopleNumber ?? "");
|
|
40
57
|
const saved = await run(
|
|
41
58
|
() => $fetch(usersApi.admin.user(props.user.id), {
|
|
42
59
|
method: "PATCH",
|
|
43
60
|
body: {
|
|
44
61
|
name,
|
|
62
|
+
...nicknameChanged ? { nickname: nickname || null } : {},
|
|
45
63
|
...emailChanged ? { email } : {},
|
|
46
64
|
// An unchanged address keeps its state unless staff toggled it; a changed one is verified by email. Both
|
|
47
65
|
// need `users:manage`, so they are only sent when they change.
|
|
48
66
|
...!emailChanged && emailVerified !== !!props.user.emailVerifiedAt ? { emailVerified } : {},
|
|
49
|
-
...phoneChanged ? { phone: phone || null } : {}
|
|
67
|
+
...phoneChanged ? { phone: phone || null } : {},
|
|
68
|
+
...peopleNumberChanged ? { peopleNumber: peopleNumber || null } : {}
|
|
50
69
|
}
|
|
51
70
|
}).then(() => true),
|
|
52
71
|
{ success: emailChanged ? t("admin.detail.savedEmail", "Saved. A verification email was sent to the new address.") : t("admin.detail.saved", "Saved.") }
|
|
@@ -84,6 +103,17 @@ async function save(event) {
|
|
|
84
103
|
:disabled="!user.can.update"
|
|
85
104
|
/>
|
|
86
105
|
</FormRow>
|
|
106
|
+
<FormRow
|
|
107
|
+
name="nickname"
|
|
108
|
+
:label="t('admin.nickname', 'Nickname')"
|
|
109
|
+
:description="t('admin.detail.nicknameHelp', 'What they like to be called. Leave it empty to remove it.')"
|
|
110
|
+
>
|
|
111
|
+
<UInput
|
|
112
|
+
v-model="form.nickname"
|
|
113
|
+
class="w-full sm:max-w-sm"
|
|
114
|
+
:disabled="!user.can.update"
|
|
115
|
+
/>
|
|
116
|
+
</FormRow>
|
|
87
117
|
<FormRow
|
|
88
118
|
name="email"
|
|
89
119
|
:label="t('admin.email', 'Email')"
|
|
@@ -121,6 +151,19 @@ async function save(event) {
|
|
|
121
151
|
:disabled="!user.can.pii"
|
|
122
152
|
/>
|
|
123
153
|
</FormRow>
|
|
154
|
+
<FormRow
|
|
155
|
+
v-if="user.peopleNumber !== void 0"
|
|
156
|
+
name="peopleNumber"
|
|
157
|
+
:label="t('admin.peopleNumber', 'People number')"
|
|
158
|
+
:description="t('admin.detail.peopleNumberHelp', 'Their id in an external system, such as a volunteer system. Leave it empty to remove it.')"
|
|
159
|
+
>
|
|
160
|
+
<UInput
|
|
161
|
+
v-model="form.peopleNumber"
|
|
162
|
+
autocomplete="off"
|
|
163
|
+
class="w-full sm:max-w-sm"
|
|
164
|
+
:disabled="!user.can.pii"
|
|
165
|
+
/>
|
|
166
|
+
</FormRow>
|
|
124
167
|
</UForm>
|
|
125
168
|
<template #footer>
|
|
126
169
|
<div class="flex justify-end">
|
|
@@ -135,9 +178,30 @@ async function save(event) {
|
|
|
135
178
|
</template>
|
|
136
179
|
</SectionCard>
|
|
137
180
|
|
|
138
|
-
<
|
|
139
|
-
<
|
|
140
|
-
|
|
181
|
+
<div class="flex flex-col gap-4">
|
|
182
|
+
<SectionCard :title="t('admin.detail.account', 'Account')">
|
|
183
|
+
<DescriptionList :items="accountFacts" />
|
|
184
|
+
</SectionCard>
|
|
185
|
+
<SectionCard
|
|
186
|
+
:title="t('admin.media.title', 'Photos and tagging')"
|
|
187
|
+
:description="t('admin.media.description', 'The user\'s own choice, changed on their profile.')"
|
|
188
|
+
>
|
|
189
|
+
<!-- Label above value: this column is narrow, and the values are sentences. -->
|
|
190
|
+
<dl class="flex flex-col gap-3 text-sm">
|
|
191
|
+
<div
|
|
192
|
+
v-for="fact in mediaFacts"
|
|
193
|
+
:key="fact.key"
|
|
194
|
+
>
|
|
195
|
+
<dt class="text-muted">
|
|
196
|
+
{{ fact.label }}
|
|
197
|
+
</dt>
|
|
198
|
+
<dd class="text-highlighted">
|
|
199
|
+
{{ fact.value }}
|
|
200
|
+
</dd>
|
|
201
|
+
</div>
|
|
202
|
+
</dl>
|
|
203
|
+
</SectionCard>
|
|
204
|
+
</div>
|
|
141
205
|
</div>
|
|
142
206
|
</div>
|
|
143
207
|
</template>
|
|
@@ -36,6 +36,23 @@ export declare const users: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
36
36
|
identity: undefined;
|
|
37
37
|
generated: undefined;
|
|
38
38
|
}, {}, {}>;
|
|
39
|
+
nickname: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
|
+
name: "nickname";
|
|
41
|
+
tableName: "users";
|
|
42
|
+
dataType: "string";
|
|
43
|
+
columnType: "PgText";
|
|
44
|
+
data: string;
|
|
45
|
+
driverParam: string;
|
|
46
|
+
notNull: false;
|
|
47
|
+
hasDefault: false;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: [string, ...string[]];
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
39
56
|
searchText: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
57
|
name: "searchText";
|
|
41
58
|
tableName: "users";
|
|
@@ -104,6 +121,57 @@ export declare const users: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
104
121
|
identity: undefined;
|
|
105
122
|
generated: undefined;
|
|
106
123
|
}, {}, {}>;
|
|
124
|
+
peopleNumber: import("drizzle-orm/pg-core").PgColumn<{
|
|
125
|
+
name: "peopleNumber";
|
|
126
|
+
tableName: "users";
|
|
127
|
+
dataType: "string";
|
|
128
|
+
columnType: "PgText";
|
|
129
|
+
data: string;
|
|
130
|
+
driverParam: string;
|
|
131
|
+
notNull: false;
|
|
132
|
+
hasDefault: false;
|
|
133
|
+
isPrimaryKey: false;
|
|
134
|
+
isAutoincrement: false;
|
|
135
|
+
hasRuntimeDefault: false;
|
|
136
|
+
enumValues: [string, ...string[]];
|
|
137
|
+
baseColumn: never;
|
|
138
|
+
identity: undefined;
|
|
139
|
+
generated: undefined;
|
|
140
|
+
}, {}, {}>;
|
|
141
|
+
photoOptOut: import("drizzle-orm/pg-core").PgColumn<{
|
|
142
|
+
name: "photoOptOut";
|
|
143
|
+
tableName: "users";
|
|
144
|
+
dataType: "boolean";
|
|
145
|
+
columnType: "PgBoolean";
|
|
146
|
+
data: boolean;
|
|
147
|
+
driverParam: boolean;
|
|
148
|
+
notNull: true;
|
|
149
|
+
hasDefault: true;
|
|
150
|
+
isPrimaryKey: false;
|
|
151
|
+
isAutoincrement: false;
|
|
152
|
+
hasRuntimeDefault: false;
|
|
153
|
+
enumValues: undefined;
|
|
154
|
+
baseColumn: never;
|
|
155
|
+
identity: undefined;
|
|
156
|
+
generated: undefined;
|
|
157
|
+
}, {}, {}>;
|
|
158
|
+
tagOptOut: import("drizzle-orm/pg-core").PgColumn<{
|
|
159
|
+
name: "tagOptOut";
|
|
160
|
+
tableName: "users";
|
|
161
|
+
dataType: "boolean";
|
|
162
|
+
columnType: "PgBoolean";
|
|
163
|
+
data: boolean;
|
|
164
|
+
driverParam: boolean;
|
|
165
|
+
notNull: true;
|
|
166
|
+
hasDefault: true;
|
|
167
|
+
isPrimaryKey: false;
|
|
168
|
+
isAutoincrement: false;
|
|
169
|
+
hasRuntimeDefault: false;
|
|
170
|
+
enumValues: undefined;
|
|
171
|
+
baseColumn: never;
|
|
172
|
+
identity: undefined;
|
|
173
|
+
generated: undefined;
|
|
174
|
+
}, {}, {}>;
|
|
107
175
|
locale: import("drizzle-orm/pg-core").PgColumn<{
|
|
108
176
|
name: "locale";
|
|
109
177
|
tableName: "users";
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { pgTable, text, serial, bigint, timestamp } from "drizzle-orm/pg-core";
|
|
1
|
+
import { pgTable, text, serial, bigint, timestamp, boolean, index } from "drizzle-orm/pg-core";
|
|
2
2
|
export const users = pgTable("users", {
|
|
3
3
|
id: serial().primaryKey(),
|
|
4
4
|
name: text().notNull(),
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
// What the user likes to be called, next to their name (at most 50 characters).
|
|
6
|
+
nickname: text(),
|
|
7
|
+
// `name` and `nickname` folded for search (`searchText` of `@frigear-nu/module-kit/server`), written with them
|
|
8
|
+
// (`withUserSearchText`): `searchUserRefs` and other modules' user searches match it.
|
|
7
9
|
searchText: text().notNull().default(""),
|
|
8
10
|
email: text().notNull().unique(),
|
|
9
11
|
avatar: text(),
|
|
10
12
|
// Personal data: shown to staff with `users:pii` only, and to other modules' staff through their own `:pii`.
|
|
11
13
|
phone: text(),
|
|
14
|
+
// The person's id in an external system (e.g. an event's volunteer system), trimmed, at most 64 characters. Typed in
|
|
15
|
+
// by the user or staff, so not unique: imports matching on it report duplicates. Personal data, like `phone`.
|
|
16
|
+
peopleNumber: text(),
|
|
17
|
+
// The user's own choices: no photos with them as the main subject, and no tagging of them in posts and photos online.
|
|
18
|
+
// Staff and team leads see them; only the user changes them.
|
|
19
|
+
photoOptOut: boolean().notNull().default(false),
|
|
20
|
+
tagOptOut: boolean().notNull().default(false),
|
|
12
21
|
// The user's language (an i18n locale code such as `da`, or a short BCP-47 tag): messages to them use it.
|
|
13
22
|
locale: text(),
|
|
14
23
|
acceptedTermsAt: bigint("accepted_terms_at", { mode: "number" }),
|
|
15
24
|
createdAt: timestamp({ withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
16
25
|
updatedAt: timestamp({ withTimezone: true }).notNull().$onUpdateFn(() => /* @__PURE__ */ new Date())
|
|
17
|
-
})
|
|
26
|
+
}, (t) => [
|
|
27
|
+
index("users_people_number_idx").on(t.peopleNumber)
|
|
28
|
+
]);
|
|
@@ -38,6 +38,25 @@ export declare const users: import("drizzle-orm/sqlite-core").SQLiteTableWithCol
|
|
|
38
38
|
}, {}, {
|
|
39
39
|
length: undefined;
|
|
40
40
|
}>;
|
|
41
|
+
nickname: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
42
|
+
name: "nickname";
|
|
43
|
+
tableName: "users";
|
|
44
|
+
dataType: "string";
|
|
45
|
+
columnType: "SQLiteText";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
notNull: false;
|
|
49
|
+
hasDefault: false;
|
|
50
|
+
isPrimaryKey: false;
|
|
51
|
+
isAutoincrement: false;
|
|
52
|
+
hasRuntimeDefault: false;
|
|
53
|
+
enumValues: [string, ...string[]];
|
|
54
|
+
baseColumn: never;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}, {}, {
|
|
58
|
+
length: undefined;
|
|
59
|
+
}>;
|
|
41
60
|
searchText: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
42
61
|
name: "searchText";
|
|
43
62
|
tableName: "users";
|
|
@@ -114,6 +133,59 @@ export declare const users: import("drizzle-orm/sqlite-core").SQLiteTableWithCol
|
|
|
114
133
|
}, {}, {
|
|
115
134
|
length: undefined;
|
|
116
135
|
}>;
|
|
136
|
+
peopleNumber: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
137
|
+
name: "peopleNumber";
|
|
138
|
+
tableName: "users";
|
|
139
|
+
dataType: "string";
|
|
140
|
+
columnType: "SQLiteText";
|
|
141
|
+
data: string;
|
|
142
|
+
driverParam: string;
|
|
143
|
+
notNull: false;
|
|
144
|
+
hasDefault: false;
|
|
145
|
+
isPrimaryKey: false;
|
|
146
|
+
isAutoincrement: false;
|
|
147
|
+
hasRuntimeDefault: false;
|
|
148
|
+
enumValues: [string, ...string[]];
|
|
149
|
+
baseColumn: never;
|
|
150
|
+
identity: undefined;
|
|
151
|
+
generated: undefined;
|
|
152
|
+
}, {}, {
|
|
153
|
+
length: undefined;
|
|
154
|
+
}>;
|
|
155
|
+
photoOptOut: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
156
|
+
name: "photoOptOut";
|
|
157
|
+
tableName: "users";
|
|
158
|
+
dataType: "boolean";
|
|
159
|
+
columnType: "SQLiteBoolean";
|
|
160
|
+
data: boolean;
|
|
161
|
+
driverParam: number;
|
|
162
|
+
notNull: true;
|
|
163
|
+
hasDefault: true;
|
|
164
|
+
isPrimaryKey: false;
|
|
165
|
+
isAutoincrement: false;
|
|
166
|
+
hasRuntimeDefault: false;
|
|
167
|
+
enumValues: undefined;
|
|
168
|
+
baseColumn: never;
|
|
169
|
+
identity: undefined;
|
|
170
|
+
generated: undefined;
|
|
171
|
+
}, {}, {}>;
|
|
172
|
+
tagOptOut: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
173
|
+
name: "tagOptOut";
|
|
174
|
+
tableName: "users";
|
|
175
|
+
dataType: "boolean";
|
|
176
|
+
columnType: "SQLiteBoolean";
|
|
177
|
+
data: boolean;
|
|
178
|
+
driverParam: number;
|
|
179
|
+
notNull: true;
|
|
180
|
+
hasDefault: true;
|
|
181
|
+
isPrimaryKey: false;
|
|
182
|
+
isAutoincrement: false;
|
|
183
|
+
hasRuntimeDefault: false;
|
|
184
|
+
enumValues: undefined;
|
|
185
|
+
baseColumn: never;
|
|
186
|
+
identity: undefined;
|
|
187
|
+
generated: undefined;
|
|
188
|
+
}, {}, {}>;
|
|
117
189
|
locale: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
118
190
|
name: "locale";
|
|
119
191
|
tableName: "users";
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
|
1
|
+
import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
|
|
2
2
|
export const users = sqliteTable("users", {
|
|
3
3
|
id: integer().primaryKey({ autoIncrement: true }),
|
|
4
4
|
name: text().notNull(),
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
// What the user likes to be called, next to their name (at most 50 characters).
|
|
6
|
+
nickname: text(),
|
|
7
|
+
// `name` and `nickname` folded for search (`searchText` of `@frigear-nu/module-kit/server`), written with them
|
|
8
|
+
// (`withUserSearchText`): `searchUserRefs` and other modules' user searches match it.
|
|
7
9
|
searchText: text().notNull().default(""),
|
|
8
10
|
email: text().notNull().unique(),
|
|
9
11
|
avatar: text(),
|
|
10
12
|
// Personal data: shown to staff with `users:pii` only, and to other modules' staff through their own `:pii`.
|
|
11
13
|
phone: text(),
|
|
14
|
+
// The person's id in an external system (e.g. an event's volunteer system), trimmed, at most 64 characters. Typed in
|
|
15
|
+
// by the user or staff, so not unique: imports matching on it report duplicates. Personal data, like `phone`.
|
|
16
|
+
peopleNumber: text(),
|
|
17
|
+
// The user's own choices: no photos with them as the main subject, and no tagging of them in posts and photos online.
|
|
18
|
+
// Staff and team leads see them; only the user changes them.
|
|
19
|
+
photoOptOut: integer({ mode: "boolean" }).notNull().default(false),
|
|
20
|
+
tagOptOut: integer({ mode: "boolean" }).notNull().default(false),
|
|
12
21
|
// The user's language (an i18n locale code such as `da`, or a short BCP-47 tag): messages to them use it.
|
|
13
22
|
locale: text(),
|
|
14
23
|
acceptedTermsAt: integer("accepted_terms_at"),
|
|
15
24
|
createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
16
25
|
updatedAt: integer({ mode: "timestamp" }).notNull().$onUpdateFn(() => /* @__PURE__ */ new Date())
|
|
17
|
-
})
|
|
26
|
+
}, (t) => [
|
|
27
|
+
index("users_people_number_idx").on(t.peopleNumber)
|
|
28
|
+
]);
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"description": "Tilmeldt inden for de seneste 30 dage.",
|
|
26
26
|
"empty": "Ingen nye endnu."
|
|
27
27
|
},
|
|
28
|
-
"search": "Søg i navn eller e-mail...",
|
|
28
|
+
"search": "Søg i navn, kaldenavn eller e-mail...",
|
|
29
29
|
"empty": "Ingen brugere matcher",
|
|
30
30
|
"total": "{count} brugere",
|
|
31
31
|
"lastLogin": "Seneste login",
|
|
@@ -53,7 +53,9 @@
|
|
|
53
53
|
"never": "Aldrig",
|
|
54
54
|
"saveProfile": "Gem profil",
|
|
55
55
|
"notFoundHint": "Den er måske slettet.",
|
|
56
|
-
"phoneHelp": "Bruges til sms'er. Lad feltet stå tomt for at fjerne det."
|
|
56
|
+
"phoneHelp": "Bruges til sms'er. Lad feltet stå tomt for at fjerne det.",
|
|
57
|
+
"nicknameHelp": "Det, personen gerne vil kaldes. Lad feltet stå tomt for at fjerne det.",
|
|
58
|
+
"peopleNumberHelp": "Personens id i et eksternt system, fx et frivilligsystem. Lad feltet stå tomt for at fjerne det."
|
|
57
59
|
},
|
|
58
60
|
"tabs": {
|
|
59
61
|
"overview": "Oversigt"
|
|
@@ -85,7 +87,24 @@
|
|
|
85
87
|
"selectExisting": "Vælg eksisterende bruger",
|
|
86
88
|
"createPhoneHelp": "Valgfrit. Bruges til sms.",
|
|
87
89
|
"sendInvite": "Send invitation på e-mail",
|
|
88
|
-
"sendInviteHelp": "Et engangslink til at logge ind og bekræfte adressen, gyldigt i flere dage."
|
|
90
|
+
"sendInviteHelp": "Et engangslink til at logge ind og bekræfte adressen, gyldigt i flere dage.",
|
|
91
|
+
"nickname": "Kaldenavn",
|
|
92
|
+
"peopleNumber": "Eksternt ID",
|
|
93
|
+
"nicknameTooLong": "Brug højst {max} tegn.",
|
|
94
|
+
"peopleNumberTooLong": "Brug højst {max} tegn.",
|
|
95
|
+
"media": {
|
|
96
|
+
"title": "Fotos og tagging",
|
|
97
|
+
"description": "Brugerens eget valg, som ændres på deres profil.",
|
|
98
|
+
"filter": "Fotovalg",
|
|
99
|
+
"all": "Alle fotovalg",
|
|
100
|
+
"noPhotos": "Ingen fotos",
|
|
101
|
+
"noTagging": "Ingen tagging",
|
|
102
|
+
"photos": "Fotos",
|
|
103
|
+
"photosOptOut": "Må ikke fotograferes som hovedmotiv",
|
|
104
|
+
"tagging": "Tagging online",
|
|
105
|
+
"taggingOptOut": "Må ikke tagges i opslag eller på fotos",
|
|
106
|
+
"allowed": "Ingen indvendinger"
|
|
107
|
+
}
|
|
89
108
|
},
|
|
90
109
|
"emailChange": {
|
|
91
110
|
"verify": {
|
|
@@ -137,7 +156,7 @@
|
|
|
137
156
|
"update": "Redigere brugere",
|
|
138
157
|
"delete": "Slette brugere",
|
|
139
158
|
"manage": "Administrere brugeres login",
|
|
140
|
-
"pii": "Se brugeres telefonnumre"
|
|
159
|
+
"pii": "Se brugeres telefonnumre og eksterne ID'er"
|
|
141
160
|
},
|
|
142
161
|
"picker": {
|
|
143
162
|
"placeholder": "Søg efter personer",
|
|
@@ -148,7 +167,8 @@
|
|
|
148
167
|
"offerLocale": {
|
|
149
168
|
"title": "Dit sprog er {language}",
|
|
150
169
|
"description": "Din konto er sat til {language}. Vil du se siden på det sprog?",
|
|
151
|
-
"switch": "Skift til {language}"
|
|
170
|
+
"switch": "Skift til {language}",
|
|
171
|
+
"keep": "Behold {language} indtil videre"
|
|
152
172
|
}
|
|
153
173
|
}
|
|
154
174
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"description": "Signed up in the last 30 days.",
|
|
26
26
|
"empty": "Nobody new yet."
|
|
27
27
|
},
|
|
28
|
-
"search": "Search name or email...",
|
|
28
|
+
"search": "Search name, nickname or email...",
|
|
29
29
|
"empty": "No users match",
|
|
30
30
|
"total": "{count} users",
|
|
31
31
|
"lastLogin": "Last sign-in",
|
|
@@ -53,7 +53,9 @@
|
|
|
53
53
|
"never": "Never",
|
|
54
54
|
"saveProfile": "Save profile",
|
|
55
55
|
"notFoundHint": "It may have been deleted.",
|
|
56
|
-
"phoneHelp": "Used for text messages. Leave it empty to remove it."
|
|
56
|
+
"phoneHelp": "Used for text messages. Leave it empty to remove it.",
|
|
57
|
+
"nicknameHelp": "What they like to be called. Leave it empty to remove it.",
|
|
58
|
+
"peopleNumberHelp": "Their id in an external system, such as a volunteer system. Leave it empty to remove it."
|
|
57
59
|
},
|
|
58
60
|
"tabs": {
|
|
59
61
|
"overview": "Overview"
|
|
@@ -85,7 +87,24 @@
|
|
|
85
87
|
"selectExisting": "Select existing user",
|
|
86
88
|
"createPhoneHelp": "Optional. Used for text messages.",
|
|
87
89
|
"sendInvite": "Send invite email",
|
|
88
|
-
"sendInviteHelp": "A single-use link to sign in and verify the address, valid for several days."
|
|
90
|
+
"sendInviteHelp": "A single-use link to sign in and verify the address, valid for several days.",
|
|
91
|
+
"nickname": "Nickname",
|
|
92
|
+
"peopleNumber": "People number",
|
|
93
|
+
"nicknameTooLong": "Use at most {max} characters.",
|
|
94
|
+
"peopleNumberTooLong": "Use at most {max} characters.",
|
|
95
|
+
"media": {
|
|
96
|
+
"title": "Photos and tagging",
|
|
97
|
+
"description": "The user's own choice, changed on their profile.",
|
|
98
|
+
"filter": "Photo choices",
|
|
99
|
+
"all": "Any photo choice",
|
|
100
|
+
"noPhotos": "No photos",
|
|
101
|
+
"noTagging": "No tagging",
|
|
102
|
+
"photos": "Photos",
|
|
103
|
+
"photosOptOut": "Do not photograph as the main subject",
|
|
104
|
+
"tagging": "Tagging online",
|
|
105
|
+
"taggingOptOut": "Do not tag in posts or photos",
|
|
106
|
+
"allowed": "No objection"
|
|
107
|
+
}
|
|
89
108
|
},
|
|
90
109
|
"emailChange": {
|
|
91
110
|
"verify": {
|
|
@@ -137,7 +156,7 @@
|
|
|
137
156
|
"update": "Edit users",
|
|
138
157
|
"delete": "Delete users",
|
|
139
158
|
"manage": "Manage sign-in of users",
|
|
140
|
-
"pii": "See users' phone numbers"
|
|
159
|
+
"pii": "See users' phone and people numbers"
|
|
141
160
|
},
|
|
142
161
|
"picker": {
|
|
143
162
|
"placeholder": "Search people",
|
|
@@ -148,7 +167,8 @@
|
|
|
148
167
|
"offerLocale": {
|
|
149
168
|
"title": "Your language is {language}",
|
|
150
169
|
"description": "Your account is set to {language}. Show this site in it?",
|
|
151
|
-
"switch": "Switch to {language}"
|
|
170
|
+
"switch": "Switch to {language}",
|
|
171
|
+
"keep": "Keep {language} for now"
|
|
152
172
|
}
|
|
153
173
|
}
|
|
154
174
|
}
|
|
@@ -2,13 +2,18 @@ import { db, schema } from "@nuxthub/db";
|
|
|
2
2
|
import { eq } from "drizzle-orm";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { usersAccess } from "../../../access.js";
|
|
5
|
-
import { emailField, nameField, phoneField } from "../../schemas.js";
|
|
5
|
+
import { emailField, nameField, nicknameField, peopleNumberField, phoneField } from "../../schemas.js";
|
|
6
6
|
const bodySchema = z.object({
|
|
7
7
|
name: nameField().optional(),
|
|
8
|
+
// `null` or an empty string clears it.
|
|
9
|
+
nickname: nicknameField().optional(),
|
|
8
10
|
email: emailField().optional(),
|
|
9
11
|
emailVerified: z.boolean().optional(),
|
|
10
12
|
// `null` or an empty string clears it; changing it needs `users:pii` as well.
|
|
11
|
-
phone: phoneField().optional()
|
|
13
|
+
phone: phoneField().optional(),
|
|
14
|
+
// The person's id in an external system: personal data like the phone number, so `users:pii` as well. The media
|
|
15
|
+
// opt-outs are not here: they are the user's own choice.
|
|
16
|
+
peopleNumber: peopleNumberField().optional()
|
|
12
17
|
});
|
|
13
18
|
export default defineEventHandler(async (event) => {
|
|
14
19
|
const { target } = await loadUsersAdminTarget(event, "update");
|
|
@@ -16,12 +21,18 @@ export default defineEventHandler(async (event) => {
|
|
|
16
21
|
const emailChanged = !!input.email && !sameUserEmail(input.email, target.email);
|
|
17
22
|
if (emailChanged || input.emailVerified !== void 0) await authorize(event, USERS_MANAGE_PERMISSION, target);
|
|
18
23
|
if (emailChanged) await assertEmailAvailable(input.email, { exceptUserId: target.id });
|
|
19
|
-
if (input.phone !== void 0) await authorize(event, usersAccess.permissions.pii, target);
|
|
24
|
+
if (input.phone !== void 0 || input.peopleNumber !== void 0) await authorize(event, usersAccess.permissions.pii, target);
|
|
20
25
|
const phoneChanged = input.phone !== void 0 && input.phone !== (target.phone ?? null);
|
|
21
|
-
const
|
|
26
|
+
const peopleNumberChanged = input.peopleNumber !== void 0 && input.peopleNumber !== (target.peopleNumber ?? null);
|
|
27
|
+
const pii = input.phone !== void 0 || input.peopleNumber !== void 0 || await allows(event, usersAccess.permissions.pii, target);
|
|
28
|
+
const nicknameChanged = input.nickname !== void 0 && input.nickname !== (target.nickname ?? null);
|
|
22
29
|
const changes = {
|
|
23
|
-
...input.name ? withUserSearchText({
|
|
30
|
+
...input.name || nicknameChanged ? withUserSearchText({
|
|
31
|
+
...input.name ? { name: input.name } : {},
|
|
32
|
+
...nicknameChanged ? { nickname: input.nickname } : {}
|
|
33
|
+
}, target) : {},
|
|
24
34
|
...phoneChanged ? { phone: input.phone } : {},
|
|
35
|
+
...peopleNumberChanged ? { peopleNumber: input.peopleNumber } : {},
|
|
25
36
|
// A changed address was typed in by staff, so it is unverified until its owner confirms it (unless staff
|
|
26
37
|
// explicitly marks it verified in the same request).
|
|
27
38
|
...emailChanged ? { email: input.email, emailVerifiedAt: input.emailVerified ? /* @__PURE__ */ new Date() : null } : {},
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { db, schema } from "@nuxthub/db";
|
|
2
|
-
import { and, asc, count, inArray, isNotNull, isNull, or, sql } from "drizzle-orm";
|
|
2
|
+
import { and, asc, count, eq, inArray, isNotNull, isNull, or, sql } from "drizzle-orm";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { likeContains, orderByQuery, pageQuery, pageRange, paginate, searchContains } from "@frigear-nu/module-kit/server";
|
|
5
|
+
import { usersAccess } from "../../../access.js";
|
|
6
|
+
import { USER_MEDIA_OPT_OUTS, normalizeUserPeopleNumber } from "../../../utils/profile.js";
|
|
5
7
|
const querySchema = pageQuery({
|
|
6
8
|
sort: ["id", "name", "email", "role", "createdAt", "lastLoginAt"],
|
|
7
9
|
defaultSort: "createdAt",
|
|
8
10
|
filters: {
|
|
9
11
|
role: z.string().trim().min(1).max(60).optional(),
|
|
10
|
-
verified: z.enum(["true", "false"]).optional()
|
|
12
|
+
verified: z.enum(["true", "false"]).optional(),
|
|
13
|
+
// Users who opted out of photos (`photo`) or of tagging (`tag`).
|
|
14
|
+
mediaOptOut: z.enum(USER_MEDIA_OPT_OUTS).optional()
|
|
11
15
|
}
|
|
12
16
|
});
|
|
13
17
|
export default defineEventHandler(async (event) => {
|
|
@@ -15,7 +19,12 @@ export default defineEventHandler(async (event) => {
|
|
|
15
19
|
const query = await getValidatedQuery(event, querySchema.parse);
|
|
16
20
|
const userRoles = usersRoleAssignments();
|
|
17
21
|
const conditions = [];
|
|
18
|
-
if (query.q)
|
|
22
|
+
if (query.q) {
|
|
23
|
+
const peopleNumber = normalizeUserPeopleNumber(query.q);
|
|
24
|
+
const byPeopleNumber = peopleNumber && await allows(event, usersAccess.permissions.pii) ? eq(schema.users.peopleNumber, peopleNumber) : void 0;
|
|
25
|
+
conditions.push(or(searchContains(schema.users.searchText, query.q), likeContains(schema.users.email, query.q), byPeopleNumber));
|
|
26
|
+
}
|
|
27
|
+
if (query.mediaOptOut) conditions.push(eq(query.mediaOptOut === "photo" ? schema.users.photoOptOut : schema.users.tagOptOut, true));
|
|
19
28
|
if (query.role && userRoles) {
|
|
20
29
|
conditions.push(sql`exists (select 1 from ${userRoles} where ${userRoles.userId} = ${schema.users.id} and ${userRoles.role} = ${query.role})`);
|
|
21
30
|
}
|
|
@@ -34,6 +34,7 @@ export default defineEventHandler(async (event) => {
|
|
|
34
34
|
if (!user) {
|
|
35
35
|
throw apiError(500, "internal_error", "Failed to create the user.");
|
|
36
36
|
}
|
|
37
|
+
await notifyAuthUserCreated({ event, user, source: "admin" });
|
|
37
38
|
if (input.sendWelcomeEmail && useRuntimeConfig(event).public.authentication?.mode !== "resource") {
|
|
38
39
|
await sendVerificationLink(event, user, { invite: true });
|
|
39
40
|
}
|
|
@@ -2,23 +2,37 @@ import { db, schema } from "@nuxthub/db";
|
|
|
2
2
|
import { eq } from "drizzle-orm";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { notFound } from "@frigear-nu/module-kit/server";
|
|
5
|
-
import { avatarField, localeField, nameField, phoneField } from "../../schemas.js";
|
|
5
|
+
import { avatarField, localeField, nameField, nicknameField, peopleNumberField, phoneField } from "../../schemas.js";
|
|
6
6
|
const bodySchema = (locales) => z.object({
|
|
7
7
|
name: nameField().optional(),
|
|
8
|
+
// `null` or an empty string clears the nickname; leaving it out keeps it.
|
|
9
|
+
nickname: nicknameField().optional(),
|
|
8
10
|
// `null` clears the avatar; leaving it out keeps it.
|
|
9
11
|
avatar: avatarField().optional(),
|
|
10
12
|
// `null` or an empty string clears the phone number; leaving it out keeps it.
|
|
11
13
|
phone: phoneField().optional(),
|
|
14
|
+
// The caller's id in an external system; `null` or an empty string clears it.
|
|
15
|
+
peopleNumber: peopleNumberField().optional(),
|
|
16
|
+
// The caller's own media choices: no photos of them as the main subject, no tagging online.
|
|
17
|
+
photoOptOut: z.boolean().optional(),
|
|
18
|
+
tagOptOut: z.boolean().optional(),
|
|
12
19
|
// The user's language: one of the app's i18n locales (else a short BCP-47 tag); `null` or `''` clears it.
|
|
13
20
|
locale: localeField(locales).optional()
|
|
14
21
|
});
|
|
15
22
|
export default defineEventHandler(async (event) => {
|
|
16
23
|
const { user, kind } = await authorize(event, "profile:write");
|
|
17
|
-
const { name, avatar, phone, locale } = await readValidatedBody(event, bodySchema(usersLocales()).parse);
|
|
24
|
+
const { name, nickname, avatar, phone, peopleNumber, photoOptOut, tagOptOut, locale } = await readValidatedBody(event, bodySchema(usersLocales()).parse);
|
|
25
|
+
const current = name !== void 0 || nickname !== void 0 ? (await db.select({ name: schema.users.name, nickname: schema.users.nickname }).from(schema.users).where(eq(schema.users.id, user.id)))[0] : void 0;
|
|
18
26
|
const [updated] = await db.update(schema.users).set({
|
|
19
|
-
...
|
|
27
|
+
...withUserSearchText({
|
|
28
|
+
...name !== void 0 ? { name } : {},
|
|
29
|
+
...nickname !== void 0 ? { nickname } : {}
|
|
30
|
+
}, current),
|
|
20
31
|
...avatar !== void 0 ? { avatar } : {},
|
|
21
32
|
...phone !== void 0 ? { phone } : {},
|
|
33
|
+
...peopleNumber !== void 0 ? { peopleNumber } : {},
|
|
34
|
+
...photoOptOut !== void 0 ? { photoOptOut } : {},
|
|
35
|
+
...tagOptOut !== void 0 ? { tagOptOut } : {},
|
|
22
36
|
...locale !== void 0 ? { locale } : {},
|
|
23
37
|
updatedAt: /* @__PURE__ */ new Date()
|
|
24
38
|
}).where(eq(schema.users.id, user.id)).returning();
|
|
@@ -3,6 +3,13 @@ import { z } from 'zod';
|
|
|
3
3
|
export declare const emailField: () => z.ZodString;
|
|
4
4
|
/** A display name. */
|
|
5
5
|
export declare const nameField: () => z.ZodString;
|
|
6
|
+
/** A nickname: trimmed, at most 50 characters, or `null` to clear it. An empty string clears it too. */
|
|
7
|
+
export declare const nicknameField: () => z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string | null, string>>>;
|
|
8
|
+
/**
|
|
9
|
+
* A people number (the person's id in an external system): trimmed, at most 64 characters, or `null` to clear it. An
|
|
10
|
+
* empty string clears it too. Not unique: two users may type the same number.
|
|
11
|
+
*/
|
|
12
|
+
export declare const peopleNumberField: () => z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string | null, string>>>;
|
|
6
13
|
/** An avatar: an absolute http(s) URL, or `null` to clear it. */
|
|
7
14
|
export declare const avatarField: () => z.ZodNullable<z.ZodString>;
|
|
8
15
|
/**
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from "../utils/phone.js";
|
|
3
3
|
import { USER_LOCALE_MAX_LENGTH, normalizeUserLocale } from "../utils/locale.js";
|
|
4
|
+
import { USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH } from "../utils/profile.js";
|
|
4
5
|
export const emailField = () => z.string().trim().toLowerCase().email().max(254);
|
|
5
6
|
export const nameField = () => z.string().trim().min(1).max(120);
|
|
7
|
+
const singleLine = /^[^\p{Cc}\p{Cf}]*$/u;
|
|
8
|
+
export const nicknameField = () => z.string().trim().max(USER_NICKNAME_MAX_LENGTH).regex(singleLine, { message: "Enter the nickname on one line." }).transform((value) => value || null).nullable();
|
|
9
|
+
export const peopleNumberField = () => z.string().trim().max(USER_PEOPLE_NUMBER_MAX_LENGTH).regex(singleLine, { message: "Enter the number on one line." }).transform((value) => value || null).nullable();
|
|
6
10
|
export const avatarField = () => z.string().trim().max(2048).url().refine((value) => /^https?:$/.test(new URL(value).protocol), { message: "The avatar must be an http(s) URL." }).nullable();
|
|
7
11
|
export const phoneField = () => z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, { message: "Enter a phone number of digits, spaces and + - ( )." }).transform((value) => value || null).nullable();
|
|
8
12
|
export const localeField = (known = []) => z.string().trim().max(USER_LOCALE_MAX_LENGTH).refine((value) => !value || normalizeUserLocale(value, known) !== null, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { schema } from "@nuxthub/db";
|
|
2
2
|
import { defineSearchIndex } from "@frigear-nu/module-kit/server";
|
|
3
|
-
import {
|
|
3
|
+
import { userSearchTextOf } from "./utils/user-search.js";
|
|
4
4
|
export default defineSearchIndex({
|
|
5
5
|
table: schema.users,
|
|
6
|
-
columns: (user) => ({ searchText:
|
|
6
|
+
columns: (user) => ({ searchText: userSearchTextOf({ name: user.name ?? "", nickname: user.nickname ?? null }) })
|
|
7
7
|
});
|
|
@@ -55,7 +55,8 @@ const store = {
|
|
|
55
55
|
return user;
|
|
56
56
|
},
|
|
57
57
|
async update(id, values) {
|
|
58
|
-
const
|
|
58
|
+
const current = typeof values.name === "string" ? (await db.select({ nickname: schema.users.nickname }).from(schema.users).where(eq(schema.users.id, id)))[0] : void 0;
|
|
59
|
+
const [user] = await db.update(schema.users).set(withUserSearchText(withNormalizedEmail(values), current)).where(eq(schema.users.id, id)).returning();
|
|
59
60
|
return user ?? null;
|
|
60
61
|
},
|
|
61
62
|
async remove(id) {
|
|
@@ -3,9 +3,13 @@ import type { AdminUserDto, ProfileDto } from '../../../types.js';
|
|
|
3
3
|
type UserRowLike = {
|
|
4
4
|
id: number;
|
|
5
5
|
name: string;
|
|
6
|
+
nickname?: string | null;
|
|
6
7
|
email: string;
|
|
7
8
|
avatar?: string | null;
|
|
8
9
|
phone?: string | null;
|
|
10
|
+
peopleNumber?: string | null;
|
|
11
|
+
photoOptOut?: boolean | number | null;
|
|
12
|
+
tagOptOut?: boolean | number | null;
|
|
9
13
|
locale?: string | null;
|
|
10
14
|
emailVerifiedAt?: Date | number | string | null;
|
|
11
15
|
lastLoginAt?: Date | number | string | null;
|
|
@@ -13,13 +17,13 @@ type UserRowLike = {
|
|
|
13
17
|
};
|
|
14
18
|
/**
|
|
15
19
|
* A stored user as the users admin returns it: an allowlist (never the password hash or other modules' columns). `pii`
|
|
16
|
-
* (the caller holds `users:pii`) adds the phone number.
|
|
20
|
+
* (the caller holds `users:pii`) adds the phone number and the people number.
|
|
17
21
|
*/
|
|
18
22
|
export declare function toAdminUserDto(user: UserRowLike, options?: {
|
|
19
23
|
pii?: boolean;
|
|
20
24
|
}): AdminUserDto;
|
|
21
25
|
/** The signed-in user's own profile, as the self-service routes return it. */
|
|
22
|
-
export declare function toProfileDto(user: Pick<UserRowLike, 'name' | 'email' | 'avatar' | 'phone' | 'locale' | 'emailVerifiedAt'> & {
|
|
26
|
+
export declare function toProfileDto(user: Pick<UserRowLike, 'name' | 'nickname' | 'email' | 'avatar' | 'phone' | 'peopleNumber' | 'photoOptOut' | 'tagOptOut' | 'locale' | 'emailVerifiedAt'> & {
|
|
23
27
|
id: number | string;
|
|
24
28
|
}): ProfileDto;
|
|
25
29
|
export {};
|
|
@@ -3,9 +3,12 @@ export function toAdminUserDto(user, options = {}) {
|
|
|
3
3
|
return {
|
|
4
4
|
id: user.id,
|
|
5
5
|
name: user.name,
|
|
6
|
+
nickname: user.nickname ?? null,
|
|
6
7
|
email: user.email,
|
|
7
8
|
avatar: user.avatar ?? null,
|
|
8
|
-
...options.pii ? { phone: user.phone ?? null } : {},
|
|
9
|
+
...options.pii ? { phone: user.phone ?? null, peopleNumber: user.peopleNumber ?? null } : {},
|
|
10
|
+
photoOptOut: !!user.photoOptOut,
|
|
11
|
+
tagOptOut: !!user.tagOptOut,
|
|
9
12
|
emailVerifiedAt: isoDate(user.emailVerifiedAt),
|
|
10
13
|
lastLoginAt: isoDate(user.lastLoginAt),
|
|
11
14
|
createdAt: isoDate(user.createdAt)
|
|
@@ -15,9 +18,13 @@ export function toProfileDto(user) {
|
|
|
15
18
|
return {
|
|
16
19
|
id: Number(user.id),
|
|
17
20
|
name: user.name,
|
|
21
|
+
nickname: user.nickname ?? null,
|
|
18
22
|
email: user.email,
|
|
19
23
|
avatar: user.avatar ?? null,
|
|
20
24
|
phone: user.phone ?? null,
|
|
25
|
+
peopleNumber: user.peopleNumber ?? null,
|
|
26
|
+
photoOptOut: !!user.photoOptOut,
|
|
27
|
+
tagOptOut: !!user.tagOptOut,
|
|
21
28
|
locale: user.locale ?? null,
|
|
22
29
|
emailVerifiedAt: isoDate(user.emailVerifiedAt)
|
|
23
30
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UserRef } from '../../../types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Users by id: `id`, `name`, `email`, `avatar`, `phone
|
|
3
|
+
* Users by id: `id`, `name`, `email`, `avatar`, `phone`, `locale` (the language to write to them in), `nickname` and the
|
|
4
|
+
* media opt-outs (`photoOptOut`, `tagOptOut`). Ids that are not whole numbers are skipped, and an unknown id
|
|
4
5
|
* is missing from the map. Any number of ids works: they are looked up in D1-sized chunks.
|
|
5
6
|
*/
|
|
6
7
|
export declare function loadUserRefs(ids: Iterable<number | string | null | undefined>): Promise<Map<number, UserRef>>;
|
|
@@ -7,7 +7,10 @@ const userRefColumns = () => ({
|
|
|
7
7
|
email: schema.users.email,
|
|
8
8
|
avatar: schema.users.avatar,
|
|
9
9
|
phone: schema.users.phone,
|
|
10
|
-
locale: schema.users.locale
|
|
10
|
+
locale: schema.users.locale,
|
|
11
|
+
nickname: schema.users.nickname,
|
|
12
|
+
photoOptOut: schema.users.photoOptOut,
|
|
13
|
+
tagOptOut: schema.users.tagOptOut
|
|
11
14
|
});
|
|
12
15
|
const toUserRef = (row) => ({
|
|
13
16
|
id: Number(row.id),
|
|
@@ -15,7 +18,10 @@ const toUserRef = (row) => ({
|
|
|
15
18
|
email: row.email ?? null,
|
|
16
19
|
avatar: row.avatar ?? null,
|
|
17
20
|
phone: row.phone || null,
|
|
18
|
-
locale: row.locale || null
|
|
21
|
+
locale: row.locale || null,
|
|
22
|
+
nickname: row.nickname || null,
|
|
23
|
+
photoOptOut: !!row.photoOptOut,
|
|
24
|
+
tagOptOut: !!row.tagOptOut
|
|
19
25
|
});
|
|
20
26
|
function userIdsOf(ids) {
|
|
21
27
|
const unique = /* @__PURE__ */ new Set();
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
/** The columns `users.searchText` is built from. */
|
|
2
|
+
type UserSearchSource = {
|
|
3
|
+
name?: string | null;
|
|
4
|
+
nickname?: string | null;
|
|
5
|
+
};
|
|
6
|
+
/** `users.searchText` of a user: the name and the nickname, folded for search. */
|
|
7
|
+
export declare const userSearchTextOf: (user: UserSearchSource) => string;
|
|
1
8
|
/**
|
|
2
|
-
* `values` with the user's search column (`users.searchText
|
|
3
|
-
* written. Every write of
|
|
9
|
+
* `values` with the user's search column (`users.searchText`: the name and nickname folded for search) set whenever
|
|
10
|
+
* `name` or `nickname` is written. Every write of either goes through it, so `searchUserRefs` finds `Øyvind` for
|
|
11
|
+
* `øyvind` on sqlite. `current` is the stored user: the column it leaves out of `values` comes from there, so renaming
|
|
12
|
+
* someone keeps their nickname searchable.
|
|
4
13
|
*/
|
|
5
|
-
export declare const withUserSearchText: <T extends {
|
|
6
|
-
name?: string | null;
|
|
7
|
-
}>(values: T) => T & {
|
|
14
|
+
export declare const withUserSearchText: <T extends UserSearchSource>(values: T, current?: UserSearchSource | null) => T & {
|
|
8
15
|
searchText?: string;
|
|
9
16
|
};
|
|
17
|
+
export {};
|
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import { searchText } from "@frigear-nu/module-kit/server";
|
|
2
|
-
export const
|
|
2
|
+
export const userSearchTextOf = (user) => searchText(user.name, user.nickname);
|
|
3
|
+
export const withUserSearchText = (values, current) => {
|
|
4
|
+
const nameWritten = typeof values.name === "string";
|
|
5
|
+
const nicknameWritten = values.nickname !== void 0;
|
|
6
|
+
if (!nameWritten && !nicknameWritten) return values;
|
|
7
|
+
return {
|
|
8
|
+
...values,
|
|
9
|
+
searchText: userSearchTextOf({
|
|
10
|
+
name: nameWritten ? values.name : current?.name,
|
|
11
|
+
nickname: nicknameWritten ? values.nickname : current?.nickname
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AdminUserDto, ProfileDto, UserPickerCreateInitial, UserPickerOption } from '../../types.js';
|
|
2
2
|
export type { AdminUserDto, ProfileDto, UserPickerCreateInitial, UserPickerOption };
|
|
3
3
|
export { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from './phone.js';
|
|
4
|
+
export { USER_MEDIA_OPT_OUTS, USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH, normalizeUserPeopleNumber, userDisplayName } from './profile.js';
|
|
5
|
+
export type { UserMediaOptOut } from './profile.js';
|
|
4
6
|
/** The users API: self-service under `/api/users`, staff under `/api/admin/users`. */
|
|
5
7
|
export declare const usersApi: {
|
|
6
8
|
readonly me: {
|
|
7
|
-
/** `PATCH { name?, avatar?, phone?, locale? }`: updates the caller's profile, answers the profile DTO. `profile:write` (implicit). */
|
|
9
|
+
/** `PATCH { name?, nickname?, avatar?, phone?, peopleNumber?, photoOptOut?, tagOptOut?, locale? }`: updates the caller's profile, answers the profile DTO. `profile:write` (implicit). */
|
|
8
10
|
readonly profile: "/api/users/me";
|
|
9
11
|
/**
|
|
10
12
|
* `PUT { locale, ifUnset? }`: sets the caller's language, answers the profile DTO. With `ifUnset: true` it only fills
|
|
@@ -23,7 +25,7 @@ export declare const usersApi: {
|
|
|
23
25
|
/** `GET ?code=` (preview) and `POST { code }` (restore the old address). The code is the proof, no sign-in needed. */
|
|
24
26
|
readonly emailChangeRevert: "/api/users/email-change/revert";
|
|
25
27
|
readonly admin: {
|
|
26
|
-
/** `GET` (paginated list, `users:list`; `useTableQuery` keys plus `role`, `verified`) and `POST` (create, `users:create`, 201). */
|
|
28
|
+
/** `GET` (paginated list, `users:list`; `useTableQuery` keys plus `role`, `verified`, `mediaOptOut=photo|tag`) and `POST` (create, `users:create`, 201). */
|
|
27
29
|
readonly users: "/api/admin/users";
|
|
28
30
|
/** `GET` (detail), `PATCH` (edit) and `DELETE` (204). */
|
|
29
31
|
readonly user: (id: number | string) => string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from "./phone.js";
|
|
2
|
+
export { USER_MEDIA_OPT_OUTS, USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH, normalizeUserPeopleNumber, userDisplayName } from "./profile.js";
|
|
2
3
|
const base = "/api/users";
|
|
3
4
|
const adminBase = "/api/admin/users";
|
|
4
5
|
export const usersApi = {
|
|
5
6
|
me: {
|
|
6
|
-
/** `PATCH { name?, avatar?, phone?, locale? }`: updates the caller's profile, answers the profile DTO. `profile:write` (implicit). */
|
|
7
|
+
/** `PATCH { name?, nickname?, avatar?, phone?, peopleNumber?, photoOptOut?, tagOptOut?, locale? }`: updates the caller's profile, answers the profile DTO. `profile:write` (implicit). */
|
|
7
8
|
profile: `${base}/me`,
|
|
8
9
|
/**
|
|
9
10
|
* `PUT { locale, ifUnset? }`: sets the caller's language, answers the profile DTO. With `ifUnset: true` it only fills
|
|
@@ -22,7 +23,7 @@ export const usersApi = {
|
|
|
22
23
|
/** `GET ?code=` (preview) and `POST { code }` (restore the old address). The code is the proof, no sign-in needed. */
|
|
23
24
|
emailChangeRevert: `${base}/email-change/revert`,
|
|
24
25
|
admin: {
|
|
25
|
-
/** `GET` (paginated list, `users:list`; `useTableQuery` keys plus `role`, `verified`) and `POST` (create, `users:create`, 201). */
|
|
26
|
+
/** `GET` (paginated list, `users:list`; `useTableQuery` keys plus `role`, `verified`, `mediaOptOut=photo|tag`) and `POST` (create, `users:create`, 201). */
|
|
26
27
|
users: adminBase,
|
|
27
28
|
/** `GET` (detail), `PATCH` (edit) and `DELETE` (204). */
|
|
28
29
|
user: (id) => `${adminBase}/${encodeURIComponent(String(id))}`,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The longest nickname stored on a user. */
|
|
2
|
+
export declare const USER_NICKNAME_MAX_LENGTH = 50;
|
|
3
|
+
/** The longest people number (a person's id in an external system) stored on a user. */
|
|
4
|
+
export declare const USER_PEOPLE_NUMBER_MAX_LENGTH = 64;
|
|
5
|
+
/** The media opt-outs a user can choose, as the admin list filters them (`?mediaOptOut=`). */
|
|
6
|
+
export declare const USER_MEDIA_OPT_OUTS: readonly ["photo", "tag"];
|
|
7
|
+
export type UserMediaOptOut = typeof USER_MEDIA_OPT_OUTS[number];
|
|
8
|
+
/** A people number as stored: trimmed, or `null` when empty. */
|
|
9
|
+
export declare const normalizeUserPeopleNumber: (value: string | null | undefined) => string | null;
|
|
10
|
+
/** How staff lists show a person: "Name (nickname)", or the name alone. */
|
|
11
|
+
export declare const userDisplayName: (user: {
|
|
12
|
+
name: string | null | undefined;
|
|
13
|
+
nickname?: string | null;
|
|
14
|
+
}) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const USER_NICKNAME_MAX_LENGTH = 50;
|
|
2
|
+
export const USER_PEOPLE_NUMBER_MAX_LENGTH = 64;
|
|
3
|
+
export const USER_MEDIA_OPT_OUTS = ["photo", "tag"];
|
|
4
|
+
export const normalizeUserPeopleNumber = (value) => value?.trim() || null;
|
|
5
|
+
export const userDisplayName = (user) => {
|
|
6
|
+
const name = user.name ?? "";
|
|
7
|
+
return user.nickname && user.nickname !== name ? `${name} (${user.nickname})` : name;
|
|
8
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/users",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "The user entity for the main frigear app: the users table, admin user management and self-service profile, email and password changes. Sign-in lives in @frigear-nu/auth.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/identity/users",
|
|
6
6
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"playground"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@frigear-nu/auth": "^0.6.
|
|
38
|
-
"@frigear-nu/mcp": "^0.5.
|
|
39
|
-
"@frigear-nu/module-kit": "^1.3.
|
|
40
|
-
"@frigear-nu/notify": "^0.
|
|
41
|
-
"@frigear-nu/ui": "^0.2.
|
|
37
|
+
"@frigear-nu/auth": "^0.6.8",
|
|
38
|
+
"@frigear-nu/mcp": "^0.5.2",
|
|
39
|
+
"@frigear-nu/module-kit": "^1.3.12",
|
|
40
|
+
"@frigear-nu/notify": "^0.3.1",
|
|
41
|
+
"@frigear-nu/ui": "^0.2.11",
|
|
42
42
|
"@libsql/client": "^0.18.0",
|
|
43
43
|
"@nuxt/kit": "^4.6.4",
|
|
44
44
|
"drizzle-kit": "^0.31.11",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@frigear-nu/admin": ">=0.0.0",
|
|
51
|
-
"@frigear-nu/email-templates": "^0.1.
|
|
51
|
+
"@frigear-nu/email-templates": "^0.1.5",
|
|
52
52
|
"@frigear-nu/menu": "^0.4.1",
|
|
53
|
-
"@frigear-nu/widget": "^0.4.
|
|
53
|
+
"@frigear-nu/widget": "^0.4.3",
|
|
54
54
|
"@nuxt/ui": "^4.12.0",
|
|
55
55
|
"@nuxthub/core": "^0.10.12"
|
|
56
56
|
},
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@electric-sql/pglite": "^0.5.16",
|
|
76
76
|
"@frigear-nu/admin": "^0.5.2",
|
|
77
|
-
"@frigear-nu/email-templates": "^0.1.
|
|
77
|
+
"@frigear-nu/email-templates": "^0.1.5",
|
|
78
78
|
"@frigear-nu/menu": "^0.4.1",
|
|
79
|
-
"@frigear-nu/widget": "^0.4.
|
|
79
|
+
"@frigear-nu/widget": "^0.4.3",
|
|
80
80
|
"@nuxt/devtools": "^4.2.0",
|
|
81
81
|
"@nuxt/eslint-config": "^1.17.0",
|
|
82
82
|
"@nuxt/module-builder": "^1.0.4",
|