mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-04-10 23:15:34 -04:00
chore: Nuxt 4 upgrade (#7426)
This commit is contained in:
106
frontend/app/pages/admin/manage/groups/[id].vue
Normal file
106
frontend/app/pages/admin/manage/groups/[id].vue
Normal file
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<v-container
|
||||
v-if="group"
|
||||
class="narrow-container"
|
||||
>
|
||||
<BasePageTitle>
|
||||
<template #header>
|
||||
<v-img
|
||||
width="100%"
|
||||
max-height="125"
|
||||
max-width="125"
|
||||
src="/svgs/manage-group-settings.svg"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ $t('group.admin-group-management') }}
|
||||
</template>
|
||||
{{ $t('group.admin-group-management-text') }}
|
||||
</BasePageTitle>
|
||||
<AppToolbar back />
|
||||
<v-card-text> {{ $t('group.group-id-value', [group.id]) }} </v-card-text>
|
||||
<v-form
|
||||
v-if="!userError"
|
||||
ref="refGroupEditForm"
|
||||
@submit.prevent="handleSubmit"
|
||||
>
|
||||
<v-card variant="outlined" style="border-color: lightgrey;">
|
||||
<v-card-text>
|
||||
<v-text-field
|
||||
v-model="group.name"
|
||||
:label="$t('group.group-name')"
|
||||
/>
|
||||
<GroupPreferencesEditor
|
||||
v-if="group.preferences"
|
||||
v-model="group.preferences"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<div class="d-flex pa-2">
|
||||
<BaseButton
|
||||
type="submit"
|
||||
edit
|
||||
class="ml-auto"
|
||||
>
|
||||
{{ $t("general.update") }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import GroupPreferencesEditor from "~/components/Domain/Group/GroupPreferencesEditor.vue";
|
||||
import { useAdminApi } from "~/composables/api";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import type { VForm } from "vuetify/components";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
const route = useRoute();
|
||||
|
||||
const i18n = useI18n();
|
||||
|
||||
const groupId = computed(() => route.params.id as string);
|
||||
|
||||
// ==============================================
|
||||
// New User Form
|
||||
|
||||
const refGroupEditForm = ref<VForm | null>(null);
|
||||
|
||||
const adminApi = useAdminApi();
|
||||
|
||||
const userError = ref(false);
|
||||
|
||||
const { data: group } = useLazyAsyncData(`get-household-${groupId.value}`, async () => {
|
||||
if (!groupId.value) {
|
||||
return null;
|
||||
}
|
||||
const { data, error } = await adminApi.groups.getOne(groupId.value);
|
||||
|
||||
if (error?.response?.status === 404) {
|
||||
alert.error(i18n.t("user.user-not-found"));
|
||||
userError.value = true;
|
||||
}
|
||||
return data;
|
||||
}, { watch: [groupId] });
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!refGroupEditForm.value?.validate() || group.value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { response, data } = await adminApi.groups.updateOne(group.value.id, group.value);
|
||||
if (response?.status === 200 && data) {
|
||||
if (group.value.slug !== data.slug) {
|
||||
// the slug updated, which invalidates the nav URLs
|
||||
window.location.reload();
|
||||
}
|
||||
group.value = data;
|
||||
}
|
||||
else {
|
||||
alert.error(i18n.t("settings.settings-update-failed"));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
160
frontend/app/pages/admin/manage/groups/index.vue
Normal file
160
frontend/app/pages/admin/manage/groups/index.vue
Normal file
@@ -0,0 +1,160 @@
|
||||
<template>
|
||||
<v-container fluid>
|
||||
<BaseDialog
|
||||
v-model="state.createDialog"
|
||||
:title="$t('group.create-group')"
|
||||
:icon="$globals.icons.group"
|
||||
can-submit
|
||||
@submit="createGroup(state.createGroupForm.data)"
|
||||
>
|
||||
<template #activator />
|
||||
<v-card-text>
|
||||
<AutoForm
|
||||
v-model="state.createGroupForm.data"
|
||||
:update-mode="state.updateMode"
|
||||
:items="state.createGroupForm.items"
|
||||
/>
|
||||
</v-card-text>
|
||||
</BaseDialog>
|
||||
|
||||
<BaseDialog
|
||||
v-model="state.confirmDialog"
|
||||
:title="$t('general.confirm')"
|
||||
:icon="$globals.icons.alertCircle"
|
||||
color="error"
|
||||
can-confirm
|
||||
@confirm="deleteGroup(state.deleteTarget)"
|
||||
>
|
||||
<template #activator />
|
||||
<v-card-text>
|
||||
{{ $t("general.confirm-delete-generic") }}
|
||||
</v-card-text>
|
||||
</BaseDialog>
|
||||
|
||||
<BaseCardSectionTitle :title="$t('group.group-management')" />
|
||||
<section>
|
||||
<v-toolbar
|
||||
flat
|
||||
color="transparent"
|
||||
class="justify-between"
|
||||
>
|
||||
<BaseButton @click="openDialog">
|
||||
{{ $t("general.create") }}
|
||||
</BaseButton>
|
||||
</v-toolbar>
|
||||
|
||||
<v-data-table
|
||||
:headers="state.headers"
|
||||
:items="groups || []"
|
||||
item-key="id"
|
||||
class="elevation-0"
|
||||
:items-per-page="-1"
|
||||
hide-default-footer
|
||||
disable-pagination
|
||||
:search="state.search"
|
||||
@click:row="($event, { item }) => handleRowClick(item)"
|
||||
>
|
||||
<template #[`item.households`]="{ item }">
|
||||
{{ item.households!.length }}
|
||||
</template>
|
||||
<template #[`item.users`]="{ item }">
|
||||
{{ item.users!.length }}
|
||||
</template>
|
||||
<template #[`item.actions`]="{ item }">
|
||||
<v-tooltip
|
||||
location="bottom"
|
||||
:disabled="!(item && (item.households!.length > 0 || item.users!.length > 0))"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<div v-bind="props">
|
||||
<v-btn
|
||||
:disabled="item && (item.households!.length > 0 || item.users!.length > 0)"
|
||||
class="mr-1"
|
||||
icon
|
||||
color="error"
|
||||
variant="text"
|
||||
@click.stop="
|
||||
state.confirmDialog = true;
|
||||
state.deleteTarget = item.id;
|
||||
"
|
||||
>
|
||||
<v-icon>
|
||||
{{ $globals.icons.delete }}
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
</template>
|
||||
<span>{{ $t("admin.group-delete-note") }}</span>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-data-table>
|
||||
<v-divider />
|
||||
</section>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fieldTypes } from "~/composables/forms";
|
||||
import { useGroups } from "~/composables/use-groups";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { GroupInDB } from "~/lib/api/types/user";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const i18n = useI18n();
|
||||
|
||||
useHead({
|
||||
title: i18n.t("group.manage-groups"),
|
||||
});
|
||||
|
||||
// Set page title
|
||||
useSeoMeta({
|
||||
title: i18n.t("group.manage-groups"),
|
||||
});
|
||||
|
||||
const { groups, deleteGroup, createGroup } = useGroups();
|
||||
|
||||
const state = reactive({
|
||||
createDialog: false,
|
||||
confirmDialog: false,
|
||||
deleteTarget: "",
|
||||
search: "",
|
||||
headers: [
|
||||
{
|
||||
title: i18n.t("group.group"),
|
||||
align: "start",
|
||||
sortable: false,
|
||||
value: "id",
|
||||
},
|
||||
{ title: i18n.t("general.name"), value: "name" },
|
||||
{ title: i18n.t("group.total-households"), value: "households" },
|
||||
{ title: i18n.t("user.total-users"), value: "users" },
|
||||
{ title: i18n.t("general.delete"), value: "actions" },
|
||||
],
|
||||
updateMode: false,
|
||||
createGroupForm: {
|
||||
items: [
|
||||
{
|
||||
label: i18n.t("group.group-name"),
|
||||
varName: "name",
|
||||
type: fieldTypes.TEXT,
|
||||
rules: [validators.required],
|
||||
},
|
||||
],
|
||||
data: {
|
||||
name: "",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function openDialog() {
|
||||
state.createDialog = true;
|
||||
state.createGroupForm.data.name = "";
|
||||
}
|
||||
|
||||
function handleRowClick(item: GroupInDB) {
|
||||
navigateTo(`/admin/manage/groups/${item.id}`);
|
||||
}
|
||||
</script>
|
||||
124
frontend/app/pages/admin/manage/households/[id].vue
Normal file
124
frontend/app/pages/admin/manage/households/[id].vue
Normal file
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<v-container
|
||||
v-if="household"
|
||||
class="narrow-container"
|
||||
>
|
||||
<BasePageTitle>
|
||||
<template #header>
|
||||
<v-img
|
||||
width="100%"
|
||||
max-height="125"
|
||||
max-width="125"
|
||||
src="/svgs/manage-group-settings.svg"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ $t('household.admin-household-management') }}
|
||||
</template>
|
||||
{{ $t('household.admin-household-management-text') }}
|
||||
</BasePageTitle>
|
||||
<AppToolbar back />
|
||||
<v-card-text> {{ $t('household.household-id-value', [household.id]) }} </v-card-text>
|
||||
<v-form
|
||||
v-if="!userError"
|
||||
ref="refHouseholdEditForm"
|
||||
@submit.prevent="handleSubmit"
|
||||
>
|
||||
<v-card variant="outlined" style="border-color: lightgrey;">
|
||||
<v-card-text>
|
||||
<v-select
|
||||
v-if="groups"
|
||||
v-model="household.groupId"
|
||||
disabled
|
||||
:items="groups"
|
||||
variant="solo-filled"
|
||||
flat
|
||||
item-title="name"
|
||||
item-value="id"
|
||||
:return-object="false"
|
||||
:label="$t('group.user-group')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="household.name"
|
||||
variant="solo-filled"
|
||||
flat
|
||||
:label="$t('household.household-name')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
<HouseholdPreferencesEditor
|
||||
v-if="household.preferences"
|
||||
v-model="household.preferences"
|
||||
variant="solo-filled"
|
||||
flat
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<div class="d-flex pa-2">
|
||||
<BaseButton
|
||||
type="submit"
|
||||
edit
|
||||
class="ml-auto"
|
||||
>
|
||||
{{ $t("general.update") }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import HouseholdPreferencesEditor from "~/components/Domain/Household/HouseholdPreferencesEditor.vue";
|
||||
import { useGroups } from "~/composables/use-groups";
|
||||
import { useAdminApi } from "~/composables/api";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { VForm } from "vuetify/components";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const i18n = useI18n();
|
||||
|
||||
const { groups } = useGroups();
|
||||
const householdId = computed(() => route.params.id as string);
|
||||
|
||||
// ==============================================
|
||||
// New User Form
|
||||
|
||||
const refHouseholdEditForm = ref<VForm | null>(null);
|
||||
|
||||
const adminApi = useAdminApi();
|
||||
|
||||
const userError = ref(false);
|
||||
|
||||
const { data: household } = useAsyncData(`get-household-${householdId.value}`, async () => {
|
||||
if (!householdId.value) {
|
||||
return null;
|
||||
}
|
||||
const { data, error } = await adminApi.households.getOne(householdId.value);
|
||||
|
||||
if (error?.response?.status === 404) {
|
||||
alert.error(i18n.t("user.user-not-found"));
|
||||
userError.value = true;
|
||||
}
|
||||
return data;
|
||||
}, { watch: [householdId] });
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!refHouseholdEditForm.value?.validate() || household.value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { response, data } = await adminApi.households.updateOne(household.value.id, household.value);
|
||||
if (response?.status === 200 && data) {
|
||||
household.value = data;
|
||||
alert.success(i18n.t("settings.settings-updated"));
|
||||
}
|
||||
else {
|
||||
alert.error(i18n.t("settings.settings-update-failed"));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
192
frontend/app/pages/admin/manage/households/index.vue
Normal file
192
frontend/app/pages/admin/manage/households/index.vue
Normal file
@@ -0,0 +1,192 @@
|
||||
<template>
|
||||
<v-container fluid>
|
||||
<BaseDialog
|
||||
v-model="createDialog"
|
||||
:title="$t('household.create-household')"
|
||||
:icon="$globals.icons.household"
|
||||
>
|
||||
<template #activator />
|
||||
<v-card-text>
|
||||
<v-form ref="refNewHouseholdForm" @keydown.enter.prevent="handleCreateSubmit">
|
||||
<v-select
|
||||
v-if="groups"
|
||||
v-model="createHouseholdForm.data.groupId"
|
||||
:items="groups"
|
||||
item-title="name"
|
||||
item-value="id"
|
||||
variant="filled"
|
||||
:label="$t('household.household-group')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
<AutoForm
|
||||
v-model="createHouseholdForm.data"
|
||||
:update-mode="updateMode"
|
||||
:items="createHouseholdForm.items"
|
||||
/>
|
||||
</v-form>
|
||||
</v-card-text>
|
||||
<template #custom-card-action>
|
||||
<BaseButton
|
||||
type="submit"
|
||||
@click="handleCreateSubmit"
|
||||
>
|
||||
{{ $t("general.create") }}
|
||||
</BaseButton>
|
||||
</template>
|
||||
</BaseDialog>
|
||||
|
||||
<BaseDialog
|
||||
v-model="confirmDialog"
|
||||
:title="$t('general.confirm')"
|
||||
:icon="$globals.icons.alertCircle"
|
||||
color="error"
|
||||
can-confirm
|
||||
@confirm="deleteHousehold(deleteTarget)"
|
||||
>
|
||||
<template #activator />
|
||||
<v-card-text>
|
||||
{{ $t("general.confirm-delete-generic") }}
|
||||
</v-card-text>
|
||||
</BaseDialog>
|
||||
|
||||
<BaseCardSectionTitle :title="$t('household.household-management')" />
|
||||
<section>
|
||||
<v-toolbar
|
||||
flat
|
||||
color="transparent"
|
||||
class="justify-between"
|
||||
>
|
||||
<BaseButton @click="openDialog">
|
||||
{{ $t("general.create") }}
|
||||
</BaseButton>
|
||||
</v-toolbar>
|
||||
|
||||
<v-data-table
|
||||
v-if="headers && households"
|
||||
:headers="headers"
|
||||
:items="households"
|
||||
item-key="id"
|
||||
class="elevation-0"
|
||||
:items-per-page="-1"
|
||||
hide-default-footer
|
||||
disable-pagination
|
||||
:search="search"
|
||||
@click:row="($event, { item }) => handleRowClick(item)"
|
||||
>
|
||||
<template #[`item.users`]="{ item }">
|
||||
{{ item.users?.length }}
|
||||
</template>
|
||||
<template #[`item.group`]="{ item }">
|
||||
{{ item.group }}
|
||||
</template>
|
||||
<template #[`item.webhookEnable`]="{ item }">
|
||||
{{ item.webhooks!.length > 0 ? $t("general.yes") : $t("general.no") }}
|
||||
</template>
|
||||
<template #[`item.actions`]="{ item }">
|
||||
<v-tooltip
|
||||
location="bottom"
|
||||
:disabled="!(item && item.users!.length > 0)"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<div v-bind="props">
|
||||
<v-btn
|
||||
:disabled="item && item.users!.length > 0"
|
||||
class="mr-1"
|
||||
icon
|
||||
color="error"
|
||||
variant="text"
|
||||
@click.stop="confirmDialog = true; deleteTarget = item.id"
|
||||
>
|
||||
<v-icon>
|
||||
{{ $globals.icons.delete }}
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
</template>
|
||||
<span>{{ $t("admin.household-delete-note") }}</span>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-data-table>
|
||||
<v-divider />
|
||||
</section>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fieldTypes } from "~/composables/forms";
|
||||
import { useGroups } from "~/composables/use-groups";
|
||||
import { useAdminHouseholds } from "~/composables/use-households";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { HouseholdInDB } from "~/lib/api/types/household";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const i18n = useI18n();
|
||||
|
||||
useSeoMeta({
|
||||
title: i18n.t("household.manage-households"),
|
||||
});
|
||||
|
||||
const { groups } = useGroups();
|
||||
const { households, deleteHousehold, createHousehold } = useAdminHouseholds();
|
||||
|
||||
const refNewHouseholdForm = ref<VForm | null>(null);
|
||||
|
||||
const createDialog = ref(false);
|
||||
const confirmDialog = ref(false);
|
||||
const deleteTarget = ref<string>("");
|
||||
const search = ref("");
|
||||
const updateMode = ref(false);
|
||||
|
||||
const headers = [
|
||||
{
|
||||
title: i18n.t("household.household"),
|
||||
align: "start",
|
||||
sortable: false,
|
||||
value: "id",
|
||||
},
|
||||
{ title: i18n.t("general.name"), value: "name" },
|
||||
{ title: i18n.t("group.group"), value: "group" },
|
||||
{ title: i18n.t("user.total-users"), value: "users" },
|
||||
{ title: i18n.t("user.webhooks-enabled"), value: "webhookEnable" },
|
||||
{ title: i18n.t("general.delete"), value: "actions" },
|
||||
];
|
||||
|
||||
const createHouseholdForm = reactive({
|
||||
items: [
|
||||
{
|
||||
label: i18n.t("household.household-name"),
|
||||
varName: "name",
|
||||
type: fieldTypes.TEXT,
|
||||
rules: [validators.required],
|
||||
},
|
||||
],
|
||||
data: {
|
||||
groupId: "",
|
||||
name: "",
|
||||
},
|
||||
});
|
||||
|
||||
function openDialog() {
|
||||
createDialog.value = true;
|
||||
createHouseholdForm.data.name = "";
|
||||
createHouseholdForm.data.groupId = "";
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
function handleRowClick(item: HouseholdInDB) {
|
||||
router.push(`/admin/manage/households/${item.id}`);
|
||||
}
|
||||
|
||||
async function handleCreateSubmit() {
|
||||
if (!refNewHouseholdForm.value?.validate()) {
|
||||
return;
|
||||
}
|
||||
createDialog.value = false;
|
||||
await createHousehold(createHouseholdForm.data);
|
||||
}
|
||||
</script>
|
||||
228
frontend/app/pages/admin/manage/users/[id].vue
Normal file
228
frontend/app/pages/admin/manage/users/[id].vue
Normal file
@@ -0,0 +1,228 @@
|
||||
<template>
|
||||
<v-container
|
||||
v-if="user"
|
||||
class="narrow-container"
|
||||
>
|
||||
<BasePageTitle>
|
||||
<template #header>
|
||||
<v-img
|
||||
width="100%"
|
||||
max-height="125"
|
||||
max-width="125"
|
||||
src="/svgs/manage-profile.svg"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ $t("user.admin-user-management") }}
|
||||
</template>
|
||||
{{ $t("user.changes-reflected-immediately") }}
|
||||
</BasePageTitle>
|
||||
<AppToolbar back />
|
||||
<v-form
|
||||
v-if="!userError"
|
||||
ref="refNewUserForm"
|
||||
@submit.prevent="handleSubmit"
|
||||
>
|
||||
<v-card
|
||||
variant="outlined"
|
||||
style="border-color: lightgrey;"
|
||||
>
|
||||
<v-sheet class="pt-4">
|
||||
<v-card-text>
|
||||
<div class="d-flex">
|
||||
<p> {{ $t("user.user-id-with-value", { id: user.id }) }}</p>
|
||||
</div>
|
||||
<!-- This is disabled since we can't properly handle changing the user's group in most scenarios -->
|
||||
|
||||
<v-row>
|
||||
<v-col cols="6">
|
||||
<v-select
|
||||
v-if="groups"
|
||||
v-model="user.group"
|
||||
disabled
|
||||
:items="groups"
|
||||
variant="solo-filled"
|
||||
flat
|
||||
item-title="name"
|
||||
item-value="name"
|
||||
:return-object="false"
|
||||
:label="$t('group.user-group')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="6">
|
||||
<v-select
|
||||
v-if="households"
|
||||
v-model="user.household"
|
||||
:items="households"
|
||||
variant="solo-filled"
|
||||
flat
|
||||
item-title="name"
|
||||
item-value="name"
|
||||
:return-object="false"
|
||||
:label="$t('household.user-household')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<div class="d-flex py-2 pr-2">
|
||||
<BaseButton
|
||||
type="button"
|
||||
:loading="generatingToken"
|
||||
create
|
||||
@click.prevent="handlePasswordReset"
|
||||
>
|
||||
{{ $t("user.generate-password-reset-link") }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="resetUrl"
|
||||
class="mb-2"
|
||||
>
|
||||
<v-card-text>
|
||||
<p class="text-center pb-0">
|
||||
{{ resetUrl }}
|
||||
</p>
|
||||
</v-card-text>
|
||||
<v-card-actions
|
||||
class="align-center pt-0"
|
||||
style="gap: 4px"
|
||||
>
|
||||
<BaseButton
|
||||
cancel
|
||||
@click="resetUrl = ''"
|
||||
>
|
||||
{{ $t("general.close") }}
|
||||
</BaseButton>
|
||||
<v-spacer />
|
||||
<BaseButton
|
||||
v-if="user.email"
|
||||
color="info"
|
||||
class="mr-1"
|
||||
@click="sendResetEmail"
|
||||
>
|
||||
<template #icon>
|
||||
{{ $globals.icons.email }}
|
||||
</template>
|
||||
{{ $t("user.email") }}
|
||||
</BaseButton>
|
||||
<AppButtonCopy
|
||||
:icon="false"
|
||||
color="info"
|
||||
:copy-text="resetUrl"
|
||||
/>
|
||||
</v-card-actions>
|
||||
</div>
|
||||
|
||||
<AutoForm
|
||||
v-model="user"
|
||||
:items="userForm"
|
||||
update-mode
|
||||
:disabled-fields="disabledFields"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-sheet>
|
||||
</v-card>
|
||||
<div class="d-flex pa-2">
|
||||
<BaseButton
|
||||
type="submit"
|
||||
edit
|
||||
class="ml-auto"
|
||||
>
|
||||
{{ $t("general.update") }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAdminApi, useUserApi } from "~/composables/api";
|
||||
import { useGroups } from "~/composables/use-groups";
|
||||
import { useAdminHouseholds } from "~/composables/use-households";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import { useUserForm } from "~/composables/use-users";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { UserOut } from "~/lib/api/types/user";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const { userForm } = useUserForm();
|
||||
const { groups } = useGroups();
|
||||
const { useHouseholdsInGroup } = useAdminHouseholds();
|
||||
const i18n = useI18n();
|
||||
const route = useRoute();
|
||||
|
||||
const userId = route.params.id as string;
|
||||
|
||||
// ==============================================
|
||||
// New User Form
|
||||
|
||||
const refNewUserForm = ref<VForm | null>(null);
|
||||
|
||||
const adminApi = useAdminApi();
|
||||
|
||||
const user = ref<UserOut | null>(null);
|
||||
const households = useHouseholdsInGroup(computed(() => user.value?.groupId || ""));
|
||||
|
||||
const disabledFields = computed(() => {
|
||||
return user.value?.authMethod !== "Mealie" ? ["admin"] : [];
|
||||
});
|
||||
|
||||
const userError = ref(false);
|
||||
|
||||
const resetUrl = ref<string | null>(null);
|
||||
const generatingToken = ref(false);
|
||||
|
||||
onMounted(async () => {
|
||||
const { data, error } = await adminApi.users.getOne(userId);
|
||||
|
||||
if (error?.response?.status === 404) {
|
||||
alert.error(i18n.t("user.user-not-found"));
|
||||
userError.value = true;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
user.value = data;
|
||||
}
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!refNewUserForm.value?.validate() || user.value === null) return;
|
||||
|
||||
const { response, data } = await adminApi.users.updateOne(user.value.id, user.value);
|
||||
|
||||
if (response?.status === 200 && data) {
|
||||
user.value = data;
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePasswordReset() {
|
||||
if (user.value === null) return;
|
||||
generatingToken.value = true;
|
||||
|
||||
const { response, data } = await adminApi.users.generatePasswordResetToken({ email: user.value.email });
|
||||
|
||||
if (response?.status === 201 && data) {
|
||||
const token: string = data.token;
|
||||
resetUrl.value = `${window.location.origin}/reset-password/?token=${token}`;
|
||||
}
|
||||
|
||||
generatingToken.value = false;
|
||||
}
|
||||
|
||||
const userApi = useUserApi();
|
||||
async function sendResetEmail() {
|
||||
if (!user.value?.email) return;
|
||||
const { response } = await userApi.email.sendForgotPassword({ email: user.value.email });
|
||||
if (response && response.status === 200) {
|
||||
alert.success(i18n.t("profile.email-sent"));
|
||||
}
|
||||
else {
|
||||
alert.error(i18n.t("profile.error-sending-email"));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
115
frontend/app/pages/admin/manage/users/create.vue
Normal file
115
frontend/app/pages/admin/manage/users/create.vue
Normal file
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<v-container class="narrow-container">
|
||||
<BasePageTitle class="mb-2">
|
||||
<template #header>
|
||||
<v-img
|
||||
width="100%"
|
||||
max-height="125"
|
||||
max-width="125"
|
||||
src="/svgs/manage-profile.svg"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ $t('user.admin-user-creation') }}
|
||||
</template>
|
||||
</BasePageTitle>
|
||||
<AppToolbar back />
|
||||
<v-form
|
||||
ref="refNewUserForm"
|
||||
@submit.prevent="handleSubmit"
|
||||
>
|
||||
<v-card variant="outlined">
|
||||
<v-card-text>
|
||||
<v-sheet>
|
||||
<v-row>
|
||||
<v-col cols="6">
|
||||
<v-select
|
||||
v-model="selectedGroup"
|
||||
:items="groups || []"
|
||||
item-title="name"
|
||||
return-object
|
||||
variant="filled"
|
||||
:label="$t('group.user-group')"
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="6">
|
||||
<v-select
|
||||
v-model="newUserData.household"
|
||||
:disabled="!selectedGroup"
|
||||
:items="households"
|
||||
item-title="name"
|
||||
item-value="name"
|
||||
variant="filled"
|
||||
:label="$t('household.user-household')"
|
||||
:hint="selectedGroup ? '' : $t('group.you-must-select-a-group-before-selecting-a-household')"
|
||||
persistent-hint
|
||||
:rules="[validators.required]"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-sheet>
|
||||
<AutoForm
|
||||
v-model="newUserData"
|
||||
:items="userForm"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<div class="d-flex pa-2">
|
||||
<BaseButton
|
||||
type="submit"
|
||||
class="ml-auto"
|
||||
/>
|
||||
</div>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAdminApi } from "~/composables/api";
|
||||
import { useGroups } from "~/composables/use-groups";
|
||||
import { useUserForm } from "~/composables/use-users";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { GroupInDB, UserIn } from "~/lib/api/types/user";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
const { userForm } = useUserForm();
|
||||
const { groups } = useGroups();
|
||||
const router = useRouter();
|
||||
|
||||
const refNewUserForm = ref<VForm | null>(null);
|
||||
const adminApi = useAdminApi();
|
||||
|
||||
const selectedGroup = ref<GroupInDB | undefined>(undefined);
|
||||
const households = computed(() => selectedGroup.value?.households || []);
|
||||
|
||||
const newUserData = ref({
|
||||
username: "",
|
||||
fullName: "",
|
||||
email: "",
|
||||
admin: false,
|
||||
group: computed(() => selectedGroup.value?.name || ""),
|
||||
household: "",
|
||||
advanced: false,
|
||||
canInvite: false,
|
||||
canManage: false,
|
||||
canOrganize: false,
|
||||
password: "",
|
||||
authMethod: "Mealie",
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!refNewUserForm.value?.validate()) return;
|
||||
|
||||
const { response } = await adminApi.users.createOne(newUserData.value as UserIn);
|
||||
|
||||
if (response?.status === 201) {
|
||||
router.push("/admin/manage/users");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
192
frontend/app/pages/admin/manage/users/index.vue
Normal file
192
frontend/app/pages/admin/manage/users/index.vue
Normal file
@@ -0,0 +1,192 @@
|
||||
<template>
|
||||
<v-container fluid>
|
||||
<UserInviteDialog v-model="inviteDialog" />
|
||||
<BaseDialog
|
||||
v-model="state.deleteDialog"
|
||||
:title="$t('general.confirm')"
|
||||
:icon="$globals.icons.alertCircle"
|
||||
color="error"
|
||||
can-confirm
|
||||
@confirm="deleteUser(state.deleteTargetId)"
|
||||
>
|
||||
<template #activator />
|
||||
|
||||
<v-card-text>
|
||||
<v-alert
|
||||
v-if="isUserOwnAccount"
|
||||
type="warning"
|
||||
:text="$t('general.confirm-delete-own-admin-account')"
|
||||
variant="outlined"
|
||||
/>
|
||||
{{ $t("general.confirm-delete-generic") }}
|
||||
</v-card-text>
|
||||
</BaseDialog>
|
||||
|
||||
<BaseCardSectionTitle :title="$t('user.user-management')" />
|
||||
<section>
|
||||
<v-toolbar
|
||||
color="transparent"
|
||||
flat
|
||||
class="justify-between"
|
||||
>
|
||||
<BaseButton
|
||||
to="/admin/manage/users/create"
|
||||
class="mr-2"
|
||||
>
|
||||
{{ $t("general.create") }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-if="$appInfo.allowPasswordLogin"
|
||||
class="mr-2"
|
||||
color="info"
|
||||
:icon="$globals.icons.link"
|
||||
@click="inviteDialog = true"
|
||||
>
|
||||
{{ $t("group.invite") }}
|
||||
</BaseButton>
|
||||
|
||||
<BaseOverflowButton
|
||||
mode="event"
|
||||
variant="elevated"
|
||||
:items="ACTIONS_OPTIONS"
|
||||
@unlock-all-users="unlockAllUsers"
|
||||
/>
|
||||
</v-toolbar>
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="users || []"
|
||||
item-key="id"
|
||||
class="elevation-0"
|
||||
elevation="0"
|
||||
:items-per-page="-1"
|
||||
hide-default-footer
|
||||
disable-pagination
|
||||
:search="state.search"
|
||||
@click:row="($event, { item }) => handleRowClick(item)"
|
||||
>
|
||||
<template #[`item.admin`]="{ item }">
|
||||
<v-icon
|
||||
end
|
||||
:color="item.admin ? 'success' : undefined"
|
||||
>
|
||||
{{ item.admin ? $globals.icons.checkboxMarkedCircle : $globals.icons.windowClose }}
|
||||
</v-icon>
|
||||
</template>
|
||||
<template #[`item.actions`]="{ item }">
|
||||
<v-btn
|
||||
icon
|
||||
:disabled="+item.id == 1"
|
||||
color="error"
|
||||
variant="text"
|
||||
@click.stop="
|
||||
state.deleteDialog = true;
|
||||
state.deleteTargetId = item.id;
|
||||
"
|
||||
>
|
||||
<v-icon>
|
||||
{{ $globals.icons.delete }}
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-data-table>
|
||||
<v-divider />
|
||||
</section>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAdminApi } from "~/composables/api";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import { useUser, useAllUsers } from "~/composables/use-user";
|
||||
import type { UserOut } from "~/lib/api/types/user";
|
||||
import UserInviteDialog from "~/components/Domain/User/UserInviteDialog.vue";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
const i18n = useI18n();
|
||||
|
||||
useHead({
|
||||
title: i18n.t("sidebar.manage-users"),
|
||||
});
|
||||
|
||||
const api = useAdminApi();
|
||||
const inviteDialog = ref();
|
||||
const auth = useMealieAuth();
|
||||
|
||||
const user = computed(() => auth.user.value);
|
||||
|
||||
const { $globals } = useNuxtApp();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const isUserOwnAccount = computed(() => {
|
||||
return state.deleteTargetId === user.value?.id;
|
||||
});
|
||||
|
||||
const ACTIONS_OPTIONS = [
|
||||
{
|
||||
text: i18n.t("user.reset-locked-users"),
|
||||
icon: $globals.icons.lock,
|
||||
event: "unlock-all-users",
|
||||
},
|
||||
];
|
||||
|
||||
const state = reactive({
|
||||
deleteDialog: false,
|
||||
deleteTargetId: "",
|
||||
search: "",
|
||||
groups: [],
|
||||
households: [],
|
||||
sendTo: "",
|
||||
});
|
||||
|
||||
const { users, refreshAllUsers } = useAllUsers();
|
||||
const { deleteUser: deleteUserMixin } = useUser(refreshAllUsers);
|
||||
|
||||
function deleteUser(id: string) {
|
||||
deleteUserMixin(id);
|
||||
|
||||
if (isUserOwnAccount.value) {
|
||||
auth.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
function handleRowClick(item: UserOut) {
|
||||
router.push(`/admin/manage/users/${item.id}`);
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Constants / Non-reactive
|
||||
|
||||
const headers = [
|
||||
{
|
||||
title: i18n.t("user.user-id"),
|
||||
align: "start",
|
||||
value: "id",
|
||||
},
|
||||
{ title: i18n.t("user.username"), value: "username" },
|
||||
{ title: i18n.t("user.full-name"), value: "fullName" },
|
||||
{ title: i18n.t("user.email"), value: "email" },
|
||||
{ title: i18n.t("group.group"), value: "group" },
|
||||
{ title: i18n.t("household.household"), value: "household" },
|
||||
{ title: i18n.t("user.auth-method"), value: "authMethod" },
|
||||
{ title: i18n.t("user.admin"), value: "admin" },
|
||||
{ title: i18n.t("general.delete"), value: "actions", sortable: false, align: "center" },
|
||||
];
|
||||
|
||||
async function unlockAllUsers(): Promise<void> {
|
||||
const { data } = await api.users.unlockAllUsers(true);
|
||||
|
||||
if (data) {
|
||||
const unlocked = data.unlocked ?? 0;
|
||||
|
||||
alert.success(`${unlocked} user(s) unlocked`);
|
||||
refreshAllUsers();
|
||||
}
|
||||
}
|
||||
|
||||
useSeoMeta({
|
||||
title: i18n.t("sidebar.manage-users"),
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user