Skip to content

Commit

Permalink
feat(forum): Add permissions to query for show forums in AdminCP
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Feb 26, 2024
1 parent 4ca7d68 commit 59d90a2
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 55 deletions.
5 changes: 1 addition & 4 deletions backend/src/admin/forum/forums/create/create.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ export class CreateForumForumsService {
permissions.groups.map(item => ({
forum_id: data[0].id,
group_id: item.id,
can_create: item.create,
can_read: item.read,
can_reply: item.reply,
can_view: item.view
...item
}))
);
}
Expand Down
8 changes: 4 additions & 4 deletions backend/src/admin/forum/forums/create/dto/create.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class GroupsPermissionsCreateForumForums {
id: number;

@Field(() => Boolean)
view: boolean;
can_view: boolean;

@Field(() => Boolean)
read: boolean;
can_read: boolean;

@Field(() => Boolean)
create: boolean;
can_create: boolean;

@Field(() => Boolean)
reply: boolean;
can_reply: boolean;
}

@InputType()
Expand Down
45 changes: 42 additions & 3 deletions backend/src/admin/forum/forums/show/dto/show.obj.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
import { Field, ObjectType, OmitType } from "@nestjs/graphql";
import { Field, Int, ObjectType, OmitType } from "@nestjs/graphql";

import { ShowForumForumsWithParent } from "../../../../../forum/forums/show/dto/show.obj";
import { PageInfo } from "@/types/database/pagination.type";

@ObjectType()
class GroupsPermissionsForumForums {
@Field(() => Int)
id: number;

@Field(() => Boolean)
can_view: boolean;

@Field(() => Boolean)
can_read: boolean;

@Field(() => Boolean)
can_create: boolean;

@Field(() => Boolean)
can_reply: boolean;
}

@ObjectType()
export class PermissionsForumForums {
@Field(() => Boolean)
can_all_view: boolean;

@Field(() => Boolean)
can_all_read: boolean;

@Field(() => Boolean)
can_all_create: boolean;

@Field(() => Boolean)
can_all_reply: boolean;

@Field(() => [GroupsPermissionsForumForums])
groups: GroupsPermissionsForumForums[];
}

@ObjectType()
export class ShowForumForumsAdmin extends OmitType(ShowForumForumsWithParent, [
"permissions"
] as const) {}
] as const) {
@Field(() => PermissionsForumForums)
permissions: PermissionsForumForums;
}

@ObjectType()
export class ShowForumForumsAdminObj {
@Field(() => [ShowForumForumsAdmin])
@Field(() => [ShowForumForumsWithParent])
edges: ShowForumForumsAdmin[];

@Field(() => PageInfo)
Expand Down
21 changes: 19 additions & 2 deletions backend/src/admin/forum/forums/show/show.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class ShowForumForumsAdminService {
name: true,
description: true
}
}
},
permissions: true
}
});

