@frigear-nu/users 3.1.5 → 3.2.0
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 +118 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +136 -16
- 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 +70 -2
- package/dist/runtime/app/pages/revert-email-change.vue +2 -1
- package/dist/runtime/app/plugins/terms-gate.client.d.ts +2 -0
- package/dist/runtime/app/plugins/terms-gate.client.js +70 -0
- package/dist/runtime/app/tabs/Overview.vue +24 -13
- package/dist/runtime/app/utils/admin-user.d.ts +9 -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 +43 -28
- 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 +24 -3
- 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/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 +75 -5
- package/dist/runtime/i18n/lang/en.json +75 -5
- 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/stats.get.js +9 -5
- 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 +2 -2
- package/dist/runtime/server/routes/admin/users.get.js +7 -40
- 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 +7 -2
- 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 +5 -1
- package/dist/runtime/server/schemas.js +2 -1
- package/dist/runtime/server/utils/admin-list.d.ts +45 -0
- package/dist/runtime/server/utils/admin-list.js +54 -0
- package/dist/runtime/server/utils/admin.d.ts +2 -0
- package/dist/runtime/server/utils/admin.js +1 -0
- package/dist/runtime/server/utils/dto.d.ts +1 -1
- package/dist/runtime/server/utils/dto.js +2 -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 +22 -3
- package/dist/runtime/utils/api.js +21 -2
- package/dist/runtime/utils/avatar.d.ts +25 -0
- package/dist/runtime/utils/avatar.js +23 -0
- package/dist/runtime/utils/terms-claim.d.ts +27 -0
- package/dist/runtime/utils/terms-claim.js +15 -0
- package/dist/runtime/utils/trend.d.ts +9 -0
- package/dist/runtime/utils/trend.js +5 -0
- package/dist/types.d.mts +1 -1
- package/package.json +18 -13
|
@@ -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
|
}
|
|
@@ -10,7 +10,7 @@ const format = useFormat();
|
|
|
10
10
|
const actions = useUserActions();
|
|
11
11
|
const { page, pageSize, search, sort: sortState, filters, query, filtered, reset } = useTableQuery({
|
|
12
12
|
sort: { id: "createdAt", desc: true },
|
|
13
|
-
filters: { verified: "all", role: "all", mediaOptOut: "all" }
|
|
13
|
+
filters: { verified: "all", role: "all", mediaOptOut: "all", membership: "all", membershipPlan: "*" }
|
|
14
14
|
});
|
|
15
15
|
const sort = useTableSort(null, sortState);
|
|
16
16
|
const { sorting } = sort;
|
|
@@ -19,6 +19,17 @@ const { data, status, error, refresh } = await useFetch(usersApi.admin.users, {
|
|
|
19
19
|
query
|
|
20
20
|
});
|
|
21
21
|
const rows = computed(() => data.value?.items ?? []);
|
|
22
|
+
const membershipExportHref = computed(() => {
|
|
23
|
+
const url = data.value?.membershipExportUrl;
|
|
24
|
+
if (!url) return void 0;
|
|
25
|
+
const { page: _page, pageSize: _pageSize, ...filterQuery } = query.value;
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
for (const [key, value] of Object.entries(filterQuery)) {
|
|
28
|
+
if (value !== void 0 && value !== "") params.set(key, String(value));
|
|
29
|
+
}
|
|
30
|
+
const search2 = params.toString();
|
|
31
|
+
return search2 ? `${url}?${search2}` : url;
|
|
32
|
+
});
|
|
22
33
|
const hasRoles = computed(() => data.value?.hasRoles ?? false);
|
|
23
34
|
const hasSubscriptions = computed(() => data.value?.hasSubscriptions ?? false);
|
|
24
35
|
const roles = computed(() => data.value?.roles ?? []);
|
|
@@ -26,9 +37,29 @@ const forbidden = computed(() => [401, 403].includes(error.value?.statusCode ??
|
|
|
26
37
|
const roleLabels = computed(() => new Map(roles.value.map((role) => [role.value, role.label])));
|
|
27
38
|
const roleLabel = (value) => roleLabels.value.get(value) ?? value;
|
|
28
39
|
const roleFilterItems = computed(() => [{ label: t("admin.filters.allRoles", "All roles"), value: "all" }, ...roles.value.map(({ value, label }) => ({ value, label }))]);
|
|
40
|
+
const membershipOptions = computed(() => [
|
|
41
|
+
{ label: t("admin.filters.anyMembership", "Any membership status"), value: "all" },
|
|
42
|
+
{ label: t("admin.filters.activeMember", "Active membership"), value: "active" },
|
|
43
|
+
{ label: t("admin.filters.expiredMember", "Expired membership"), value: "expired" },
|
|
44
|
+
{ label: t("admin.filters.noMembership", "No membership"), value: "none" }
|
|
45
|
+
]);
|
|
46
|
+
const membershipPlanItems = computed(() => data.value?.membershipPlans ?? []);
|
|
47
|
+
const membershipPlanOptions = computed(() => [
|
|
48
|
+
{ label: t("admin.filters.allPlans", "All plans"), value: "*" },
|
|
49
|
+
...membershipPlanItems.value
|
|
50
|
+
]);
|
|
29
51
|
const pending = computed(() => status.value === "pending");
|
|
30
52
|
const loading = computed(() => pending.value && !data.value);
|
|
31
53
|
const refreshing = computed(() => pending.value && !!data.value);
|
|
54
|
+
function showMembers() {
|
|
55
|
+
reset();
|
|
56
|
+
filters.membership = "active";
|
|
57
|
+
page.value = 1;
|
|
58
|
+
}
|
|
59
|
+
function selectMembership(value) {
|
|
60
|
+
filters.membership = value;
|
|
61
|
+
if (value === "none") filters.membershipPlan = "*";
|
|
62
|
+
}
|
|
32
63
|
const StatusBadge = resolveComponent("StatusBadge");
|
|
33
64
|
const TableIdentity = resolveComponent("TableIdentity");
|
|
34
65
|
const RowMenu = resolveComponent("RowMenu");
|
|
@@ -102,9 +133,12 @@ const addUser = () => actions.create();
|
|
|
102
133
|
<div class="flex flex-col gap-4">
|
|
103
134
|
<PageHeading :title="t('admin.title', 'Users')">
|
|
104
135
|
<template #actions>
|
|
105
|
-
<
|
|
136
|
+
<TooltipButton
|
|
137
|
+
:kbds="['meta', 'enter']"
|
|
138
|
+
shortcut-level="page"
|
|
106
139
|
icon="i-lucide-plus"
|
|
107
140
|
:label="t('admin.create', 'Add user')"
|
|
141
|
+
:tooltip="t('admin.createButtonHint', 'Create an account, with a welcome email if you choose')"
|
|
108
142
|
@click="addUser"
|
|
109
143
|
/>
|
|
110
144
|
</template>
|
|
@@ -146,6 +180,40 @@ const addUser = () => actions.create();
|
|
|
146
180
|
class="w-48"
|
|
147
181
|
icon="i-lucide-shield"
|
|
148
182
|
/>
|
|
183
|
+
<UButton
|
|
184
|
+
v-if="hasSubscriptions"
|
|
185
|
+
color="neutral"
|
|
186
|
+
:variant="filters.membership === 'active' ? 'soft' : 'outline'"
|
|
187
|
+
icon="i-lucide-badge-check"
|
|
188
|
+
:label="t('admin.filters.members', 'Members')"
|
|
189
|
+
@click="showMembers"
|
|
190
|
+
/>
|
|
191
|
+
<USelect
|
|
192
|
+
v-if="hasSubscriptions"
|
|
193
|
+
:model-value="filters.membership"
|
|
194
|
+
:items="membershipOptions"
|
|
195
|
+
:aria-label="t('admin.filters.membershipStatus', 'Membership status')"
|
|
196
|
+
class="w-48"
|
|
197
|
+
@update:model-value="selectMembership"
|
|
198
|
+
/>
|
|
199
|
+
<USelect
|
|
200
|
+
v-if="hasSubscriptions && membershipPlanItems.length && filters.membership !== 'none'"
|
|
201
|
+
v-model="filters.membershipPlan"
|
|
202
|
+
:items="membershipPlanOptions"
|
|
203
|
+
:aria-label="t('admin.filters.membershipPlan', 'Membership plan')"
|
|
204
|
+
class="w-40"
|
|
205
|
+
/>
|
|
206
|
+
<TooltipButton
|
|
207
|
+
v-if="membershipExportHref && filters.membership !== 'none'"
|
|
208
|
+
:to="membershipExportHref"
|
|
209
|
+
external
|
|
210
|
+
download
|
|
211
|
+
variant="outline"
|
|
212
|
+
color="neutral"
|
|
213
|
+
icon="i-lucide-download"
|
|
214
|
+
:label="t('admin.exportMembers', 'Export members')"
|
|
215
|
+
:tooltip="t('admin.exportMembersHint', 'Download all memberships matching the filters as CSV')"
|
|
216
|
+
/>
|
|
149
217
|
<UButton
|
|
150
218
|
v-if="filtered"
|
|
151
219
|
variant="ghost"
|
|
@@ -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>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { usersApi } from "../../utils/api.js";
|
|
3
|
+
import UsersTermsGate from "../components/UsersTermsGate.vue";
|
|
4
|
+
import { $fetch, defineNuxtPlugin, useCookie, useLocaleLink, useOverlay, useRouter, useRuntimeConfig, useUserSession } from "#imports";
|
|
5
|
+
const TERMS_OK_COOKIE = "users-terms-ok";
|
|
6
|
+
const TERMS_OK_MAX_AGE = 60 * 60 * 24;
|
|
7
|
+
export default defineNuxtPlugin({
|
|
8
|
+
name: "users:terms-gate",
|
|
9
|
+
setup(nuxtApp) {
|
|
10
|
+
const terms = useRuntimeConfig().public.users?.terms;
|
|
11
|
+
if (!terms) return;
|
|
12
|
+
nuxtApp.hook("app:mounted", () => {
|
|
13
|
+
nuxtApp.runWithContext(() => {
|
|
14
|
+
const { loggedIn, user } = useUserSession();
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
const { isActive } = useLocaleLink();
|
|
17
|
+
const gate = useOverlay().create(UsersTermsGate, { destroyOnClose: true });
|
|
18
|
+
const termsOk = useCookie(TERMS_OK_COOKIE, { maxAge: TERMS_OK_MAX_AGE, path: "/", sameSite: "lax" });
|
|
19
|
+
const okKey = (id) => `${String(id)}:${terms.version}`;
|
|
20
|
+
const remember = (id, next) => {
|
|
21
|
+
termsOk.value = next?.upToDate ? okKey(id) : null;
|
|
22
|
+
};
|
|
23
|
+
let status = null;
|
|
24
|
+
let open = false;
|
|
25
|
+
let checked;
|
|
26
|
+
const onLegalPage = () => isActive(terms.url) || !!terms.privacyUrl && isActive(terms.privacyUrl);
|
|
27
|
+
const sync = () => {
|
|
28
|
+
const needed = !!status && !status.upToDate && loggedIn.value && !onLegalPage();
|
|
29
|
+
if (needed && !open) {
|
|
30
|
+
open = true;
|
|
31
|
+
void gate.open({ status }).then((next) => {
|
|
32
|
+
open = false;
|
|
33
|
+
if (next) {
|
|
34
|
+
status = next;
|
|
35
|
+
if (checked !== void 0) remember(checked, next);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} else if (!needed && open) {
|
|
39
|
+
open = false;
|
|
40
|
+
gate.close();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const check = async () => {
|
|
44
|
+
const id = user.value?.id;
|
|
45
|
+
if (!loggedIn.value || id === void 0) {
|
|
46
|
+
status = null;
|
|
47
|
+
checked = void 0;
|
|
48
|
+
return sync();
|
|
49
|
+
}
|
|
50
|
+
if (checked === id) return sync();
|
|
51
|
+
checked = id;
|
|
52
|
+
if (termsOk.value === okKey(id)) {
|
|
53
|
+
status = null;
|
|
54
|
+
return sync();
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
status = await $fetch(usersApi.me.terms);
|
|
58
|
+
remember(id, status);
|
|
59
|
+
} catch {
|
|
60
|
+
status = null;
|
|
61
|
+
checked = void 0;
|
|
62
|
+
}
|
|
63
|
+
sync();
|
|
64
|
+
};
|
|
65
|
+
watch([loggedIn, () => user.value?.id], () => void check(), { immediate: true });
|
|
66
|
+
router.afterEach(() => sync());
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
@@ -1,9 +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";
|
|
4
5
|
import { USER_NICKNAME_MAX_LENGTH, USER_PEOPLE_NUMBER_MAX_LENGTH } from "../../utils/profile";
|
|
5
6
|
import { z } from "zod";
|
|
6
|
-
import
|
|
7
|
+
import UsersAdminTerms from "../components/UsersAdminTerms.vue";
|
|
8
|
+
import { $fetch, computed, reactive, resolveComponent, useAction, useFormat, useModuleT, useRuntimeConfig, watch } from "#imports";
|
|
7
9
|
defineOptions({ name: "UsersAdminOverviewTab" });
|
|
8
10
|
const props = defineProps({
|
|
9
11
|
user: { type: Object, required: true }
|
|
@@ -13,14 +15,17 @@ const t = useModuleT("users");
|
|
|
13
15
|
const format = useFormat();
|
|
14
16
|
const { busy: saving, run } = useAction();
|
|
15
17
|
const OverviewWidgets = resolveComponent("WidgetArea");
|
|
18
|
+
const terms = useRuntimeConfig().public.users?.terms;
|
|
19
|
+
const showTerms = computed(() => !!terms && props.user.phone !== void 0);
|
|
16
20
|
const overviewWidgets = typeof OverviewWidgets === "string" ? void 0 : OverviewWidgets;
|
|
17
21
|
const schema = z.object({
|
|
18
22
|
name: z.string().trim().min(1, t("admin.nameRequired", "Enter a name.")).max(120),
|
|
19
23
|
nickname: z.string().trim().max(USER_NICKNAME_MAX_LENGTH, t("admin.nicknameTooLong", "Use at most {max} characters.", { max: USER_NICKNAME_MAX_LENGTH })),
|
|
20
24
|
email: z.string().trim().email(t("admin.emailInvalid", "Enter a valid email address.")),
|
|
21
25
|
emailVerified: z.boolean(),
|
|
22
|
-
// The server's rule (`phoneField`)
|
|
23
|
-
|
|
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.")),
|
|
24
29
|
// The server's rule (`peopleNumberField`): at most 64 characters; empty clears it.
|
|
25
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 }))
|
|
26
31
|
});
|
|
@@ -47,13 +52,13 @@ const mediaFacts = computed(() => [
|
|
|
47
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") },
|
|
48
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") }
|
|
49
54
|
]);
|
|
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 ?? "") ||
|
|
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 ?? ""));
|
|
51
56
|
async function save(event) {
|
|
52
57
|
const { name, nickname, email, emailVerified, phone, peopleNumber } = event.data;
|
|
53
58
|
const emailChanged = email !== props.user.email;
|
|
54
59
|
const nicknameChanged = nickname !== (props.user.nickname ?? "");
|
|
55
60
|
const phoneChanged = props.user.can.pii && phone !== (props.user.phone ?? "");
|
|
56
|
-
const peopleNumberChanged =
|
|
61
|
+
const peopleNumberChanged = peopleNumber !== (props.user.peopleNumber ?? "");
|
|
57
62
|
const saved = await run(
|
|
58
63
|
() => $fetch(usersApi.admin.user(props.user.id), {
|
|
59
64
|
method: "PATCH",
|
|
@@ -143,16 +148,15 @@ async function save(event) {
|
|
|
143
148
|
:label="t('admin.phone', 'Phone')"
|
|
144
149
|
:description="t('admin.detail.phoneHelp', 'Used for text messages. Leave it empty to remove it.')"
|
|
145
150
|
>
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
class="w-full sm:max-w-sm"
|
|
151
|
+
<PhoneInput
|
|
152
|
+
:model-value="form.phone"
|
|
153
|
+
:country-label="t('admin.phoneCountry', 'Country')"
|
|
154
|
+
class="sm:max-w-sm"
|
|
151
155
|
:disabled="!user.can.pii"
|
|
156
|
+
@update:model-value="form.phone = $event ?? ''"
|
|
152
157
|
/>
|
|
153
158
|
</FormRow>
|
|
154
159
|
<FormRow
|
|
155
|
-
v-if="user.peopleNumber !== void 0"
|
|
156
160
|
name="peopleNumber"
|
|
157
161
|
:label="t('admin.peopleNumber', 'People number')"
|
|
158
162
|
:description="t('admin.detail.peopleNumberHelp', 'Their id in an external system, such as a volunteer system. Leave it empty to remove it.')"
|
|
@@ -161,15 +165,16 @@ async function save(event) {
|
|
|
161
165
|
v-model="form.peopleNumber"
|
|
162
166
|
autocomplete="off"
|
|
163
167
|
class="w-full sm:max-w-sm"
|
|
164
|
-
:disabled="!user.can.
|
|
168
|
+
:disabled="!user.can.update"
|
|
165
169
|
/>
|
|
166
170
|
</FormRow>
|
|
167
171
|
</UForm>
|
|
168
172
|
<template #footer>
|
|
169
173
|
<div class="flex justify-end">
|
|
170
|
-
<
|
|
174
|
+
<TooltipButton
|
|
171
175
|
type="submit"
|
|
172
176
|
form="user-profile-form"
|
|
177
|
+
:kbds="['meta', 'enter']"
|
|
173
178
|
:loading="saving"
|
|
174
179
|
:disabled="!dirty || !user.can.update"
|
|
175
180
|
:label="t('admin.detail.saveProfile', 'Save profile')"
|
|
@@ -203,5 +208,11 @@ async function save(event) {
|
|
|
203
208
|
</SectionCard>
|
|
204
209
|
</div>
|
|
205
210
|
</div>
|
|
211
|
+
|
|
212
|
+
<UsersAdminTerms
|
|
213
|
+
v-if="showTerms && terms"
|
|
214
|
+
:user-id="user.id"
|
|
215
|
+
:current-version="terms.version"
|
|
216
|
+
/>
|
|
206
217
|
</div>
|
|
207
218
|
</template>
|
|
@@ -23,6 +23,11 @@ export type UsersPage = {
|
|
|
23
23
|
pageSize: number;
|
|
24
24
|
hasRoles: boolean;
|
|
25
25
|
hasSubscriptions: boolean;
|
|
26
|
+
membershipPlans?: {
|
|
27
|
+
value: string;
|
|
28
|
+
label: string;
|
|
29
|
+
}[];
|
|
30
|
+
membershipExportUrl?: string;
|
|
26
31
|
roles: UserRoleOption[];
|
|
27
32
|
};
|
|
28
33
|
/** The shape of `GET /api/admin/users/:id`. */
|
|
@@ -38,8 +43,10 @@ export type UserDetail = AdminUserDto & {
|
|
|
38
43
|
pii: boolean;
|
|
39
44
|
};
|
|
40
45
|
};
|
|
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'
|
|
46
|
+
/** What the actions need of a user: the list rows and the detail both satisfy it. Without `avatar` there is no "Remove avatar". */
|
|
47
|
+
export type UserSubject = Pick<UserRow, 'id' | 'name' | 'emailVerifiedAt'> & {
|
|
48
|
+
avatar?: string | null;
|
|
49
|
+
};
|
|
43
50
|
/** The key of the list's `useFetch`, refreshed after a user is created or deleted. */
|
|
44
51
|
export declare const ADMIN_USERS_KEY = "admin-users";
|
|
45
52
|
/** What the create form closes with: the created user, the existing user staff chose after a 409, or `false` (cancelled). */
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A part of a sentence: plain text, or the link named by its placeholder. */
|
|
2
|
+
export type UsersTermsTextPart = {
|
|
3
|
+
text: string;
|
|
4
|
+
} | {
|
|
5
|
+
link: string;
|
|
6
|
+
};
|
|
7
|
+
/** The placeholder values to translate a sentence with, so `splitUsersTermsText` can find the links again. */
|
|
8
|
+
export declare function usersTermsLinkParams(...names: string[]): Record<string, string>;
|
|
9
|
+
/** `translated` (made with `usersTermsLinkParams`) cut into text and link parts, in order. */
|
|
10
|
+
export declare function splitUsersTermsText(translated: string): UsersTermsTextPart[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const MARK = "\uE000";
|
|
2
|
+
export function usersTermsLinkParams(...names) {
|
|
3
|
+
return Object.fromEntries(names.map((name) => [name, `${MARK}${name}${MARK}`]));
|
|
4
|
+
}
|
|
5
|
+
export function splitUsersTermsText(translated) {
|
|
6
|
+
return translated.split(new RegExp(`${MARK}([^${MARK}]+)${MARK}`)).map((piece, index) => index % 2 ? { link: piece } : { text: piece }).filter((part) => "link" in part || part.text);
|
|
7
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
framed?: boolean;
|
|
3
|
+
};
|
|
4
|
+
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>;
|
|
2
5
|
declare const _default: typeof __VLS_export;
|
|
3
6
|
export default _default;
|
|
@@ -1,51 +1,66 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
|
-
import { statusColor, useFormat, useLazyFetch, useLocaleLink, useModuleT, useRuntimeConfig } from "#imports";
|
|
3
|
+
import { computed, statusColor, useFormat, useLazyFetch, useLocaleLink, useModuleT, useRuntimeConfig } from "#imports";
|
|
4
4
|
defineOptions({ name: "UsersNewUsersWidget" });
|
|
5
|
+
defineProps({
|
|
6
|
+
framed: { type: Boolean, required: false }
|
|
7
|
+
});
|
|
5
8
|
const t = useModuleT("users");
|
|
6
9
|
const format = useFormat();
|
|
7
10
|
const { localize } = useLocaleLink();
|
|
8
11
|
const adminPage = useRuntimeConfig().public.users?.pages?.admin;
|
|
9
12
|
const listPath = adminPage ? localize(adminPage.replace(/\/+$/, "")) : void 0;
|
|
10
|
-
const { data
|
|
13
|
+
const { data, status } = useLazyFetch(usersApi.admin.new, { key: "admin-users-new", default: () => [] });
|
|
14
|
+
const users = computed(() => data.value?.slice(0, 6) ?? []);
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
17
|
<template>
|
|
14
18
|
<ListCard
|
|
15
|
-
:title="t('admin.newUsers.title', 'New users')"
|
|
19
|
+
:title="framed ? void 0 : t('admin.newUsers.title', 'New users')"
|
|
16
20
|
:description="t('admin.newUsers.description', 'Signed up in the last 30 days.')"
|
|
17
|
-
:loading="status === 'pending' && !users?.length"
|
|
18
|
-
:is-empty="!users?.length"
|
|
19
|
-
:empty="t('admin.newUsers.empty', 'Nobody new yet.')"
|
|
21
|
+
:loading="(status === 'pending' || status === 'idle') && !users?.length"
|
|
22
|
+
:is-empty="(status === 'success' || status === 'error') && !users?.length"
|
|
23
|
+
:empty="status === 'error' ? t('admin.newUsers.error', 'Could not load the new users.') : t('admin.newUsers.empty', 'Nobody new yet.')"
|
|
20
24
|
:to="listPath"
|
|
21
25
|
:to-label="t('admin.allUsers', 'All users')"
|
|
22
26
|
>
|
|
23
27
|
<li
|
|
24
28
|
v-for="user in users"
|
|
25
29
|
:key="user.id"
|
|
26
|
-
class="flex items-center
|
|
30
|
+
class="flex items-center gap-3"
|
|
27
31
|
>
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
<UAvatar
|
|
33
|
+
:src="user.avatar ?? void 0"
|
|
34
|
+
:alt="user.name"
|
|
35
|
+
size="sm"
|
|
36
|
+
/>
|
|
37
|
+
<div class="min-w-0 flex-1">
|
|
38
|
+
<div class="flex min-w-0 items-center gap-2">
|
|
39
|
+
<NuxtLink
|
|
40
|
+
v-if="listPath"
|
|
41
|
+
:to="`${listPath}/${user.id}`"
|
|
42
|
+
class="text-highlighted truncate font-medium hover:underline"
|
|
43
|
+
>{{ user.name }}</NuxtLink>
|
|
44
|
+
<span
|
|
45
|
+
v-else
|
|
46
|
+
class="text-highlighted truncate font-medium"
|
|
47
|
+
>{{ user.name }}</span>
|
|
48
|
+
<UBadge
|
|
49
|
+
v-if="user.subscription"
|
|
50
|
+
size="sm"
|
|
51
|
+
variant="subtle"
|
|
52
|
+
:color="statusColor(user.subscription.status)"
|
|
53
|
+
:label="user.subscription.planKey ?? user.subscription.status"
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
<p class="text-muted truncate text-xs">
|
|
57
|
+
{{ user.email }}
|
|
58
|
+
</p>
|
|
59
|
+
</div>
|
|
60
|
+
<time
|
|
61
|
+
class="text-muted shrink-0 text-xs tabular-nums"
|
|
62
|
+
:datetime="user.createdAt"
|
|
63
|
+
>{{ format.shortDate(user.createdAt) }}</time>
|
|
49
64
|
</li>
|
|
50
65
|
</ListCard>
|
|
51
66
|
</template>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
framed?: boolean;
|
|
3
|
+
};
|
|
4
|
+
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>;
|
|
2
5
|
declare const _default: typeof __VLS_export;
|
|
3
6
|
export default _default;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
framed?: boolean;
|
|
3
|
+
};
|
|
4
|
+
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>;
|
|
2
5
|
declare const _default: typeof __VLS_export;
|
|
3
6
|
export default _default;
|