mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 18:53:17 -05:00 
			
		
		
		
	Merge branch 'mealie-next' into l10n_mealie-next
This commit is contained in:
		@@ -1,30 +1,39 @@
 | 
				
			|||||||
import { useAsync, ref } from "@nuxtjs/composition-api";
 | 
					import { useAsync, ref } from "@nuxtjs/composition-api";
 | 
				
			||||||
import { useAsyncKey } from "./use-utils";
 | 
					 | 
				
			||||||
import { useUserApi } from "~/composables/api";
 | 
					import { useUserApi } from "~/composables/api";
 | 
				
			||||||
import { GroupBase } from "~/lib/api/types/user";
 | 
					import { GroupBase, GroupSummary } from "~/lib/api/types/user";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const groupSelfRef = ref<GroupSummary | null>(null);
 | 
				
			||||||
 | 
					const loading = ref(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const useGroupSelf = function () {
 | 
					export const useGroupSelf = function () {
 | 
				
			||||||
  const api = useUserApi();
 | 
					  const api = useUserApi();
 | 
				
			||||||
 | 
					  async function refreshGroupSelf() {
 | 
				
			||||||
 | 
					    loading.value = true;
 | 
				
			||||||
 | 
					    const { data } = await api.groups.getCurrentUserGroup();
 | 
				
			||||||
 | 
					    groupSelfRef.value = data;
 | 
				
			||||||
 | 
					    loading.value = false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const actions = {
 | 
					  const actions = {
 | 
				
			||||||
    get() {
 | 
					    get() {
 | 
				
			||||||
      const group = useAsync(async () => {
 | 
					      if (!(groupSelfRef.value || loading.value)) {
 | 
				
			||||||
        const { data } = await api.groups.getCurrentUserGroup();
 | 
					        refreshGroupSelf();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return data;
 | 
					      return groupSelfRef;
 | 
				
			||||||
      }, useAsyncKey());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      return group;
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    async updatePreferences() {
 | 
					    async updatePreferences() {
 | 
				
			||||||
      if (!group.value?.preferences) {
 | 
					      if (!groupSelfRef.value) {
 | 
				
			||||||
 | 
					        await refreshGroupSelf();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (!groupSelfRef.value?.preferences) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const { data } = await api.groups.setPreferences(group.value.preferences);
 | 
					      const { data } = await api.groups.setPreferences(groupSelfRef.value.preferences);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (data) {
 | 
					      if (data) {
 | 
				
			||||||
        group.value.preferences = data;
 | 
					        groupSelfRef.value.preferences = data;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,6 +48,13 @@ export interface GroupInDB {
 | 
				
			|||||||
  users?: UserOut[];
 | 
					  users?: UserOut[];
 | 
				
			||||||
  preferences?: ReadGroupPreferences;
 | 
					  preferences?: ReadGroupPreferences;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					export interface GroupSummary {
 | 
				
			||||||
 | 
					  name: string;
 | 
				
			||||||
 | 
					  id: string;
 | 
				
			||||||
 | 
					  slug: string;
 | 
				
			||||||
 | 
					  preferences?: ReadGroupPreferences;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
export interface CategoryBase {
 | 
					export interface CategoryBase {
 | 
				
			||||||
  name: string;
 | 
					  name: string;
 | 
				
			||||||
  id: string;
 | 
					  id: string;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { BaseCRUDAPI } from "../base/base-clients";
 | 
					import { BaseCRUDAPI } from "../base/base-clients";
 | 
				
			||||||
import { CategoryBase, GroupBase, GroupInDB, UserOut } from "~/lib/api/types/user";
 | 
					import { CategoryBase, GroupBase, GroupInDB, GroupSummary, UserOut } from "~/lib/api/types/user";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  CreateInviteToken,
 | 
					  CreateInviteToken,
 | 
				
			||||||
  GroupAdminUpdate,
 | 
					  GroupAdminUpdate,
 | 
				
			||||||
@@ -35,7 +35,7 @@ export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate
 | 
				
			|||||||
  /** Returns the Group Data for the Current User
 | 
					  /** Returns the Group Data for the Current User
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  async getCurrentUserGroup() {
 | 
					  async getCurrentUserGroup() {
 | 
				
			||||||
    return await this.requests.get<GroupInDB>(routes.groupsSelf);
 | 
					    return await this.requests.get<GroupSummary>(routes.groupsSelf);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getCategories() {
 | 
					  async getCategories() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ from mealie.routes._base.routers import UserAPIRouter
 | 
				
			|||||||
from mealie.schema.group.group_permissions import SetPermissions
 | 
					from mealie.schema.group.group_permissions import SetPermissions
 | 
				
			||||||
from mealie.schema.group.group_preferences import ReadGroupPreferences, UpdateGroupPreferences
 | 
					from mealie.schema.group.group_preferences import ReadGroupPreferences, UpdateGroupPreferences
 | 
				
			||||||
from mealie.schema.group.group_statistics import GroupStatistics, GroupStorage
 | 
					from mealie.schema.group.group_statistics import GroupStatistics, GroupStorage
 | 
				
			||||||
from mealie.schema.user.user import GroupInDB, UserOut
 | 
					from mealie.schema.user.user import GroupSummary, UserOut
 | 
				
			||||||
from mealie.services.group_services.group_service import GroupService
 | 
					from mealie.services.group_services.group_service import GroupService
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router = UserAPIRouter(prefix="/groups", tags=["Groups: Self Service"])
 | 
					router = UserAPIRouter(prefix="/groups", tags=["Groups: Self Service"])
 | 
				
			||||||
@@ -20,10 +20,10 @@ class GroupSelfServiceController(BaseUserController):
 | 
				
			|||||||
    def service(self) -> GroupService:
 | 
					    def service(self) -> GroupService:
 | 
				
			||||||
        return GroupService(self.group_id, self.repos)
 | 
					        return GroupService(self.group_id, self.repos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @router.get("/self", response_model=GroupInDB)
 | 
					    @router.get("/self", response_model=GroupSummary)
 | 
				
			||||||
    def get_logged_in_user_group(self):
 | 
					    def get_logged_in_user_group(self):
 | 
				
			||||||
        """Returns the Group Data for the Current User"""
 | 
					        """Returns the Group Data for the Current User"""
 | 
				
			||||||
        return self.group
 | 
					        return self.group.cast(GroupSummary)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @router.get("/members", response_model=list[UserOut])
 | 
					    @router.get("/members", response_model=list[UserOut])
 | 
				
			||||||
    def get_group_members(self):
 | 
					    def get_group_members(self):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -249,6 +249,19 @@ class GroupInDB(UpdateGroup):
 | 
				
			|||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GroupSummary(GroupBase):
 | 
				
			||||||
 | 
					    id: UUID4
 | 
				
			||||||
 | 
					    name: str
 | 
				
			||||||
 | 
					    slug: str
 | 
				
			||||||
 | 
					    preferences: ReadGroupPreferences | None = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def loader_options(cls) -> list[LoaderOption]:
 | 
				
			||||||
 | 
					        return [
 | 
				
			||||||
 | 
					            joinedload(Group.preferences),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GroupPagination(PaginationBase):
 | 
					class GroupPagination(PaginationBase):
 | 
				
			||||||
    items: list[GroupInDB]
 | 
					    items: list[GroupInDB]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user