mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 10:13:32 -04:00 
			
		
		
		
	* add groupSlug to most routes * fixed more routing issues * fixed jank and incorrect routes * remove public explore links * remove unused groupSlug and explore routes * nuked explore pages * fixed public toolstore bug * fixed various routes missing group slug * restored public app header menu * fix janky login redirect * 404 recipe API call returns to login * removed unused explore layout * force redirect when using the wrong group slug * fixed dead admin links * removed unused middleware from earlier attempt * 🧹 * improve cookbooks sidebar fixed sidebar link not working fixed sidebar link target hide cookbooks header when there are none * added group slug to user * fix $auth typehints * vastly simplified groupSlug logic * allow logged-in users to view other groups * fixed some edgecases that bypassed isOwnGroup * fixed static home ref * 🧹 * fixed redirect logic * lint warning * removed group slug from group and user pages refactored all components to use route groupSlug or user group slug moved some group pages to recipe pages * fixed some bad types * 🧹 * moved groupSlug routes under /g/groupSlug * move /recipe/ to /r/ * fix backend url generation and metadata injection * moved shopping lists to root/other route fixes * changed shared from /recipes/ to /r/ * fixed 404 redirect not awaiting * removed unused import * fix doc links * fix public recipe setting not affecting public API * fixed backend tests * fix nuxt-generate command --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
		
			
				
	
	
		
			169 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <template>
 | |
|   <v-container fluid>
 | |
|     <BaseDialog
 | |
|       v-model="deleteDialog"
 | |
|       :title="$tc('general.confirm')"
 | |
|       color="error"
 | |
|       @confirm="deleteUser(deleteTargetId)"
 | |
|     >
 | |
|       <template #activator> </template>
 | |
| 
 | |
|       <v-card-text>
 | |
|         <v-alert v-if="isUserOwnAccount" type="warning" text outlined>
 | |
|           {{ $t("general.confirm-delete-own-admin-account") }}
 | |
|         </v-alert>
 | |
|         {{ $t("general.confirm-delete-generic") }}
 | |
|       </v-card-text>
 | |
|     </BaseDialog>
 | |
| 
 | |
|     <BaseCardSectionTitle :title="$tc('user.user-management')"> </BaseCardSectionTitle>
 | |
|     <section>
 | |
|       <v-toolbar color="background" flat class="justify-between">
 | |
|         <BaseButton to="/admin/manage/users/create" class="mr-2">
 | |
|           {{ $t("general.create") }}
 | |
|         </BaseButton>
 | |
| 
 | |
|         <BaseOverflowButton mode="event" :items="ACTIONS_OPTIONS" @unlock-all-users="unlockAllUsers">
 | |
|         </BaseOverflowButton>
 | |
|       </v-toolbar>
 | |
|       <v-data-table
 | |
|         :headers="headers"
 | |
|         :items="users || []"
 | |
|         item-key="id"
 | |
|         class="elevation-0"
 | |
|         elevation="0"
 | |
|         hide-default-footer
 | |
|         disable-pagination
 | |
|         :search="search"
 | |
|         @click:row="handleRowClick"
 | |
|       >
 | |
|         <template #item.admin="{ item }">
 | |
|           <v-icon right :color="item.admin ? 'success' : null">
 | |
|             {{ item.admin ? $globals.icons.checkboxMarkedCircle : $globals.icons.windowClose }}
 | |
|           </v-icon>
 | |
|         </template>
 | |
|         <template #item.actions="{ item }">
 | |
|           <v-btn
 | |
|             icon
 | |
|             :disabled="item.id == 1"
 | |
|             color="error"
 | |
|             @click.stop="
 | |
|               deleteDialog = true;
 | |
|               deleteTargetId = item.id;
 | |
|             "
 | |
|           >
 | |
|             <v-icon>
 | |
|               {{ $globals.icons.delete }}
 | |
|             </v-icon>
 | |
|           </v-btn>
 | |
|         </template>
 | |
|       </v-data-table>
 | |
|       <v-divider></v-divider>
 | |
|     </section>
 | |
|   </v-container>
 | |
| </template>
 | |
| 
 | |
| <script lang="ts">
 | |
| import { defineComponent, reactive, ref, toRefs, useContext, useRouter, computed } from "@nuxtjs/composition-api";
 | |
| import { useAdminApi } from "~/composables/api";
 | |
| import { alert } from "~/composables/use-toast";
 | |
| import { useUser, useAllUsers } from "~/composables/use-user";
 | |
| import { UserOut } from "~/lib/api/types/user";
 | |
| 
 | |
| export default defineComponent({
 | |
|   layout: "admin",
 | |
|   setup() {
 | |
|     const api = useAdminApi();
 | |
|     const refUserDialog = ref();
 | |
|     const { $auth } = useContext();
 | |
| 
 | |
|     const user = computed(() => $auth.user);
 | |
| 
 | |
|     const { $globals, i18n } = useContext();
 | |
| 
 | |
|     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: "",
 | |
|     });
 | |
| 
 | |
|     const { users, refreshAllUsers } = useAllUsers();
 | |
|     const { loading, deleteUser: deleteUserMixin } = useUser(refreshAllUsers);
 | |
| 
 | |
|     function deleteUser(id: string) {
 | |
|       deleteUserMixin(id);
 | |
| 
 | |
|       if (isUserOwnAccount.value) {
 | |
|         $auth.logout();
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     function handleRowClick(item: UserOut) {
 | |
|       router.push(`/admin/manage/users/${item.id}`);
 | |
|     }
 | |
| 
 | |
|     // ==========================================================
 | |
|     // Constants / Non-reactive
 | |
| 
 | |
|     const headers = [
 | |
|       {
 | |
|         text: i18n.t("user.user-id"),
 | |
|         align: "start",
 | |
|         value: "id",
 | |
|       },
 | |
|       { text: i18n.t("user.username"), value: "username" },
 | |
|       { text: i18n.t("user.full-name"), value: "fullName" },
 | |
|       { text: i18n.t("user.email"), value: "email" },
 | |
|       { text: i18n.t("group.group"), value: "group" },
 | |
|       { text: i18n.t("user.auth-method"), value: "authMethod" },
 | |
|       { text: i18n.t("user.admin"), value: "admin" },
 | |
|       { text: 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();
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     return {
 | |
|       isUserOwnAccount,
 | |
|       unlockAllUsers,
 | |
|       ...toRefs(state),
 | |
|       headers,
 | |
|       deleteUser,
 | |
|       loading,
 | |
|       refUserDialog,
 | |
|       users,
 | |
|       user,
 | |
|       handleRowClick,
 | |
|       ACTIONS_OPTIONS,
 | |
|     };
 | |
|   },
 | |
|   head() {
 | |
|     return {
 | |
|       title: this.$t("sidebar.manage-users") as string,
 | |
|     };
 | |
|   },
 | |
| });
 | |
| </script>
 |