Skip to content

Commit 060d4d2

Browse files
committed
feat: add sessions and turns resources with superadmin access control
- Introduced new resources for sessions and turns, including their respective models in the Prisma schema. - Implemented access control for listing and showing sessions and turns, restricted to superadmin users. - Updated package dependencies, including a new agent package and an updated completion adapter. - Enhanced user resource to integrate the new agent functionality with multiple completion modes.
1 parent e66a36b commit 060d4d2

9 files changed

Lines changed: 953 additions & 23 deletions

File tree

adminforth/documentation/docs/tutorial/08-Plugins/26-agent.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ First create two resources for sessions and turns:
2929

3030
```ts title="./resources/agent_resources/sessions.ts"
3131
import AdminForth, { AdminForthDataTypes } from 'adminforth';
32-
import type { AdminForthResourceInput } from 'adminforth';
32+
import type { AdminForthResourceInput, AdminUser } from 'adminforth';
3333
import { randomUUID } from 'crypto';
3434

35+
async function allowedForSuperAdmins({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
36+
return adminUser.dbUser.role === 'superadmin';
37+
}
38+
3539
export default {
3640
dataSource: 'sqlite',
3741
table: 'sessions',
@@ -70,14 +74,27 @@ export default {
7074
},
7175
},
7276
],
77+
options: {
78+
allowedActions: {
79+
list: allowedForSuperAdmins,
80+
show: allowedForSuperAdmins,
81+
create: false,
82+
edit: false,
83+
delete: false,
84+
},
85+
},
7386
} as AdminForthResourceInput;
7487
```
7588

7689
```ts title="./resources/agent_resources/turns.ts"
7790
import AdminForth, { AdminForthDataTypes } from 'adminforth';
78-
import type { AdminForthResourceInput } from 'adminforth';
91+
import type { AdminForthResourceInput, AdminUser } from 'adminforth';
7992
import { randomUUID } from 'crypto';
8093

94+
async function allowedForSuperAdmins({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
95+
return adminUser.dbUser.role === 'superadmin';
96+
}
97+
8198
export default {
8299
dataSource: 'sqlite',
83100
table: 'turns',
@@ -116,6 +133,15 @@ export default {
116133
type: AdminForthDataTypes.TEXT,
117134
},
118135
],
136+
options: {
137+
allowedActions: {
138+
list: allowedForSuperAdmins,
139+
show: allowedForSuperAdmins,
140+
create: false,
141+
edit: false,
142+
delete: false,
143+
},
144+
},
119145
} as AdminForthResourceInput;
120146
```
121147

live-demo/app/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import usersResource from "./resources/users";
66
import apartmentsResource from "./resources/apartments";
77
import auditLogsResource from "./resources/auditLogs"
88
import translations from "./resources/translations";
9+
import sessionsResource from './resources/agent_resources/sessions';
10+
import turnsResource from './resources/agent_resources/turns';
911
import { randomUUID } from 'crypto';
1012
try { fs.mkdirSync('db') } catch (e) {}
1113

@@ -69,6 +71,8 @@ new AdminForth({
6971
usersResource,
7072
auditLogsResource,
7173
translations,
74+
sessionsResource,
75+
turnsResource,
7276
],
7377
menu: [
7478

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- CreateTable
2+
CREATE TABLE "sessions" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"title" TEXT NOT NULL,
5+
"turns" INTEGER,
6+
"asker_id" TEXT NOT NULL,
7+
"created_at" DATETIME NOT NULL
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "turns" (
12+
"id" TEXT NOT NULL PRIMARY KEY,
13+
"session_id" TEXT NOT NULL,
14+
"created_at" DATETIME NOT NULL,
15+
"prompt" TEXT,
16+
"response" TEXT
17+
);

0 commit comments

Comments
 (0)