0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(schemas,cli): seed default scope for management api (#2869)

Co-authored-by: Gao Sun <gao@silverhand.io>
This commit is contained in:
wangsijie 2023-01-09 15:34:08 +08:00 committed by GitHub
parent 8f809da308
commit 385966625e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 2 deletions

View file

@ -10,6 +10,8 @@ import {
createDefaultSetting,
createDemoAppApplication,
defaultRole,
managementResourceScope,
defaultRoleScopeRelation,
} from '@logto/schemas';
import { Hooks } from '@logto/schemas/models';
import chalk from 'chalk';
@ -57,10 +59,12 @@ const createTables = async (connection: DatabaseTransactionConnection) => {
const seedTables = async (connection: DatabaseTransactionConnection, latestTimestamp: number) => {
await Promise.all([
connection.query(insertInto(managementResource, 'resources')),
connection.query(insertInto(managementResourceScope, 'scopes')),
connection.query(insertInto(createDefaultSetting(), 'settings')),
connection.query(insertInto(defaultSignInExperience, 'sign_in_experiences')),
connection.query(insertInto(createDemoAppApplication(generateStandardId()), 'applications')),
connection.query(insertInto(defaultRole, 'roles')),
connection.query(insertInto(defaultRoleScopeRelation, 'roles_scopes')),
updateDatabaseTimestamp(connection, latestTimestamp),
]);
};

View file

@ -3,3 +3,4 @@ export * from './resource.js';
export * from './setting.js';
export * from './sign-in-experience.js';
export * from './roles.js';
export * from './scope.js';

View file

@ -1,7 +1,9 @@
import type { CreateResource } from '../db-entries/index.js';
export const managementResourceId = 'management-api';
export const managementResource: Readonly<CreateResource> = Object.freeze({
id: 'management-api',
id: managementResourceId,
/**
* The fixed resource indicator for Management APIs.
*

View file

@ -1,5 +1,6 @@
import type { CreateRole } from '../db-entries/index.js';
import type { CreateRole, CreateRolesScope } from '../db-entries/index.js';
import { UserRole } from '../types/index.js';
import { managementResourceScopeId } from './scope.js';
export const adminConsoleAdminRoleId = 'ac-admin-id';
@ -11,3 +12,8 @@ export const defaultRole: Readonly<CreateRole> = {
name: UserRole.Admin,
description: 'Admin role for Logto.',
};
export const defaultRoleScopeRelation: Readonly<CreateRolesScope> = {
roleId: adminConsoleAdminRoleId,
scopeId: managementResourceScopeId,
};

View file

@ -0,0 +1,11 @@
import type { CreateScope } from '../db-entries/index.js';
import { managementResourceId } from './resource.js';
export const managementResourceScopeId = 'management-api-scope';
export const managementResourceScope: Readonly<CreateScope> = Object.freeze({
id: managementResourceScopeId,
name: 'default',
description: 'Default scope for management API',
resourceId: managementResourceId,
});