Skip to content

Commit

Permalink
fix: add db_connection permission action to resolve db connection per…
Browse files Browse the repository at this point in the history
…misison (#596)
  • Loading branch information
boris-w committed May 9, 2024
1 parent a45e9b2 commit 5a9a0e7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions apps/nestjs-backend/src/features/base/base.controller.ts
Expand Up @@ -107,19 +107,19 @@ export class BaseController {
return await this.baseService.deleteBase(baseId);
}

@Permissions('base|create')
@Permissions('base|db_connection')
@Post(':baseId/connection')
async createDbConnection(@Param('baseId') baseId: string): Promise<IDbConnectionVo> {
return await this.dbConnectionService.create(baseId);
}

@Permissions('base|create')
@Permissions('base|db_connection')
@Get(':baseId/connection')
async getDBConnection(@Param('baseId') baseId: string): Promise<IDbConnectionVo | null> {
return await this.dbConnectionService.retrieve(baseId);
}

@Permissions('base|create')
@Permissions('base|db_connection')
@Delete(':baseId/connection')
async deleteDbConnection(@Param('baseId') baseId: string) {
await this.dbConnectionService.remove(baseId);
Expand Down
Expand Up @@ -168,7 +168,7 @@ export const DbConnectionPanel = ({ className }: { className?: string }) => {
<CardDescription>{t('table:connection.description')}</CardDescription>
</CardHeader>
<CardContent className="flex flex-col">
{permissions['base|create'] ? <ContentCard /> : t('table:connection.noPermission')}
{permissions['base|db_connection'] ? <ContentCard /> : t('table:connection.noPermission')}
</CardContent>
</Card>
);
Expand Down
1 change: 1 addition & 0 deletions packages/common-i18n/src/locales/en/sdk.json
Expand Up @@ -131,6 +131,7 @@
"baseTableImport": "Import data into base",
"baseTableExport": "Export data from base",
"baseAuthorityMatrixConfig": "Configure authority matrix",
"baseDbConnect": "Connect to database",
"tableCreate": "Create table",
"tableRead": "Read table",
"tableDelete": "Delete table",
Expand Down
1 change: 1 addition & 0 deletions packages/common-i18n/src/locales/zh/sdk.json
Expand Up @@ -122,6 +122,7 @@
"baseTableImport": "导入到数据库",
"baseTableExport": "导出数据库",
"baseAuthorityMatrixConfig": "配置权限矩阵",
"baseDbConnect": "连接数据库",
"tableCreate": "创建表格",
"tableRead": "查看表格",
"tableDelete": "删除表格",
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/auth/actions.ts
Expand Up @@ -20,7 +20,14 @@ export const spaceActionsSchema = defaultActionsSchema.or(
export type SpaceActions = `${ActionPrefix.Space}|${z.infer<typeof spaceActionsSchema>}`;

export const baseActionsSchema = defaultActionsSchema.or(
z.enum(['invite_email', 'invite_link', 'table_import', 'table_export', 'authority_matrix_config'])
z.enum([
'invite_email',
'invite_link',
'table_import',
'table_export',
'authority_matrix_config',
'db_connection',
])
);

export type BaseActions = `${ActionPrefix.Base}|${z.infer<typeof baseActionsSchema>}`;
Expand Down Expand Up @@ -74,6 +81,8 @@ export const actionPrefixMap: ActionPrefixMap = {
'base|update',
'base|table_import',
'base|table_export',
'base|db_connection',
'base|authority_matrix_config',
],
[ActionPrefix.Table]: ['table|create', 'table|delete', 'table|read', 'table|update'],
[ActionPrefix.View]: ['view|create', 'view|delete', 'view|read', 'view|update'],
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/auth/role/base.role.ts
Expand Up @@ -41,6 +41,7 @@ export const basePermissions: Record<
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': true,
'base|db_connection': true,
'table|create': true,
'table|delete': true,
'table|read': true,
Expand Down Expand Up @@ -75,6 +76,7 @@ export const basePermissions: Record<
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': true,
'table|delete': true,
'table|read': true,
Expand Down Expand Up @@ -109,6 +111,7 @@ export const basePermissions: Record<
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|read': true,
'table|delete': false,
Expand Down Expand Up @@ -143,6 +146,7 @@ export const basePermissions: Record<
'base|table_import': false,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|delete': false,
'table|read': true,
Expand Down Expand Up @@ -177,6 +181,7 @@ export const basePermissions: Record<
'base|table_import': false,
'base|table_export': false,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|delete': false,
'table|read': true,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/auth/role/space.role.ts
Expand Up @@ -32,6 +32,7 @@ export const spacePermissions: Record<SpaceRole, Record<SpacePermission, boolean
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': true,
'base|db_connection': true,
'table|create': true,
'table|read': true,
'table|delete': true,
Expand Down Expand Up @@ -73,6 +74,7 @@ export const spacePermissions: Record<SpaceRole, Record<SpacePermission, boolean
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': true,
'table|read': true,
'table|delete': true,
Expand Down Expand Up @@ -114,6 +116,7 @@ export const spacePermissions: Record<SpaceRole, Record<SpacePermission, boolean
'base|table_import': true,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|read': true,
'table|delete': false,
Expand Down Expand Up @@ -155,6 +158,7 @@ export const spacePermissions: Record<SpaceRole, Record<SpacePermission, boolean
'base|table_import': false,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|read': true,
'table|delete': false,
Expand Down Expand Up @@ -196,6 +200,7 @@ export const spacePermissions: Record<SpaceRole, Record<SpacePermission, boolean
'base|table_import': false,
'base|table_export': true,
'base|authority_matrix_config': false,
'base|db_connection': false,
'table|create': false,
'table|read': true,
'table|delete': false,
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/hooks/use-permission-actions-static.ts
Expand Up @@ -59,6 +59,9 @@ const actionsI18nMap: Record<
'base|authority_matrix_config': {
description: 'permission.actionDescription.baseAuthorityMatrixConfig',
},
'base|db_connection': {
description: 'permission.actionDescription.baseDbConnect',
},
'table|create': {
description: 'permission.actionDescription.tableCreate',
},
Expand Down

0 comments on commit 5a9a0e7

Please sign in to comment.