Skip to content

Commit 783578e

Browse files
add type in permission profile
Co-authored-by: tc-imba <[email protected]> Co-authored-by: Reapor-Yurnero <[email protected]>
1 parent fdcc4bc commit 783578e

File tree

9 files changed

+63
-32
lines changed

9 files changed

+63
-32
lines changed

projects/sbos-frontend/src/pages/Domain/ProfileList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const ProfileList: React.FC = () => {
151151
pagination={false}
152152
search={false}
153153
request={async (params, sort, filter) => {
154-
const result = await listProfilesBrickapiV1ProfilesGet();
154+
const result = await listProfilesBrickapiV1ProfilesGet({type: "user"});
155155
return {
156156
data: result.data?.results || [],
157157
success: true,

projects/sbos-frontend/src/pages/Domain/UserList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ const UserList: React.FC = () => {
335335
label="Select a profile"
336336
name="profile"
337337
request={async () => {
338-
const result = await listProfilesBrickapiV1ProfilesGet();
338+
const result = await listProfilesBrickapiV1ProfilesGet({type: "user"});
339339
return map(
340340
filter(result.data?.results || [], (x) => x.name),
341341
(profile: API.PermissionProfileRead) => ({

projects/sbos-frontend/src/services/brick-server-playground/apps.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ export async function appsSubmitDataBrickapiV1AppsAppSubmitPost2(
293293
}
294294

295295
/** Apps:Api Call a backend api of an app. GET /brickapi/v1/apps/api/${param0} */
296-
export async function appsApiBrickapiV1AppsApiPathPut(
296+
export async function appsApiBrickapiV1AppsApiPathOptions(
297297
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
298-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
298+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
299299
options?: { [key: string]: any },
300300
) {
301301
const { path: param0, ...queryParams } = params;
@@ -307,9 +307,9 @@ export async function appsApiBrickapiV1AppsApiPathPut(
307307
}
308308

309309
/** Apps:Api Call a backend api of an app. GET /brickapi/v1/apps/api/${param0} */
310-
export async function appsApiBrickapiV1AppsApiPathPut2(
310+
export async function appsApiBrickapiV1AppsApiPathOptions2(
311311
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
312-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
312+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
313313
options?: { [key: string]: any },
314314
) {
315315
const { path: param0, ...queryParams } = params;
@@ -321,9 +321,9 @@ export async function appsApiBrickapiV1AppsApiPathPut2(
321321
}
322322

323323
/** Apps:Api Call a backend api of an app. PUT /brickapi/v1/apps/api/${param0} */
324-
export async function appsApiBrickapiV1AppsApiPathPut3(
324+
export async function appsApiBrickapiV1AppsApiPathOptions3(
325325
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
326-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
326+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
327327
options?: { [key: string]: any },
328328
) {
329329
const { path: param0, ...queryParams } = params;
@@ -335,9 +335,9 @@ export async function appsApiBrickapiV1AppsApiPathPut3(
335335
}
336336

337337
/** Apps:Api Call a backend api of an app. PUT /brickapi/v1/apps/api/${param0} */
338-
export async function appsApiBrickapiV1AppsApiPathPut4(
338+
export async function appsApiBrickapiV1AppsApiPathOptions4(
339339
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
340-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
340+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
341341
options?: { [key: string]: any },
342342
) {
343343
const { path: param0, ...queryParams } = params;
@@ -349,9 +349,9 @@ export async function appsApiBrickapiV1AppsApiPathPut4(
349349
}
350350

351351
/** Apps:Api Call a backend api of an app. POST /brickapi/v1/apps/api/${param0} */
352-
export async function appsApiBrickapiV1AppsApiPathPut5(
352+
export async function appsApiBrickapiV1AppsApiPathOptions5(
353353
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
354-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
354+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
355355
options?: { [key: string]: any },
356356
) {
357357
const { path: param0, ...queryParams } = params;
@@ -363,9 +363,9 @@ export async function appsApiBrickapiV1AppsApiPathPut5(
363363
}
364364

365365
/** Apps:Api Call a backend api of an app. POST /brickapi/v1/apps/api/${param0} */
366-
export async function appsApiBrickapiV1AppsApiPathPut6(
366+
export async function appsApiBrickapiV1AppsApiPathOptions6(
367367
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
368-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
368+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
369369
options?: { [key: string]: any },
370370
) {
371371
const { path: param0, ...queryParams } = params;
@@ -377,9 +377,9 @@ export async function appsApiBrickapiV1AppsApiPathPut6(
377377
}
378378

379379
/** Apps:Api Call a backend api of an app. DELETE /brickapi/v1/apps/api/${param0} */
380-
export async function appsApiBrickapiV1AppsApiPathPut7(
380+
export async function appsApiBrickapiV1AppsApiPathOptions7(
381381
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
382-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
382+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
383383
options?: { [key: string]: any },
384384
) {
385385
const { path: param0, ...queryParams } = params;
@@ -391,9 +391,9 @@ export async function appsApiBrickapiV1AppsApiPathPut7(
391391
}
392392

393393
/** Apps:Api Call a backend api of an app. DELETE /brickapi/v1/apps/api/${param0} */
394-
export async function appsApiBrickapiV1AppsApiPathPut8(
394+
export async function appsApiBrickapiV1AppsApiPathOptions8(
395395
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
396-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
396+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
397397
options?: { [key: string]: any },
398398
) {
399399
const { path: param0, ...queryParams } = params;
@@ -405,9 +405,9 @@ export async function appsApiBrickapiV1AppsApiPathPut8(
405405
}
406406

407407
/** Apps:Api Call a backend api of an app. PATCH /brickapi/v1/apps/api/${param0} */
408-
export async function appsApiBrickapiV1AppsApiPathPut9(
408+
export async function appsApiBrickapiV1AppsApiPathOptions9(
409409
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
410-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
410+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
411411
options?: { [key: string]: any },
412412
) {
413413
const { path: param0, ...queryParams } = params;
@@ -419,9 +419,9 @@ export async function appsApiBrickapiV1AppsApiPathPut9(
419419
}
420420

421421
/** Apps:Api Call a backend api of an app. PATCH /brickapi/v1/apps/api/${param0} */
422-
export async function appsApiBrickapiV1AppsApiPathPut10(
422+
export async function appsApiBrickapiV1AppsApiPathOptions10(
423423
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
424-
params: API.appsApiBrickapiV1AppsApiPathPutParams,
424+
params: API.appsApiBrickapiV1AppsApiPathOptionsParams,
425425
options?: { [key: string]: any },
426426
) {
427427
const { path: param0, ...queryParams } = params;

projects/sbos-frontend/src/services/brick-server-playground/profiles.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@
33
import { request } from '@umijs/max';
44

55
/** List Profiles GET /brickapi/v1/profiles/ */
6-
export async function listProfilesBrickapiV1ProfilesGet(options?: { [key: string]: any }) {
6+
export async function listProfilesBrickapiV1ProfilesGet(
7+
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
8+
params: API.listProfilesBrickapiV1ProfilesGetParams,
9+
options?: { [key: string]: any },
10+
) {
711
return request<API.PermissionProfileReadListResp>('/brickapi/v1/profiles/', {
812
method: 'GET',
13+
params: {
14+
// type has a default value: user
15+
type: 'user',
16+
...params,
17+
},
918
...(options || {}),
1019
});
1120
}
1221

1322
/** List Profiles GET /brickapi/v1/profiles/ */
14-
export async function listProfilesBrickapiV1ProfilesGet2(options?: { [key: string]: any }) {
23+
export async function listProfilesBrickapiV1ProfilesGet2(
24+
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
25+
params: API.listProfilesBrickapiV1ProfilesGetParams,
26+
options?: { [key: string]: any },
27+
) {
1528
return request<API.PermissionProfileReadListResp>('/brickapi/v1/profiles/', {
1629
method: 'GET',
30+
params: {
31+
// type has a default value: user
32+
type: 'user',
33+
...params,
34+
},
1735
...(options || {}),
1836
});
1937
}

projects/sbos-frontend/src/services/brick-server-playground/typings.d.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,27 @@ declare namespace API {
141141
data?: AppReadWithApprovedData | null;
142142
};
143143

144-
type appsApiBrickapiV1AppsApiPathPutParams = {
144+
type appsApiBrickapiV1AppsApiPathOptionsParams = {
145145
/** Api endpoint in the app */
146146
path: string;
147147
};
148148

149-
type appsApiBrickapiV1AppsApiPathPutParams = {
149+
type appsApiBrickapiV1AppsApiPathOptionsParams = {
150150
/** Api endpoint in the app */
151151
path: string;
152152
};
153153

154-
type appsApiBrickapiV1AppsApiPathPutParams = {
154+
type appsApiBrickapiV1AppsApiPathOptionsParams = {
155155
/** Api endpoint in the app */
156156
path: string;
157157
};
158158

159-
type appsApiBrickapiV1AppsApiPathPutParams = {
159+
type appsApiBrickapiV1AppsApiPathOptionsParams = {
160160
/** Api endpoint in the app */
161161
path: string;
162162
};
163163

164-
type appsApiBrickapiV1AppsApiPathPutParams = {
164+
type appsApiBrickapiV1AppsApiPathOptionsParams = {
165165
/** Api endpoint in the app */
166166
path: string;
167167
};
@@ -718,6 +718,10 @@ declare namespace API {
718718
user: string;
719719
};
720720

721+
type listProfilesBrickapiV1ProfilesGetParams = {
722+
type?: 'app' | 'user';
723+
};
724+
721725
type listResourcesBrickapiV1DomainsDomainResourcesGetParams = {
722726
domain: string;
723727
};
@@ -771,6 +775,8 @@ declare namespace API {
771775
id: string;
772776
/** Name */
773777
name?: string;
778+
/** Type */
779+
type?: 'app' | 'user';
774780
/** Read */
775781
read: string;
776782
/** Write */

projects/sbos-playground/sbos/playground/models/permission.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from beanie import Document
2-
2+
from typing import Literal
33

44
class PermissionProfile(Document):
55
name: str = ""
6+
type: Literal["app", "user"] = "user"
67
read: str
78
write: str
89
arguments: dict[str, str] = {}

projects/sbos-playground/sbos/playground/schemas/permission.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from typing import Literal
23

34
from beanie import PydanticObjectId
45
from sbos.minimal.schemas.base import BaseModel, StrEnumMixin
@@ -19,6 +20,7 @@ class PermissionProfileCreate(BaseModel):
1920
class PermissionProfileRead(BaseModel):
2021
id: PydanticObjectId
2122
name: str = ""
23+
type: Literal["app", "user"] = "user"
2224
read: str
2325
write: str
2426
arguments: dict[str, str]

projects/sbos-playground/sbos/playground/services/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ async def submit_app_data(
259259
app.submitted_data = models.AppData()
260260
if app.submitted_data.permission_profile is None:
261261
permission_profile_model = models.PermissionProfile(
262+
name=f"{app.name}.submitted",
262263
read=permission_profile_read,
263264
write=permission_profile_write,
264265
arguments=permission_profile_arguments,
@@ -342,6 +343,7 @@ async def approve_app(
342343
)
343344
if app.approved_data is None:
344345
approved_permission_profile = models.PermissionProfile(
346+
name=f"{app.name}.approved",
345347
read=submitted_permission_profile.read,
346348
write=submitted_permission_profile.write,
347349
arguments=submitted_permission_profile.arguments,

projects/sbos-playground/sbos/playground/services/profile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
from typing import Literal
23

3-
from fastapi import APIRouter, Body, Depends
4+
from fastapi import APIRouter, Body, Depends, Query
45
from fastapi_restful.cbv import cbv
56
from loguru import logger
67
from sbos.minimal.interfaces import AsyncpgTimeseries, GraphDB
@@ -49,8 +50,9 @@ async def create_profile(
4950
@router.get("/")
5051
async def list_profiles(
5152
self,
53+
type: Literal["app", "user"] = Query("user"),
5254
) -> schemas.StandardListResponse[schemas.PermissionProfileRead]:
53-
profiles = await models.PermissionProfile.find_all().to_list()
55+
profiles = await models.PermissionProfile.find_many(models.PermissionProfile.type == type).to_list()
5456
return schemas.StandardListResponse(
5557
results=[
5658
schemas.PermissionProfileRead.model_validate(profile.dict())

0 commit comments

Comments
 (0)