Expand All @@ -77,6 +78,13 @@ export class ShowForumForumsAdminService {
parent: forum.parent_id
? { ...forum.parent, _count: { children: 0 } }
: null,
permissions: {
can_all_view: forum.can_all_view,
can_all_read: forum.can_all_read,
can_all_create: forum.can_all_create,
can_all_reply: forum.can_all_reply,
groups: forum.permissions
},
_count: { children: children.length },
children: await Promise.all(
children.map(async child => {
Expand All @@ -93,7 +101,16 @@ export class ShowForumForumsAdminService {

return {
...child,
children,
children: children.map(child => ({
...child,
permissions: {
can_all_view: child.can_all_view,
can_all_read: child.can_all_read,
can_all_create: child.can_all_create,
can_all_reply: child.can_all_reply,
groups: child.permissions
}
})),
_count: { children: children.length }
};
})
Expand Down
36 changes: 21 additions & 15 deletions backend/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ type GroupUser {
}

input GroupsPermissionsCreateForumForums {
create: Boolean!
can_create: Boolean!
can_read: Boolean!
can_reply: Boolean!
can_view: Boolean!
id: Int!
}

type GroupsPermissionsForumForums {
can_create: Boolean!
can_read: Boolean!
can_reply: Boolean!
can_view: Boolean!
id: Int!
read: Boolean!
reply: Boolean!
view: Boolean!
}

enum LayoutAdminInstallEnum {
Expand Down Expand Up @@ -140,6 +148,14 @@ input PermissionsCreateForumForums {
groups: [GroupsPermissionsCreateForumForums!]!
}

type PermissionsForumForums {
can_all_create: Boolean!
can_all_read: Boolean!
can_all_reply: Boolean!
can_all_view: Boolean!
groups: [GroupsPermissionsForumForums!]!
}

type PermissionsForumForumsCount {
can_create: Boolean!
can_read: Boolean!
Expand Down Expand Up @@ -425,18 +441,8 @@ type ShowForumForums {
position: Int!
}

type ShowForumForumsAdmin {
children: [ChildrenShowForumForums!]!
created: Int!
description: [TextLanguage!]!
id: Int!
name: [TextLanguage!]!
parent: ShowForumForums
position: Int!
}

type ShowForumForumsAdminObj {
edges: [ShowForumForumsAdmin!]!
edges: [ShowForumForumsWithParent!]!
pageInfo: PageInfo!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export const PermissionsContentCreateEditFormForumAdmin = () => {
<ContentPermissionsContentCreateEditFormForumAdmin
permissions={[
{
id: "view",
id: "can_view",
title: "View"
},
{
id: "read",
id: "can_read",
title: "Read"
},
{
id: "create",
id: "can_create",
title: "Create",
disableForGuest: true
},
{
id: "reply",
id: "can_reply",
title: "Reply",
disableForGuest: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const useCreateEditFormForumAdmin = () => {
groups: z.array(
z.object({
id: z.number(),
view: z.boolean(),
read: z.boolean(),
create: z.boolean(),
reply: z.boolean()
can_view: z.boolean(),
can_read: z.boolean(),
can_create: z.boolean(),
can_reply: z.boolean()
})
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useState } from "react";
import { toast } from "sonner";
import { useTranslations } from "next-intl";

import { type ShowForumForumsAdmin } from "@/graphql/hooks";
import { mutationUpdateDataApi } from "./mutation-update-data-api";
import { buildTree, flattenTree, type FlatTree } from "../use-functions";
import type { ChildrenShowForumForums } from "@/graphql/hooks";

export interface ShowForumForumsAdminWithChildren
extends Omit<ShowForumForumsAdmin, "children" | "__typename"> {
extends Omit<ChildrenShowForumForums, "children" | "__typename"> {
children: ShowForumForumsAdminWithChildren[];
}

Expand Down
41 changes: 24 additions & 17 deletions frontend/graphql/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,20 @@ export type GroupUser = {
};

export type GroupsPermissionsCreateForumForums = {
create: Scalars['Boolean']['input'];
can_create: Scalars['Boolean']['input'];
can_read: Scalars['Boolean']['input'];
can_reply: Scalars['Boolean']['input'];
can_view: Scalars['Boolean']['input'];
id: Scalars['Int']['input'];
read: Scalars['Boolean']['input'];
reply: Scalars['Boolean']['input'];
view: Scalars['Boolean']['input'];
};

export type GroupsPermissionsForumForums = {
__typename?: 'GroupsPermissionsForumForums';
can_create: Scalars['Boolean']['output'];
can_read: Scalars['Boolean']['output'];
can_reply: Scalars['Boolean']['output'];
can_view: Scalars['Boolean']['output'];
id: Scalars['Int']['output'];
};

export const LayoutAdminInstallEnum = {
Expand Down Expand Up @@ -383,6 +392,15 @@ export type PermissionsCreateForumForums = {
groups: Array<GroupsPermissionsCreateForumForums>;
};

export type PermissionsForumForums = {
__typename?: 'PermissionsForumForums';
can_all_create: Scalars['Boolean']['output'];
can_all_read: Scalars['Boolean']['output'];
can_all_reply: Scalars['Boolean']['output'];
can_all_view: Scalars['Boolean']['output'];
groups: Array<GroupsPermissionsForumForums>;
};

export type PermissionsForumForumsCount = {
__typename?: 'PermissionsForumForumsCount';
can_create: Scalars['Boolean']['output'];
Expand Down Expand Up @@ -819,20 +837,9 @@ export type ShowForumForums = {
position: Scalars['Int']['output'];
};

export type ShowForumForumsAdmin = {
__typename?: 'ShowForumForumsAdmin';
children: Array<ChildrenShowForumForums>;
created: Scalars['Int']['output'];
description: Array<TextLanguage>;
id: Scalars['Int']['output'];
name: Array<TextLanguage>;
parent?: Maybe<ShowForumForums>;
position: Scalars['Int']['output'];
};

export type ShowForumForumsAdminObj = {
__typename?: 'ShowForumForumsAdminObj';
edges: Array<ShowForumForumsAdmin>;
edges: Array<ShowForumForumsWithParent>;
pageInfo: PageInfo;
};

Expand Down Expand Up @@ -1283,7 +1290,7 @@ export type Admin__Forum_Forums__ShowQueryVariables = Exact<{
}>;


export type Admin__Forum_Forums__ShowQuery = { __typename?: 'Query', admin__forum_forums__show: { __typename?: 'ShowForumForumsAdminObj', edges: Array<{ __typename?: 'ShowForumForumsAdmin', id: number, position: number, created: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', created: number, id: number, position: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }> }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number | null, totalCount: number } } };
export type Admin__Forum_Forums__ShowQuery = { __typename?: 'Query', admin__forum_forums__show: { __typename?: 'ShowForumForumsAdminObj', edges: Array<{ __typename?: 'ShowForumForumsWithParent', id: number, position: number, created: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', created: number, id: number, position: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }> }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number | null, totalCount: number } } };

export type Admin__Core_Groups__ShowQueryVariables = Exact<{
first?: InputMaybe<Scalars['Int']['input']>;
Expand Down

0 comments on commit 59d90a2

Please sign in to comment.