openadminjs 0.1.19 → 0.1.20
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/package.json
CHANGED
|
@@ -28,6 +28,6 @@ import { SsoOidcService } from "./sso-oidc.service";
|
|
|
28
28
|
],
|
|
29
29
|
controllers: [AuthController, SsoOidcController],
|
|
30
30
|
providers: [AuthService, SsoOidcService, PrismaService, AuthGuard],
|
|
31
|
-
exports: [AuthService, AuthGuard, JwtModule]
|
|
31
|
+
exports: [AuthService, AuthGuard, JwtModule, PrismaService]
|
|
32
32
|
})
|
|
33
33
|
export class AuthModule {}
|
|
@@ -11,7 +11,6 @@ describe("AdminResourcesResolver", () => {
|
|
|
11
11
|
|
|
12
12
|
await resolver.adminResourceList(
|
|
13
13
|
"posts",
|
|
14
|
-
user as never,
|
|
15
14
|
2,
|
|
16
15
|
15,
|
|
17
16
|
"hello",
|
|
@@ -21,7 +20,8 @@ describe("AdminResourcesResolver", () => {
|
|
|
21
20
|
status: { eq: "published" },
|
|
22
21
|
views: { gte: 10, lte: 100 },
|
|
23
22
|
authorId: "u1"
|
|
24
|
-
}
|
|
23
|
+
},
|
|
24
|
+
{ req: { user } } as never
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
expect(adminResources.list).toHaveBeenCalledWith(
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { UseGuards } from "@nestjs/common";
|
|
2
|
-
import { Args, Int, Query, Resolver } from "@nestjs/graphql";
|
|
2
|
+
import { Args, Context, Int, Query, Resolver } from "@nestjs/graphql";
|
|
3
3
|
import { GraphQLJSON } from "graphql-scalars";
|
|
4
4
|
import { AdminResourceService } from "../admin/admin-resource.service";
|
|
5
5
|
import { AuthGuard } from "../common/auth.guard";
|
|
6
6
|
import type { RequestUser } from "../common/auth.guard";
|
|
7
7
|
import { RequireAuthRealm } from "../common/auth-realm.decorator";
|
|
8
|
-
import { CurrentUser } from "../common/current-user.decorator";
|
|
9
8
|
import { resources } from "../resources/registry";
|
|
10
9
|
|
|
10
|
+
type GqlAuthContext = { req: { user: RequestUser } };
|
|
11
|
+
|
|
11
12
|
@Resolver()
|
|
12
13
|
@UseGuards(AuthGuard)
|
|
13
14
|
@RequireAuthRealm("admin")
|
|
@@ -30,7 +31,8 @@ export class AdminResourcesResolver {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
@Query(() => [String], { name: "adminRegisteredResourceNames" })
|
|
33
|
-
adminRegisteredResourceNames(@
|
|
34
|
+
adminRegisteredResourceNames(@Context() ctx: GqlAuthContext): string[] {
|
|
35
|
+
const user = ctx.req.user;
|
|
34
36
|
return resources
|
|
35
37
|
.filter(
|
|
36
38
|
(r) =>
|
|
@@ -43,23 +45,23 @@ export class AdminResourcesResolver {
|
|
|
43
45
|
@Query(() => GraphQLJSON, { name: "adminResourceList", description: "Paginated list (same rules as REST /admin/resources/:name)" })
|
|
44
46
|
adminResourceList(
|
|
45
47
|
@Args("name") name: string,
|
|
46
|
-
@CurrentUser() user: RequestUser,
|
|
47
48
|
@Args("page", { type: () => Int, nullable: true, defaultValue: 1 }) page: number,
|
|
48
49
|
@Args("limit", { type: () => Int, nullable: true, defaultValue: 20 }) limit: number,
|
|
49
|
-
@Args("search", { nullable: true }) search
|
|
50
|
-
@Args("sort", { nullable: true }) sort
|
|
51
|
-
@Args("locale", { nullable: true }) locale
|
|
52
|
-
@Args("filter", { type: () => GraphQLJSON, nullable: true }) filter
|
|
50
|
+
@Args("search", { type: () => String, nullable: true }) search: string | undefined,
|
|
51
|
+
@Args("sort", { type: () => String, nullable: true }) sort: string | undefined,
|
|
52
|
+
@Args("locale", { type: () => String, nullable: true }) locale: string | undefined,
|
|
53
|
+
@Args("filter", { type: () => GraphQLJSON, nullable: true }) filter: unknown | undefined,
|
|
54
|
+
@Context() ctx: GqlAuthContext
|
|
53
55
|
) {
|
|
54
56
|
const query: Record<string, unknown> = { page, limit, ...this.flattenFilters(filter) };
|
|
55
57
|
if (search) query.search = search;
|
|
56
58
|
if (sort) query.sort = sort;
|
|
57
59
|
if (locale) query.locale = locale;
|
|
58
|
-
return this.adminResources.list(name, query, user);
|
|
60
|
+
return this.adminResources.list(name, query, ctx.req.user);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
@Query(() => GraphQLJSON, { name: "adminResourceRecord" })
|
|
62
|
-
adminResourceRecord(@Args("name") name: string, @Args("id") id: string, @
|
|
63
|
-
return this.adminResources.get(name, id, user);
|
|
64
|
+
adminResourceRecord(@Args("name") name: string, @Args("id") id: string, @Context() ctx: GqlAuthContext) {
|
|
65
|
+
return this.adminResources.get(name, id, ctx.req.user);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -4,7 +4,6 @@ import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
|
|
|
4
4
|
import { GraphQLJSON } from "graphql-scalars";
|
|
5
5
|
import { AdminModule } from "../admin/admin.module";
|
|
6
6
|
import { AuthModule } from "../auth/auth.module";
|
|
7
|
-
import { AuthGuard } from "../common/auth.guard";
|
|
8
7
|
import { AdminResourcesResolver } from "./admin-resources.resolver";
|
|
9
8
|
|
|
10
9
|
@Module({
|
|
@@ -21,6 +20,6 @@ import { AdminResourcesResolver } from "./admin-resources.resolver";
|
|
|
21
20
|
AdminModule,
|
|
22
21
|
AuthModule
|
|
23
22
|
],
|
|
24
|
-
providers: [AdminResourcesResolver
|
|
23
|
+
providers: [AdminResourcesResolver]
|
|
25
24
|
})
|
|
26
25
|
export class GraphqlApiModule {}
|