@frigear-nu/users 3.1.4 → 3.1.6
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 +117 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +144 -27
- package/dist/runtime/access.js +3 -3
- package/dist/runtime/app/components/UserCreateSlideover.vue +8 -6
- package/dist/runtime/app/components/UserPicker.d.vue.ts +2 -2
- package/dist/runtime/app/components/UserPicker.vue.d.ts +2 -2
- package/dist/runtime/app/components/UsersAdminTerms.d.vue.ts +7 -0
- package/dist/runtime/app/components/UsersAdminTerms.vue +55 -0
- package/dist/runtime/app/components/UsersAdminTerms.vue.d.ts +7 -0
- package/dist/runtime/app/components/UsersTermsGate.d.vue.ts +11 -0
- package/dist/runtime/app/components/UsersTermsGate.vue +82 -0
- package/dist/runtime/app/components/UsersTermsGate.vue.d.ts +11 -0
- package/dist/runtime/app/components/UsersTermsText.d.vue.ts +7 -0
- package/dist/runtime/app/components/UsersTermsText.vue +34 -0
- package/dist/runtime/app/components/UsersTermsText.vue.d.ts +7 -0
- package/dist/runtime/app/composables/useUserActions.d.ts +6 -2
- package/dist/runtime/app/composables/useUserActions.js +32 -3
- package/dist/runtime/app/pages/admin-user.vue +3 -0
- package/dist/runtime/app/pages/admin.vue +23 -5
- package/dist/runtime/app/pages/revert-email-change.vue +2 -1
- package/dist/runtime/app/plugins/offer-locale.client.js +22 -3
- package/dist/runtime/app/plugins/terms-gate.client.d.ts +2 -0
- package/dist/runtime/app/plugins/terms-gate.client.js +55 -0
- package/dist/runtime/app/tabs/Overview.vue +88 -14
- package/dist/runtime/app/utils/admin-user.d.ts +4 -2
- package/dist/runtime/app/utils/terms.d.ts +10 -0
- package/dist/runtime/app/utils/terms.js +7 -0
- package/dist/runtime/app/widgets/NewUsers.d.vue.ts +4 -1
- package/dist/runtime/app/widgets/NewUsers.vue +7 -4
- package/dist/runtime/app/widgets/NewUsers.vue.d.ts +4 -1
- package/dist/runtime/app/widgets/NewUsersStat.d.vue.ts +4 -1
- package/dist/runtime/app/widgets/NewUsersStat.vue +4 -1
- package/dist/runtime/app/widgets/NewUsersStat.vue.d.ts +4 -1
- package/dist/runtime/app/widgets/UsersAccountTerms.d.vue.ts +6 -0
- package/dist/runtime/app/widgets/UsersAccountTerms.vue +63 -0
- package/dist/runtime/app/widgets/UsersAccountTerms.vue.d.ts +6 -0
- package/dist/runtime/app/widgets/UsersRegisterTerms.d.vue.ts +9 -0
- package/dist/runtime/app/widgets/UsersRegisterTerms.vue +37 -0
- package/dist/runtime/app/widgets/UsersRegisterTerms.vue.d.ts +9 -0
- 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/db/terms-users.postgresql.d.ts +24 -0
- package/dist/runtime/db/terms-users.postgresql.js +4 -0
- package/dist/runtime/db/terms-users.sqlite.d.ts +26 -0
- package/dist/runtime/db/terms-users.sqlite.js +4 -0
- package/dist/runtime/db/terms.postgresql.d.ts +162 -0
- package/dist/runtime/db/terms.postgresql.js +21 -0
- package/dist/runtime/db/terms.sqlite.d.ts +173 -0
- package/dist/runtime/db/terms.sqlite.js +21 -0
- package/dist/runtime/i18n/lang/da.json +85 -6
- package/dist/runtime/i18n/lang/en.json +85 -6
- package/dist/runtime/server/plugins/terms-claims.d.ts +13 -0
- package/dist/runtime/server/plugins/terms-claims.js +19 -0
- package/dist/runtime/server/plugins/terms.d.ts +15 -0
- package/dist/runtime/server/plugins/terms.js +43 -0
- package/dist/runtime/server/routes/admin/user-avatar.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/user-avatar.delete.js +11 -0
- package/dist/runtime/server/routes/admin/user-terms.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/user-terms.get.js +12 -0
- package/dist/runtime/server/routes/admin/user.delete.js +2 -0
- package/dist/runtime/server/routes/admin/user.patch.js +14 -3
- package/dist/runtime/server/routes/admin/users.get.js +11 -3
- package/dist/runtime/server/routes/admin/users.post.js +1 -0
- package/dist/runtime/server/routes/avatar.get.d.ts +2 -0
- package/dist/runtime/server/routes/avatar.get.js +12 -0
- package/dist/runtime/server/routes/me/avatar.delete.d.ts +2 -0
- package/dist/runtime/server/routes/me/avatar.delete.js +13 -0
- package/dist/runtime/server/routes/me/avatar.put.d.ts +2 -0
- package/dist/runtime/server/routes/me/avatar.put.js +20 -0
- package/dist/runtime/server/routes/me/profile.patch.js +23 -4
- package/dist/runtime/server/routes/me/terms.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/terms.get.js +4 -0
- package/dist/runtime/server/routes/me/terms.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/terms.post.js +18 -0
- package/dist/runtime/server/schemas.d.ts +12 -1
- package/dist/runtime/server/schemas.js +6 -1
- 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 +5 -1
- package/dist/runtime/server/utils/dto.js +8 -0
- 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/server/utils/users-avatar.d.ts +29 -0
- package/dist/runtime/server/utils/users-avatar.js +69 -0
- package/dist/runtime/server/utils/users-terms.d.ts +35 -0
- package/dist/runtime/server/utils/users-terms.js +90 -0
- package/dist/runtime/utils/api.d.ts +25 -4
- package/dist/runtime/utils/api.js +23 -3
- package/dist/runtime/utils/avatar.d.ts +25 -0
- package/dist/runtime/utils/avatar.js +23 -0
- package/dist/runtime/utils/profile.d.ts +14 -0
- package/dist/runtime/utils/profile.js +8 -0
- package/dist/runtime/utils/terms-claim.d.ts +27 -0
- package/dist/runtime/utils/terms-claim.js +15 -0
- package/dist/types.d.mts +1 -1
- package/package.json +18 -13
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { usersApi } from "../../utils/api";
|
|
3
|
+
import UsersTermsText from "./UsersTermsText.vue";
|
|
4
|
+
import { $fetch, reloadNuxtApp, useAction, useAuth, useFormat, useLocaleLink, useModuleT, useNuxtApp } from "#imports";
|
|
5
|
+
defineOptions({ name: "UsersTermsGate" });
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
status: { type: Object, required: true }
|
|
8
|
+
});
|
|
9
|
+
const emit = defineEmits(["close"]);
|
|
10
|
+
const t = useModuleT("users");
|
|
11
|
+
const format = useFormat();
|
|
12
|
+
const { localize } = useLocaleLink();
|
|
13
|
+
const { busy, run } = useAction();
|
|
14
|
+
const signingOut = useAction();
|
|
15
|
+
const i18n = useNuxtApp().$i18n;
|
|
16
|
+
async function accept() {
|
|
17
|
+
const status = await run(async () => {
|
|
18
|
+
try {
|
|
19
|
+
return await $fetch(usersApi.me.terms, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: { version: props.status.current.version, ...i18n?.locale?.value ? { locale: i18n.locale.value } : {} }
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.data?.data?.code === "outdated_version") reloadNuxtApp();
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}, { success: t("terms.gate.accepted", "Terms accepted"), error: t("terms.gate.acceptFailed", "The terms could not be accepted.") });
|
|
28
|
+
if (status) emit("close", status);
|
|
29
|
+
}
|
|
30
|
+
function signOut() {
|
|
31
|
+
return signingOut.run(() => useAuth().logout(), { error: t("terms.gate.signOutFailed", "You could not be signed out.") });
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<UModal
|
|
37
|
+
:title="status.accepted ? t('terms.gate.changedTitle', 'Our terms have changed') : t('terms.gate.title', 'Accept our terms')"
|
|
38
|
+
:description="status.accepted ? t('terms.gate.changedDescription', 'You accepted version {version} on {date}. Read and accept the new terms to go on.', { version: status.accepted.version, date: format.date(status.accepted.acceptedAt) }) : t('terms.gate.description', 'Read and accept the terms to go on using your account.')"
|
|
39
|
+
:dismissible="false"
|
|
40
|
+
:close="false"
|
|
41
|
+
>
|
|
42
|
+
<template #body>
|
|
43
|
+
<div
|
|
44
|
+
class="flex flex-col gap-3 text-sm"
|
|
45
|
+
data-users-terms-gate
|
|
46
|
+
>
|
|
47
|
+
<p class="text-highlighted">
|
|
48
|
+
<UsersTermsText :terms="status.current" />
|
|
49
|
+
</p>
|
|
50
|
+
<p class="text-muted">
|
|
51
|
+
{{ t("terms.gate.version", "Version {version}", { version: status.current.version }) }}
|
|
52
|
+
</p>
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
55
|
+
<template #footer>
|
|
56
|
+
<div class="flex w-full flex-wrap justify-end gap-2">
|
|
57
|
+
<UButton
|
|
58
|
+
color="neutral"
|
|
59
|
+
variant="outline"
|
|
60
|
+
icon="i-lucide-scroll-text"
|
|
61
|
+
:to="localize(status.current.url)"
|
|
62
|
+
target="_blank"
|
|
63
|
+
:label="t('terms.gate.read', 'Read the terms')"
|
|
64
|
+
/>
|
|
65
|
+
<UButton
|
|
66
|
+
color="neutral"
|
|
67
|
+
variant="ghost"
|
|
68
|
+
icon="i-lucide-log-out"
|
|
69
|
+
:loading="signingOut.busy.value"
|
|
70
|
+
:label="t('terms.gate.signOut', 'Sign out')"
|
|
71
|
+
@click="signOut"
|
|
72
|
+
/>
|
|
73
|
+
<UButton
|
|
74
|
+
icon="i-lucide-check"
|
|
75
|
+
:loading="busy"
|
|
76
|
+
:label="t('terms.gate.accept', 'Accept terms')"
|
|
77
|
+
@click="accept"
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
81
|
+
</UModal>
|
|
82
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UserTermsStatusDto } from '../../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
status: UserTermsStatusDto;
|
|
4
|
+
};
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
6
|
+
close: (args_0: UserTermsStatusDto | null) => any;
|
|
7
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
8
|
+
onClose?: ((args_0: UserTermsStatusDto | null) => any) | undefined;
|
|
9
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UsersPublicTerms } from '../../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
terms: UsersPublicTerms;
|
|
4
|
+
};
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
declare const _default: typeof __VLS_export;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { splitUsersTermsText, usersTermsLinkParams } from "../utils/terms";
|
|
4
|
+
import { useLocaleLink, useModuleT } from "#imports";
|
|
5
|
+
defineOptions({ name: "UsersTermsText" });
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
terms: { type: Object, required: true }
|
|
8
|
+
});
|
|
9
|
+
const t = useModuleT("users");
|
|
10
|
+
const { localize } = useLocaleLink();
|
|
11
|
+
const parts = computed(() => {
|
|
12
|
+
const links = usersTermsLinkParams("terms", "privacy");
|
|
13
|
+
const sentence = props.terms.privacyUrl ? t("terms.acceptWithPrivacy", "I accept the {terms} and have read the {privacy}.", links) : t("terms.accept", "I accept the {terms}.", links);
|
|
14
|
+
return splitUsersTermsText(sentence);
|
|
15
|
+
});
|
|
16
|
+
const linkOf = (name) => name === "privacy" ? { to: localize(props.terms.privacyUrl ?? ""), label: t("terms.privacyLink", "privacy policy") } : { to: localize(props.terms.url), label: t("terms.termsLink", "terms") };
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<span>
|
|
21
|
+
<template
|
|
22
|
+
v-for="(part, index) in parts"
|
|
23
|
+
:key="index"
|
|
24
|
+
>
|
|
25
|
+
<ULink
|
|
26
|
+
v-if="'link' in part"
|
|
27
|
+
:to="linkOf(part.link).to"
|
|
28
|
+
target="_blank"
|
|
29
|
+
class="text-primary font-medium underline-offset-2 hover:underline"
|
|
30
|
+
>{{ linkOf(part.link).label }}</ULink>
|
|
31
|
+
<template v-else>{{ part.text }}</template>
|
|
32
|
+
</template>
|
|
33
|
+
</span>
|
|
34
|
+
</template>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UsersPublicTerms } from '../../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
terms: UsersPublicTerms;
|
|
4
|
+
};
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
declare const _default: typeof __VLS_export;
|
|
7
|
+
export default _default;
|
|
@@ -5,6 +5,8 @@ export interface UserMenuOptions {
|
|
|
5
5
|
extra?: DropdownMenuItem[][];
|
|
6
6
|
/** Runs after the user was deleted; without it the users list is refreshed. */
|
|
7
7
|
onRemoved?: () => void | Promise<void>;
|
|
8
|
+
/** Runs after the user's avatar was removed; without it the users list is refreshed. */
|
|
9
|
+
onAvatarRemoved?: () => void | Promise<void>;
|
|
8
10
|
/** Leave out "Open", e.g. on the user's own page. Default `true`. */
|
|
9
11
|
open?: boolean;
|
|
10
12
|
/** Hide the entries the acting staff member may not use (known on the detail page). Both default to `true`. */
|
|
@@ -14,14 +16,16 @@ export interface UserMenuOptions {
|
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
|
-
* Everything staff do to a user: `create` (a slideover, then the new user's page), `remove` (confirm, toast, refresh)
|
|
18
|
-
* `RowMenu` of the list rows and the detail heading, ordered Open,
|
|
19
|
+
* Everything staff do to a user: `create` (a slideover, then the new user's page), `remove` (confirm, toast, refresh),
|
|
20
|
+
* `removeAvatar` (the same) and `menu(user)` for the `RowMenu` of the list rows and the detail heading, ordered Open,
|
|
21
|
+
* sign-in link, extras, then Remove avatar and Delete in their own group.
|
|
19
22
|
*/
|
|
20
23
|
export declare function useUserActions(): {
|
|
21
24
|
listPath: import("vue").ComputedRef<any>;
|
|
22
25
|
userPath: (id: number) => string;
|
|
23
26
|
create: () => Promise<UserRow | false>;
|
|
24
27
|
remove: (user: UserSubject, options?: Pick<UserMenuOptions, "onRemoved">) => Promise<boolean>;
|
|
28
|
+
removeAvatar: (user: UserSubject, options?: Pick<UserMenuOptions, "onAvatarRemoved">) => Promise<boolean>;
|
|
25
29
|
resend: (user: UserSubject) => Promise<boolean>;
|
|
26
30
|
menu: (user: UserSubject, options?: UserMenuOptions) => DropdownMenuItem[][];
|
|
27
31
|
};
|
|
@@ -34,6 +34,23 @@ export function useUserActions() {
|
|
|
34
34
|
else await refreshNuxtData(ADMIN_USERS_KEY);
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
|
+
async function removeAvatar(user, options = {}) {
|
|
38
|
+
const confirmed = await confirm({
|
|
39
|
+
title: t("admin.removeAvatarTitle", "Remove the avatar of {name}?", { name: user.name }),
|
|
40
|
+
description: t("admin.removeAvatarBody", "The photo disappears from their profile everywhere in the app, and an uploaded photo is deleted. They can add a new one."),
|
|
41
|
+
confirmText: t("admin.removeAvatar", "Remove avatar"),
|
|
42
|
+
destructive: true
|
|
43
|
+
});
|
|
44
|
+
if (!confirmed) return false;
|
|
45
|
+
const done = await run(
|
|
46
|
+
() => $fetch(usersApi.admin.avatar(user.id), { method: "DELETE" }).then(() => true),
|
|
47
|
+
{ success: t("admin.avatarRemoved", "Removed the avatar of {name}", { name: user.name }) }
|
|
48
|
+
);
|
|
49
|
+
if (!done) return false;
|
|
50
|
+
if (options.onAvatarRemoved) await options.onAvatarRemoved();
|
|
51
|
+
else await refreshNuxtData(ADMIN_USERS_KEY);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
37
54
|
async function resend(user) {
|
|
38
55
|
const sent = await run(
|
|
39
56
|
() => $fetch(usersApi.admin.resend(user.id), { method: "POST" }).then(() => true),
|
|
@@ -60,17 +77,29 @@ export function useUserActions() {
|
|
|
60
77
|
}
|
|
61
78
|
if (first.length) groups.push(first);
|
|
62
79
|
groups.push(...(options.extra ?? []).filter((group) => group.length));
|
|
80
|
+
const destructive = [];
|
|
81
|
+
if (canUpdate && user.avatar) {
|
|
82
|
+
destructive.push({
|
|
83
|
+
label: t("admin.removeAvatar", "Remove avatar"),
|
|
84
|
+
icon: "i-lucide-image-off",
|
|
85
|
+
color: "error",
|
|
86
|
+
onSelect: () => {
|
|
87
|
+
void removeAvatar(user, { onAvatarRemoved: options.onAvatarRemoved });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
63
91
|
if (canDelete) {
|
|
64
|
-
|
|
92
|
+
destructive.push({
|
|
65
93
|
label: t("admin.deleteUser", "Delete user"),
|
|
66
94
|
icon: "i-lucide-trash-2",
|
|
67
95
|
color: "error",
|
|
68
96
|
onSelect: () => {
|
|
69
97
|
void remove(user, { onRemoved: options.onRemoved });
|
|
70
98
|
}
|
|
71
|
-
}
|
|
99
|
+
});
|
|
72
100
|
}
|
|
101
|
+
if (destructive.length) groups.push(destructive);
|
|
73
102
|
return groups;
|
|
74
103
|
}
|
|
75
|
-
return { listPath, userPath, create, remove, resend, menu };
|
|
104
|
+
return { listPath, userPath, create, remove, removeAvatar, resend, menu };
|
|
76
105
|
}
|
|
@@ -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" },
|
|
@@ -92,9 +102,10 @@ const addUser = () => actions.create();
|
|
|
92
102
|
<div class="flex flex-col gap-4">
|
|
93
103
|
<PageHeading :title="t('admin.title', 'Users')">
|
|
94
104
|
<template #actions>
|
|
95
|
-
<
|
|
105
|
+
<TooltipButton
|
|
96
106
|
icon="i-lucide-plus"
|
|
97
107
|
:label="t('admin.create', 'Add user')"
|
|
108
|
+
:tooltip="t('admin.createButtonHint', 'Create an account, with a welcome email if you choose')"
|
|
98
109
|
@click="addUser"
|
|
99
110
|
/>
|
|
100
111
|
</template>
|
|
@@ -115,13 +126,20 @@ const addUser = () => actions.create();
|
|
|
115
126
|
class="w-full max-w-sm"
|
|
116
127
|
icon="i-lucide-search"
|
|
117
128
|
:loading="pending"
|
|
118
|
-
:placeholder="t('admin.search', 'Search name or email...')"
|
|
129
|
+
:placeholder="t('admin.search', 'Search name, nickname or email...')"
|
|
119
130
|
/>
|
|
120
131
|
<USelect
|
|
121
132
|
v-model="filters.verified"
|
|
122
133
|
:items="verifiedOptions"
|
|
123
134
|
class="w-40"
|
|
124
135
|
/>
|
|
136
|
+
<USelect
|
|
137
|
+
v-model="filters.mediaOptOut"
|
|
138
|
+
:items="mediaOptOutOptions"
|
|
139
|
+
:aria-label="t('admin.media.filter', 'Photo choices')"
|
|
140
|
+
class="w-44"
|
|
141
|
+
icon="i-lucide-camera-off"
|
|
142
|
+
/>
|
|
125
143
|
<USelect
|
|
126
144
|
v-if="hasRoles"
|
|
127
145
|
v-model="filters.role"
|
|
@@ -93,11 +93,12 @@ async function onRevert() {
|
|
|
93
93
|
variant="subtle"
|
|
94
94
|
:title="error"
|
|
95
95
|
/>
|
|
96
|
-
<
|
|
96
|
+
<TooltipButton
|
|
97
97
|
block
|
|
98
98
|
color="error"
|
|
99
99
|
:loading="reverting"
|
|
100
100
|
:label="t('revert.submit', 'Restore {email}', { email: preview.oldEmail })"
|
|
101
|
+
:tooltip="t('revert.submitHint', 'Your account goes back to this address; you may be signed out')"
|
|
101
102
|
@click="onRevert"
|
|
102
103
|
/>
|
|
103
104
|
</template>
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { usersApi } from "../../utils/api.js";
|
|
3
|
+
import UsersTermsGate from "../components/UsersTermsGate.vue";
|
|
4
|
+
import { $fetch, defineNuxtPlugin, useLocaleLink, useOverlay, useRouter, useRuntimeConfig, useUserSession } from "#imports";
|
|
5
|
+
export default defineNuxtPlugin({
|
|
6
|
+
name: "users:terms-gate",
|
|
7
|
+
setup(nuxtApp) {
|
|
8
|
+
const terms = useRuntimeConfig().public.users?.terms;
|
|
9
|
+
if (!terms) return;
|
|
10
|
+
nuxtApp.hook("app:mounted", () => {
|
|
11
|
+
nuxtApp.runWithContext(() => {
|
|
12
|
+
const { loggedIn, user } = useUserSession();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const { isActive } = useLocaleLink();
|
|
15
|
+
const gate = useOverlay().create(UsersTermsGate, { destroyOnClose: true });
|
|
16
|
+
let status = null;
|
|
17
|
+
let open = false;
|
|
18
|
+
let checked;
|
|
19
|
+
const onLegalPage = () => isActive(terms.url) || !!terms.privacyUrl && isActive(terms.privacyUrl);
|
|
20
|
+
const sync = () => {
|
|
21
|
+
const needed = !!status && !status.upToDate && loggedIn.value && !onLegalPage();
|
|
22
|
+
if (needed && !open) {
|
|
23
|
+
open = true;
|
|
24
|
+
void gate.open({ status }).then((next) => {
|
|
25
|
+
open = false;
|
|
26
|
+
if (next) status = next;
|
|
27
|
+
});
|
|
28
|
+
} else if (!needed && open) {
|
|
29
|
+
open = false;
|
|
30
|
+
gate.close();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const check = async () => {
|
|
34
|
+
const id = user.value?.id;
|
|
35
|
+
if (!loggedIn.value || id === void 0) {
|
|
36
|
+
status = null;
|
|
37
|
+
checked = void 0;
|
|
38
|
+
return sync();
|
|
39
|
+
}
|
|
40
|
+
if (checked === id) return sync();
|
|
41
|
+
checked = id;
|
|
42
|
+
try {
|
|
43
|
+
status = await $fetch(usersApi.me.terms);
|
|
44
|
+
} catch {
|
|
45
|
+
status = null;
|
|
46
|
+
checked = void 0;
|
|
47
|
+
}
|
|
48
|
+
sync();
|
|
49
|
+
};
|
|
50
|
+
watch([loggedIn, () => user.value?.id], () => void check(), { immediate: true });
|
|
51
|
+
router.afterEach(() => sync());
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -1,8 +1,11 @@
|
|
|
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 { phoneIssue } from "@frigear-nu/ui/phone";
|
|
5
|
+
import { USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH } from "../../utils/profile";
|
|
4
6
|
import { z } from "zod";
|
|
5
|
-
import
|
|
7
|
+
import UsersAdminTerms from "../components/UsersAdminTerms.vue";
|
|
8
|
+
import { $fetch, computed, reactive, resolveComponent, useAction, useFormat, useModuleT, useRuntimeConfig, watch } from "#imports";
|
|
6
9
|
defineOptions({ name: "UsersAdminOverviewTab" });
|
|
7
10
|
const props = defineProps({
|
|
8
11
|
user: { type: Object, required: true }
|
|
@@ -12,17 +15,30 @@ const t = useModuleT("users");
|
|
|
12
15
|
const format = useFormat();
|
|
13
16
|
const { busy: saving, run } = useAction();
|
|
14
17
|
const OverviewWidgets = resolveComponent("WidgetArea");
|
|
18
|
+
const terms = useRuntimeConfig().public.users?.terms;
|
|
19
|
+
const showTerms = computed(() => !!terms && props.user.phone !== void 0);
|
|
15
20
|
const overviewWidgets = typeof OverviewWidgets === "string" ? void 0 : OverviewWidgets;
|
|
16
21
|
const schema = z.object({
|
|
17
22
|
name: z.string().trim().min(1, t("admin.nameRequired", "Enter a name.")).max(120),
|
|
23
|
+
nickname: z.string().trim().max(USER_NICKNAME_MAX_LENGTH, t("admin.nicknameTooLong", "Use at most {max} characters.", { max: USER_NICKNAME_MAX_LENGTH })),
|
|
18
24
|
email: z.string().trim().email(t("admin.emailInvalid", "Enter a valid email address.")),
|
|
19
25
|
emailVerified: z.boolean(),
|
|
20
|
-
// The server's rule (`phoneField`)
|
|
21
|
-
|
|
26
|
+
// The server's rule (`phoneField`) and a full international number (`PhoneInput` writes `+4512345678`); empty
|
|
27
|
+
// clears it. A number stored before the country selector passes until it is changed.
|
|
28
|
+
phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("admin.phoneInvalid", "Enter a valid phone number.")).refine((value) => !value || value === (props.user.phone ?? "") || !phoneIssue(value), t("admin.phoneInvalid", "Enter a valid phone number.")),
|
|
29
|
+
// The server's rule (`peopleNumberField`): at most 64 characters; empty clears it.
|
|
30
|
+
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
31
|
});
|
|
23
|
-
const form = reactive({ name: "", email: "", emailVerified: false, phone: "" });
|
|
32
|
+
const form = reactive({ name: "", nickname: "", email: "", emailVerified: false, phone: "", peopleNumber: "" });
|
|
24
33
|
function fill(value) {
|
|
25
|
-
Object.assign(form, {
|
|
34
|
+
Object.assign(form, {
|
|
35
|
+
name: value.name,
|
|
36
|
+
nickname: value.nickname ?? "",
|
|
37
|
+
email: value.email,
|
|
38
|
+
emailVerified: !!value.emailVerifiedAt,
|
|
39
|
+
phone: value.phone ?? "",
|
|
40
|
+
peopleNumber: value.peopleNumber ?? ""
|
|
41
|
+
});
|
|
26
42
|
}
|
|
27
43
|
fill(props.user);
|
|
28
44
|
watch(() => props.user, fill);
|
|
@@ -32,21 +48,29 @@ const accountFacts = computed(() => [
|
|
|
32
48
|
{ key: "password", label: t("admin.detail.password", "Password"), value: props.user.hasPassword ? t("admin.detail.set", "Set") : null },
|
|
33
49
|
{ key: "passkeys", label: t("admin.detail.passkeys", "Passkeys"), value: props.user.passkeys }
|
|
34
50
|
]);
|
|
35
|
-
const
|
|
51
|
+
const mediaFacts = computed(() => [
|
|
52
|
+
{ 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") },
|
|
53
|
+
{ 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") }
|
|
54
|
+
]);
|
|
55
|
+
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 ?? "") || form.peopleNumber.trim() !== (props.user.peopleNumber ?? ""));
|
|
36
56
|
async function save(event) {
|
|
37
|
-
const { name, email, emailVerified, phone } = event.data;
|
|
57
|
+
const { name, nickname, email, emailVerified, phone, peopleNumber } = event.data;
|
|
38
58
|
const emailChanged = email !== props.user.email;
|
|
59
|
+
const nicknameChanged = nickname !== (props.user.nickname ?? "");
|
|
39
60
|
const phoneChanged = props.user.can.pii && phone !== (props.user.phone ?? "");
|
|
61
|
+
const peopleNumberChanged = peopleNumber !== (props.user.peopleNumber ?? "");
|
|
40
62
|
const saved = await run(
|
|
41
63
|
() => $fetch(usersApi.admin.user(props.user.id), {
|
|
42
64
|
method: "PATCH",
|
|
43
65
|
body: {
|
|
44
66
|
name,
|
|
67
|
+
...nicknameChanged ? { nickname: nickname || null } : {},
|
|
45
68
|
...emailChanged ? { email } : {},
|
|
46
69
|
// An unchanged address keeps its state unless staff toggled it; a changed one is verified by email. Both
|
|
47
70
|
// need `users:manage`, so they are only sent when they change.
|
|
48
71
|
...!emailChanged && emailVerified !== !!props.user.emailVerifiedAt ? { emailVerified } : {},
|
|
49
|
-
...phoneChanged ? { phone: phone || null } : {}
|
|
72
|
+
...phoneChanged ? { phone: phone || null } : {},
|
|
73
|
+
...peopleNumberChanged ? { peopleNumber: peopleNumber || null } : {}
|
|
50
74
|
}
|
|
51
75
|
}).then(() => true),
|
|
52
76
|
{ success: emailChanged ? t("admin.detail.savedEmail", "Saved. A verification email was sent to the new address.") : t("admin.detail.saved", "Saved.") }
|
|
@@ -84,6 +108,17 @@ async function save(event) {
|
|
|
84
108
|
:disabled="!user.can.update"
|
|
85
109
|
/>
|
|
86
110
|
</FormRow>
|
|
111
|
+
<FormRow
|
|
112
|
+
name="nickname"
|
|
113
|
+
:label="t('admin.nickname', 'Nickname')"
|
|
114
|
+
:description="t('admin.detail.nicknameHelp', 'What they like to be called. Leave it empty to remove it.')"
|
|
115
|
+
>
|
|
116
|
+
<UInput
|
|
117
|
+
v-model="form.nickname"
|
|
118
|
+
class="w-full sm:max-w-sm"
|
|
119
|
+
:disabled="!user.can.update"
|
|
120
|
+
/>
|
|
121
|
+
</FormRow>
|
|
87
122
|
<FormRow
|
|
88
123
|
name="email"
|
|
89
124
|
:label="t('admin.email', 'Email')"
|
|
@@ -112,13 +147,25 @@ async function save(event) {
|
|
|
112
147
|
name="phone"
|
|
113
148
|
:label="t('admin.phone', 'Phone')"
|
|
114
149
|
:description="t('admin.detail.phoneHelp', 'Used for text messages. Leave it empty to remove it.')"
|
|
150
|
+
>
|
|
151
|
+
<PhoneInput
|
|
152
|
+
:model-value="form.phone"
|
|
153
|
+
:country-label="t('admin.phoneCountry', 'Country')"
|
|
154
|
+
class="sm:max-w-sm"
|
|
155
|
+
:disabled="!user.can.pii"
|
|
156
|
+
@update:model-value="form.phone = $event ?? ''"
|
|
157
|
+
/>
|
|
158
|
+
</FormRow>
|
|
159
|
+
<FormRow
|
|
160
|
+
name="peopleNumber"
|
|
161
|
+
:label="t('admin.peopleNumber', 'People number')"
|
|
162
|
+
:description="t('admin.detail.peopleNumberHelp', 'Their id in an external system, such as a volunteer system. Leave it empty to remove it.')"
|
|
115
163
|
>
|
|
116
164
|
<UInput
|
|
117
|
-
v-model="form.
|
|
118
|
-
type="tel"
|
|
165
|
+
v-model="form.peopleNumber"
|
|
119
166
|
autocomplete="off"
|
|
120
167
|
class="w-full sm:max-w-sm"
|
|
121
|
-
:disabled="!user.can.
|
|
168
|
+
:disabled="!user.can.update"
|
|
122
169
|
/>
|
|
123
170
|
</FormRow>
|
|
124
171
|
</UForm>
|
|
@@ -135,9 +182,36 @@ async function save(event) {
|
|
|
135
182
|
</template>
|
|
136
183
|
</SectionCard>
|
|
137
184
|
|
|
138
|
-
<
|
|
139
|
-
<
|
|
140
|
-
|
|
185
|
+
<div class="flex flex-col gap-4">
|
|
186
|
+
<SectionCard :title="t('admin.detail.account', 'Account')">
|
|
187
|
+
<DescriptionList :items="accountFacts" />
|
|
188
|
+
</SectionCard>
|
|
189
|
+
<SectionCard
|
|
190
|
+
:title="t('admin.media.title', 'Photos and tagging')"
|
|
191
|
+
:description="t('admin.media.description', 'The user\'s own choice, changed on their profile.')"
|
|
192
|
+
>
|
|
193
|
+
<!-- Label above value: this column is narrow, and the values are sentences. -->
|
|
194
|
+
<dl class="flex flex-col gap-3 text-sm">
|
|
195
|
+
<div
|
|
196
|
+
v-for="fact in mediaFacts"
|
|
197
|
+
:key="fact.key"
|
|
198
|
+
>
|
|
199
|
+
<dt class="text-muted">
|
|
200
|
+
{{ fact.label }}
|
|
201
|
+
</dt>
|
|
202
|
+
<dd class="text-highlighted">
|
|
203
|
+
{{ fact.value }}
|
|
204
|
+
</dd>
|
|
205
|
+
</div>
|
|
206
|
+
</dl>
|
|
207
|
+
</SectionCard>
|
|
208
|
+
</div>
|
|
141
209
|
</div>
|
|
210
|
+
|
|
211
|
+
<UsersAdminTerms
|
|
212
|
+
v-if="showTerms && terms"
|
|
213
|
+
:user-id="user.id"
|
|
214
|
+
:current-version="terms.version"
|
|
215
|
+
/>
|
|
142
216
|
</div>
|
|
143
217
|
</template>
|
|
@@ -38,8 +38,10 @@ export type UserDetail = AdminUserDto & {
|
|
|
38
38
|
pii: boolean;
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
/** What the actions need of a user: the list rows and the detail both satisfy it. */
|
|
42
|
-
export type UserSubject = Pick<UserRow, 'id' | 'name' | 'emailVerifiedAt'
|
|
41
|
+
/** What the actions need of a user: the list rows and the detail both satisfy it. Without `avatar` there is no "Remove avatar". */
|
|
42
|
+
export type UserSubject = Pick<UserRow, 'id' | 'name' | 'emailVerifiedAt'> & {
|
|
43
|
+
avatar?: string | null;
|
|
44
|
+
};
|
|
43
45
|
/** The key of the list's `useFetch`, refreshed after a user is created or deleted. */
|
|
44
46
|
export declare const ADMIN_USERS_KEY = "admin-users";
|
|
45
47
|
/** What the create form closes with: the created user, the existing user staff chose after a 409, or `false` (cancelled). */
|