0.0.12 • Published 2 years ago

@l1go/system-permission v0.0.12

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

修改config.ts

config.permission = {
  passport: true,
  override: false,
  mode: 'safe', // safe,
  roles: {
    guest: {
      can: ['LEVEL0']
    }
  }
}

config.orm = {
  type: 'mysql', // 数据库类型
  host: '127.0.0.1', // 数据库地址
  port: 3306, // 数据库端口号
  username: 'root', // 数据库用户名
  password: '111111', // 密码
  database: 'midway', // 数据库名
  synchronize: true,
}

修改configuration.ts

import * as systemPermission from '@l1go/system-permission'

@Configuration({
  imports: [
    systemPermission
  ],
  importConfigs: ["./config"],
})

this.app.use(await this.app.generateMiddleware('permissionMiddleware'));

this.manageService = await this.app.getApplicationContext().getAsync('PERMISSION:manageService')
await this.manageService.startScan()
await this.manageService.regist(1, 'get_/graphql', 'LEVEL0:*')
await this.manageService.regist(1, 'post_/graphql', 'LEVEL0:*')
await this.manageService.regist(1, 'get_/public/*', 'LEVEL0:*')

通知管理服务当前用户的权限,目前是以session为准

if (this.app.getAttr('PERMISSION')) {
  this.manageService = await this.app.getApplicationContext().getAsync('PERMISSION:manageService')
  await this.manageService.setUserRole(this.ctx, 'admin')
}